From 6aaa8c2f783cd1b3ac27c5ce40625d032e7e3d71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 19 Jul 2013 02:45:27 -0400 Subject: [PATCH] core: add %v specifier --- TODO | 4 +--- man/systemd.unit.xml | 10 ++++++++-- src/core/unit-printf.c | 4 +++- src/shared/install-printf.c | 4 +++- src/shared/specifier.c | 12 ++++++++++++ src/shared/specifier.h | 1 + 6 files changed, 28 insertions(+), 7 deletions(-) diff --git a/TODO b/TODO index 5de106e122..b086b933bb 100644 --- a/TODO +++ b/TODO @@ -60,7 +60,7 @@ Features: * given that logind/machined now let PID 1 do all nasty work we can probably reduce the capability set they retain substantially. -* btfs raid assembly: some .device jobs stay stuck in the queue +* btrfs raid assembly: some .device jobs stay stuck in the queue * Fedora: add an rpmlint check that verifies that all unit files in the RPM are listed in %systemd_post macros. @@ -80,8 +80,6 @@ Features: * journald: optionally, when messages with a high log priority are logged, sync() immediately. -* introduce %v resolving to the string returned by "uname -r" - * systemctl list-unit-files should list generated files (and probably with a new state "generated" for them, or so) * do we really need both hasprefix() and startswith()? diff --git a/man/systemd.unit.xml b/man/systemd.unit.xml index f45632a0e3..65ba545037 100644 --- a/man/systemd.unit.xml +++ b/man/systemd.unit.xml @@ -1175,7 +1175,7 @@ The following specifiers are interpreted in the - Install section: %n, %N, %p, %i, %U, %u, %m, %H, %b. + Install section: %n, %N, %p, %i, %U, %u, %m, %H, %b, %v. For their meaning see the next section. @@ -1293,6 +1293,11 @@ Host name The hostname of the running system. + + %v + Kernel release + Identical to uname -r output. + %% Escaped % @@ -1321,7 +1326,8 @@ systemd.snapshot5, systemd.time7, capabilities7, - systemd.directives7 + systemd.directives7, + uname1 diff --git a/src/core/unit-printf.c b/src/core/unit-printf.c index caf51259d2..ffc203dd92 100644 --- a/src/core/unit-printf.c +++ b/src/core/unit-printf.c @@ -268,6 +268,7 @@ char *unit_full_printf(Unit *u, const char *format) { * %m the machine ID of the running system * %H the host name of the running system * %b the boot ID of the running system + * %v `uname -r` of the running system */ const Specifier table[] = { @@ -291,7 +292,8 @@ char *unit_full_printf(Unit *u, const char *format) { { 'm', specifier_machine_id, NULL }, { 'H', specifier_host_name, NULL }, { 'b', specifier_boot_id, NULL }, - { 0, NULL, NULL } + { 'v', specifier_kernel_release, NULL }, + {} }; assert(format); diff --git a/src/shared/install-printf.c b/src/shared/install-printf.c index c44459b4e0..1157ea989b 100644 --- a/src/shared/install-printf.c +++ b/src/shared/install-printf.c @@ -108,6 +108,7 @@ char *install_full_printf(InstallInfo *i, const char *format) { * %m the machine ID of the running system * %H the host name of the running system * %b the boot ID of the running system + * %v `uname -r` of the running system */ const Specifier table[] = { @@ -122,7 +123,8 @@ char *install_full_printf(InstallInfo *i, const char *format) { { 'm', specifier_machine_id, NULL }, { 'H', specifier_host_name, NULL }, { 'b', specifier_boot_id, NULL }, - { 0, NULL, NULL } + { 'v', specifier_kernel_release, NULL }, + {} }; assert(i); diff --git a/src/shared/specifier.c b/src/shared/specifier.c index 7577c91052..bb8859fdfd 100644 --- a/src/shared/specifier.c +++ b/src/shared/specifier.c @@ -20,6 +20,7 @@ ***/ #include +#include #include "macro.h" #include "util.h" @@ -145,3 +146,14 @@ char *specifier_boot_id(char specifier, void *data, void *userdata) { char *specifier_host_name(char specifier, void *data, void *userdata) { return gethostname_malloc(); } + +char *specifier_kernel_release(char specifier, void *data, void *userdata) { + struct utsname uts; + int r; + + r = uname(&uts); + if (r < 0) + return NULL; + + return strdup(uts.release); +} diff --git a/src/shared/specifier.h b/src/shared/specifier.h index 0440dcac48..d13e6406b6 100644 --- a/src/shared/specifier.h +++ b/src/shared/specifier.h @@ -36,3 +36,4 @@ char *specifier_string(char specifier, void *data, void *userdata); char *specifier_machine_id(char specifier, void *data, void *userdata); char *specifier_boot_id(char specifier, void *data, void *userdata); char *specifier_host_name(char specifier, void *data, void *userdata); +char *specifier_kernel_release(char specifier, void *data, void *userdata);