diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2020-01-30 23:25:12 +0900 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2020-02-02 17:13:08 +0100 |
commit | 60d0a5098b2b58c105d86e4eacad691a3bef8ffd (patch) | |
tree | 5fccea5838a583934de1cfdfce20c5e29aa9f7ec | |
parent | c757517d98ade27b9938635afb52e5621da9f1cb (diff) | |
download | systemd-60d0a5098b2b58c105d86e4eacad691a3bef8ffd.tar.gz |
util: uid_t, gid_t, and pid_t must be 32bit
We already have assert_cc(sizeof(uid_t) == sizeof(uint32_t)) or friends
at various places.
-rw-r--r-- | meson.build | 3 | ||||
-rw-r--r-- | src/basic/format-util.h | 29 | ||||
-rw-r--r-- | src/basic/process-util.h | 7 | ||||
-rw-r--r-- | src/core/dbus-manager.c | 2 | ||||
-rw-r--r-- | src/test/test-process-util.c | 2 |
5 files changed, 9 insertions, 34 deletions
diff --git a/meson.build b/meson.build index 9468b67109..184dbf5d24 100644 --- a/meson.build +++ b/meson.build @@ -449,9 +449,6 @@ conf.set('_GNU_SOURCE', true) conf.set('__SANE_USERSPACE_TYPES__', true) conf.set10('HAVE_WSTRINGOP_TRUNCATION', has_wstringop_truncation) -conf.set('SIZEOF_PID_T', cc.sizeof('pid_t', prefix : '#include <sys/types.h>')) -conf.set('SIZEOF_UID_T', cc.sizeof('uid_t', prefix : '#include <sys/types.h>')) -conf.set('SIZEOF_GID_T', cc.sizeof('gid_t', prefix : '#include <sys/types.h>')) conf.set('SIZEOF_DEV_T', cc.sizeof('dev_t', prefix : '#include <sys/types.h>')) conf.set('SIZEOF_INO_T', cc.sizeof('ino_t', prefix : '#include <sys/types.h>')) conf.set('SIZEOF_TIME_T', cc.sizeof('time_t', prefix : '#include <sys/time.h>')) diff --git a/src/basic/format-util.h b/src/basic/format-util.h index 59622508a3..29fbc947b3 100644 --- a/src/basic/format-util.h +++ b/src/basic/format-util.h @@ -5,30 +5,17 @@ #include <net/if.h> #include <stdbool.h> -#if SIZEOF_PID_T == 4 -# define PID_PRI PRIi32 -#elif SIZEOF_PID_T == 2 -# define PID_PRI PRIi16 -#else -# error Unknown pid_t size -#endif +#include "macro.h" + +assert_cc(sizeof(pid_t) == sizeof(int32_t)); +#define PID_PRI PRIi32 #define PID_FMT "%" PID_PRI -#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 +assert_cc(sizeof(uid_t) == sizeof(uint32_t)); +#define UID_FMT "%" PRIu32 -#if SIZEOF_GID_T == 4 -# define GID_FMT "%" PRIu32 -#elif SIZEOF_GID_T == 2 -# define GID_FMT "%" PRIu16 -#else -# error Unknown gid_t size -#endif +assert_cc(sizeof(gid_t) == sizeof(uint32_t)); +#define GID_FMT "%" PRIu32 #if SIZEOF_TIME_T == 8 # define PRI_TIME PRIi64 diff --git a/src/basic/process-util.h b/src/basic/process-util.h index a238b25796..4160af45ba 100644 --- a/src/basic/process-util.h +++ b/src/basic/process-util.h @@ -172,7 +172,6 @@ int fork_agent(const char *name, const int except[], size_t n_except, pid_t *pid int set_oom_score_adjust(int value); -#if SIZEOF_PID_T == 4 /* The highest possibly (theoretic) pid_t value on this architecture. */ #define PID_T_MAX ((pid_t) INT32_MAX) /* The maximum number of concurrent processes Linux allows on this architecture, as well as the highest valid PID value @@ -182,12 +181,6 @@ int set_oom_score_adjust(int value); * these values are documented in proc(5) we feel quite confident that they are stable enough for the near future at * least to define them here too. */ #define TASKS_MAX 4194303U -#elif SIZEOF_PID_T == 2 -#define PID_T_MAX ((pid_t) INT16_MAX) -#define TASKS_MAX 32767U -#else -#error "Unknown pid_t size" -#endif assert_cc(TASKS_MAX <= (unsigned long) PID_T_MAX); diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index c751e84253..b45d51f613 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -1663,7 +1663,7 @@ static int method_lookup_dynamic_user_by_uid(sd_bus_message *message, void *user assert(message); assert(m); - assert_cc(sizeof(uid) == sizeof(uint32_t)); + assert_cc(sizeof(uid_t) == sizeof(uint32_t)); r = sd_bus_message_read_basic(message, 'u', &uid); if (r < 0) return r; diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c index 4a3f211658..d78e0544a7 100644 --- a/src/test/test-process-util.c +++ b/src/test/test-process-util.c @@ -572,10 +572,8 @@ static void test_pid_to_ptr(void) { assert_se(PTR_TO_PID(PID_TO_PTR(INT16_MAX)) == INT16_MAX); assert_se(PTR_TO_PID(PID_TO_PTR(INT16_MIN)) == INT16_MIN); -#if SIZEOF_PID_T >= 4 assert_se(PTR_TO_PID(PID_TO_PTR(INT32_MAX)) == INT32_MAX); assert_se(PTR_TO_PID(PID_TO_PTR(INT32_MIN)) == INT32_MIN); -#endif } static void test_ioprio_class_from_to_string_one(const char *val, int expected) { |