From d2aaf130991149055f2f9b606d0b52d673d75cfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 19 Dec 2018 09:29:32 +0100 Subject: [PATCH 01/10] Remove use of PACKAGE_STRING PACKAGE_VERSION is more explicit, and also, we don't pretend that changing the project name in meson.build has any real effect. "systemd" is embedded in a thousand different places, so let's just use the hardcoded string consistently. This is mostly in preparation for future changes. --- meson.build | 1 - src/basic/util.c | 2 +- src/core/main.c | 4 ++-- src/journal-remote/journal-upload.c | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index 1608278fbb..88fe6a1615 100644 --- a/meson.build +++ b/meson.build @@ -20,7 +20,6 @@ libudev_version = '1.6.11' # names, sometimes. Not all variables are included in every # set. Ugh, ugh, ugh! conf = configuration_data() -conf.set_quoted('PACKAGE_STRING', meson.project_name() + ' ' + meson.project_version()) conf.set_quoted('PACKAGE_VERSION', meson.project_version()) substs = configuration_data() diff --git a/src/basic/util.c b/src/basic/util.c index c4f12a6daa..4d0c64f932 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -557,7 +557,7 @@ uint64_t system_tasks_max_scale(uint64_t v, uint64_t max) { } int version(void) { - puts(PACKAGE_STRING "\n" + puts("systemd " PACKAGE_VERSION "\n" SYSTEMD_FEATURES); return 0; } diff --git a/src/core/main.c b/src/core/main.c index 839dc062ff..0c2313fc19 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1914,7 +1914,7 @@ static void log_execution_mode(bool *ret_first_boot) { if (arg_system) { int v; - log_info(PACKAGE_STRING " running in %ssystem mode. (" SYSTEMD_FEATURES ")", + log_info("systemd " PACKAGE_VERSION " running in %ssystem mode. (" SYSTEMD_FEATURES ")", arg_action == ACTION_TEST ? "test " : "" ); v = detect_virtualization(); @@ -1942,7 +1942,7 @@ static void log_execution_mode(bool *ret_first_boot) { _cleanup_free_ char *t; t = uid_to_name(getuid()); - log_debug(PACKAGE_STRING " running in %suser mode for user " UID_FMT "/%s. (" SYSTEMD_FEATURES ")", + log_debug("systemd " PACKAGE_VERSION " running in %suser mode for user " UID_FMT "/%s. (" SYSTEMD_FEATURES ")", arg_action == ACTION_TEST ? " test" : "", getuid(), strna(t)); } diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c index 1e08fcc554..8d459235bf 100644 --- a/src/journal-remote/journal-upload.c +++ b/src/journal-remote/journal-upload.c @@ -236,7 +236,7 @@ int start_upload(Uploader *u, easy_setopt(curl, CURLOPT_VERBOSE, 1L, LOG_WARNING, ); easy_setopt(curl, CURLOPT_USERAGENT, - "systemd-journal-upload " PACKAGE_STRING, + "systemd-journal-upload " PACKAGE_VERSION, LOG_WARNING, ); if (arg_key || startswith(u->url, "https://")) { From a67c318df8800ba98d7361308937ed276dc73982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 19 Dec 2018 11:23:42 +0100 Subject: [PATCH 02/10] meson: define PROJECT_VERSION as the "bare" project version Let's not use atoi() if we can simply provide the project version as a number. In C code, this is the numerical project version. In substitutions in other files, this is just the bare substitution. The "PACKAGE_" prefix is from autotools, and is strange. We call systemd a "project", and "package" is something that distros build. Let's rename. PACKAGE_URL is renamed to PROJECT_URL for the same reasons and for consistency. (This leave PACKAGE_VERSION as the stringified define for C code.) --- meson.build | 5 +++-- src/core/systemd.pc.in | 4 ++-- src/libsystemd/libsystemd.pc.in | 4 ++-- src/libsystemd/sd-hwdb/hwdb-util.c | 2 +- src/libudev/libudev.pc.in | 2 +- src/test/test-path-util.c | 2 +- src/udev/udev.pc.in | 2 +- 7 files changed, 11 insertions(+), 10 deletions(-) diff --git a/meson.build b/meson.build index 88fe6a1615..7816ba9949 100644 --- a/meson.build +++ b/meson.build @@ -20,11 +20,12 @@ libudev_version = '1.6.11' # names, sometimes. Not all variables are included in every # set. Ugh, ugh, ugh! conf = configuration_data() +conf.set('PROJECT_VERSION', meson.project_version()) conf.set_quoted('PACKAGE_VERSION', meson.project_version()) substs = configuration_data() -substs.set('PACKAGE_URL', 'https://www.freedesktop.org/wiki/Software/systemd') -substs.set('PACKAGE_VERSION', meson.project_version()) +substs.set('PROJECT_URL', 'https://www.freedesktop.org/wiki/Software/systemd') +substs.set('PROJECT_VERSION', meson.project_version()) want_ossfuzz = get_option('oss-fuzz') want_libfuzzer = get_option('llvm-fuzz') diff --git a/src/core/systemd.pc.in b/src/core/systemd.pc.in index 655773ea8a..0dae950473 100644 --- a/src/core/systemd.pc.in +++ b/src/core/systemd.pc.in @@ -36,5 +36,5 @@ containeruidbasemax=@containeruidbasemax@ Name: systemd Description: systemd System and Service Manager -URL: @PACKAGE_URL@ -Version: @PACKAGE_VERSION@ +URL: @PROJECT_URL@ +Version: @PROJECT_VERSION@ diff --git a/src/libsystemd/libsystemd.pc.in b/src/libsystemd/libsystemd.pc.in index c861905b67..a010dea2e9 100644 --- a/src/libsystemd/libsystemd.pc.in +++ b/src/libsystemd/libsystemd.pc.in @@ -14,7 +14,7 @@ includedir=@includedir@ Name: systemd Description: systemd Library -URL: @PACKAGE_URL@ -Version: @PACKAGE_VERSION@ +URL: @PROJECT_URL@ +Version: @PROJECT_VERSION@ Libs: -L${libdir} -lsystemd Cflags: -I${includedir} diff --git a/src/libsystemd/sd-hwdb/hwdb-util.c b/src/libsystemd/sd-hwdb/hwdb-util.c index c5c329f2ac..f8529670b3 100644 --- a/src/libsystemd/sd-hwdb/hwdb-util.c +++ b/src/libsystemd/sd-hwdb/hwdb-util.c @@ -367,7 +367,7 @@ static int trie_store(struct trie *trie, const char *filename, bool compat) { int64_t size; struct trie_header_f h = { .signature = HWDB_SIG, - .tool_version = htole64(atoi(PACKAGE_VERSION)), + .tool_version = htole64(PROJECT_VERSION), .header_size = htole64(sizeof(struct trie_header_f)), .node_size = htole64(sizeof(struct trie_node_f)), .child_entry_size = htole64(sizeof(struct trie_child_entry_f)), diff --git a/src/libudev/libudev.pc.in b/src/libudev/libudev.pc.in index 69f5c6463e..40b340362e 100644 --- a/src/libudev/libudev.pc.in +++ b/src/libudev/libudev.pc.in @@ -14,6 +14,6 @@ includedir=@includedir@ Name: libudev Description: Library to access udev device information -Version: @PACKAGE_VERSION@ +Version: @PROJECT_VERSION@ Libs: -L${libdir} -ludev Cflags: -I${includedir} diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c index 8854a94f6c..c64ca7b016 100644 --- a/src/test/test-path-util.c +++ b/src/test/test-path-util.c @@ -531,7 +531,7 @@ static void test_hidden_or_backup_file(void) { static void test_systemd_installation_has_version(const char *path) { int r; - const unsigned versions[] = {0, 231, atoi(PACKAGE_VERSION), 999}; + const unsigned versions[] = {0, 231, PROJECT_VERSION, 999}; unsigned i; for (i = 0; i < ELEMENTSOF(versions); i++) { diff --git a/src/udev/udev.pc.in b/src/udev/udev.pc.in index e384a6f7c9..5acbb2d01a 100644 --- a/src/udev/udev.pc.in +++ b/src/udev/udev.pc.in @@ -1,5 +1,5 @@ Name: udev Description: udev -Version: @PACKAGE_VERSION@ +Version: @PROJECT_VERSION@ udevdir=@udevlibexecdir@ From b9da6a098b08d4eafec239fc05e0fd2073115504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 21 Dec 2018 13:36:26 +0100 Subject: [PATCH 03/10] udev: modernize ctrl_send and use PROJECT_VERSION MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PROJECT_VERSION is used in preparation for future changes. Let's simplify the code by using structured initialization. If the string written to .version ever became to long, the compiler will truncate it and tell us: ../src/udev/udev-ctrl.c: In function ‘ctrl_send’: ../src/udev/udev-ctrl.c:221:28: warning: initializer-string for array of chars is too long .version = "udev-" STRINGIFY(R_VERSION), ^~~~~~~ ../src/udev/udev-ctrl.c:221:28: note: (near initialization for ‘ctrl_msg_wire.version’) No functional change. --- src/udev/udev-ctrl.c | 50 +++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/src/udev/udev-ctrl.c b/src/udev/udev-ctrl.c index d90ebb7259..cb36c7e537 100644 --- a/src/udev/udev-ctrl.c +++ b/src/udev/udev-ctrl.c @@ -214,13 +214,11 @@ static struct udev_ctrl_connection *udev_ctrl_connection_free(struct udev_ctrl_c DEFINE_TRIVIAL_REF_UNREF_FUNC(struct udev_ctrl_connection, udev_ctrl_connection, udev_ctrl_connection_free); static int ctrl_send(struct udev_ctrl *uctrl, enum udev_ctrl_msg_type type, int intval, const char *buf, int timeout) { - struct udev_ctrl_msg_wire ctrl_msg_wire; - int err = 0; - - memzero(&ctrl_msg_wire, sizeof(struct udev_ctrl_msg_wire)); - strcpy(ctrl_msg_wire.version, "udev-" PACKAGE_VERSION); - ctrl_msg_wire.magic = UDEV_CTRL_MAGIC; - ctrl_msg_wire.type = type; + struct udev_ctrl_msg_wire ctrl_msg_wire = { + .version = "udev-" STRINGIFY(PROJECT_VERSION), + .magic = UDEV_CTRL_MAGIC, + .type = type, + }; if (buf) strscpy(ctrl_msg_wire.buf, sizeof(ctrl_msg_wire.buf), buf); @@ -228,43 +226,33 @@ static int ctrl_send(struct udev_ctrl *uctrl, enum udev_ctrl_msg_type type, int ctrl_msg_wire.intval = intval; if (!uctrl->connected) { - if (connect(uctrl->sock, &uctrl->saddr.sa, uctrl->addrlen) < 0) { - err = -errno; - goto out; - } + if (connect(uctrl->sock, &uctrl->saddr.sa, uctrl->addrlen) < 0) + return -errno; uctrl->connected = true; } - if (send(uctrl->sock, &ctrl_msg_wire, sizeof(ctrl_msg_wire), 0) < 0) { - err = -errno; - goto out; - } + if (send(uctrl->sock, &ctrl_msg_wire, sizeof(ctrl_msg_wire), 0) < 0) + return -errno; /* wait for peer message handling or disconnect */ for (;;) { - struct pollfd pfd[1]; + struct pollfd pfd = { + .fd = uctrl->sock, + .events = POLLIN, + }; int r; - pfd[0].fd = uctrl->sock; - pfd[0].events = POLLIN; - r = poll(pfd, 1, timeout * MSEC_PER_SEC); + r = poll(&pfd, 1, timeout * MSEC_PER_SEC); if (r < 0) { if (errno == EINTR) continue; - err = -errno; - break; + return -errno; } - - if (r > 0 && pfd[0].revents & POLLERR) { - err = -EIO; - break; - } - if (r == 0) - err = -ETIMEDOUT; - break; + return -ETIMEDOUT; + if (pfd.revents & POLLERR) + return -EIO; + return 0; } -out: - return err; } int udev_ctrl_send_set_log_level(struct udev_ctrl *uctrl, int priority, int timeout) { From 681bd2c524ed71ac04045c90884ba8d55eee7b66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 20 Dec 2018 20:35:25 +0100 Subject: [PATCH 04/10] meson: generate version tag from git $ build/systemctl --version systemd 239-3555-g6178cbb5b5 +PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 +IDN +PCRE2 default-hierarchy=hybrid $ git tag v240 -m 'v240' $ ninja -C build ninja: Entering directory `build' [76/76] Linking target fuzz-unit-file. $ build/systemctl --version systemd 240 +PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 +IDN +PCRE2 default-hierarchy=hybrid This is very useful during development, because a precise version string is embedded in the build product and displayed during boot, so we don't have to guess answers for questions like "did I just boot the latest version or the one from before?". This change creates an overhead for "noop" builds. On my laptop, 'ninja -C build' that does nothing goes from 0.1 to 0.5 s. It would be nice to avoid this, but I think that <1 s is still acceptable. Fixes #7183. PACKAGE_VERSION is renamed to GIT_VERSION, to make it obvious that this is the more dynamically changing version string. Why save to a file? It would be easy to generate the version tag using run_command(), but we want to go through a file so that stuff gets rebuilt when this file changes. If we just defined an variable in meson, ninja wouldn't know it needs to rebuild things. --- meson.build | 5 ++++- src/analyze/analyze.c | 3 ++- src/basic/build.h | 2 ++ src/basic/meson.build | 5 +++++ src/basic/util.c | 2 +- src/basic/version.h.in | 1 + src/boot/efi/boot.c | 8 ++++---- src/boot/efi/meson.build | 4 ++-- src/boot/efi/stub.c | 4 ++-- src/core/dbus-manager.c | 2 +- src/core/main.c | 4 ++-- src/import/curl-util.c | 3 ++- src/journal-remote/journal-upload.c | 3 ++- src/test/test-libudev.c | 3 ++- src/test/test-udev.c | 3 ++- src/udev/scsi_id/scsi_id.c | 3 ++- src/udev/udevadm.h | 4 +++- src/udev/udevd.c | 5 +++-- tools/meson-vcs-tag.sh | 9 +++++++++ 19 files changed, 51 insertions(+), 22 deletions(-) create mode 100644 src/basic/version.h.in create mode 100755 tools/meson-vcs-tag.sh diff --git a/meson.build b/meson.build index 7816ba9949..100265570d 100644 --- a/meson.build +++ b/meson.build @@ -21,7 +21,6 @@ libudev_version = '1.6.11' # set. Ugh, ugh, ugh! conf = configuration_data() conf.set('PROJECT_VERSION', meson.project_version()) -conf.set_quoted('PACKAGE_VERSION', meson.project_version()) substs = configuration_data() substs.set('PROJECT_URL', 'https://www.freedesktop.org/wiki/Software/systemd') @@ -584,6 +583,10 @@ endif ##################################################################### +vcs_tagger = [meson.source_root() + '/tools/meson-vcs-tag.sh', + '@0@/.git'.format(meson.source_root()), + meson.project_version()] + sed = find_program('sed') awk = find_program('awk') m4 = find_program('m4') diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index 1f69b9fda1..3915b66739 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -14,6 +14,7 @@ #include "alloc-util.h" #include "analyze-security.h" #include "analyze-verify.h" +#include "build.h" #include "bus-error.h" #include "bus-unit-util.h" #include "bus-util.h" @@ -696,7 +697,7 @@ static int analyze_plot(int argc, char *argv[], void *userdata) { "\n" "\n" "\n\n" - "\n\n", PACKAGE_VERSION); + "\n\n", GIT_VERSION); /* style sheet */ svg("\n