[systemd-commits] 8 commits - configure.ac Makefile.am src/core src/dbus1-generator src/initctl src/journal src/libsystemd src/libudev src/login src/machine src/network src/notify src/readahead src/run src/shared src/shutdownd src/systemctl src/test src/timedate src/udev src/update-utmp TODO
Zbigniew JÄdrzejewski-Szmek
zbyszek at kemper.freedesktop.org
Thu May 15 06:42:16 PDT 2014
Makefile.am | 13 +++
TODO | 2
configure.ac | 7 +
src/core/condition.c | 2
src/core/dbus-scope.c | 2
src/core/execute.c | 5 -
src/core/manager.c | 2
src/core/service.c | 5 -
src/core/socket.c | 6 -
src/core/swap.c | 6 -
src/core/unit-printf.c | 4 -
src/core/unit.c | 12 ++-
src/dbus1-generator/dbus1-generator.c | 2
src/initctl/initctl.c | 4 -
src/journal/journal-remote.c | 4 -
src/journal/journald-console.c | 8 +-
src/journal/journald-kmsg.c | 2
src/journal/journald-server.c | 26 +++---
src/journal/journald-syslog.c | 2
src/journal/journald.c | 4 -
src/journal/sd-journal.c | 2
src/libsystemd/sd-bus/bus-creds.c | 2
src/libsystemd/sd-bus/bus-dump.c | 26 +++---
src/libsystemd/sd-bus/bus-kernel.c | 6 -
src/libsystemd/sd-bus/bus-socket.c | 2
src/libsystemd/sd-bus/bus-util.c | 2
src/libsystemd/sd-bus/sd-bus.c | 4 -
src/libsystemd/sd-bus/test-bus-chat.c | 4 -
src/libsystemd/sd-bus/test-bus-marshal.c | 2
src/libsystemd/sd-login/sd-login.c | 6 -
src/libsystemd/sd-login/test-login.c | 10 +-
src/libudev/libudev-device-private.c | 2
src/libudev/libudev-device.c | 2
src/libudev/libudev-hwdb.c | 2
src/login/inhibit.c | 4 -
src/login/logind-action.c | 12 +--
src/login/logind-dbus.c | 18 ++--
src/login/logind-inhibit.c | 8 +-
src/login/logind-session.c | 4 -
src/login/logind-user-dbus.c | 2
src/login/logind-user.c | 10 +-
src/login/logind.c | 4 -
src/login/pam-module.c | 4 -
src/login/test-inhibit.c | 4 -
src/machine/machine.c | 4 -
src/machine/machined-dbus.c | 2
src/machine/machined.c | 4 -
src/network/networkd-link.c | 4 -
src/notify/notify.c | 2
src/readahead/readahead-common.c | 10 +-
src/readahead/test-ssd.c | 41 ++++++++++
src/run/run.c | 4 -
src/shared/ask-password-api.c | 8 +-
src/shared/cgroup-util.c | 2
src/shared/def.h | 2
src/shared/install.c | 119 ++++++++++++++++---------------
src/shared/log.c | 4 -
src/shared/logs-show.c | 30 +++----
src/shared/path-lookup.c | 12 +--
src/shared/path-lookup.h | 8 +-
src/shared/path-util.c | 49 +++++++++---
src/shared/socket-util.c | 2
src/shared/time-util.c | 50 ++++++-------
src/shared/util.c | 8 +-
src/shared/util.h | 16 ++++
src/shutdownd/shutdownd.c | 4 -
src/systemctl/systemctl.c | 21 ++---
src/test/test-cgroup-util.c | 6 -
src/test/test-log.c | 7 +
src/test/test-time.c | 4 -
src/test/test-util.c | 6 -
src/timedate/timedated.c | 2
src/udev/udev-builtin-blkid.c | 4 -
src/udev/udevadm-monitor.c | 4 -
src/update-utmp/update-utmp.c | 4 -
75 files changed, 410 insertions(+), 293 deletions(-)
New commits:
commit 574634bcacb01efe15ca2742effd461a5b7afb5f
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Tue May 13 23:22:13 2014 +0200
core: close socket fds asynchronously
http://lists.freedesktop.org/archives/systemd-devel/2014-April/018928.html
diff --git a/src/core/service.c b/src/core/service.c
index 1722330..70e7635 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -27,6 +27,7 @@
#include <linux/reboot.h>
#include <sys/syscall.h>
+#include "async.h"
#include "manager.h"
#include "unit.h"
#include "service.h"
@@ -222,7 +223,7 @@ static void service_close_socket_fd(Service *s) {
if (s->socket_fd < 0)
return;
- s->socket_fd = safe_close(s->socket_fd);
+ s->socket_fd = asynchronous_close(s->socket_fd);
}
static void service_connection_unref(Service *s) {
@@ -2712,7 +2713,7 @@ static int service_deserialize_item(Unit *u, const char *key, const char *value,
log_debug_unit(u->id, "Failed to parse socket-fd value %s", value);
else {
- safe_close(s->socket_fd);
+ asynchronous_close(s->socket_fd);
s->socket_fd = fdset_remove(fds, fd);
}
} else if (streq(key, "main-exec-status-pid")) {
commit 05cae7f3431446236139434ee58a6275f3cb31e8
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Thu Apr 24 17:23:38 2014 +0200
systemctl: small cleanup
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index b13b273..2fa8ecc 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -5009,11 +5009,11 @@ static int enable_sysv_units(const char *verb, char **args) {
r = 0;
for (f = 0; args[f]; f++) {
const char *name;
- _cleanup_free_ char *p = NULL, *q = NULL;
+ _cleanup_free_ char *p = NULL, *q = NULL, *l = NULL;
bool found_native = false, found_sysv;
unsigned c = 1;
const char *argv[6] = { "/sbin/chkconfig", NULL, NULL, NULL, NULL };
- char **k, *l;
+ char **k;
int j;
pid_t pid;
siginfo_t status;
@@ -5027,6 +5027,8 @@ static int enable_sysv_units(const char *verb, char **args) {
continue;
STRV_FOREACH(k, paths.unit_path) {
+ _cleanup_free_ char *path = NULL;
+
if (!isempty(arg_root))
asprintf(&p, "%s/%s/%s", arg_root, *k, name);
else
@@ -5038,9 +5040,6 @@ static int enable_sysv_units(const char *verb, char **args) {
}
found_native = access(p, F_OK) >= 0;
- free(p);
- p = NULL;
-
if (found_native)
break;
}
@@ -5057,9 +5056,8 @@ static int enable_sysv_units(const char *verb, char **args) {
goto finish;
}
- p[strlen(p) - sizeof(".service") + 1] = 0;
+ p[strlen(p) - strlen(".service")] = 0;
found_sysv = access(p, F_OK) >= 0;
-
if (!found_sysv)
continue;
@@ -5084,7 +5082,6 @@ static int enable_sysv_units(const char *verb, char **args) {
}
log_info("Executing %s", l);
- free(l);
pid = fork();
if (pid < 0) {
commit 058fb319964e739f3e5afa51ced3d1e25653a3f6
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Wed May 14 09:44:19 2014 -0400
readahead: add test to show fs_on_ssd() result
diff --git a/Makefile.am b/Makefile.am
index 89b1d4e..6379262 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3682,6 +3682,19 @@ nodist_systemunit_DATA += \
units/systemd-readahead-replay.service \
units/systemd-readahead-done.service
+manual_tests += \
+ test-ssd
+
+test_ssd_SOURCES = \
+ src/readahead/test-ssd.c \
+ src/readahead/readahead-common.c \
+ src/readahead/readahead-common.h
+
+test_ssd_LDADD = \
+ libsystemd-internal.la \
+ libudev-internal.la \
+ libsystemd-shared.la
+
endif
EXTRA_DIST += \
diff --git a/src/readahead/test-ssd.c b/src/readahead/test-ssd.c
new file mode 100644
index 0000000..808faf3
--- /dev/null
+++ b/src/readahead/test-ssd.c
@@ -0,0 +1,41 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright 2014 Zbigniew JÄdrzejewski-Szmek
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include "readahead-common.h"
+
+int main(int argc, char *argv[]) {
+ int i;
+
+ for (i = 1; i < argc; i++) {
+ char *name = argv[i];
+ int r;
+
+ r = fs_on_ssd(name);
+ if (r < 0) {
+ log_error("%s: %s", name, strerror(-r));
+ return EXIT_FAILURE;
+ }
+
+ log_info("%s: %s", name, r ? "SSD" : "---");
+ }
+
+ return EXIT_SUCCESS;
+}
commit 5ea846cc5197682d07ee46398996a8c3ccfbcc38
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Sun May 11 08:34:26 2014 -0400
networkd, build-sys: spelling fix
diff --git a/configure.ac b/configure.ac
index c3653e3..336938e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -843,7 +843,7 @@ AC_SUBST(NTP_SERVERS)
AC_ARG_WITH(time-epoch,
AS_HELP_STRING([--with-time-epoch=SECONDS],
- [TIme epoch for time clients]),
+ [Time epoch for time clients]),
[TIME_EPOCH="$withval"],
[TIME_EPOCH="`stat -c %Y ${srcdir}/NEWS 2>/dev/null || echo 0`"])
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 37a572d..6ce965b 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -1710,12 +1710,12 @@ int link_rtnl_process_address(sd_rtnl *rtnl, sd_rtnl_message *message, void *use
r = sd_rtnl_message_addr_get_ifindex(message, &ifindex);
if (r < 0 || ifindex <= 0) {
- log_warning("rtnl: received address message without valid ifindix, ignoring");
+ log_warning("rtnl: received address message without valid ifindex, ignoring");
return 0;
} else {
r = link_get(m, ifindex, &link);
if (r < 0 || !link) {
- log_warning("rtnl: received address for non-existing link, ignoring");
+ log_warning("rtnl: received address for a nonexistent link, ignoring");
return 0;
}
}
commit 4e595329a93ed190795c2e24bf132d5028ec6a72
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Thu Apr 17 22:12:25 2014 -0400
Make sure that keys are properly removed from hashmap
This is a speculative fix for https://bugzilla.redhat.com/show_bug.cgi?id=1088865.
Even though I cannot find a code path that where this would be
an issue, for consistency, if we assume that cgroup_path might have
been set before we got to unit_deserialize, we should make sure that
the unit is removed from the hashmap before we free the key. This seems
to be the only place where the key could be prematurely freed, leading to
hashmap corruption.
diff --git a/src/core/unit.c b/src/core/unit.c
index 6ac359e..c4ed923 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -2488,10 +2488,18 @@ int unit_deserialize(Unit *u, FILE *f, FDSet *fds) {
if (!s)
return -ENOMEM;
- free(u->cgroup_path);
- u->cgroup_path = s;
+ if (u->cgroup_path) {
+ void *p;
+
+ p = hashmap_remove(u->manager->cgroup_unit, u->cgroup_path);
+ log_info("Removing cgroup_path %s from hashmap (%p)",
+ u->cgroup_path, p);
+ free(u->cgroup_path);
+ }
+ u->cgroup_path = s;
assert(hashmap_put(u->manager->cgroup_unit, s, u) == 1);
+
continue;
}
commit de0671ee7fe465e108f62dcbbbe9366f81dd9e9a
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Fri Apr 25 07:45:15 2014 -0400
Remove unnecessary casts in printfs
No functional change expected :)
diff --git a/configure.ac b/configure.ac
index 972fc2f..c3653e3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -199,6 +199,11 @@ AC_SUBST([OUR_LDFLAGS], "$with_ldflags $sanitizer_ldflags")
AC_CHECK_SIZEOF(pid_t)
AC_CHECK_SIZEOF(uid_t)
AC_CHECK_SIZEOF(gid_t)
+AC_CHECK_SIZEOF(time_t)
+AC_CHECK_SIZEOF(rlim_t,,[
+ #include <sys/time.h>
+ #include <sys/resource.h>
+])
# ------------------------------------------------------------------------------
# we use python to build the man page index, and for systemd-python
diff --git a/src/core/condition.c b/src/core/condition.c
index 1448fa1..2468458 100644
--- a/src/core/condition.c
+++ b/src/core/condition.c
@@ -59,7 +59,7 @@ static bool condition_test_capability(Condition *c) {
cap_value_t value;
FILE *f;
char line[LINE_MAX];
- unsigned long long capabilities = (unsigned long long) -1;
+ unsigned long long capabilities = -1;
assert(c);
assert(c->parameter);
diff --git a/src/core/dbus-scope.c b/src/core/dbus-scope.c
index b9e3be4..fbb4ff5 100644
--- a/src/core/dbus-scope.c
+++ b/src/core/dbus-scope.c
@@ -138,7 +138,7 @@ static int bus_scope_set_transient_property(
if (r < 0)
return r;
- unit_write_drop_in_format(UNIT(s), mode, name, "[Scope]\nTimeoutStopSec=%lluus\n", (unsigned long long) s->timeout_stop_usec);
+ unit_write_drop_in_format(UNIT(s), mode, name, "[Scope]\nTimeoutStopSec="USEC_FMT"us\n", s->timeout_stop_usec);
} else {
r = sd_bus_message_skip(message, "t");
if (r < 0)
diff --git a/src/core/execute.c b/src/core/execute.c
index 4a3aeda..af8e7c7 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -1173,7 +1173,7 @@ static int build_environment(
return -ENOMEM;
our_env[n_env++] = x;
- if (asprintf(&x, "WATCHDOG_USEC=%llu", (unsigned long long) watchdog_usec) < 0)
+ if (asprintf(&x, "WATCHDOG_USEC="USEC_FMT, watchdog_usec) < 0)
return -ENOMEM;
our_env[n_env++] = x;
}
@@ -2139,7 +2139,8 @@ void exec_context_dump(ExecContext *c, FILE* f, const char *prefix) {
for (i = 0; i < RLIM_NLIMITS; i++)
if (c->rlimit[i])
- fprintf(f, "%s%s: %llu\n", prefix, rlimit_to_string(i), (unsigned long long) c->rlimit[i]->rlim_max);
+ fprintf(f, "%s%s: "RLIM_FMT"\n",
+ prefix, rlimit_to_string(i), c->rlimit[i]->rlim_max);
if (c->ioprio_set) {
_cleanup_free_ char *class_str = NULL;
diff --git a/src/core/socket.c b/src/core/socket.c
index 536904f..05af8fe 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -470,8 +470,8 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) {
if (s->control_pid > 0)
fprintf(f,
- "%sControl PID: %lu\n",
- prefix, (unsigned long) s->control_pid);
+ "%sControl PID: "PID_FMT"\n",
+ prefix, s->control_pid);
if (s->bind_to_device)
fprintf(f,
@@ -1710,7 +1710,7 @@ static int socket_serialize(Unit *u, FILE *f, FDSet *fds) {
unit_serialize_item_format(u, f, "n-accepted", "%u", s->n_accepted);
if (s->control_pid > 0)
- unit_serialize_item_format(u, f, "control-pid", "%lu", (unsigned long) s->control_pid);
+ unit_serialize_item_format(u, f, "control-pid", PID_FMT, s->control_pid);
if (s->control_command_id >= 0)
unit_serialize_item(u, f, "control-command", socket_exec_command_to_string(s->control_command_id));
diff --git a/src/core/swap.c b/src/core/swap.c
index 10eed6d..9f353af 100644
--- a/src/core/swap.c
+++ b/src/core/swap.c
@@ -609,8 +609,8 @@ static void swap_dump(Unit *u, FILE *f, const char *prefix) {
if (s->control_pid > 0)
fprintf(f,
- "%sControl PID: %lu\n",
- prefix, (unsigned long) s->control_pid);
+ "%sControl PID: "PID_FMT"\n",
+ prefix, s->control_pid);
exec_context_dump(&s->exec_context, f, prefix);
kill_context_dump(&s->kill_context, f, prefix);
@@ -878,7 +878,7 @@ static int swap_serialize(Unit *u, FILE *f, FDSet *fds) {
unit_serialize_item(u, f, "result", swap_result_to_string(s->result));
if (s->control_pid > 0)
- unit_serialize_item_format(u, f, "control-pid", "%lu", (unsigned long) s->control_pid);
+ unit_serialize_item_format(u, f, "control-pid", PID_FMT, s->control_pid);
if (s->control_command_id >= 0)
unit_serialize_item(u, f, "control-command", swap_exec_command_to_string(s->control_command_id));
diff --git a/src/core/unit-printf.c b/src/core/unit-printf.c
index d16d856..5bd30f0 100644
--- a/src/core/unit-printf.c
+++ b/src/core/unit-printf.c
@@ -208,7 +208,7 @@ static int specifier_user_name(char specifier, void *data, void *userdata, char
if (r < 0)
return -ENODATA;
- asprintf(&printed, "%lu", (unsigned long) uid);
+ asprintf(&printed, UID_FMT, uid);
}
}
@@ -231,7 +231,7 @@ static int specifier_user_name(char specifier, void *data, void *userdata, char
if (specifier == 'u')
printed = strdup(username);
else
- asprintf(&printed, "%lu", (unsigned long) uid);
+ asprintf(&printed, UID_FMT, uid);
}
if (!printed)
diff --git a/src/dbus1-generator/dbus1-generator.c b/src/dbus1-generator/dbus1-generator.c
index b3dedb7..95962c7 100644
--- a/src/dbus1-generator/dbus1-generator.c
+++ b/src/dbus1-generator/dbus1-generator.c
@@ -96,7 +96,7 @@ static int create_dbus_files(
}
fprintf(f, "Environment=DBUS_STARTER_ADDRESS="KERNEL_USER_BUS_FMT ";" UNIX_USER_BUS_FMT "\n",
- (unsigned long) getuid(), run);
+ getuid(), run);
}
}
diff --git a/src/initctl/initctl.c b/src/initctl/initctl.c
index f9613ea..f9a6ed4 100644
--- a/src/initctl/initctl.c
+++ b/src/initctl/initctl.c
@@ -396,7 +396,7 @@ int main(int argc, char *argv[]) {
if (server_init(&server, (unsigned) n) < 0)
return EXIT_FAILURE;
- log_debug("systemd-initctl running as pid %lu", (unsigned long) getpid());
+ log_debug("systemd-initctl running as pid "PID_FMT, getpid());
sd_notify(false,
"READY=1\n"
@@ -426,7 +426,7 @@ int main(int argc, char *argv[]) {
r = EXIT_SUCCESS;
- log_debug("systemd-initctl stopped as pid %lu", (unsigned long) getpid());
+ log_debug("systemd-initctl stopped as pid "PID_FMT, getpid());
fail:
sd_notify(false,
diff --git a/src/journal/journal-remote.c b/src/journal/journal-remote.c
index ec4054f..9adad7a 100644
--- a/src/journal/journal-remote.c
+++ b/src/journal/journal-remote.c
@@ -1210,8 +1210,8 @@ int main(int argc, char **argv) {
if (remoteserver_init(&s) < 0)
return EXIT_FAILURE;
- log_debug("%s running as pid %lu",
- program_invocation_short_name, (unsigned long) getpid());
+ log_debug("%s running as pid "PID_FMT,
+ program_invocation_short_name, getpid());
sd_notify(false,
"READY=1\n"
"STATUS=Processing requests...");
diff --git a/src/journal/journald-console.c b/src/journal/journald-console.c
index 3db5fc5..6ec2528 100644
--- a/src/journal/journald-console.c
+++ b/src/journal/journald-console.c
@@ -67,9 +67,9 @@ void server_forward_console(
/* First: timestamp */
if (prefix_timestamp()) {
assert_se(clock_gettime(CLOCK_MONOTONIC, &ts) == 0);
- snprintf(tbuf, sizeof(tbuf), "[%5llu.%06llu] ",
- (unsigned long long) ts.tv_sec,
- (unsigned long long) ts.tv_nsec / 1000);
+ snprintf(tbuf, sizeof(tbuf), "[%5"PRI_TIME".%06ld] ",
+ ts.tv_sec,
+ ts.tv_nsec / 1000);
IOVEC_SET_STRING(iovec[n++], tbuf);
}
@@ -80,7 +80,7 @@ void server_forward_console(
identifier = ident_buf;
}
- snprintf(header_pid, sizeof(header_pid), "[%lu]: ", (unsigned long) ucred->pid);
+ snprintf(header_pid, sizeof(header_pid), "["PID_FMT"]: ", ucred->pid);
char_array_0(header_pid);
if (identifier)
diff --git a/src/journal/journald-kmsg.c b/src/journal/journald-kmsg.c
index 35948ea..12992e7 100644
--- a/src/journal/journald-kmsg.c
+++ b/src/journal/journald-kmsg.c
@@ -71,7 +71,7 @@ void server_forward_kmsg(
identifier = ident_buf;
}
- snprintf(header_pid, sizeof(header_pid), "[%lu]: ", (unsigned long) ucred->pid);
+ snprintf(header_pid, sizeof(header_pid), "["PID_FMT"]: ", ucred->pid);
char_array_0(header_pid);
if (identifier)
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index 6da81e7..0439caf 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -269,8 +269,8 @@ static JournalFile* find_journal(Server *s, uid_t uid) {
if (f)
return f;
- if (asprintf(&p, "/var/log/journal/" SD_ID128_FORMAT_STR "/user-%lu.journal",
- SD_ID128_FORMAT_VAL(machine), (unsigned long) uid) < 0)
+ if (asprintf(&p, "/var/log/journal/" SD_ID128_FORMAT_STR "/user-"UID_FMT".journal",
+ SD_ID128_FORMAT_VAL(machine), uid) < 0)
return s->system_journal;
while (hashmap_size(s->user_journals) >= USER_JOURNALS_MAX) {
@@ -576,13 +576,13 @@ static void dispatch_message_real(
if (ucred) {
realuid = ucred->uid;
- sprintf(pid, "_PID=%lu", (unsigned long) ucred->pid);
+ sprintf(pid, "_PID="PID_FMT, ucred->pid);
IOVEC_SET_STRING(iovec[n++], pid);
- sprintf(uid, "_UID=%lu", (unsigned long) ucred->uid);
+ sprintf(uid, "_UID="UID_FMT, ucred->uid);
IOVEC_SET_STRING(iovec[n++], uid);
- sprintf(gid, "_GID=%lu", (unsigned long) ucred->gid);
+ sprintf(gid, "_GID="GID_FMT, ucred->gid);
IOVEC_SET_STRING(iovec[n++], gid);
r = get_process_comm(ucred->pid, &t);
@@ -616,13 +616,13 @@ static void dispatch_message_real(
#ifdef HAVE_AUDIT
r = audit_session_from_pid(ucred->pid, &audit);
if (r >= 0) {
- sprintf(audit_session, "_AUDIT_SESSION=%lu", (unsigned long) audit);
+ sprintf(audit_session, "_AUDIT_SESSION=%"PRIu32, audit);
IOVEC_SET_STRING(iovec[n++], audit_session);
}
r = audit_loginuid_from_pid(ucred->pid, &loginuid);
if (r >= 0) {
- sprintf(audit_loginuid, "_AUDIT_LOGINUID=%lu", (unsigned long) loginuid);
+ sprintf(audit_loginuid, "_AUDIT_LOGINUID="UID_FMT, loginuid);
IOVEC_SET_STRING(iovec[n++], audit_loginuid);
}
#endif
@@ -644,7 +644,7 @@ static void dispatch_message_real(
if (cg_path_get_owner_uid(c, &owner) >= 0) {
owner_valid = true;
- sprintf(owner_uid, "_SYSTEMD_OWNER_UID=%lu", (unsigned long) owner);
+ sprintf(owner_uid, "_SYSTEMD_OWNER_UID="UID_FMT, owner);
IOVEC_SET_STRING(iovec[n++], owner_uid);
}
@@ -703,13 +703,13 @@ static void dispatch_message_real(
if (object_pid) {
r = get_process_uid(object_pid, &object_uid);
if (r >= 0) {
- sprintf(o_uid, "OBJECT_UID=%lu", (unsigned long) object_uid);
+ sprintf(o_uid, "OBJECT_UID="UID_FMT, object_uid);
IOVEC_SET_STRING(iovec[n++], o_uid);
}
r = get_process_gid(object_pid, &object_gid);
if (r >= 0) {
- sprintf(o_gid, "OBJECT_GID=%lu", (unsigned long) object_gid);
+ sprintf(o_gid, "OBJECT_GID="GID_FMT, object_gid);
IOVEC_SET_STRING(iovec[n++], o_gid);
}
@@ -737,13 +737,13 @@ static void dispatch_message_real(
#ifdef HAVE_AUDIT
r = audit_session_from_pid(object_pid, &audit);
if (r >= 0) {
- sprintf(o_audit_session, "OBJECT_AUDIT_SESSION=%lu", (unsigned long) audit);
+ sprintf(o_audit_session, "OBJECT_AUDIT_SESSION=%"PRIu32, audit);
IOVEC_SET_STRING(iovec[n++], o_audit_session);
}
r = audit_loginuid_from_pid(object_pid, &loginuid);
if (r >= 0) {
- sprintf(o_audit_loginuid, "OBJECT_AUDIT_LOGINUID=%lu", (unsigned long) loginuid);
+ sprintf(o_audit_loginuid, "OBJECT_AUDIT_LOGINUID="UID_FMT, loginuid);
IOVEC_SET_STRING(iovec[n++], o_audit_loginuid);
}
#endif
@@ -761,7 +761,7 @@ static void dispatch_message_real(
}
if (cg_path_get_owner_uid(c, &owner) >= 0) {
- sprintf(o_owner_uid, "OBJECT_SYSTEMD_OWNER_UID=%lu", (unsigned long) owner);
+ sprintf(o_owner_uid, "OBJECT_SYSTEMD_OWNER_UID="UID_FMT, owner);
IOVEC_SET_STRING(iovec[n++], o_owner_uid);
}
diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c
index fee7d91..434eac4 100644
--- a/src/journal/journald-syslog.c
+++ b/src/journal/journald-syslog.c
@@ -159,7 +159,7 @@ void server_forward_syslog(Server *s, int priority, const char *identifier, cons
identifier = ident_buf;
}
- snprintf(header_pid, sizeof(header_pid), "[%lu]: ", (unsigned long) ucred->pid);
+ snprintf(header_pid, sizeof(header_pid), "["PID_FMT"]: ", ucred->pid);
char_array_0(header_pid);
if (identifier)
diff --git a/src/journal/journald.c b/src/journal/journald.c
index 7665009..886ac92 100644
--- a/src/journal/journald.c
+++ b/src/journal/journald.c
@@ -57,7 +57,7 @@ int main(int argc, char *argv[]) {
server_flush_to_var(&server);
server_flush_dev_kmsg(&server);
- log_debug("systemd-journald running as pid %lu", (unsigned long) getpid());
+ log_debug("systemd-journald running as pid "PID_FMT, getpid());
server_driver_message(&server, SD_MESSAGE_JOURNAL_START, "Journal started");
sd_notify(false,
@@ -112,7 +112,7 @@ int main(int argc, char *argv[]) {
server_maybe_warn_forward_syslog_missed(&server);
}
- log_debug("systemd-journald stopped as pid %lu", (unsigned long) getpid());
+ log_debug("systemd-journald stopped as pid "PID_FMT, getpid());
server_driver_message(&server, SD_MESSAGE_JOURNAL_STOP, "Journal stopped");
finish:
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index 7587211..11de8ef 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -1273,7 +1273,7 @@ static bool file_type_wanted(int flags, const char *filename) {
if (flags & SD_JOURNAL_CURRENT_USER) {
char prefix[5 + DECIMAL_STR_MAX(uid_t) + 1];
- assert_se(snprintf(prefix, sizeof(prefix), "user-%lu", (unsigned long) getuid())
+ assert_se(snprintf(prefix, sizeof(prefix), "user-"UID_FMT, getuid())
< (int) sizeof(prefix));
if (file_has_type_prefix(prefix, filename))
diff --git a/src/libsystemd/sd-bus/bus-creds.c b/src/libsystemd/sd-bus/bus-creds.c
index 3da77cf..26c2545 100644
--- a/src/libsystemd/sd-bus/bus-creds.c
+++ b/src/libsystemd/sd-bus/bus-creds.c
@@ -749,7 +749,7 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) {
if (tid > 0 && (missing & SD_BUS_CREDS_TID_COMM)) {
_cleanup_free_ char *p = NULL;
- if (asprintf(&p, "/proc/%lu/task/%lu/comm", (unsigned long) pid, (unsigned long) tid) < 0)
+ if (asprintf(&p, "/proc/"PID_FMT"/task/"PID_FMT"/comm", pid, tid) < 0)
return -ENOMEM;
r = read_one_line_file(p, &c->tid_comm);
diff --git a/src/libsystemd/sd-bus/bus-dump.c b/src/libsystemd/sd-bus/bus-dump.c
index 6f4ce0c..8b70b20 100644
--- a/src/libsystemd/sd-bus/bus-dump.c
+++ b/src/libsystemd/sd-bus/bus-dump.c
@@ -98,11 +98,11 @@ int bus_message_dump(sd_bus_message *m, FILE *f, bool with_header) {
ansi_highlight_red(), strna(m->error.message), ansi_highlight_off());
if (m->monotonic != 0)
- fprintf(f, " Monotonic=%llu", (unsigned long long) m->monotonic);
+ fprintf(f, " Monotonic="USEC_FMT, m->monotonic);
if (m->realtime != 0)
- fprintf(f, " Realtime=%llu", (unsigned long long) m->realtime);
+ fprintf(f, " Realtime="USEC_FMT, m->realtime);
if (m->seqnum != 0)
- fprintf(f, " SequenceNumber=%llu", (unsigned long long) m->seqnum);
+ fprintf(f, " SequenceNumber=%"PRIu64, m->seqnum);
if (m->monotonic != 0 || m->realtime != 0 || m->seqnum != 0)
fputs("\n", f);
@@ -221,11 +221,11 @@ int bus_message_dump(sd_bus_message *m, FILE *f, bool with_header) {
break;
case SD_BUS_TYPE_INT64:
- fprintf(f, "%sINT64 %s%lli%s;\n", prefix, ansi_highlight(), (long long) basic.s64, ansi_highlight_off());
+ fprintf(f, "%sINT64 %s%"PRIi64"%s;\n", prefix, ansi_highlight(), basic.s64, ansi_highlight_off());
break;
case SD_BUS_TYPE_UINT64:
- fprintf(f, "%sUINT64 %s%llu%s;\n", prefix, ansi_highlight(), (unsigned long long) basic.u64, ansi_highlight_off());
+ fprintf(f, "%sUINT64 %s%"PRIu64"%s;\n", prefix, ansi_highlight(), basic.u64, ansi_highlight_off());
break;
case SD_BUS_TYPE_DOUBLE:
@@ -319,18 +319,18 @@ int bus_creds_dump(sd_bus_creds *c, FILE *f) {
f = stdout;
if (c->mask & SD_BUS_CREDS_PID)
- fprintf(f, " PID=%lu", (unsigned long) c->pid);
+ fprintf(f, " PID="PID_FMT, c->pid);
if (c->mask & SD_BUS_CREDS_PID_STARTTIME)
- fprintf(f, " PIDStartTime=%llu", (unsigned long long) c->pid_starttime);
+ fprintf(f, " PIDStartTime="USEC_FMT, c->pid_starttime);
if (c->mask & SD_BUS_CREDS_TID)
- fprintf(f, " TID=%lu", (unsigned long) c->tid);
+ fprintf(f, " TID="PID_FMT, c->tid);
if (c->mask & SD_BUS_CREDS_UID)
- fprintf(f, " UID=%lu", (unsigned long) c->uid);
+ fprintf(f, " UID="UID_FMT, c->uid);
r = sd_bus_creds_get_owner_uid(c, &owner);
if (r >= 0)
- fprintf(f, " OwnerUID=%lu", (unsigned long) owner);
+ fprintf(f, " OwnerUID="UID_FMT, owner);
if (c->mask & SD_BUS_CREDS_GID)
- fprintf(f, " GID=%lu", (unsigned long) c->gid);
+ fprintf(f, " GID="GID_FMT, c->gid);
if ((c->mask & (SD_BUS_CREDS_PID|SD_BUS_CREDS_PID_STARTTIME|SD_BUS_CREDS_TID|SD_BUS_CREDS_UID|SD_BUS_CREDS_GID)) || r >= 0)
fputs("\n", f);
@@ -387,11 +387,11 @@ int bus_creds_dump(sd_bus_creds *c, FILE *f) {
if (sd_bus_creds_get_audit_login_uid(c, &audit_loginuid) >= 0) {
audit_loginuid_is_set = true;
- fprintf(f, " AuditLoginUID=%lu", (unsigned long) audit_loginuid);
+ fprintf(f, " AuditLoginUID="UID_FMT, audit_loginuid);
}
if (sd_bus_creds_get_audit_session_id(c, &audit_sessionid) >= 0) {
audit_sessionid_is_set = true;
- fprintf(f, " AuditSessionID=%lu", (unsigned long) audit_sessionid);
+ fprintf(f, " AuditSessionID=%"PRIu32, audit_sessionid);
}
if (audit_loginuid_is_set || audit_sessionid_is_set)
diff --git a/src/libsystemd/sd-bus/bus-kernel.c b/src/libsystemd/sd-bus/bus-kernel.c
index af42b9f..8bab6ad 100644
--- a/src/libsystemd/sd-bus/bus-kernel.c
+++ b/src/libsystemd/sd-bus/bus-kernel.c
@@ -1305,7 +1305,7 @@ int bus_kernel_create_bus(const char *name, bool world, char **s) {
make->size += ALIGN8(n->size);
n = KDBUS_ITEM_NEXT(n);
- sprintf(n->str, "%lu-%s", (unsigned long) getuid(), name);
+ sprintf(n->str, UID_FMT"-%s", getuid(), name);
n->size = offsetof(struct kdbus_item, str) + strlen(n->str) + 1;
n->type = KDBUS_ITEM_MAKE_NAME;
make->size += ALIGN8(n->size);
@@ -1396,7 +1396,7 @@ int bus_kernel_create_starter(const char *bus, const char *name, bool activating
assert(name);
p = alloca(strlen("/dev/kdbus/") + DECIMAL_STR_MAX(uid_t) + 1 + strlen(bus) + strlen("/bus") + 1);
- sprintf(p, "/dev/kdbus/%lu-%s/bus", (unsigned long) getuid(), bus);
+ sprintf(p, "/dev/kdbus/"UID_FMT"-%s/bus", getuid(), bus);
fd = open(p, O_RDWR|O_NOCTTY|O_CLOEXEC);
if (fd < 0)
@@ -1511,7 +1511,7 @@ int bus_kernel_create_monitor(const char *bus) {
assert(bus);
p = alloca(strlen("/dev/kdbus/") + DECIMAL_STR_MAX(uid_t) + 1 + strlen(bus) + strlen("/bus") + 1);
- sprintf(p, "/dev/kdbus/%lu-%s/bus", (unsigned long) getuid(), bus);
+ sprintf(p, "/dev/kdbus/"UID_FMT"-%s/bus", getuid(), bus);
fd = open(p, O_RDWR|O_NOCTTY|O_CLOEXEC);
if (fd < 0)
diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c
index 2e8f008..d124d9a 100644
--- a/src/libsystemd/sd-bus/bus-socket.c
+++ b/src/libsystemd/sd-bus/bus-socket.c
@@ -648,7 +648,7 @@ static int bus_socket_start_auth_client(sd_bus *b) {
auth_prefix = "\0AUTH EXTERNAL ";
- snprintf(text, sizeof(text), "%lu", (unsigned long) geteuid());
+ snprintf(text, sizeof(text), UID_FMT, geteuid());
char_array_0(text);
l = strlen(text);
diff --git a/src/libsystemd/sd-bus/bus-util.c b/src/libsystemd/sd-bus/bus-util.c
index b5b3c85..6220934 100644
--- a/src/libsystemd/sd-bus/bus-util.c
+++ b/src/libsystemd/sd-bus/bus-util.c
@@ -537,7 +537,7 @@ int bus_open_user_systemd(sd_bus **_bus) {
if (r < 0)
return r;
- if (asprintf(&bus->address, KERNEL_USER_BUS_FMT, (unsigned long) getuid()) < 0)
+ if (asprintf(&bus->address, KERNEL_USER_BUS_FMT, getuid()) < 0)
return -ENOMEM;
bus->bus_client = true;
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
index ea80e9d..de947bf 100644
--- a/src/libsystemd/sd-bus/sd-bus.c
+++ b/src/libsystemd/sd-bus/sd-bus.c
@@ -1162,13 +1162,13 @@ int bus_set_address_user(sd_bus *b) {
return -ENOMEM;
#ifdef ENABLE_KDBUS
- asprintf(&b->address, KERNEL_USER_BUS_FMT ";" UNIX_USER_BUS_FMT, (unsigned long) getuid(), ee);
+ asprintf(&b->address, KERNEL_USER_BUS_FMT ";" UNIX_USER_BUS_FMT, getuid(), ee);
#else
asprintf(&b->address, UNIX_USER_BUS_FMT, ee);
#endif
} else {
#ifdef ENABLE_KDBUS
- asprintf(&b->address, KERNEL_USER_BUS_FMT, (unsigned long) getuid());
+ asprintf(&b->address, KERNEL_USER_BUS_FMT, getuid());
#else
return -ECONNREFUSED;
#endif
diff --git a/src/libsystemd/sd-bus/test-bus-chat.c b/src/libsystemd/sd-bus/test-bus-chat.c
index c9eb698..d5903f4 100644
--- a/src/libsystemd/sd-bus/test-bus-chat.c
+++ b/src/libsystemd/sd-bus/test-bus-chat.c
@@ -160,9 +160,9 @@ static int server(sd_bus *bus) {
sd_bus_creds_get_pid(sd_bus_message_get_creds(m), &pid);
sd_bus_creds_get_selinux_context(sd_bus_message_get_creds(m), &label);
- log_info("Got message! member=%s pid=%lu label=%s",
+ log_info("Got message! member=%s pid="PID_FMT" label=%s",
strna(sd_bus_message_get_member(m)),
- (unsigned long) pid,
+ pid,
strna(label));
/* bus_message_dump(m); */
/* sd_bus_message_rewind(m, true); */
diff --git a/src/libsystemd/sd-bus/test-bus-marshal.c b/src/libsystemd/sd-bus/test-bus-marshal.c
index 2321873..2be4de5 100644
--- a/src/libsystemd/sd-bus/test-bus-marshal.c
+++ b/src/libsystemd/sd-bus/test-bus-marshal.c
@@ -156,7 +156,7 @@ int main(int argc, char *argv[]) {
h = hexmem(buffer, sz);
assert_se(h);
- log_info("message size = %lu, contents =\n%s", (unsigned long) sz, h);
+ log_info("message size = %zu, contents =\n%s", sz, h);
free(h);
#ifdef HAVE_GLIB
diff --git a/src/libsystemd/sd-login/sd-login.c b/src/libsystemd/sd-login/sd-login.c
index 39445a1..e7eea19 100644
--- a/src/libsystemd/sd-login/sd-login.c
+++ b/src/libsystemd/sd-login/sd-login.c
@@ -172,7 +172,7 @@ _public_ int sd_uid_get_state(uid_t uid, char**state) {
assert_return(state, -EINVAL);
- if (asprintf(&p, "/run/systemd/users/%lu", (unsigned long) uid) < 0)
+ if (asprintf(&p, "/run/systemd/users/"UID_FMT, uid) < 0)
return -ENOMEM;
r = parse_env_file(p, NEWLINE, "STATE", &s, NULL);
@@ -215,7 +215,7 @@ _public_ int sd_uid_is_on_seat(uid_t uid, int require_active, const char *seat)
if (!s)
return -EIO;
- if (asprintf(&t, "%lu", (unsigned long) uid) < 0)
+ if (asprintf(&t, UID_FMT, uid) < 0)
return -ENOMEM;
FOREACH_WORD(w, l, s, state) {
@@ -231,7 +231,7 @@ static int uid_get_array(uid_t uid, const char *variable, char ***array) {
char **a;
int r;
- if (asprintf(&p, "/run/systemd/users/%lu", (unsigned long) uid) < 0)
+ if (asprintf(&p, "/run/systemd/users/"UID_FMT, uid) < 0)
return -ENOMEM;
r = parse_env_file(p, NEWLINE,
diff --git a/src/libsystemd/sd-login/test-login.c b/src/libsystemd/sd-login/test-login.c
index 9e326de..ccf2c95 100644
--- a/src/libsystemd/sd-login/test-login.c
+++ b/src/libsystemd/sd-login/test-login.c
@@ -47,7 +47,7 @@ static void test_login(void) {
printf("session = %s\n", session);
assert_se(sd_pid_get_owner_uid(0, &u2) == 0);
- printf("user = %lu\n", (unsigned long) u2);
+ printf("user = "UID_FMT"\n", u2);
assert_se(socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == 0);
sd_peer_get_session(pair[0], &pp);
@@ -88,7 +88,7 @@ static void test_login(void) {
free(state);
assert_se(sd_session_get_uid(session, &u) >= 0);
- printf("uid = %lu\n", (unsigned long) u);
+ printf("uid = "UID_FMT"\n", u);
assert_se(u == u2);
assert_se(sd_session_get_type(session, &type) >= 0);
@@ -137,7 +137,7 @@ static void test_login(void) {
assert_se(sd_seat_get_active(seat, &session2, &u2) >= 0);
printf("session2 = %s\n", session2);
- printf("uid2 = %lu\n", (unsigned long) u2);
+ printf("uid2 = "UID_FMT"\n", u2);
r = sd_seat_get_sessions(seat, &sessions, &uids, &n);
assert_se(r >= 0);
@@ -149,7 +149,7 @@ static void test_login(void) {
free(t);
printf("uids =");
for (k = 0; k < (int) n; k++)
- printf(" %lu", (unsigned long) uids[k]);
+ printf(" "UID_FMT, uids[k]);
printf("\n");
free(uids);
@@ -192,7 +192,7 @@ static void test_login(void) {
printf("uids =");
for (k = 0; k < r; k++)
- printf(" %lu", (unsigned long) uids[k]);
+ printf(" "UID_FMT, uids[k]);
printf("\n");
free(uids);
diff --git a/src/libudev/libudev-device-private.c b/src/libudev/libudev-device-private.c
index cb4947f..637d064 100644
--- a/src/libudev/libudev-device-private.c
+++ b/src/libudev/libudev-device-private.c
@@ -154,7 +154,7 @@ int udev_device_update_db(struct udev_device *udev_device)
}
if (udev_device_get_usec_initialized(udev_device) > 0)
- fprintf(f, "I:%llu\n", (unsigned long long)udev_device_get_usec_initialized(udev_device));
+ fprintf(f, "I:"USEC_FMT"\n", udev_device_get_usec_initialized(udev_device));
udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(udev_device)) {
if (!udev_list_entry_get_num(list_entry))
diff --git a/src/libudev/libudev-device.c b/src/libudev/libudev-device.c
index 9f80f56..3a64f24 100644
--- a/src/libudev/libudev-device.c
+++ b/src/libudev/libudev-device.c
@@ -1341,7 +1341,7 @@ void udev_device_set_usec_initialized(struct udev_device *udev_device, usec_t us
char num[32];
udev_device->usec_initialized = usec_initialized;
- snprintf(num, sizeof(num), "%llu", (unsigned long long)usec_initialized);
+ snprintf(num, sizeof(num), USEC_FMT, usec_initialized);
udev_device_add_property(udev_device, "USEC_INITIALIZED", num);
}
diff --git a/src/libudev/libudev-hwdb.c b/src/libudev/libudev-hwdb.c
index ff34e5a..e0d4d7c 100644
--- a/src/libudev/libudev-hwdb.c
+++ b/src/libudev/libudev-hwdb.c
@@ -305,7 +305,7 @@ _public_ struct udev_hwdb *udev_hwdb_new(struct udev *udev) {
udev_dbg(udev, "=== trie on-disk ===\n");
udev_dbg(udev, "tool version: %"PRIu64, le64toh(hwdb->head->tool_version));
- udev_dbg(udev, "file size: %8llu bytes\n", (unsigned long long) hwdb->st.st_size);
+ udev_dbg(udev, "file size: %8zu bytes\n", hwdb->st.st_size);
udev_dbg(udev, "header size %8"PRIu64" bytes\n", le64toh(hwdb->head->header_size));
udev_dbg(udev, "strings %8"PRIu64" bytes\n", le64toh(hwdb->head->strings_len));
udev_dbg(udev, "nodes %8"PRIu64" bytes\n", le64toh(hwdb->head->nodes_len));
diff --git a/src/login/inhibit.c b/src/login/inhibit.c
index ae3afdf..24e8fb0 100644
--- a/src/login/inhibit.c
+++ b/src/login/inhibit.c
@@ -100,11 +100,11 @@ static int print_inhibitors(sd_bus *bus, sd_bus_error *error) {
get_process_comm(pid, &comm);
u = uid_to_name(uid);
- printf(" Who: %s (UID %lu/%s, PID %lu/%s)\n"
+ printf(" Who: %s (UID "UID_FMT"/%s, PID "PID_FMT"/%s)\n"
" What: %s\n"
" Why: %s\n"
" Mode: %s\n\n",
- who, (unsigned long) uid, strna(u), (unsigned long) pid, strna(comm),
+ who, uid, strna(u), pid, strna(comm),
what,
why,
mode);
diff --git a/src/login/logind-action.c b/src/login/logind-action.c
index 1928f43..ae9cd48 100644
--- a/src/login/logind-action.c
+++ b/src/login/logind-action.c
@@ -153,17 +153,17 @@ int manager_handle_action(
/* If this is just a recheck of the lid switch then don't warn about anything */
if (!is_edge) {
- log_debug("Refusing operation, %s is inhibited by UID %lu/%s, PID %lu/%s.",
+ log_debug("Refusing operation, %s is inhibited by UID "UID_FMT"/%s, PID "PID_FMT"/%s.",
inhibit_what_to_string(inhibit_operation),
- (unsigned long) offending->uid, strna(u),
- (unsigned long) offending->pid, strna(comm));
+ offending->uid, strna(u),
+ offending->pid, strna(comm));
return 0;
}
- log_error("Refusing operation, %s is inhibited by UID %lu/%s, PID %lu/%s.",
+ log_error("Refusing operation, %s is inhibited by UID "UID_FMT"/%s, PID "PID_FMT"/%s.",
inhibit_what_to_string(inhibit_operation),
- (unsigned long) offending->uid, strna(u),
- (unsigned long) offending->pid, strna(comm));
+ offending->uid, strna(u),
+ offending->pid, strna(comm));
warn_melody();
return -EPERM;
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index 0af6714..1a363c2 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -189,7 +189,7 @@ static int method_get_session_by_pid(sd_bus *bus, sd_bus_message *message, void
if (r < 0)
return r;
if (!session)
- return sd_bus_error_setf(error, BUS_ERROR_NO_SESSION_FOR_PID, "PID %lu does not belong to any known session", (unsigned long) pid);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SESSION_FOR_PID, "PID "PID_FMT" does not belong to any known session", pid);
p = session_bus_path(session);
if (!p)
@@ -215,7 +215,7 @@ static int method_get_user(sd_bus *bus, sd_bus_message *message, void *userdata,
user = hashmap_get(m->users, ULONG_TO_PTR((unsigned long) uid));
if (!user)
- return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER, "No user '%lu' known or logged in", (unsigned long) uid);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER, "No user "UID_FMT" known or logged in", uid);
p = user_bus_path(user);
if (!p)
@@ -257,7 +257,7 @@ static int method_get_user_by_pid(sd_bus *bus, sd_bus_message *message, void *us
if (r < 0)
return r;
if (!user)
- return sd_bus_error_setf(error, BUS_ERROR_NO_USER_FOR_PID, "PID %lu does not belong to any known or logged in user", (unsigned long) pid);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_USER_FOR_PID, "PID "PID_FMT" does not belong to any known or logged in user", pid);
p = user_bus_path(user);
if (!p)
@@ -621,7 +621,7 @@ static int method_create_session(sd_bus *bus, sd_bus_message *message, void *use
if (audit_id > 0) {
/* Keep our session IDs and the audit session IDs in sync */
- if (asprintf(&id, "%lu", (unsigned long) audit_id) < 0)
+ if (asprintf(&id, "%"PRIu32, audit_id) < 0)
return -ENOMEM;
/* Wut? There's already a session by this name and we
@@ -923,7 +923,7 @@ static int method_kill_user(sd_bus *bus, sd_bus_message *message, void *userdata
user = hashmap_get(m->users, ULONG_TO_PTR((unsigned long) uid));
if (!user)
- return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER, "No user '%lu' known or logged in", (unsigned long) uid);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER, "No user "UID_FMT" known or logged in", uid);
r = user_kill(user, signo);
if (r < 0)
@@ -973,7 +973,7 @@ static int method_terminate_user(sd_bus *bus, sd_bus_message *message, void *use
user = hashmap_get(m->users, ULONG_TO_PTR((unsigned long) uid));
if (!user)
- return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER, "No user '%lu' known or logged in", (unsigned long) uid);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER, "No user "UID_FMT" known or logged in", uid);
r = user_stop(user, true);
if (r < 0)
@@ -2220,9 +2220,9 @@ int manager_dispatch_delayed(Manager *manager) {
if (manager->action_timestamp + manager->inhibit_delay_max > now(CLOCK_MONOTONIC))
return 0;
- log_info("Delay lock is active (UID %lu/%s, PID %lu/%s) but inhibitor timeout is reached.",
- (unsigned long) offending->uid, strna(u),
- (unsigned long) offending->pid, strna(comm));
+ log_info("Delay lock is active (UID "UID_FMT"/%s, PID "PID_FMT"/%s) but inhibitor timeout is reached.",
+ offending->uid, strna(u),
+ offending->pid, strna(comm));
}
/* Actually do the operation */
diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c
index 8b329ab..64a62ff 100644
--- a/src/login/logind-inhibit.c
+++ b/src/login/logind-inhibit.c
@@ -151,9 +151,9 @@ int inhibitor_start(Inhibitor *i) {
dual_timestamp_get(&i->since);
- log_debug("Inhibitor %s (%s) pid=%lu uid=%lu mode=%s started.",
+ log_debug("Inhibitor %s (%s) pid="PID_FMT" uid="UID_FMT" mode=%s started.",
strna(i->who), strna(i->why),
- (unsigned long) i->pid, (unsigned long) i->uid,
+ i->pid, i->uid,
inhibit_mode_to_string(i->mode));
inhibitor_save(i);
@@ -169,9 +169,9 @@ int inhibitor_stop(Inhibitor *i) {
assert(i);
if (i->started)
- log_debug("Inhibitor %s (%s) pid=%lu uid=%lu mode=%s stopped.",
+ log_debug("Inhibitor %s (%s) pid="PID_FMT" uid="UID_FMT" mode=%s stopped.",
strna(i->who), strna(i->why),
- (unsigned long) i->pid, (unsigned long) i->uid,
+ i->pid, i->uid,
inhibit_mode_to_string(i->mode));
if (i->state_file)
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
index 8e6f95e..4fb229e 100644
--- a/src/login/logind-session.c
+++ b/src/login/logind-session.c
@@ -533,7 +533,7 @@ int session_start(Session *s) {
MESSAGE_ID(SD_MESSAGE_SESSION_START),
"SESSION_ID=%s", s->id,
"USER_ID=%s", s->user->name,
- "LEADER=%lu", (unsigned long) s->leader,
+ "LEADER="PID_FMT, s->leader,
"MESSAGE=New session %s of user %s.", s->id, s->user->name,
NULL);
@@ -632,7 +632,7 @@ int session_finalize(Session *s) {
MESSAGE_ID(SD_MESSAGE_SESSION_STOP),
"SESSION_ID=%s", s->id,
"USER_ID=%s", s->user->name,
- "LEADER=%lu", (unsigned long) s->leader,
+ "LEADER="PID_FMT, s->leader,
"MESSAGE=Removed session %s.", s->id,
NULL);
diff --git a/src/login/logind-user-dbus.c b/src/login/logind-user-dbus.c
index 4f1a079..6266ccb 100644
--- a/src/login/logind-user-dbus.c
+++ b/src/login/logind-user-dbus.c
@@ -291,7 +291,7 @@ char *user_bus_path(User *u) {
assert(u);
- if (asprintf(&s, "/org/freedesktop/login1/user/_%llu", (unsigned long long) u->uid) < 0)
+ if (asprintf(&s, "/org/freedesktop/login1/user/_"UID_FMT, u->uid) < 0)
return NULL;
return s;
diff --git a/src/login/logind-user.c b/src/login/logind-user.c
index 961cbcb..5fffa65 100644
--- a/src/login/logind-user.c
+++ b/src/login/logind-user.c
@@ -52,7 +52,7 @@ User* user_new(Manager *m, uid_t uid, gid_t gid, const char *name) {
if (!u->name)
goto fail;
- if (asprintf(&u->state_file, "/run/systemd/users/%lu", (unsigned long) uid) < 0)
+ if (asprintf(&u->state_file, "/run/systemd/users/"UID_FMT, uid) < 0)
goto fail;
if (hashmap_put(m->users, ULONG_TO_PTR((unsigned long) uid), u) < 0)
@@ -354,8 +354,8 @@ static int user_start_slice(User *u) {
if (!u->slice) {
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
- char lu[DECIMAL_STR_MAX(unsigned long) + 1], *slice;
- sprintf(lu, "%lu", (unsigned long) u->uid);
+ char lu[DECIMAL_STR_MAX(uid_t) + 1], *slice;
+ sprintf(lu, UID_FMT, u->uid);
r = build_subslice(SPECIAL_USER_SLICE, lu, &slice);
if (r < 0)
@@ -387,8 +387,8 @@ static int user_start_service(User *u) {
assert(u);
if (!u->service) {
- char lu[DECIMAL_STR_MAX(unsigned long) + 1], *service;
- sprintf(lu, "%lu", (unsigned long) u->uid);
+ char lu[DECIMAL_STR_MAX(uid_t) + 1], *service;
+ sprintf(lu, UID_FMT, u->uid);
service = unit_name_build("user", lu, ".service");
if (!service)
diff --git a/src/login/logind.c b/src/login/logind.c
index 686506c..7a7bd97 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -1160,7 +1160,7 @@ int main(int argc, char *argv[]) {
goto finish;
}
- log_debug("systemd-logind running as pid %lu", (unsigned long) getpid());
+ log_debug("systemd-logind running as pid "PID_FMT, getpid());
sd_notify(false,
"READY=1\n"
@@ -1168,7 +1168,7 @@ int main(int argc, char *argv[]) {
r = manager_run(m);
- log_debug("systemd-logind stopped as pid %lu", (unsigned long) getpid());
+ log_debug("systemd-logind stopped as pid "PID_FMT, getpid());
finish:
sd_notify(false,
diff --git a/src/login/pam-module.c b/src/login/pam-module.c
index 1259457..262621d 100644
--- a/src/login/pam-module.c
+++ b/src/login/pam-module.c
@@ -184,7 +184,7 @@ static int export_legacy_dbus_address(
return PAM_SUCCESS;
if (asprintf(&s, KERNEL_USER_BUS_FMT ";" UNIX_USER_BUS_FMT,
- (unsigned long) uid, runtime) < 0) {
+ uid, runtime) < 0) {
pam_syslog(handle, LOG_ERR, "Failed to set bus variable.");
return PAM_BUF_ERR;
}
@@ -252,7 +252,7 @@ _public_ PAM_EXTERN int pam_sm_open_session(
if (streq_ptr(service, "systemd-user")) {
_cleanup_free_ char *p = NULL, *rt = NULL;
- if (asprintf(&p, "/run/systemd/users/%lu", (unsigned long) pw->pw_uid) < 0)
+ if (asprintf(&p, "/run/systemd/users/"UID_FMT, pw->pw_uid) < 0)
return PAM_BUF_ERR;
r = parse_env_file(p, NEWLINE,
diff --git a/src/login/test-inhibit.c b/src/login/test-inhibit.c
index 70780c3..21d2339 100644
--- a/src/login/test-inhibit.c
+++ b/src/login/test-inhibit.c
@@ -73,8 +73,8 @@ static void print_inhibitors(sd_bus *bus) {
assert(r >= 0);
while ((r = sd_bus_message_read(reply, "(ssssuu)", &what, &who, &why, &mode, &uid, &pid)) > 0) {
- printf("what=<%s> who=<%s> why=<%s> mode=<%s> uid=<%lu> pid=<%lu>\n",
- what, who, why, mode, (unsigned long) uid, (unsigned long) pid);
+ printf("what=<%s> who=<%s> why=<%s> mode=<%s> uid=<"UID_FMT"> pid=<"PID_FMT">\n",
+ what, who, why, mode, uid, pid);
n++;
}
diff --git a/src/machine/machine.c b/src/machine/machine.c
index 9a5cc9a..1164ce8 100644
--- a/src/machine/machine.c
+++ b/src/machine/machine.c
@@ -303,7 +303,7 @@ int machine_start(Machine *m, sd_bus_message *properties, sd_bus_error *error) {
log_struct(LOG_INFO,
MESSAGE_ID(SD_MESSAGE_MACHINE_START),
"NAME=%s", m->name,
- "LEADER=%lu", (unsigned long) m->leader,
+ "LEADER="PID_FMT, m->leader,
"MESSAGE=New machine %s.", m->name,
NULL);
@@ -350,7 +350,7 @@ int machine_stop(Machine *m) {
log_struct(LOG_INFO,
MESSAGE_ID(SD_MESSAGE_MACHINE_STOP),
"NAME=%s", m->name,
- "LEADER=%lu", (unsigned long) m->leader,
+ "LEADER="PID_FMT, m->leader,
"MESSAGE=Machine %s terminated.", m->name,
NULL);
diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c
index 9473105..a32d7f5 100644
--- a/src/machine/machined-dbus.c
+++ b/src/machine/machined-dbus.c
@@ -118,7 +118,7 @@ static int method_get_machine_by_pid(sd_bus *bus, sd_bus_message *message, void
if (r < 0)
return r;
if (!machine)
- return sd_bus_error_setf(error, BUS_ERROR_NO_MACHINE_FOR_PID, "PID %lu does not belong to any known machine", (unsigned long) pid);
+ return sd_bus_error_setf(error, BUS_ERROR_NO_MACHINE_FOR_PID, "PID "PID_FMT" does not belong to any known machine", pid);
p = machine_bus_path(machine);
if (!p)
diff --git a/src/machine/machined.c b/src/machine/machined.c
index 45768d2..6160320 100644
--- a/src/machine/machined.c
+++ b/src/machine/machined.c
@@ -338,7 +338,7 @@ int main(int argc, char *argv[]) {
goto finish;
}
- log_debug("systemd-machined running as pid %lu", (unsigned long) getpid());
+ log_debug("systemd-machined running as pid "PID_FMT, getpid());
sd_notify(false,
"READY=1\n"
@@ -346,7 +346,7 @@ int main(int argc, char *argv[]) {
r = manager_run(m);
- log_debug("systemd-machined stopped as pid %lu", (unsigned long) getpid());
+ log_debug("systemd-machined stopped as pid "PID_FMT, getpid());
finish:
sd_notify(false,
diff --git a/src/notify/notify.c b/src/notify/notify.c
index a145b8f..68133c4 100644
--- a/src/notify/notify.c
+++ b/src/notify/notify.c
@@ -184,7 +184,7 @@ int main(int argc, char* argv[]) {
}
if (arg_pid > 0) {
- if (asprintf(&cpid, "MAINPID=%lu", (unsigned long) arg_pid) < 0) {
+ if (asprintf(&cpid, "MAINPID="PID_FMT, arg_pid) < 0) {
log_error("Failed to allocate MAINPID string.");
goto finish;
}
diff --git a/src/readahead/readahead-common.c b/src/readahead/readahead-common.c
index 49679fc..890886e 100644
--- a/src/readahead/readahead-common.c
+++ b/src/readahead/readahead-common.c
@@ -52,7 +52,7 @@ int file_verify(int fd, const char *fn, off_t file_size_max, struct stat *st) {
}
if (st->st_size <= 0 || st->st_size > file_size_max) {
- log_debug("Not preloading file %s with size out of bounds %llu", fn, (unsigned long long) st->st_size);
+ log_debug("Not preloading file %s with size out of bounds %zu", fn, st->st_size);
return 0;
}
@@ -255,7 +255,7 @@ ReadaheadShared *shared_get(void) {
Simply so that it is more unlikely that users end up picking this
value too so that we can recognize better whether the user changed
the value while we had it temporarily bumped. */
-#define BUMP_REQUEST_NR (20*1024)
+#define BUMP_REQUEST_NR (20*1024u)
int block_bump_request_nr(const char *p) {
struct stat st;
@@ -296,7 +296,7 @@ int block_bump_request_nr(const char *p) {
free(line);
line = NULL;
- if (asprintf(&line, "%lu", (unsigned long) BUMP_REQUEST_NR) < 0) {
+ if (asprintf(&line, "%u", BUMP_REQUEST_NR) < 0) {
r = -ENOMEM;
goto finish;
}
@@ -305,7 +305,7 @@ int block_bump_request_nr(const char *p) {
if (r < 0)
goto finish;
- log_info("Bumped block_nr parameter of %u:%u to %lu. This is a temporary hack and should be removed one day.", major(d), minor(d), (unsigned long) BUMP_REQUEST_NR);
+ log_info("Bumped block_nr parameter of %u:%u to %u. This is a temporary hack and should be removed one day.", major(d), minor(d), BUMP_REQUEST_NR);
r = 1;
finish:
@@ -379,7 +379,7 @@ int block_set_readahead(const char *p, uint64_t bytes) {
goto finish;
}
- if (asprintf(&line, "%llu", (unsigned long long) bytes / 1024ULL) < 0) {
+ if (asprintf(&line, "%llu", bytes / 1024ULL) < 0) {
r = -ENOMEM;
goto finish;
}
diff --git a/src/run/run.c b/src/run/run.c
index e3b040d..e4c695c 100644
--- a/src/run/run.c
+++ b/src/run/run.c
@@ -338,7 +338,7 @@ static int start_transient_service(
if (arg_unit)
name = unit_name_mangle_with_suffix(arg_unit, MANGLE_NOGLOB, ".service");
else
- asprintf(&name, "run-%lu.service", (unsigned long) getpid());
+ asprintf(&name, "run-"PID_FMT".service", getpid());
if (!name)
return log_oom();
@@ -474,7 +474,7 @@ static int start_transient_scope(
if (arg_unit)
name = unit_name_mangle_with_suffix(arg_unit, MANGLE_NOGLOB, ".scope");
else
- asprintf(&name, "run-%lu.scope", (unsigned long) getpid());
+ asprintf(&name, "run-"PID_FMT".scope", getpid());
if (!name)
return log_oom();
diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c
index c3c78b6..5997a03 100644
--- a/src/shared/ask-password-api.c
+++ b/src/shared/ask-password-api.c
@@ -359,14 +359,14 @@ int ask_password_agent(
fprintf(f,
"[Ask]\n"
- "PID=%lu\n"
+ "PID="PID_FMT"\n"
"Socket=%s\n"
"AcceptCached=%i\n"
- "NotAfter=%llu\n",
- (unsigned long) getpid(),
+ "NotAfter="USEC_FMT"\n",
+ getpid(),
socket_name,
accept_cached ? 1 : 0,
- (unsigned long long) until);
+ until);
if (message)
fprintf(f, "Message=%s\n", message);
diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c
index 139888c..c1c4d40 100644
--- a/src/shared/cgroup-util.c
+++ b/src/shared/cgroup-util.c
@@ -641,7 +641,7 @@ int cg_attach(const char *controller, const char *path, pid_t pid) {
if (pid == 0)
pid = getpid();
- snprintf(c, sizeof(c), "%lu\n", (unsigned long) pid);
+ snprintf(c, sizeof(c), PID_FMT"\n", pid);
return write_string_file(fs, c);
}
diff --git a/src/shared/def.h b/src/shared/def.h
index aa489d8..a52853c 100644
--- a/src/shared/def.h
+++ b/src/shared/def.h
@@ -71,7 +71,7 @@
#endif
#define UNIX_USER_BUS_FMT "unix:path=%s/bus"
-#define KERNEL_USER_BUS_FMT "kernel:path=/dev/kdbus/%lu-user/bus"
+#define KERNEL_USER_BUS_FMT "kernel:path=/dev/kdbus/"UID_FMT"-user/bus"
#ifndef TTY_GID
#define TTY_GID 5
diff --git a/src/shared/log.c b/src/shared/log.c
index a4b3b68..9039db3 100644
--- a/src/shared/log.c
+++ b/src/shared/log.c
@@ -378,7 +378,7 @@ static int write_to_syslog(
if (strftime(header_time, sizeof(header_time), "%h %e %T ", tm) <= 0)
return -EINVAL;
- snprintf(header_pid, sizeof(header_pid), "[%lu]: ", (unsigned long) getpid());
+ snprintf(header_pid, sizeof(header_pid), "["PID_FMT"]: ", getpid());
char_array_0(header_pid);
IOVEC_SET_STRING(iovec[0], header_priority);
@@ -426,7 +426,7 @@ static int write_to_kmsg(
snprintf(header_priority, sizeof(header_priority), "<%i>", level);
char_array_0(header_priority);
- snprintf(header_pid, sizeof(header_pid), "[%lu]: ", (unsigned long) getpid());
+ snprintf(header_pid, sizeof(header_pid), "["PID_FMT"]: ", getpid());
char_array_0(header_pid);
IOVEC_SET_STRING(iovec[0], header_priority);
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index b0b66f6..72c9ad2 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -301,8 +301,8 @@ static int output_short(
}
fprintf(f, "[%5llu.%06llu]",
- (unsigned long long) (t / USEC_PER_SEC),
- (unsigned long long) (t % USEC_PER_SEC));
+ t / USEC_PER_SEC,
+ t % USEC_PER_SEC);
n += 1 + 5 + 1 + 6 + 1;
@@ -531,12 +531,12 @@ static int output_export(
fprintf(f,
"__CURSOR=%s\n"
- "__REALTIME_TIMESTAMP=%llu\n"
- "__MONOTONIC_TIMESTAMP=%llu\n"
+ "__REALTIME_TIMESTAMP="USEC_FMT"\n"
+ "__MONOTONIC_TIMESTAMP="USEC_FMT"\n"
"_BOOT_ID=%s\n",
cursor,
- (unsigned long long) realtime,
- (unsigned long long) monotonic,
+ realtime,
+ monotonic,
sd_id128_to_string(boot_id, sid));
JOURNAL_FOREACH_DATA_RETVAL(j, data, length, r) {
@@ -673,12 +673,12 @@ static int output_json(
fprintf(f,
"{\n"
"\t\"__CURSOR\" : \"%s\",\n"
- "\t\"__REALTIME_TIMESTAMP\" : \"%llu\",\n"
- "\t\"__MONOTONIC_TIMESTAMP\" : \"%llu\",\n"
+ "\t\"__REALTIME_TIMESTAMP\" : \""USEC_FMT"\",\n"
+ "\t\"__MONOTONIC_TIMESTAMP\" : \""USEC_FMT"\",\n"
"\t\"_BOOT_ID\" : \"%s\"",
cursor,
- (unsigned long long) realtime,
- (unsigned long long) monotonic,
+ realtime,
+ monotonic,
sd_id128_to_string(boot_id, sid));
else {
if (mode == OUTPUT_JSON_SSE)
@@ -686,12 +686,12 @@ static int output_json(
fprintf(f,
"{ \"__CURSOR\" : \"%s\", "
- "\"__REALTIME_TIMESTAMP\" : \"%llu\", "
- "\"__MONOTONIC_TIMESTAMP\" : \"%llu\", "
+ "\"__REALTIME_TIMESTAMP\" : \""USEC_FMT"\", "
+ "\"__MONOTONIC_TIMESTAMP\" : \""USEC_FMT"\", "
"\"_BOOT_ID\" : \"%s\"",
cursor,
- (unsigned long long) realtime,
- (unsigned long long) monotonic,
+ realtime,
+ monotonic,
sd_id128_to_string(boot_id, sid));
}
@@ -1100,7 +1100,7 @@ int add_matches_for_user_unit(sd_journal *j, const char *unit, uid_t uid) {
m2 = strappenda("USER_UNIT=", unit);
m3 = strappenda("COREDUMP_USER_UNIT=", unit);
m4 = strappenda("OBJECT_SYSTEMD_USER_UNIT=", unit);
- sprintf(muid, "_UID=%lu", (unsigned long) uid);
+ sprintf(muid, "_UID="UID_FMT, uid);
(void) (
/* Look for messages from the user service itself */
diff --git a/src/shared/socket-util.c b/src/shared/socket-util.c
index 5ef2e22..997a1ce 100644
--- a/src/shared/socket-util.c
+++ b/src/shared/socket-util.c
@@ -594,7 +594,7 @@ int getpeername_pretty(int fd, char **ret) {
if (r < 0)
return r;
- if (asprintf(ret, "PID %lu/UID %lu", (unsigned long) ucred.pid, (unsigned long) ucred.uid) < 0)
+ if (asprintf(ret, "PID "PID_FMT"/UID "UID_FMT, ucred.pid, ucred.uid) < 0)
return -ENOMEM;
return 0;
diff --git a/src/shared/time-util.c b/src/shared/time-util.c
index eb5c1ae..c667638 100644
--- a/src/shared/time-util.c
+++ b/src/shared/time-util.c
@@ -209,44 +209,44 @@ char *format_timestamp_relative(char *buf, size_t l, usec_t t) {
if (d >= USEC_PER_YEAR)
snprintf(buf, l, "%llu years %llu months %s",
- (unsigned long long) (d / USEC_PER_YEAR),
- (unsigned long long) ((d % USEC_PER_YEAR) / USEC_PER_MONTH), s);
+ d / USEC_PER_YEAR,
+ (d % USEC_PER_YEAR) / USEC_PER_MONTH, s);
else if (d >= USEC_PER_MONTH)
snprintf(buf, l, "%llu months %llu days %s",
- (unsigned long long) (d / USEC_PER_MONTH),
- (unsigned long long) ((d % USEC_PER_MONTH) / USEC_PER_DAY), s);
+ d / USEC_PER_MONTH,
+ (d % USEC_PER_MONTH) / USEC_PER_DAY, s);
else if (d >= USEC_PER_WEEK)
snprintf(buf, l, "%llu weeks %llu days %s",
- (unsigned long long) (d / USEC_PER_WEEK),
- (unsigned long long) ((d % USEC_PER_WEEK) / USEC_PER_DAY), s);
+ d / USEC_PER_WEEK,
+ (d % USEC_PER_WEEK) / USEC_PER_DAY, s);
else if (d >= 2*USEC_PER_DAY)
- snprintf(buf, l, "%llu days %s", (unsigned long long) (d / USEC_PER_DAY), s);
+ snprintf(buf, l, "%llu days %s", d / USEC_PER_DAY, s);
else if (d >= 25*USEC_PER_HOUR)
snprintf(buf, l, "1 day %lluh %s",
- (unsigned long long) ((d - USEC_PER_DAY) / USEC_PER_HOUR), s);
+ (d - USEC_PER_DAY) / USEC_PER_HOUR, s);
else if (d >= 6*USEC_PER_HOUR)
snprintf(buf, l, "%lluh %s",
- (unsigned long long) (d / USEC_PER_HOUR), s);
+ d / USEC_PER_HOUR, s);
else if (d >= USEC_PER_HOUR)
snprintf(buf, l, "%lluh %llumin %s",
- (unsigned long long) (d / USEC_PER_HOUR),
- (unsigned long long) ((d % USEC_PER_HOUR) / USEC_PER_MINUTE), s);
+ d / USEC_PER_HOUR,
+ (d % USEC_PER_HOUR) / USEC_PER_MINUTE, s);
else if (d >= 5*USEC_PER_MINUTE)
snprintf(buf, l, "%llumin %s",
- (unsigned long long) (d / USEC_PER_MINUTE), s);
+ d / USEC_PER_MINUTE, s);
else if (d >= USEC_PER_MINUTE)
snprintf(buf, l, "%llumin %llus %s",
- (unsigned long long) (d / USEC_PER_MINUTE),
- (unsigned long long) ((d % USEC_PER_MINUTE) / USEC_PER_SEC), s);
+ d / USEC_PER_MINUTE,
+ (d % USEC_PER_MINUTE) / USEC_PER_SEC, s);
else if (d >= USEC_PER_SEC)
snprintf(buf, l, "%llus %s",
- (unsigned long long) (d / USEC_PER_SEC), s);
+ d / USEC_PER_SEC, s);
else if (d >= USEC_PER_MSEC)
snprintf(buf, l, "%llums %s",
- (unsigned long long) (d / USEC_PER_MSEC), s);
+ d / USEC_PER_MSEC, s);
else if (d > 0)
- snprintf(buf, l, "%lluus %s",
- (unsigned long long) d, s);
+ snprintf(buf, l, USEC_FMT"us %s",
+ d, s);
else
snprintf(buf, l, "now");
@@ -325,9 +325,9 @@ char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) {
if (j > 0) {
k = snprintf(p, l,
- "%s%llu.%0*llu%s",
+ "%s"USEC_FMT".%0*llu%s",
p > buf ? " " : "",
- (unsigned long long) a,
+ a,
j,
(unsigned long long) b,
table[i].suffix);
@@ -340,9 +340,9 @@ char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) {
/* No? Then let's show it normally */
if (!done) {
k = snprintf(p, l,
- "%s%llu%s",
+ "%s"USEC_FMT"%s",
p > buf ? " " : "",
- (unsigned long long) a,
+ a,
table[i].suffix);
t = b;
@@ -370,10 +370,10 @@ void dual_timestamp_serialize(FILE *f, const char *name, dual_timestamp *t) {
if (!dual_timestamp_is_set(t))
return;
- fprintf(f, "%s=%llu %llu\n",
+ fprintf(f, "%s="USEC_FMT" "USEC_FMT"\n",
name,
- (unsigned long long) t->realtime,
- (unsigned long long) t->monotonic);
+ t->realtime,
+ t->monotonic);
}
void dual_timestamp_deserialize(const char *value, dual_timestamp *t) {
diff --git a/src/shared/util.c b/src/shared/util.c
index d1dc476..020c1da 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -2499,7 +2499,7 @@ static char *lookup_uid(uid_t uid) {
if (getpwuid_r(uid, &pwbuf, buf, bufsize, &pw) == 0 && pw)
return strdup(pw->pw_name);
- if (asprintf(&name, "%lu", (unsigned long) uid) < 0)
+ if (asprintf(&name, UID_FMT, uid) < 0)
return NULL;
return name;
@@ -2624,7 +2624,7 @@ int get_ctty(pid_t pid, dev_t *_devnr, char **r) {
/* This is an ugly hack */
if (major(devnr) == 136) {
- asprintf(&b, "pts/%lu", (unsigned long) minor(devnr));
+ asprintf(&b, "pts/%u", minor(devnr));
goto finish;
}
@@ -4299,7 +4299,7 @@ char* uid_to_name(uid_t uid) {
if (p)
return strdup(p->pw_name);
- if (asprintf(&r, "%lu", (unsigned long) uid) < 0)
+ if (asprintf(&r, UID_FMT, uid) < 0)
return NULL;
return r;
@@ -4316,7 +4316,7 @@ char* gid_to_name(gid_t gid) {
if (p)
return strdup(p->gr_name);
- if (asprintf(&r, "%lu", (unsigned long) gid) < 0)
+ if (asprintf(&r, GID_FMT, gid) < 0)
return NULL;
return r;
diff --git a/src/shared/util.h b/src/shared/util.h
index 891fcee..f2ce4f0 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -67,6 +67,22 @@
# error Unknown gid_t size
#endif
+#if SIZEOF_TIME_T == 8
+# define PRI_TIME PRIu64
+#elif SIZEOF_GID_T == 4
+# define PRI_TIME PRIu32
+#else
+# error Unknown time_t size
+#endif
+
+#if SIZEOF_RLIM_T == 8
+# define RLIM_FMT "%" PRIu64
+#elif SIZEOF_RLIM_T == 4
+# define RLIM_FMT "%" PRIu32
+#else
+# error Unknown rlim_t size
+#endif
+
#include "macro.h"
#include "time-util.h"
diff --git a/src/shutdownd/shutdownd.c b/src/shutdownd/shutdownd.c
index 578920c..25427d6 100644
--- a/src/shutdownd/shutdownd.c
+++ b/src/shutdownd/shutdownd.c
@@ -305,7 +305,7 @@ int main(int argc, char *argv[]) {
}
}
- log_debug("systemd-shutdownd running as pid %lu", (unsigned long) getpid());
+ log_debug("systemd-shutdownd running as pid "PID_FMT, getpid());
sd_notify(false,
"READY=1\n"
@@ -425,7 +425,7 @@ int main(int argc, char *argv[]) {
r = EXIT_SUCCESS;
- log_debug("systemd-shutdownd stopped as pid %lu", (unsigned long) getpid());
+ log_debug("systemd-shutdownd stopped as pid "PID_FMT, getpid());
finish:
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index a60a301..b13b273 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -2884,8 +2884,8 @@ static int check_inhibitors(sd_bus *bus, enum action a) {
get_process_comm(pid, &comm);
user = uid_to_name(uid);
- log_warning("Operation inhibited by \"%s\" (PID %lu \"%s\", user %s), reason is \"%s\".",
- who, (unsigned long) pid, strna(comm), strna(user), why);
+ log_warning("Operation inhibited by \"%s\" (PID "PID_FMT" \"%s\", user %s), reason is \"%s\".",
+ who, pid, strna(comm), strna(user), why);
c++;
}
@@ -4256,7 +4256,7 @@ static int get_unit_dbus_path_by_pid(
&reply,
"u", pid);
if (r < 0) {
- log_error("Failed to get unit for PID %lu: %s", (unsigned long) pid, bus_error_message(&error, r));
+ log_error("Failed to get unit for PID "PID_FMT": %s", pid, bus_error_message(&error, r));
return r;
}
diff --git a/src/test/test-cgroup-util.c b/src/test/test-cgroup-util.c
index b37468b..fda8bcc 100644
--- a/src/test/test-cgroup-util.c
+++ b/src/test/test-cgroup-util.c
@@ -162,11 +162,11 @@ static void test_proc(void) {
cg_pid_get_machine_name(pid, &machine);
cg_pid_get_slice(pid, &slice);
- printf("%lu\t%s\t%s\t%lu\t%s\t%s\t%s\t%s\t%s\n",
- (unsigned long) pid,
+ printf(PID_FMT"\t%s\t%s\t"UID_FMT"\t%s\t%s\t%s\t%s\t%s\n",
+ pid,
path,
path_shifted,
- (unsigned long) uid,
+ uid,
session,
unit,
user_unit,
diff --git a/src/test/test-log.c b/src/test/test-log.c
index 8dc3d53..ca64004 100644
--- a/src/test/test-log.c
+++ b/src/test/test-log.c
@@ -23,6 +23,7 @@
#include <unistd.h>
#include "log.h"
+#include "util.h"
int main(int argc, char* argv[]) {
@@ -30,7 +31,7 @@ int main(int argc, char* argv[]) {
log_open();
log_struct(LOG_INFO,
- "MESSAGE=Waldo PID=%lu", (unsigned long) getpid(),
+ "MESSAGE=Waldo PID="PID_FMT, getpid(),
"SERVICE=piepapo",
NULL);
@@ -38,12 +39,12 @@ int main(int argc, char* argv[]) {
log_open();
log_struct(LOG_INFO,
- "MESSAGE=Foobar PID=%lu", (unsigned long) getpid(),
+ "MESSAGE=Foobar PID="PID_FMT, getpid(),
"SERVICE=foobar",
NULL);
log_struct(LOG_INFO,
- "MESSAGE=Foobar PID=%lu", (unsigned long) getpid(),
+ "MESSAGE=Foobar PID="PID_FMT, getpid(),
"FORMAT_STR_TEST=1=%i A=%c 2=%hi 3=%li 4=%lli 1=%p foo=%s 2.5=%g 3.5=%g 4.5=%Lg",
(int) 1, 'A', (short) 2, (long int) 3, (long long int) 4, (void*) 1, "foo", (float) 2.5f, (double) 3.5, (long double) 4.5,
"SUFFIX=GOT IT",
diff --git a/src/test/test-time.c b/src/test/test-time.c
index 36a3304..7c29f96 100644
--- a/src/test/test-time.c
+++ b/src/test/test-time.c
@@ -84,7 +84,7 @@ static void test_format_timespan_one(usec_t x, usec_t accuracy) {
char l[FORMAT_TIMESPAN_MAX];
usec_t y;
- log_info("%llu (at accuracy %llu)", (unsigned long long) x, (unsigned long long) accuracy);
+ log_info(USEC_FMT" (at accuracy "USEC_FMT")", x, accuracy);
r = format_timespan(l, sizeof(l), x, accuracy);
assert_se(r);
@@ -93,7 +93,7 @@ static void test_format_timespan_one(usec_t x, usec_t accuracy) {
assert_se(parse_sec(l, &y) >= 0);
- log_info(" = %llu", (unsigned long long) y);
+ log_info(" = "USEC_FMT, y);
if (accuracy <= 0)
accuracy = 1;
diff --git a/src/test/test-util.c b/src/test/test-util.c
index caf8d2b..2b46699 100644
--- a/src/test/test-util.c
+++ b/src/test/test-util.c
@@ -434,7 +434,7 @@ static void test_get_process_comm(void) {
log_info("pid1 cmdline truncated: '%s'", d);
assert_se(get_parent_of_pid(1, &e) >= 0);
- log_info("pid1 ppid: '%llu'", (unsigned long long) e);
+ log_info("pid1 ppid: "PID_FMT, e);
assert_se(e == 0);
assert_se(is_kernel_thread(1) == 0);
@@ -444,11 +444,11 @@ static void test_get_process_comm(void) {
log_info("pid1 exe: '%s'", strna(f));
assert_se(get_process_uid(1, &u) == 0);
- log_info("pid1 uid: '%llu'", (unsigned long long) u);
+ log_info("pid1 uid: "UID_FMT, u);
assert_se(u == 0);
assert_se(get_process_gid(1, &g) == 0);
- log_info("pid1 gid: '%llu'", (unsigned long long) g);
+ log_info("pid1 gid: "GID_FMT, g);
assert_se(g == 0);
assert(get_ctty_devnr(1, &h) == -ENOENT);
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index 1b09380..3e0f70c 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -710,7 +710,7 @@ static int method_set_time(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bu
log_struct(LOG_INFO,
MESSAGE_ID(SD_MESSAGE_TIME_CHANGE),
- "REALTIME=%llu", (unsigned long long) timespec_load(&ts),
+ "REALTIME="USEC_FMT, timespec_load(&ts),
"MESSAGE=Changed local time to %s", ctime(&ts.tv_sec),
NULL);
diff --git a/src/udev/udev-builtin-blkid.c b/src/udev/udev-builtin-blkid.c
index db652f7..cf194c0 100644
--- a/src/udev/udev-builtin-blkid.c
+++ b/src/udev/udev-builtin-blkid.c
@@ -274,9 +274,9 @@ static int builtin_blkid(struct udev_device *dev, int argc, char *argv[], bool t
if (err < 0)
goto out;
- log_debug("probe %s %sraid offset=%llu",
+ log_debug("probe %s %sraid offset=%"PRIu64,
udev_device_get_devnode(dev),
- noraid ? "no" : "", (unsigned long long) offset);
+ noraid ? "no" : "", offset);
err = probe_superblocks(pr);
if (err < 0)
diff --git a/src/udev/udevadm-monitor.c b/src/udev/udevadm-monitor.c
index b2f7f6b..a54aa82 100644
--- a/src/udev/udevadm-monitor.c
+++ b/src/udev/udevadm-monitor.c
@@ -48,9 +48,9 @@ static void print_device(struct udev_device *device, const char *source, int pro
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
- printf("%-6s[%llu.%06u] %-8s %s (%s)\n",
+ printf("%-6s[%"PRI_TIME".%06ld] %-8s %s (%s)\n",
source,
- (unsigned long long) ts.tv_sec, (unsigned int) ts.tv_nsec/1000,
+ ts.tv_sec, ts.tv_nsec/1000,
udev_device_get_action(device),
udev_device_get_devpath(device),
udev_device_get_subsystem(device));
diff --git a/src/update-utmp/update-utmp.c b/src/update-utmp/update-utmp.c
index e5fb5f8..31cae70 100644
--- a/src/update-utmp/update-utmp.c
+++ b/src/update-utmp/update-utmp.c
@@ -270,7 +270,7 @@ int main(int argc, char *argv[]) {
goto finish;
}
- log_debug("systemd-update-utmp running as pid %lu", (unsigned long) getpid());
+ log_debug("systemd-update-utmp running as pid "PID_FMT, getpid());
if (streq(argv[1], "reboot"))
r = on_reboot(&c);
@@ -283,7 +283,7 @@ int main(int argc, char *argv[]) {
r = -EINVAL;
}
- log_debug("systemd-update-utmp stopped as pid %lu", (unsigned long) getpid());
+ log_debug("systemd-update-utmp stopped as pid "PID_FMT, getpid());
finish:
#ifdef HAVE_AUDIT
commit 12ed81d9c88406234c20e9261ae8c8b992d8bc4d
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Thu Apr 24 01:44:10 2014 -0400
Make systemctl --root look for files in the proper places
Running systemctl enable/disable/set-default/... with the --root
option under strace reveals that it accessed various files and
directories in the main fs, and not underneath the specified root.
This can lead to correct results only when the layout and
configuration in the container are identical, which often is not the
case. Fix this by adding the specified root to all file access
operations.
This patch does not handle some corner cases: symlinks which point
outside of the specified root might be interpreted differently than
they would be by the kernel if the specified root was the real root.
But systemctl does not create such symlinks by itself, and I think
this is enough of a corner case not to be worth the additional
complexity of reimplementing link chasing in systemd.
Also, simplify the code in a few places and remove an hypothetical
memory leak on error.
diff --git a/TODO b/TODO
index 3154fbd..37a5713 100644
--- a/TODO
+++ b/TODO
@@ -16,8 +16,6 @@ Bugfixes:
Cannot add dependency job for unit display-manager.service, ignoring: Unit display-manager.service failed to load: No such file or directory. See system logs and 'systemctl status display-manager.service' for details.
-* systemctl --root=container/ set-default ... is totally borked.
-
* sd_bus_unref() is broken regarding self-references and "pseudo thread-safety".
See the comment in sd_bus_unref() for more..
diff --git a/src/core/manager.c b/src/core/manager.c
index 5772f40..1e3e127 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -968,6 +968,7 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds) {
r = lookup_paths_init(
&m->lookup_paths, m->running_as, true,
+ NULL,
m->generator_unit_path,
m->generator_unit_path_early,
m->generator_unit_path_late);
@@ -2374,6 +2375,7 @@ int manager_reload(Manager *m) {
q = lookup_paths_init(
&m->lookup_paths, m->running_as, true,
+ NULL,
m->generator_unit_path,
m->generator_unit_path_early,
m->generator_unit_path_late);
diff --git a/src/shared/install.c b/src/shared/install.c
index 2822e61..487d0f6 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -47,7 +47,9 @@ typedef struct {
#define _cleanup_install_context_done_ _cleanup_(install_context_done)
-static int lookup_paths_init_from_scope(LookupPaths *paths, UnitFileScope scope) {
+static int lookup_paths_init_from_scope(LookupPaths *paths,
+ UnitFileScope scope,
+ const char *root_dir) {
assert(paths);
assert(scope >= 0);
assert(scope < _UNIT_FILE_SCOPE_MAX);
@@ -57,6 +59,7 @@ static int lookup_paths_init_from_scope(LookupPaths *paths, UnitFileScope scope)
return lookup_paths_init(paths,
scope == UNIT_FILE_SYSTEM ? SYSTEMD_SYSTEM : SYSTEMD_USER,
scope == UNIT_FILE_USER,
+ root_dir,
NULL, NULL, NULL);
}
@@ -701,7 +704,7 @@ int unit_file_link(
assert(scope >= 0);
assert(scope < _UNIT_FILE_SCOPE_MAX);
- r = lookup_paths_init_from_scope(&paths, scope);
+ r = lookup_paths_init_from_scope(&paths, scope, root_dir);
if (r < 0)
return r;
@@ -1473,7 +1476,7 @@ int unit_file_enable(
assert(scope >= 0);
assert(scope < _UNIT_FILE_SCOPE_MAX);
- r = lookup_paths_init_from_scope(&paths, scope);
+ r = lookup_paths_init_from_scope(&paths, scope, root_dir);
if (r < 0)
return r;
@@ -1513,7 +1516,7 @@ int unit_file_disable(
assert(scope >= 0);
assert(scope < _UNIT_FILE_SCOPE_MAX);
- r = lookup_paths_init_from_scope(&paths, scope);
+ r = lookup_paths_init_from_scope(&paths, scope, root_dir);
if (r < 0)
return r;
@@ -1577,7 +1580,7 @@ int unit_file_set_default(
if (unit_name_to_type(file) != UNIT_TARGET)
return -EINVAL;
- r = lookup_paths_init_from_scope(&paths, scope);
+ r = lookup_paths_init_from_scope(&paths, scope, root_dir);
if (r < 0)
return r;
@@ -1617,7 +1620,7 @@ int unit_file_get_default(
assert(scope < _UNIT_FILE_SCOPE_MAX);
assert(name);
- r = lookup_paths_init_from_scope(&paths, scope);
+ r = lookup_paths_init_from_scope(&paths, scope, root_dir);
if (r < 0)
return r;
@@ -1675,12 +1678,13 @@ UnitFileState unit_file_get_state(
if (!unit_name_is_valid(name, TEMPLATE_VALID))
return -EINVAL;
- r = lookup_paths_init_from_scope(&paths, scope);
+ r = lookup_paths_init_from_scope(&paths, scope, root_dir);
if (r < 0)
return r;
STRV_FOREACH(i, paths.unit_path) {
struct stat st;
+ char *partial;
free(path);
path = NULL;
@@ -1689,10 +1693,14 @@ UnitFileState unit_file_get_state(
asprintf(&path, "%s/%s/%s", root_dir, *i, name);
else
asprintf(&path, "%s/%s", *i, name);
-
if (!path)
return -ENOMEM;
+ if (root_dir)
+ partial = path + strlen(root_dir) + 1;
+ else
+ partial = path;
+
/*
* Search for a unit file in our default paths, to
* be sure, that there are no broken symlinks.
@@ -1724,7 +1732,7 @@ UnitFileState unit_file_get_state(
else if (r > 0)
return state;
- r = unit_file_can_install(&paths, root_dir, path, true);
+ r = unit_file_can_install(&paths, root_dir, partial, true);
if (r < 0 && errno != ENOENT)
return r;
else if (r > 0)
@@ -1832,7 +1840,7 @@ int unit_file_preset(
assert(scope >= 0);
assert(scope < _UNIT_FILE_SCOPE_MAX);
- r = lookup_paths_init_from_scope(&paths, scope);
+ r = lookup_paths_init_from_scope(&paths, scope, root_dir);
if (r < 0)
return r;
@@ -1902,7 +1910,7 @@ int unit_file_get_list(
if (root_dir && scope != UNIT_FILE_SYSTEM)
return -EINVAL;
- r = lookup_paths_init_from_scope(&paths, scope);
+ r = lookup_paths_init_from_scope(&paths, scope, root_dir);
if (r < 0)
return r;
diff --git a/src/shared/path-lookup.c b/src/shared/path-lookup.c
index 63af43c..c6b4ba1 100644
--- a/src/shared/path-lookup.c
+++ b/src/shared/path-lookup.c
@@ -198,6 +198,7 @@ int lookup_paths_init(
LookupPaths *p,
SystemdRunningAs running_as,
bool personal,
+ const char *root_dir,
const char *generator,
const char *generator_early,
const char *generator_late) {
@@ -275,11 +276,9 @@ int lookup_paths_init(
}
}
- if (!path_strv_canonicalize_absolute(p->unit_path, NULL))
+ if (!path_strv_canonicalize_absolute_uniq(p->unit_path, root_dir))
return -ENOMEM;
- strv_uniq(p->unit_path);
-
if (!strv_isempty(p->unit_path)) {
_cleanup_free_ char *t = strv_join(p->unit_path, "\n\t");
if (!t)
@@ -331,15 +330,12 @@ int lookup_paths_init(
return -ENOMEM;
}
- if (!path_strv_canonicalize_absolute(p->sysvinit_path, NULL))
+ if (!path_strv_canonicalize_absolute_uniq(p->sysvinit_path, root_dir))
return -ENOMEM;
- if (!path_strv_canonicalize_absolute(p->sysvrcnd_path, NULL))
+ if (!path_strv_canonicalize_absolute_uniq(p->sysvrcnd_path, root_dir))
return -ENOMEM;
- strv_uniq(p->sysvinit_path);
- strv_uniq(p->sysvrcnd_path);
-
if (!strv_isempty(p->sysvinit_path)) {
_cleanup_free_ char *t = strv_join(p->sysvinit_path, "\n\t");
if (!t)
diff --git a/src/shared/path-lookup.h b/src/shared/path-lookup.h
index a3ef824..847a52f 100644
--- a/src/shared/path-lookup.h
+++ b/src/shared/path-lookup.h
@@ -43,5 +43,11 @@ SystemdRunningAs systemd_running_as_from_string(const char *s) _pure_;
int user_config_home(char **config_home);
-int lookup_paths_init(LookupPaths *p, SystemdRunningAs running_as, bool personal, const char *generator, const char *generator_early, const char *generator_late);
+int lookup_paths_init(LookupPaths *p,
+ SystemdRunningAs running_as,
+ bool personal,
+ const char *root_dir,
+ const char *generator,
+ const char *generator_early,
+ const char *generator_late);
void lookup_paths_free(LookupPaths *p);
diff --git a/src/shared/path-util.c b/src/shared/path-util.c
index 69fcb16..8bf9a3c 100644
--- a/src/shared/path-util.c
+++ b/src/shared/path-util.c
@@ -167,36 +167,63 @@ char **path_strv_canonicalize_absolute(char **l, const char *prefix) {
STRV_FOREACH(s, l) {
char *t, *u;
+ _cleanup_free_ char *orig = NULL;
- if (!path_is_absolute(*s))
+ if (!path_is_absolute(*s)) {
+ free(*s);
continue;
+ }
if (prefix) {
- t = strappend(prefix, *s);
- free(*s);
- *s = NULL;
-
+ orig = *s;
+ t = strappend(prefix, orig);
if (!t) {
enomem = true;
continue;
}
- } else {
+ } else
t = *s;
- *s = NULL;
- }
errno = 0;
u = canonicalize_file_name(t);
if (!u) {
- if (errno == ENOENT)
- u = t;
- else {
+ if (errno == ENOENT) {
+ if (prefix) {
+ u = orig;
+ orig = NULL;
+ free(t);
+ } else
+ u = t;
+ } else {
free(t);
if (errno == ENOMEM || errno == 0)
enomem = true;
continue;
}
+ } else if (prefix) {
+ char *x;
+
+ free(t);
+ x = path_startswith(u, prefix);
+ if (x) {
+ /* restore the slash if it was lost */
+ if (!startswith(x, "/"))
+ *(--x) = '/';
+
+ t = strdup(x);
+ free(u);
+ if (!t) {
+ enomem = true;
+ continue;
+ }
+ u = t;
+ } else {
+ /* canonicalized path goes outside of
+ * prefix, keep the original path instead */
+ u = orig;
+ orig = NULL;
+ }
} else
free(t);
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 91d8032..a60a301 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -5002,7 +5002,7 @@ static int enable_sysv_units(const char *verb, char **args) {
/* Processes all SysV units, and reshuffles the array so that
* afterwards only the native units remain */
- r = lookup_paths_init(&paths, SYSTEMD_SYSTEM, false, NULL, NULL, NULL);
+ r = lookup_paths_init(&paths, SYSTEMD_SYSTEM, false, arg_root, NULL, NULL, NULL);
if (r < 0)
return r;
commit 62b002337727093c21d020c730bd65971f7783a7
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Mon Apr 21 19:17:40 2014 -0400
shared/install: do not prefix created symlink with root path
Before: /var/tmp/inst1//etc/systemd/system/default.target -> /var/tmp/inst1//usr/lib/systemd/system/graphical.target
After: /var/tmp/inst1/etc/systemd/system/default.target -> /usr/lib/systemd/system/graphical.target
diff --git a/src/shared/install.c b/src/shared/install.c
index 9ce9403..2822e61 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -1037,67 +1037,64 @@ static int unit_file_search(
assert(info);
assert(paths);
- if (info->path)
- return unit_file_load(c, info, info->path, allow_symlink);
+ if (info->path) {
+ char *full_path = NULL;
+
+ if (!isempty(root_dir))
+ full_path = strappenda(root_dir, info->path);
+
+ return unit_file_load(c, info, full_path ?: info->path, allow_symlink);
+ }
assert(info->name);
STRV_FOREACH(p, paths->unit_path) {
- char *path = NULL;
-
- if (isempty(root_dir))
- asprintf(&path, "%s/%s", *p, info->name);
- else
- asprintf(&path, "%s/%s/%s", root_dir, *p, info->name);
+ _cleanup_free_ char *path = NULL, *full_path = NULL;
+ path = strjoin(*p, "/", info->name, NULL);
if (!path)
return -ENOMEM;
- r = unit_file_load(c, info, path, allow_symlink);
+ if (!isempty(root_dir)) {
+ full_path = strappend(root_dir, path);
+ if (!full_path)
+ return -ENOMEM;
+ }
- if (r >= 0)
+ r = unit_file_load(c, info, full_path ?: path, allow_symlink);
+ if (r >= 0) {
info->path = path;
- else {
- if (r == -ENOENT && unit_name_is_instance(info->name)) {
- /* Unit file doesn't exist, however instance enablement was requested.
- * We will check if it is possible to load template unit file. */
- char *template = NULL,
- *template_path = NULL,
- *template_dir = NULL;
-
- template = unit_name_template(info->name);
- if (!template) {
- free(path);
- return -ENOMEM;
- }
+ path = NULL;
+ } else if (r == -ENOENT && unit_name_is_instance(info->name)) {
+ /* Unit file doesn't exist, however instance enablement was requested.
+ * We will check if it is possible to load template unit file. */
+ _cleanup_free_ char *template = NULL, *template_dir = NULL;
+
+ template = unit_name_template(info->name);
+ if (!template)
+ return -ENOMEM;
- /* We will reuse path variable since we don't need it anymore. */
- template_dir = path;
- *(strrchr(path, '/') + 1) = '\0';
+ /* We will reuse path variable since we don't need it anymore. */
+ template_dir = path;
+ *(strrchr(template_dir, '/') + 1) = '\0';
- template_path = strjoin(template_dir, template, NULL);
- if (!template_path) {
- free(path);
- free(template);
- return -ENOMEM;
- }
+ path = strappend(template_dir, template);
+ if (!path)
+ return -ENOMEM;
- /* Let's try to load template unit. */
- r = unit_file_load(c, info, template_path, allow_symlink);
- if (r >= 0) {
- info->path = strdup(template_path);
- if (!info->path) {
- free(path);
- free(template);
- free(template_path);
- return -ENOMEM;
- }
- }
+ if (!isempty(root_dir)) {
+ free(full_path);
+ full_path = strappend(root_dir, path);
+ if (!full_path)
+ return -ENOMEM;
+ }
- free(template);
- free(template_path);
+ /* Let's try to load template unit. */
+ r = unit_file_load(c, info, full_path ?: path, allow_symlink);
+ if (r >= 0) {
+ info->path = path;
+ path = NULL;
}
- free(path);
}
if (r != -ENOENT && r != -ELOOP)
More information about the systemd-commits
mailing list