summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
ab9001a)
It is nicer to predefine patterns using configure time check instead of
using casts everywhere.
Since we do not need to use any flags, include "%" in the format instead
of excluding it like PRI* macros.
14 files changed:
/test-bus-creds
/test-bus-error
/test-bus-gvariant
/test-bus-creds
/test-bus-error
/test-bus-gvariant
/test-bus-introspect
/test-bus-kernel
/test-bus-kernel-benchmark
/test-bus-introspect
/test-bus-kernel
/test-bus-kernel-benchmark
-Wl,-z,now])
AC_SUBST([OUR_LDFLAGS], "$with_ldflags $address_sanitizer_ldflags")
-Wl,-z,now])
AC_SUBST([OUR_LDFLAGS], "$with_ldflags $address_sanitizer_ldflags")
+AC_CHECK_SIZEOF(pid_t)
+AC_CHECK_SIZEOF(uid_t)
+
# ------------------------------------------------------------------------------
# we use python to build the man page index, and for systemd-python
have_python=no
# ------------------------------------------------------------------------------
# we use python to build the man page index, and for systemd-python
have_python=no
/* The status string gets the full command line ... */
sd_notifyf(false,
/* The status string gets the full command line ... */
sd_notifyf(false,
- "STATUS=Processing requests from client PID %lu (%s); UID %lu (%s)",
- (unsigned long) pid, p,
- (unsigned long) uid, name);
+ "STATUS=Processing requests from client PID "PID_FMT" (%s); UID "UID_FMT" (%s)",
+ pid, p,
+ uid, name);
/* ... and the argv line only the short comm */
if (arg_command_line_buffer) {
/* ... and the argv line only the short comm */
if (arg_command_line_buffer) {
m = strlen(arg_command_line_buffer);
w = snprintf(arg_command_line_buffer, m,
m = strlen(arg_command_line_buffer);
w = snprintf(arg_command_line_buffer, m,
- "[PID %lu/%s; UID %lu/%s]",
- (unsigned long) pid, comm,
- (unsigned long) uid, name);
+ "[PID "PID_FMT"/%s; UID "UID_FMT"/%s]",
+ pid, comm,
+ uid, name);
if (m > w)
memset(arg_command_line_buffer + w, 0, m - w);
}
if (m > w)
memset(arg_command_line_buffer + w, 0, m - w);
}
- log_debug("Running on behalf of PID %lu (%s), UID %lu (%s), %s",
- (unsigned long) pid, p,
- (unsigned long) uid, name,
+ log_debug("Running on behalf of PID "PID_FMT" (%s), UID "UID_FMT" (%s), %s",
+ pid, p,
+ uid, name,
a->unique_name);
;
return 0;
a->unique_name);
;
return 0;
get_process_comm(packet.v5_packet.pid, &p);
log_info_unit(UNIT(a)->id,
get_process_comm(packet.v5_packet.pid, &p);
log_info_unit(UNIT(a)->id,
- "Got automount request for %s, triggered by %lu (%s)",
- a->where, (unsigned long) packet.v5_packet.pid, strna(p));
+ "Got automount request for %s, triggered by "PID_FMT" (%s)",
+ a->where, packet.v5_packet.pid, strna(p));
} else
log_debug_unit(UNIT(a)->id, "Got direct mount request on %s", a->where);
} else
log_debug_unit(UNIT(a)->id, "Got direct mount request on %s", a->where);
- while (( r = sd_bus_message_read(message, "(st)", &path, &u64)) > 0) {
- unsigned long ul;
+ while ((r = sd_bus_message_read(message, "(st)", &path, &u64)) > 0) {
+ unsigned long ul = u64;
- ul = (unsigned long) u64;
if (ul < 10 || ul > 1000)
return sd_bus_error_set_errnof(error, EINVAL, "BlockIODeviceWeight out of range");
if (ul < 10 || ul > 1000)
return sd_bus_error_set_errnof(error, EINVAL, "BlockIODeviceWeight out of range");
return -ENOMEM;
if (n_fds > 0) {
return -ENOMEM;
if (n_fds > 0) {
- if (asprintf(&x, "LISTEN_PID=%lu", (unsigned long) getpid()) < 0)
+ if (asprintf(&x, "LISTEN_PID="PID_FMT, getpid()) < 0)
return -ENOMEM;
our_env[n_env++] = x;
return -ENOMEM;
our_env[n_env++] = x;
}
if (watchdog_usec > 0) {
}
if (watchdog_usec > 0) {
- if (asprintf(&x, "WATCHDOG_PID=%lu", (unsigned long) getpid()) < 0)
+ if (asprintf(&x, "WATCHDOG_PID="PID_FMT, getpid()) < 0)
return -ENOMEM;
our_env[n_env++] = x;
return -ENOMEM;
our_env[n_env++] = x;
log_struct_unit(LOG_DEBUG,
unit_id,
log_struct_unit(LOG_DEBUG,
unit_id,
- "MESSAGE=Forked %s as %lu",
- command->path, (unsigned long) pid,
+ "MESSAGE=Forked %s as "PID_FMT,
+ command->path, pid,
NULL);
/* We add the new process to the cgroup both in the child (so
NULL);
/* We add the new process to the cgroup both in the child (so
}
if (c->timer_slack_nsec != (nsec_t) -1)
}
if (c->timer_slack_nsec != (nsec_t) -1)
- fprintf(f, "%sTimerSlackNSec: %lu\n", prefix, (unsigned long)c->timer_slack_nsec);
+ fprintf(f, "%sTimerSlackNSec: "NSEC_FMT "\n", prefix, c->timer_slack_nsec);
fprintf(f,
"%sStandardInput: %s\n"
fprintf(f,
"%sStandardInput: %s\n"
- "%sPID: %lu\n",
- prefix, (unsigned long) s->pid);
+ "%sPID: "PID_FMT"\n",
+ prefix, s->pid);
if (s->start_timestamp.realtime > 0)
fprintf(f,
if (s->start_timestamp.realtime > 0)
fprintf(f,
- if (asprintf(&p, "/org/freedesktop/systemd1/job/%lu", (unsigned long) j->id) < 0)
+ if (asprintf(&p, "/org/freedesktop/systemd1/job/%"PRIu32, j->id) < 0)
fprintf(f, "job-ignore-order=%s\n", yes_no(j->ignore_order));
if (j->begin_usec > 0)
fprintf(f, "job-ignore-order=%s\n", yes_no(j->ignore_order));
if (j->begin_usec > 0)
- fprintf(f, "job-begin=%llu\n", (unsigned long long) j->begin_usec);
+ fprintf(f, "job-begin="USEC_FMT"\n", j->begin_usec);
bus_client_track_serialize(j->manager, f, j->subscribed);
bus_client_track_serialize(j->manager, f, j->subscribed);
_cleanup_free_ char *s;
get_process_comm(pid, &s);
_cleanup_free_ char *s;
get_process_comm(pid, &s);
- log_notice("Sending SIGKILL to PID %lu (%s).", (unsigned long) pid, strna(s));
+ log_notice("Sending SIGKILL to PID "PID_FMT" (%s).", pid, strna(s));
}
if (kill(pid, sig) >= 0) {
if (pids)
}
if (kill(pid, sig) >= 0) {
if (pids)
- set_put(pids, ULONG_TO_PTR((unsigned long) pid));
+ set_put(pids, ULONG_TO_PTR(pid));
} else if (errno != ENOENT)
log_warning("Could not kill %d: %m", pid);
} else if (errno != ENOENT)
log_warning("Could not kill %d: %m", pid);
else if (status.si_code != CLD_DUMPED)
log_error("Caught <%s>, core dump failed.", signal_to_string(sig));
else
else if (status.si_code != CLD_DUMPED)
log_error("Caught <%s>, core dump failed.", signal_to_string(sig));
else
- log_error("Caught <%s>, dumped core as pid %lu.", signal_to_string(sig), (unsigned long) pid);
+ log_error("Caught <%s>, dumped core as pid "PID_FMT".", signal_to_string(sig), pid);
- log_info("Successfully spawned crash shell as pid %lu.", (unsigned long) pid);
+ log_info("Successfully spawned crash shell as pid "PID_FMT".", pid);
}
log_info("Freezing execution.");
}
log_info("Freezing execution.");
watchdog_close(false);
/* Tell the binary how often to ping */
watchdog_close(false);
/* Tell the binary how often to ping */
- snprintf(e, sizeof(e), "WATCHDOG_USEC=%llu", (unsigned long long) arg_shutdown_watchdog);
+ snprintf(e, sizeof(e), "WATCHDOG_USEC="USEC_FMT, arg_shutdown_watchdog);
char_array_0(e);
env_block = strv_append(environ, e);
char_array_0(e);
env_block = strv_append(environ, e);
if (!u) {
u = manager_get_unit_by_pid(m, ucred->pid);
if (!u) {
if (!u) {
u = manager_get_unit_by_pid(m, ucred->pid);
if (!u) {
- log_warning("Cannot find unit for notify message of PID %lu.", (unsigned long) ucred->pid);
+ log_warning("Cannot find unit for notify message of PID "PID_FMT".", ucred->pid);
_cleanup_free_ char *name = NULL;
get_process_comm(si.si_pid, &name);
_cleanup_free_ char *name = NULL;
get_process_comm(si.si_pid, &name);
- log_debug("Got SIGCHLD for process %lu (%s)", (unsigned long) si.si_pid, strna(name));
+ log_debug("Got SIGCHLD for process "PID_FMT" (%s)", si.si_pid, strna(name));
}
/* And now figure out the unit this belongs to */
}
/* And now figure out the unit this belongs to */
log_full(sfsi.ssi_signo == SIGCHLD ||
(sfsi.ssi_signo == SIGTERM && m->running_as == SYSTEMD_USER)
? LOG_DEBUG : LOG_INFO,
log_full(sfsi.ssi_signo == SIGCHLD ||
(sfsi.ssi_signo == SIGTERM && m->running_as == SYSTEMD_USER)
? LOG_DEBUG : LOG_INFO,
- "Received SIG%s from PID %lu (%s).",
+ "Received SIG%s from PID "PID_FMT" (%s).",
signal_to_string(sfsi.ssi_signo),
signal_to_string(sfsi.ssi_signo),
- (unsigned long) sfsi.ssi_pid, strna(p));
+ sfsi.ssi_pid, strna(p));
} else
log_full(sfsi.ssi_signo == SIGCHLD ||
(sfsi.ssi_signo == SIGTERM && m->running_as == SYSTEMD_USER)
} else
log_full(sfsi.ssi_signo == SIGCHLD ||
(sfsi.ssi_signo == SIGTERM && m->running_as == SYSTEMD_USER)
assert(_f);
if (m->running_as == SYSTEMD_SYSTEM)
assert(_f);
if (m->running_as == SYSTEMD_SYSTEM)
- asprintf(&path, "/run/systemd/dump-%lu-XXXXXX", (unsigned long) getpid());
+ asprintf(&path, "/run/systemd/dump-"PID_FMT"-XXXXXX", getpid());
- asprintf(&path, "/tmp/systemd-dump-%lu-XXXXXX", (unsigned long) getpid());
+ asprintf(&path, "/tmp/systemd-dump-"PID_FMT"-XXXXXX", getpid());
if (!path)
return -ENOMEM;
if (!path)
return -ENOMEM;
if (!log_on_console())
log_struct(LOG_INFO,
MESSAGE_ID(SD_MESSAGE_STARTUP_FINISHED),
if (!log_on_console())
log_struct(LOG_INFO,
MESSAGE_ID(SD_MESSAGE_STARTUP_FINISHED),
- "KERNEL_USEC=%llu", (unsigned long long) kernel_usec,
- "INITRD_USEC=%llu", (unsigned long long) initrd_usec,
- "USERSPACE_USEC=%llu", (unsigned long long) userspace_usec,
+ "KERNEL_USEC="USEC_FMT, kernel_usec,
+ "INITRD_USEC="USEC_FMT, initrd_usec,
+ "USERSPACE_USEC="USEC_FMT, userspace_usec,
"MESSAGE=Startup finished in %s (kernel) + %s (initrd) + %s (userspace) = %s.",
format_timespan(kernel, sizeof(kernel), kernel_usec, USEC_PER_MSEC),
format_timespan(initrd, sizeof(initrd), initrd_usec, USEC_PER_MSEC),
"MESSAGE=Startup finished in %s (kernel) + %s (initrd) + %s (userspace) = %s.",
format_timespan(kernel, sizeof(kernel), kernel_usec, USEC_PER_MSEC),
format_timespan(initrd, sizeof(initrd), initrd_usec, USEC_PER_MSEC),
if (!log_on_console())
log_struct(LOG_INFO,
MESSAGE_ID(SD_MESSAGE_STARTUP_FINISHED),
if (!log_on_console())
log_struct(LOG_INFO,
MESSAGE_ID(SD_MESSAGE_STARTUP_FINISHED),
- "KERNEL_USEC=%llu", (unsigned long long) kernel_usec,
- "USERSPACE_USEC=%llu", (unsigned long long) userspace_usec,
+ "KERNEL_USEC="USEC_FMT, kernel_usec,
+ "USERSPACE_USEC="USEC_FMT, userspace_usec,
"MESSAGE=Startup finished in %s (kernel) + %s (userspace) = %s.",
format_timespan(kernel, sizeof(kernel), kernel_usec, USEC_PER_MSEC),
format_timespan(userspace, sizeof(userspace), userspace_usec, USEC_PER_MSEC),
"MESSAGE=Startup finished in %s (kernel) + %s (userspace) = %s.",
format_timespan(kernel, sizeof(kernel), kernel_usec, USEC_PER_MSEC),
format_timespan(userspace, sizeof(userspace), userspace_usec, USEC_PER_MSEC),
if (!log_on_console())
log_struct(LOG_INFO,
MESSAGE_ID(SD_MESSAGE_STARTUP_FINISHED),
if (!log_on_console())
log_struct(LOG_INFO,
MESSAGE_ID(SD_MESSAGE_STARTUP_FINISHED),
- "USERSPACE_USEC=%llu", (unsigned long long) userspace_usec,
+ "USERSPACE_USEC="USEC_FMT, userspace_usec,
"MESSAGE=Startup finished in %s.",
format_timespan(sum, sizeof(sum), total_usec, USEC_PER_MSEC),
NULL);
"MESSAGE=Startup finished in %s.",
format_timespan(sum, sizeof(sum), total_usec, USEC_PER_MSEC),
NULL);
if (m->control_pid > 0)
fprintf(f,
if (m->control_pid > 0)
fprintf(f,
- "%sControl PID: %lu\n",
- prefix, (unsigned long) m->control_pid);
+ "%sControl PID: "PID_FMT"\n",
+ prefix, m->control_pid);
exec_context_dump(&m->exec_context, f, prefix);
kill_context_dump(&m->kill_context, f, prefix);
exec_context_dump(&m->exec_context, f, prefix);
kill_context_dump(&m->kill_context, f, prefix);
unit_serialize_item(u, f, "reload-result", mount_result_to_string(m->reload_result));
if (m->control_pid > 0)
unit_serialize_item(u, f, "reload-result", mount_result_to_string(m->reload_result));
if (m->control_pid > 0)
- unit_serialize_item_format(u, f, "control-pid", "%lu", (unsigned long) m->control_pid);
+ unit_serialize_item_format(u, f, "control-pid", PID_FMT, m->control_pid);
if (m->control_command_id >= 0)
unit_serialize_item(u, f, "control-command", mount_exec_command_to_string(m->control_command_id));
if (m->control_command_id >= 0)
unit_serialize_item(u, f, "control-command", mount_exec_command_to_string(m->control_command_id));
if (get_parent_of_pid(pid, &ppid) >= 0 && ppid != getpid()) {
log_warning_unit(UNIT(s)->id,
if (get_parent_of_pid(pid, &ppid) >= 0 && ppid != getpid()) {
log_warning_unit(UNIT(s)->id,
- "%s: Supervising process %lu which is not our child. We'll most likely not notice when it exits.",
- UNIT(s)->id, (unsigned long) pid);
+ "%s: Supervising process "PID_FMT" which is not our child. We'll most likely not notice when it exits.",
+ UNIT(s)->id, pid);
s->main_pid_alien = true;
} else
s->main_pid_alien = true;
} else
if (s->control_pid > 0)
fprintf(f,
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->main_pid > 0)
fprintf(f,
if (s->main_pid > 0)
fprintf(f,
+ "%sMain PID: "PID_FMT"\n"
"%sMain PID Known: %s\n"
"%sMain PID Alien: %s\n",
"%sMain PID Known: %s\n"
"%sMain PID Alien: %s\n",
- prefix, (unsigned long) s->main_pid,
prefix, yes_no(s->main_pid_known),
prefix, yes_no(s->main_pid_alien));
prefix, yes_no(s->main_pid_known),
prefix, yes_no(s->main_pid_alien));
if (kill(pid, 0) < 0 && errno != EPERM) {
if (may_warn)
log_info_unit(UNIT(s)->id,
if (kill(pid, 0) < 0 && errno != EPERM) {
if (may_warn)
log_info_unit(UNIT(s)->id,
- "PID %lu read from file %s does not exist.",
- (unsigned long) pid, s->pid_file);
+ "PID "PID_FMT" read from file %s does not exist.",
+ pid, s->pid_file);
return 0;
log_debug_unit(UNIT(s)->id,
return 0;
log_debug_unit(UNIT(s)->id,
- "Main PID changing: %lu -> %lu",
- (unsigned long) s->main_pid, (unsigned long) pid);
+ "Main PID changing: "PID_FMT" -> "PID_FMT,
+ s->main_pid, pid);
service_unwatch_main_pid(s);
s->main_pid_known = false;
} else
log_debug_unit(UNIT(s)->id,
service_unwatch_main_pid(s);
s->main_pid_known = false;
} else
log_debug_unit(UNIT(s)->id,
- "Main PID loaded: %lu", (unsigned long) pid);
+ "Main PID loaded: "PID_FMT, pid);
r = service_set_main_pid(s, pid);
if (r < 0)
r = service_set_main_pid(s, pid);
if (r < 0)
if (r < 0) {
/* FIXME: we need to do something here */
log_warning_unit(UNIT(s)->id,
if (r < 0) {
/* FIXME: we need to do something here */
log_warning_unit(UNIT(s)->id,
- "Failed to watch PID %lu from service %s",
- (unsigned long) pid, UNIT(s)->id);
+ "Failed to watch PID "PID_FMT" from service %s",
+ pid, UNIT(s)->id);
return -ENOENT;
log_debug_unit(UNIT(s)->id,
return -ENOENT;
log_debug_unit(UNIT(s)->id,
- "Main PID guessed: %lu", (unsigned long) pid);
+ "Main PID guessed: "PID_FMT, pid);
r = service_set_main_pid(s, pid);
if (r < 0)
return r;
r = service_set_main_pid(s, pid);
if (r < 0)
return r;
if (r < 0)
/* FIXME: we need to do something here */
log_warning_unit(UNIT(s)->id,
if (r < 0)
/* FIXME: we need to do something here */
log_warning_unit(UNIT(s)->id,
- "Failed to watch PID %lu from service %s",
- (unsigned long) pid, UNIT(s)->id);
+ "Failed to watch PID "PID_FMT" from service %s",
+ pid, UNIT(s)->id);
- if (asprintf(our_env + n_env++, "MAINPID=%lu", (unsigned long) s->main_pid) < 0) {
+ if (asprintf(our_env + n_env++, "MAINPID="PID_FMT, s->main_pid) < 0) {
r = -ENOMEM;
goto fail;
}
if (UNIT(s)->manager->running_as != SYSTEMD_SYSTEM)
r = -ENOMEM;
goto fail;
}
if (UNIT(s)->manager->running_as != SYSTEMD_SYSTEM)
- if (asprintf(our_env + n_env++, "MANAGERPID=%lu", (unsigned long) getpid()) < 0) {
+ if (asprintf(our_env + n_env++, "MANAGERPID="PID_FMT, getpid()) < 0) {
r = -ENOMEM;
goto fail;
}
r = -ENOMEM;
goto fail;
}
unit_serialize_item(u, f, "reload-result", service_result_to_string(s->reload_result));
if (s->control_pid > 0)
unit_serialize_item(u, f, "reload-result", service_result_to_string(s->reload_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->main_pid_known && s->main_pid > 0)
if (s->main_pid_known && s->main_pid > 0)
- unit_serialize_item_format(u, f, "main-pid", "%lu", (unsigned long) s->main_pid);
+ unit_serialize_item_format(u, f, "main-pid", PID_FMT, s->main_pid);
unit_serialize_item(u, f, "main-pid-known", yes_no(s->main_pid_known));
unit_serialize_item(u, f, "main-pid-known", yes_no(s->main_pid_known));
}
if (s->main_exec_status.pid > 0) {
}
if (s->main_exec_status.pid > 0) {
- unit_serialize_item_format(u, f, "main-exec-status-pid", "%lu",
- (unsigned long) s->main_exec_status.pid);
+ unit_serialize_item_format(u, f, "main-exec-status-pid", PID_FMT,
+ s->main_exec_status.pid);
dual_timestamp_serialize(f, "main-exec-status-start",
&s->main_exec_status.start_timestamp);
dual_timestamp_serialize(f, "main-exec-status-exit",
dual_timestamp_serialize(f, "main-exec-status-start",
&s->main_exec_status.start_timestamp);
dual_timestamp_serialize(f, "main-exec-status-exit",
- log_debug_unit(u->id, "%s: Got notification message from PID %lu (%s...)",
- u->id, (unsigned long) pid, tags && *tags ? tags[0] : "(empty)");
+ log_debug_unit(u->id, "%s: Got notification message from PID "PID_FMT" (%s...)",
+ u->id, pid, tags && *tags ? tags[0] : "(empty)");
if (s->notify_access == NOTIFY_NONE) {
log_warning_unit(u->id,
if (s->notify_access == NOTIFY_NONE) {
log_warning_unit(u->id,
- "%s: Got notification message from PID %lu, but reception is disabled.",
- u->id, (unsigned long) pid);
+ "%s: Got notification message from PID "PID_FMT", but reception is disabled.",
+ u->id, pid);
return;
}
if (s->notify_access == NOTIFY_MAIN && s->main_pid != 0 && pid != s->main_pid) {
log_warning_unit(u->id,
return;
}
if (s->notify_access == NOTIFY_MAIN && s->main_pid != 0 && pid != s->main_pid) {
log_warning_unit(u->id,
- "%s: Got notification message from PID %lu, but reception only permitted for PID %lu",
- u->id, (unsigned long) pid, (unsigned long) s->main_pid);
+ "%s: Got notification message from PID "PID_FMT", but reception only permitted for PID "PID_FMT,
+ u->id, pid, s->main_pid);
typedef uint64_t usec_t;
typedef uint64_t nsec_t;
typedef uint64_t usec_t;
typedef uint64_t nsec_t;
+#define NSEC_FMT "%" PRIu64
+#define USEC_FMT "%" PRIu64
+
#include "macro.h"
typedef struct dual_timestamp {
#include "macro.h"
typedef struct dual_timestamp {
#include <mntent.h>
#include <sys/socket.h>
#include <mntent.h>
#include <sys/socket.h>
+#if SIZEOF_PID_T == 4
+# define PID_FMT "%" PRIu32
+#elif SIZEOF_PID_T == 2
+# define PID_FMT "%" PRIu16
+#else
+# error Unknown pid_t size
+#endif
+
+#if SIZEOF_UID_T == 4
+# define UID_FMT "%" PRIu32
+#elif SIZEOF_UID_T == 2
+# define UID_FMT "%" PRIu16
+#else
+# error Unknown uid_t size
+#endif
+
#include "macro.h"
#include "time-util.h"
#include "macro.h"
#include "time-util.h"
pid_t _pid_ = (pid); \
char *_r_; \
_r_ = alloca(sizeof("/proc/") -1 + DECIMAL_STR_MAX(pid_t) + 1 + sizeof(field)); \
pid_t _pid_ = (pid); \
char *_r_; \
_r_ = alloca(sizeof("/proc/") -1 + DECIMAL_STR_MAX(pid_t) + 1 + sizeof(field)); \
- sprintf(_r_, "/proc/%lu/" field, (unsigned long) _pid_); \
+ sprintf(_r_, "/proc/"PID_FMT"/" field, _pid_); \