chiark / gitweb /
Remove unnecessary casts in printfs
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 25 Apr 2014 11:45:15 +0000 (07:45 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 15 May 2014 13:29:58 +0000 (15:29 +0200)
No functional change expected :)

64 files changed:
configure.ac
src/core/condition.c
src/core/dbus-scope.c
src/core/execute.c
src/core/socket.c
src/core/swap.c
src/core/unit-printf.c
src/dbus1-generator/dbus1-generator.c
src/initctl/initctl.c
src/journal/journal-remote.c
src/journal/journald-console.c
src/journal/journald-kmsg.c
src/journal/journald-server.c
src/journal/journald-syslog.c
src/journal/journald.c
src/journal/sd-journal.c
src/libsystemd/sd-bus/bus-creds.c
src/libsystemd/sd-bus/bus-dump.c
src/libsystemd/sd-bus/bus-kernel.c
src/libsystemd/sd-bus/bus-socket.c
src/libsystemd/sd-bus/bus-util.c
src/libsystemd/sd-bus/sd-bus.c
src/libsystemd/sd-bus/test-bus-chat.c
src/libsystemd/sd-bus/test-bus-marshal.c
src/libsystemd/sd-login/sd-login.c
src/libsystemd/sd-login/test-login.c
src/libudev/libudev-device-private.c
src/libudev/libudev-device.c
src/libudev/libudev-hwdb.c
src/login/inhibit.c
src/login/logind-action.c
src/login/logind-dbus.c
src/login/logind-inhibit.c
src/login/logind-session.c
src/login/logind-user-dbus.c
src/login/logind-user.c
src/login/logind.c
src/login/pam-module.c
src/login/test-inhibit.c
src/machine/machine.c
src/machine/machined-dbus.c
src/machine/machined.c
src/notify/notify.c
src/readahead/readahead-common.c
src/run/run.c
src/shared/ask-password-api.c
src/shared/cgroup-util.c
src/shared/def.h
src/shared/log.c
src/shared/logs-show.c
src/shared/socket-util.c
src/shared/time-util.c
src/shared/util.c
src/shared/util.h
src/shutdownd/shutdownd.c
src/systemctl/systemctl.c
src/test/test-cgroup-util.c
src/test/test-log.c
src/test/test-time.c
src/test/test-util.c
src/timedate/timedated.c
src/udev/udev-builtin-blkid.c
src/udev/udevadm-monitor.c
src/update-utmp/update-utmp.c

index 972fc2f..c3653e3 100644 (file)
@@ -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
index 1448fa1..2468458 100644 (file)
@@ -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);
index b9e3be4..fbb4ff5 100644 (file)
@@ -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)
index 4a3aeda..af8e7c7 100644 (file)
@@ -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;
index 536904f..05af8fe 100644 (file)
@@ -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));
index 10eed6d..9f353af 100644 (file)
@@ -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));
index d16d856..5bd30f0 100644 (file)
@@ -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)
index b3dedb7..95962c7 100644 (file)
@@ -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);
                         }
                 }
 
index f9613ea..f9a6ed4 100644 (file)
@@ -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,
index ec4054f..9adad7a 100644 (file)
@@ -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...");
index 3db5fc5..6ec2528 100644 (file)
@@ -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)
index 35948ea..12992e7 100644 (file)
@@ -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)
index 6da81e7..0439caf 100644 (file)
@@ -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);
                         }
 
index fee7d91..434eac4 100644 (file)
@@ -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)
index 7665009..886ac92 100644 (file)
@@ -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:
index 7587211..11de8ef 100644 (file)
@@ -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))
index 3da77cf..26c2545 100644 (file)
@@ -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);
index 6f4ce0c..8b70b20 100644 (file)
@@ -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)
index af42b9f..8bab6ad 100644 (file)
@@ -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)
index 2e8f008..d124d9a 100644 (file)
@@ -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);
index b5b3c85..6220934 100644 (file)
@@ -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;
index ea80e9d..de947bf 100644 (file)
@@ -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
index c9eb698..d5903f4 100644 (file)
@@ -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); */
index 2321873..2be4de5 100644 (file)
@@ -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
index 39445a1..e7eea19 100644 (file)
@@ -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,
index 9e326de..ccf2c95 100644 (file)
@@ -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);
 
index cb4947f..637d064 100644 (file)
@@ -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))
index 9f80f56..3a64f24 100644 (file)
@@ -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);
 }
 
index ff34e5a..e0d4d7c 100644 (file)
@@ -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));
index ae3afdf..24e8fb0 100644 (file)
@@ -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);
index 1928f43..ae9cd48 100644 (file)
@@ -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;
index 0af6714..1a363c2 100644 (file)
@@ -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 */
index 8b329ab..64a62ff 100644 (file)
@@ -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)
index 8e6f95e..4fb229e 100644 (file)
@@ -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);
 
index 4f1a079..6266ccb 100644 (file)
@@ -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;
index 961cbcb..5fffa65 100644 (file)
@@ -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)
index 686506c..7a7bd97 100644 (file)
@@ -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,
index 1259457..262621d 100644 (file)
@@ -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,
index 70780c3..21d2339 100644 (file)
@@ -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++;
         }
index 9a5cc9a..1164ce8 100644 (file)
@@ -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);
 
index 9473105..a32d7f5 100644 (file)
@@ -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)
index 45768d2..6160320 100644 (file)
@@ -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,
index a145b8f..68133c4 100644 (file)
@@ -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;
                 }
index 49679fc..890886e 100644 (file)
@@ -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;
         }
index e3b040d..e4c695c 100644 (file)
@@ -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();
 
index c3c78b6..5997a03 100644 (file)
@@ -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);
index 139888c..c1c4d40 100644 (file)
@@ -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);
 }
index aa489d8..a52853c 100644 (file)
@@ -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
index a4b3b68..9039db3 100644 (file)
@@ -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);
index b0b66f6..72c9ad2 100644 (file)
@@ -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 */
index 5ef2e22..997a1ce 100644 (file)
@@ -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;
index eb5c1ae..c667638 100644 (file)
@@ -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) {
index d1dc476..020c1da 100644 (file)
@@ -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;
index 891fcee..f2ce4f0 100644 (file)
 #  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"
 
index 578920c..25427d6 100644 (file)
@@ -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:
 
index a60a301..b13b273 100644 (file)
@@ -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;
         }
 
index b37468b..fda8bcc 100644 (file)
@@ -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,
index 8dc3d53..ca64004 100644 (file)
@@ -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",
index 36a3304..7c29f96 100644 (file)
@@ -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;
index caf8d2b..2b46699 100644 (file)
@@ -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);
index 1b09380..3e0f70c 100644 (file)
@@ -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);
 
index db652f7..cf194c0 100644 (file)
@@ -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)
index b2f7f6b..a54aa82 100644 (file)
@@ -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));
index e5fb5f8..31cae70 100644 (file)
@@ -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