mirror of
https://github.com/systemd/systemd.git
synced 2024-12-22 17:35:35 +03:00
Use format patterns for usec_t, pid_t, nsec_t, usec_t
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.
This commit is contained in:
parent
ab9001a1e3
commit
ccd06097c7
1
.gitignore
vendored
1
.gitignore
vendored
@ -112,6 +112,7 @@
|
|||||||
/test-bus-creds
|
/test-bus-creds
|
||||||
/test-bus-error
|
/test-bus-error
|
||||||
/test-bus-gvariant
|
/test-bus-gvariant
|
||||||
|
/test-bus-cleanup
|
||||||
/test-bus-introspect
|
/test-bus-introspect
|
||||||
/test-bus-kernel
|
/test-bus-kernel
|
||||||
/test-bus-kernel-benchmark
|
/test-bus-kernel-benchmark
|
||||||
|
@ -178,6 +178,9 @@ CC_CHECK_FLAGS_APPEND([with_ldflags], [LDFLAGS], [\
|
|||||||
-Wl,-z,now])
|
-Wl,-z,now])
|
||||||
AC_SUBST([OUR_LDFLAGS], "$with_ldflags $address_sanitizer_ldflags")
|
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
|
# we use python to build the man page index, and for systemd-python
|
||||||
have_python=no
|
have_python=no
|
||||||
|
@ -157,9 +157,9 @@ static int rename_service(sd_bus *a, sd_bus *b) {
|
|||||||
|
|
||||||
/* The status string gets the full command line ... */
|
/* The status string gets the full command line ... */
|
||||||
sd_notifyf(false,
|
sd_notifyf(false,
|
||||||
"STATUS=Processing requests from client PID %lu (%s); UID %lu (%s)",
|
"STATUS=Processing requests from client PID "PID_FMT" (%s); UID "UID_FMT" (%s)",
|
||||||
(unsigned long) pid, p,
|
pid, p,
|
||||||
(unsigned long) uid, name);
|
uid, name);
|
||||||
|
|
||||||
/* ... and the argv line only the short comm */
|
/* ... and the argv line only the short comm */
|
||||||
if (arg_command_line_buffer) {
|
if (arg_command_line_buffer) {
|
||||||
@ -167,17 +167,17 @@ static int rename_service(sd_bus *a, sd_bus *b) {
|
|||||||
|
|
||||||
m = strlen(arg_command_line_buffer);
|
m = strlen(arg_command_line_buffer);
|
||||||
w = snprintf(arg_command_line_buffer, m,
|
w = snprintf(arg_command_line_buffer, m,
|
||||||
"[PID %lu/%s; UID %lu/%s]",
|
"[PID "PID_FMT"/%s; UID "UID_FMT"/%s]",
|
||||||
(unsigned long) pid, comm,
|
pid, comm,
|
||||||
(unsigned long) uid, name);
|
uid, name);
|
||||||
|
|
||||||
if (m > w)
|
if (m > w)
|
||||||
memset(arg_command_line_buffer + w, 0, m - w);
|
memset(arg_command_line_buffer + w, 0, m - w);
|
||||||
}
|
}
|
||||||
|
|
||||||
log_debug("Running on behalf of PID %lu (%s), UID %lu (%s), %s",
|
log_debug("Running on behalf of PID "PID_FMT" (%s), UID "UID_FMT" (%s), %s",
|
||||||
(unsigned long) pid, p,
|
pid, p,
|
||||||
(unsigned long) uid, name,
|
uid, name,
|
||||||
a->unique_name);
|
a->unique_name);
|
||||||
;
|
;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -774,8 +774,8 @@ static int automount_dispatch_io(sd_event_source *s, int fd, uint32_t events, vo
|
|||||||
|
|
||||||
get_process_comm(packet.v5_packet.pid, &p);
|
get_process_comm(packet.v5_packet.pid, &p);
|
||||||
log_info_unit(UNIT(a)->id,
|
log_info_unit(UNIT(a)->id,
|
||||||
"Got automount request for %s, triggered by %lu (%s)",
|
"Got automount request for %s, triggered by "PID_FMT" (%s)",
|
||||||
a->where, (unsigned long) packet.v5_packet.pid, strna(p));
|
a->where, packet.v5_packet.pid, strna(p));
|
||||||
} else
|
} else
|
||||||
log_debug_unit(UNIT(a)->id, "Got direct mount request on %s", a->where);
|
log_debug_unit(UNIT(a)->id, "Got direct mount request on %s", a->where);
|
||||||
|
|
||||||
|
@ -321,10 +321,9 @@ int bus_cgroup_set_property(
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
while (( r = sd_bus_message_read(message, "(st)", &path, &u64)) > 0) {
|
while ((r = sd_bus_message_read(message, "(st)", &path, &u64)) > 0) {
|
||||||
unsigned long ul;
|
unsigned long ul = u64;
|
||||||
|
|
||||||
ul = (unsigned long) u64;
|
|
||||||
if (ul < 10 || ul > 1000)
|
if (ul < 10 || ul > 1000)
|
||||||
return sd_bus_error_set_errnof(error, EINVAL, "BlockIODeviceWeight out of range");
|
return sd_bus_error_set_errnof(error, EINVAL, "BlockIODeviceWeight out of range");
|
||||||
|
|
||||||
|
@ -1038,7 +1038,7 @@ static int build_environment(
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
if (n_fds > 0) {
|
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;
|
return -ENOMEM;
|
||||||
our_env[n_env++] = x;
|
our_env[n_env++] = x;
|
||||||
|
|
||||||
@ -1048,7 +1048,7 @@ static int build_environment(
|
|||||||
}
|
}
|
||||||
|
|
||||||
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;
|
return -ENOMEM;
|
||||||
our_env[n_env++] = x;
|
our_env[n_env++] = x;
|
||||||
|
|
||||||
@ -1636,8 +1636,8 @@ int exec_spawn(ExecCommand *command,
|
|||||||
|
|
||||||
log_struct_unit(LOG_DEBUG,
|
log_struct_unit(LOG_DEBUG,
|
||||||
unit_id,
|
unit_id,
|
||||||
"MESSAGE=Forked %s as %lu",
|
"MESSAGE=Forked %s as "PID_FMT,
|
||||||
command->path, (unsigned long) pid,
|
command->path, pid,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
/* We add the new process to the cgroup both in the child (so
|
/* We add the new process to the cgroup both in the child (so
|
||||||
@ -1979,7 +1979,7 @@ void exec_context_dump(ExecContext *c, FILE* f, const char *prefix) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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,
|
fprintf(f,
|
||||||
"%sStandardInput: %s\n"
|
"%sStandardInput: %s\n"
|
||||||
@ -2139,8 +2139,8 @@ void exec_status_dump(ExecStatus *s, FILE *f, const char *prefix) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
fprintf(f,
|
fprintf(f,
|
||||||
"%sPID: %lu\n",
|
"%sPID: "PID_FMT"\n",
|
||||||
prefix, (unsigned long) s->pid);
|
prefix, s->pid);
|
||||||
|
|
||||||
if (s->start_timestamp.realtime > 0)
|
if (s->start_timestamp.realtime > 0)
|
||||||
fprintf(f,
|
fprintf(f,
|
||||||
|
@ -906,7 +906,7 @@ char *job_dbus_path(Job *j) {
|
|||||||
|
|
||||||
assert(j);
|
assert(j);
|
||||||
|
|
||||||
if (asprintf(&p, "/org/freedesktop/systemd1/job/%lu", (unsigned long) j->id) < 0)
|
if (asprintf(&p, "/org/freedesktop/systemd1/job/%"PRIu32, j->id) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
@ -922,7 +922,7 @@ int job_serialize(Job *j, FILE *f, FDSet *fds) {
|
|||||||
fprintf(f, "job-ignore-order=%s\n", yes_no(j->ignore_order));
|
fprintf(f, "job-ignore-order=%s\n", yes_no(j->ignore_order));
|
||||||
|
|
||||||
if (j->begin_usec > 0)
|
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);
|
||||||
|
|
||||||
|
@ -170,12 +170,12 @@ static int killall(int sig, Set *pids, bool send_sighup) {
|
|||||||
_cleanup_free_ char *s;
|
_cleanup_free_ char *s;
|
||||||
|
|
||||||
get_process_comm(pid, &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 (kill(pid, sig) >= 0) {
|
||||||
if (pids)
|
if (pids)
|
||||||
set_put(pids, ULONG_TO_PTR((unsigned long) pid));
|
set_put(pids, ULONG_TO_PTR(pid));
|
||||||
} else if (errno != ENOENT)
|
} else if (errno != ENOENT)
|
||||||
log_warning("Could not kill %d: %m", pid);
|
log_warning("Could not kill %d: %m", pid);
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ noreturn static void crash(int sig) {
|
|||||||
else if (status.si_code != CLD_DUMPED)
|
else if (status.si_code != CLD_DUMPED)
|
||||||
log_error("Caught <%s>, core dump failed.", signal_to_string(sig));
|
log_error("Caught <%s>, core dump failed.", signal_to_string(sig));
|
||||||
else
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,7 +197,7 @@ noreturn static void crash(int sig) {
|
|||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
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.");
|
||||||
@ -1865,7 +1865,7 @@ finish:
|
|||||||
watchdog_close(false);
|
watchdog_close(false);
|
||||||
|
|
||||||
/* Tell the binary how often to ping */
|
/* 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);
|
char_array_0(e);
|
||||||
|
|
||||||
env_block = strv_append(environ, e);
|
env_block = strv_append(environ, e);
|
||||||
|
@ -1334,7 +1334,7 @@ static int manager_dispatch_notify_fd(sd_event_source *source, int fd, uint32_t
|
|||||||
if (!u) {
|
if (!u) {
|
||||||
u = manager_get_unit_by_pid(m, ucred->pid);
|
u = manager_get_unit_by_pid(m, ucred->pid);
|
||||||
if (!u) {
|
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);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1382,7 +1382,7 @@ static int manager_dispatch_sigchld(Manager *m) {
|
|||||||
_cleanup_free_ char *name = NULL;
|
_cleanup_free_ char *name = NULL;
|
||||||
|
|
||||||
get_process_comm(si.si_pid, &name);
|
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 */
|
||||||
@ -1470,9 +1470,9 @@ static int manager_dispatch_signal_fd(sd_event_source *source, int fd, uint32_t
|
|||||||
log_full(sfsi.ssi_signo == SIGCHLD ||
|
log_full(sfsi.ssi_signo == SIGCHLD ||
|
||||||
(sfsi.ssi_signo == SIGTERM && m->running_as == SYSTEMD_USER)
|
(sfsi.ssi_signo == SIGTERM && m->running_as == SYSTEMD_USER)
|
||||||
? LOG_DEBUG : LOG_INFO,
|
? 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
|
} else
|
||||||
log_full(sfsi.ssi_signo == SIGCHLD ||
|
log_full(sfsi.ssi_signo == SIGCHLD ||
|
||||||
(sfsi.ssi_signo == SIGTERM && m->running_as == SYSTEMD_USER)
|
(sfsi.ssi_signo == SIGTERM && m->running_as == SYSTEMD_USER)
|
||||||
@ -1974,9 +1974,9 @@ int manager_open_serialization(Manager *m, FILE **_f) {
|
|||||||
assert(_f);
|
assert(_f);
|
||||||
|
|
||||||
if (m->running_as == SYSTEMD_SYSTEM)
|
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());
|
||||||
else
|
else
|
||||||
asprintf(&path, "/tmp/systemd-dump-%lu-XXXXXX", (unsigned long) getpid());
|
asprintf(&path, "/tmp/systemd-dump-"PID_FMT"-XXXXXX", getpid());
|
||||||
|
|
||||||
if (!path)
|
if (!path)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
@ -2454,9 +2454,9 @@ void manager_check_finished(Manager *m) {
|
|||||||
if (!log_on_console())
|
if (!log_on_console())
|
||||||
log_struct(LOG_INFO,
|
log_struct(LOG_INFO,
|
||||||
MESSAGE_ID(SD_MESSAGE_STARTUP_FINISHED),
|
MESSAGE_ID(SD_MESSAGE_STARTUP_FINISHED),
|
||||||
"KERNEL_USEC=%llu", (unsigned long long) kernel_usec,
|
"KERNEL_USEC="USEC_FMT, kernel_usec,
|
||||||
"INITRD_USEC=%llu", (unsigned long long) initrd_usec,
|
"INITRD_USEC="USEC_FMT, initrd_usec,
|
||||||
"USERSPACE_USEC=%llu", (unsigned long long) userspace_usec,
|
"USERSPACE_USEC="USEC_FMT, userspace_usec,
|
||||||
"MESSAGE=Startup finished in %s (kernel) + %s (initrd) + %s (userspace) = %s.",
|
"MESSAGE=Startup finished in %s (kernel) + %s (initrd) + %s (userspace) = %s.",
|
||||||
format_timespan(kernel, sizeof(kernel), kernel_usec, USEC_PER_MSEC),
|
format_timespan(kernel, sizeof(kernel), kernel_usec, USEC_PER_MSEC),
|
||||||
format_timespan(initrd, sizeof(initrd), initrd_usec, USEC_PER_MSEC),
|
format_timespan(initrd, sizeof(initrd), initrd_usec, USEC_PER_MSEC),
|
||||||
@ -2470,8 +2470,8 @@ void manager_check_finished(Manager *m) {
|
|||||||
if (!log_on_console())
|
if (!log_on_console())
|
||||||
log_struct(LOG_INFO,
|
log_struct(LOG_INFO,
|
||||||
MESSAGE_ID(SD_MESSAGE_STARTUP_FINISHED),
|
MESSAGE_ID(SD_MESSAGE_STARTUP_FINISHED),
|
||||||
"KERNEL_USEC=%llu", (unsigned long long) kernel_usec,
|
"KERNEL_USEC="USEC_FMT, kernel_usec,
|
||||||
"USERSPACE_USEC=%llu", (unsigned long long) userspace_usec,
|
"USERSPACE_USEC="USEC_FMT, userspace_usec,
|
||||||
"MESSAGE=Startup finished in %s (kernel) + %s (userspace) = %s.",
|
"MESSAGE=Startup finished in %s (kernel) + %s (userspace) = %s.",
|
||||||
format_timespan(kernel, sizeof(kernel), kernel_usec, USEC_PER_MSEC),
|
format_timespan(kernel, sizeof(kernel), kernel_usec, USEC_PER_MSEC),
|
||||||
format_timespan(userspace, sizeof(userspace), userspace_usec, USEC_PER_MSEC),
|
format_timespan(userspace, sizeof(userspace), userspace_usec, USEC_PER_MSEC),
|
||||||
@ -2485,7 +2485,7 @@ void manager_check_finished(Manager *m) {
|
|||||||
if (!log_on_console())
|
if (!log_on_console())
|
||||||
log_struct(LOG_INFO,
|
log_struct(LOG_INFO,
|
||||||
MESSAGE_ID(SD_MESSAGE_STARTUP_FINISHED),
|
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.",
|
"MESSAGE=Startup finished in %s.",
|
||||||
format_timespan(sum, sizeof(sum), total_usec, USEC_PER_MSEC),
|
format_timespan(sum, sizeof(sum), total_usec, USEC_PER_MSEC),
|
||||||
NULL);
|
NULL);
|
||||||
|
@ -750,8 +750,8 @@ static void mount_dump(Unit *u, FILE *f, const char *prefix) {
|
|||||||
|
|
||||||
if (m->control_pid > 0)
|
if (m->control_pid > 0)
|
||||||
fprintf(f,
|
fprintf(f,
|
||||||
"%sControl PID: %lu\n",
|
"%sControl PID: "PID_FMT"\n",
|
||||||
prefix, (unsigned long) m->control_pid);
|
prefix, m->control_pid);
|
||||||
|
|
||||||
exec_context_dump(&m->exec_context, f, prefix);
|
exec_context_dump(&m->exec_context, f, prefix);
|
||||||
kill_context_dump(&m->kill_context, f, prefix);
|
kill_context_dump(&m->kill_context, f, prefix);
|
||||||
@ -1093,7 +1093,7 @@ static int mount_serialize(Unit *u, FILE *f, FDSet *fds) {
|
|||||||
unit_serialize_item(u, f, "reload-result", mount_result_to_string(m->reload_result));
|
unit_serialize_item(u, f, "reload-result", mount_result_to_string(m->reload_result));
|
||||||
|
|
||||||
if (m->control_pid > 0)
|
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)
|
if (m->control_command_id >= 0)
|
||||||
unit_serialize_item(u, f, "control-command", mount_exec_command_to_string(m->control_command_id));
|
unit_serialize_item(u, f, "control-command", mount_exec_command_to_string(m->control_command_id));
|
||||||
|
@ -210,8 +210,8 @@ static int service_set_main_pid(Service *s, pid_t pid) {
|
|||||||
|
|
||||||
if (get_parent_of_pid(pid, &ppid) >= 0 && ppid != getpid()) {
|
if (get_parent_of_pid(pid, &ppid) >= 0 && ppid != getpid()) {
|
||||||
log_warning_unit(UNIT(s)->id,
|
log_warning_unit(UNIT(s)->id,
|
||||||
"%s: Supervising process %lu which is not our child. We'll most likely not notice when it exits.",
|
"%s: Supervising process "PID_FMT" which is not our child. We'll most likely not notice when it exits.",
|
||||||
UNIT(s)->id, (unsigned long) pid);
|
UNIT(s)->id, pid);
|
||||||
|
|
||||||
s->main_pid_alien = true;
|
s->main_pid_alien = true;
|
||||||
} else
|
} else
|
||||||
@ -1309,15 +1309,15 @@ static void service_dump(Unit *u, FILE *f, const char *prefix) {
|
|||||||
|
|
||||||
if (s->control_pid > 0)
|
if (s->control_pid > 0)
|
||||||
fprintf(f,
|
fprintf(f,
|
||||||
"%sControl PID: %lu\n",
|
"%sControl PID: "PID_FMT"\n",
|
||||||
prefix, (unsigned long) s->control_pid);
|
prefix, s->control_pid);
|
||||||
|
|
||||||
if (s->main_pid > 0)
|
if (s->main_pid > 0)
|
||||||
fprintf(f,
|
fprintf(f,
|
||||||
"%sMain PID: %lu\n"
|
"%sMain PID: "PID_FMT"\n"
|
||||||
"%sMain PID Known: %s\n"
|
"%sMain PID Known: %s\n"
|
||||||
"%sMain PID Alien: %s\n",
|
"%sMain PID Alien: %s\n",
|
||||||
prefix, (unsigned long) s->main_pid,
|
prefix, s->main_pid,
|
||||||
prefix, yes_no(s->main_pid_known),
|
prefix, yes_no(s->main_pid_known),
|
||||||
prefix, yes_no(s->main_pid_alien));
|
prefix, yes_no(s->main_pid_alien));
|
||||||
|
|
||||||
@ -1401,8 +1401,8 @@ static int service_load_pid_file(Service *s, bool may_warn) {
|
|||||||
if (kill(pid, 0) < 0 && errno != EPERM) {
|
if (kill(pid, 0) < 0 && errno != EPERM) {
|
||||||
if (may_warn)
|
if (may_warn)
|
||||||
log_info_unit(UNIT(s)->id,
|
log_info_unit(UNIT(s)->id,
|
||||||
"PID %lu read from file %s does not exist.",
|
"PID "PID_FMT" read from file %s does not exist.",
|
||||||
(unsigned long) pid, s->pid_file);
|
pid, s->pid_file);
|
||||||
return -ESRCH;
|
return -ESRCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1411,13 +1411,13 @@ static int service_load_pid_file(Service *s, bool may_warn) {
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
log_debug_unit(UNIT(s)->id,
|
log_debug_unit(UNIT(s)->id,
|
||||||
"Main PID changing: %lu -> %lu",
|
"Main PID changing: "PID_FMT" -> "PID_FMT,
|
||||||
(unsigned long) s->main_pid, (unsigned long) pid);
|
s->main_pid, pid);
|
||||||
service_unwatch_main_pid(s);
|
service_unwatch_main_pid(s);
|
||||||
s->main_pid_known = false;
|
s->main_pid_known = false;
|
||||||
} else
|
} else
|
||||||
log_debug_unit(UNIT(s)->id,
|
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);
|
r = service_set_main_pid(s, pid);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
@ -1427,8 +1427,8 @@ static int service_load_pid_file(Service *s, bool may_warn) {
|
|||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
/* FIXME: we need to do something here */
|
/* FIXME: we need to do something here */
|
||||||
log_warning_unit(UNIT(s)->id,
|
log_warning_unit(UNIT(s)->id,
|
||||||
"Failed to watch PID %lu from service %s",
|
"Failed to watch PID "PID_FMT" from service %s",
|
||||||
(unsigned long) pid, UNIT(s)->id);
|
pid, UNIT(s)->id);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1456,7 +1456,7 @@ static int service_search_main_pid(Service *s) {
|
|||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
|
||||||
log_debug_unit(UNIT(s)->id,
|
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);
|
r = service_set_main_pid(s, pid);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
@ -1465,8 +1465,8 @@ static int service_search_main_pid(Service *s) {
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
/* FIXME: we need to do something here */
|
/* FIXME: we need to do something here */
|
||||||
log_warning_unit(UNIT(s)->id,
|
log_warning_unit(UNIT(s)->id,
|
||||||
"Failed to watch PID %lu from service %s",
|
"Failed to watch PID "PID_FMT" from service %s",
|
||||||
(unsigned long) pid, UNIT(s)->id);
|
pid, UNIT(s)->id);
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -1763,13 +1763,13 @@ static int service_spawn(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (s->main_pid > 0)
|
if (s->main_pid > 0)
|
||||||
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;
|
r = -ENOMEM;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UNIT(s)->manager->running_as != SYSTEMD_SYSTEM)
|
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;
|
r = -ENOMEM;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
@ -2562,11 +2562,11 @@ static int service_serialize(Unit *u, FILE *f, FDSet *fds) {
|
|||||||
unit_serialize_item(u, f, "reload-result", service_result_to_string(s->reload_result));
|
unit_serialize_item(u, f, "reload-result", service_result_to_string(s->reload_result));
|
||||||
|
|
||||||
if (s->control_pid > 0)
|
if (s->control_pid > 0)
|
||||||
unit_serialize_item_format(u, f, "control-pid", "%lu",
|
unit_serialize_item_format(u, f, "control-pid", PID_FMT,
|
||||||
(unsigned long) s->control_pid);
|
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));
|
||||||
|
|
||||||
@ -2590,8 +2590,8 @@ static int service_serialize(Unit *u, FILE *f, FDSet *fds) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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",
|
unit_serialize_item_format(u, f, "main-exec-status-pid", PID_FMT,
|
||||||
(unsigned long) s->main_exec_status.pid);
|
s->main_exec_status.pid);
|
||||||
dual_timestamp_serialize(f, "main-exec-status-start",
|
dual_timestamp_serialize(f, "main-exec-status-start",
|
||||||
&s->main_exec_status.start_timestamp);
|
&s->main_exec_status.start_timestamp);
|
||||||
dual_timestamp_serialize(f, "main-exec-status-exit",
|
dual_timestamp_serialize(f, "main-exec-status-exit",
|
||||||
@ -3343,20 +3343,20 @@ static void service_notify_message(Unit *u, pid_t pid, char **tags) {
|
|||||||
|
|
||||||
assert(u);
|
assert(u);
|
||||||
|
|
||||||
log_debug_unit(u->id, "%s: Got notification message from PID %lu (%s...)",
|
log_debug_unit(u->id, "%s: Got notification message from PID "PID_FMT" (%s...)",
|
||||||
u->id, (unsigned long) pid, tags && *tags ? tags[0] : "(empty)");
|
u->id, pid, tags && *tags ? tags[0] : "(empty)");
|
||||||
|
|
||||||
if (s->notify_access == NOTIFY_NONE) {
|
if (s->notify_access == NOTIFY_NONE) {
|
||||||
log_warning_unit(u->id,
|
log_warning_unit(u->id,
|
||||||
"%s: Got notification message from PID %lu, but reception is disabled.",
|
"%s: Got notification message from PID "PID_FMT", but reception is disabled.",
|
||||||
u->id, (unsigned long) pid);
|
u->id, pid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->notify_access == NOTIFY_MAIN && s->main_pid != 0 && pid != s->main_pid) {
|
if (s->notify_access == NOTIFY_MAIN && s->main_pid != 0 && pid != s->main_pid) {
|
||||||
log_warning_unit(u->id,
|
log_warning_unit(u->id,
|
||||||
"%s: Got notification message from PID %lu, but reception only permitted for PID %lu",
|
"%s: Got notification message from PID "PID_FMT", but reception only permitted for PID "PID_FMT,
|
||||||
u->id, (unsigned long) pid, (unsigned long) s->main_pid);
|
u->id, pid, s->main_pid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,9 @@
|
|||||||
typedef uint64_t usec_t;
|
typedef uint64_t usec_t;
|
||||||
typedef uint64_t nsec_t;
|
typedef uint64_t nsec_t;
|
||||||
|
|
||||||
|
#define NSEC_FMT "%" PRIu64
|
||||||
|
#define USEC_FMT "%" PRIu64
|
||||||
|
|
||||||
#include "macro.h"
|
#include "macro.h"
|
||||||
|
|
||||||
typedef struct dual_timestamp {
|
typedef struct dual_timestamp {
|
||||||
|
@ -42,6 +42,22 @@
|
|||||||
#include <mntent.h>
|
#include <mntent.h>
|
||||||
#include <sys/socket.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 "macro.h"
|
||||||
#include "time-util.h"
|
#include "time-util.h"
|
||||||
|
|
||||||
@ -763,7 +779,7 @@ int unlink_noerrno(const char *path);
|
|||||||
pid_t _pid_ = (pid); \
|
pid_t _pid_ = (pid); \
|
||||||
char *_r_; \
|
char *_r_; \
|
||||||
_r_ = alloca(sizeof("/proc/") -1 + DECIMAL_STR_MAX(pid_t) + 1 + sizeof(field)); \
|
_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_); \
|
||||||
_r_; \
|
_r_; \
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user