X Tutup
Skip to content

Commit 60d0a50

Browse files
yuwatapoettering
authored andcommitted
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.
1 parent c757517 commit 60d0a50

File tree

5 files changed

+9
-34
lines changed

5 files changed

+9
-34
lines changed

meson.build

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,6 @@ conf.set('_GNU_SOURCE', true)
449449
conf.set('__SANE_USERSPACE_TYPES__', true)
450450
conf.set10('HAVE_WSTRINGOP_TRUNCATION', has_wstringop_truncation)
451451

452-
conf.set('SIZEOF_PID_T', cc.sizeof('pid_t', prefix : '#include <sys/types.h>'))
453-
conf.set('SIZEOF_UID_T', cc.sizeof('uid_t', prefix : '#include <sys/types.h>'))
454-
conf.set('SIZEOF_GID_T', cc.sizeof('gid_t', prefix : '#include <sys/types.h>'))
455452
conf.set('SIZEOF_DEV_T', cc.sizeof('dev_t', prefix : '#include <sys/types.h>'))
456453
conf.set('SIZEOF_INO_T', cc.sizeof('ino_t', prefix : '#include <sys/types.h>'))
457454
conf.set('SIZEOF_TIME_T', cc.sizeof('time_t', prefix : '#include <sys/time.h>'))

src/basic/format-util.h

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,17 @@
55
#include <net/if.h>
66
#include <stdbool.h>
77

8-
#if SIZEOF_PID_T == 4
9-
# define PID_PRI PRIi32
10-
#elif SIZEOF_PID_T == 2
11-
# define PID_PRI PRIi16
12-
#else
13-
# error Unknown pid_t size
14-
#endif
8+
#include "macro.h"
9+
10+
assert_cc(sizeof(pid_t) == sizeof(int32_t));
11+
#define PID_PRI PRIi32
1512
#define PID_FMT "%" PID_PRI
1613

17-
#if SIZEOF_UID_T == 4
18-
# define UID_FMT "%" PRIu32
19-
#elif SIZEOF_UID_T == 2
20-
# define UID_FMT "%" PRIu16
21-
#else
22-
# error Unknown uid_t size
23-
#endif
14+
assert_cc(sizeof(uid_t) == sizeof(uint32_t));
15+
#define UID_FMT "%" PRIu32
2416

25-
#if SIZEOF_GID_T == 4
26-
# define GID_FMT "%" PRIu32
27-
#elif SIZEOF_GID_T == 2
28-
# define GID_FMT "%" PRIu16
29-
#else
30-
# error Unknown gid_t size
31-
#endif
17+
assert_cc(sizeof(gid_t) == sizeof(uint32_t));
18+
#define GID_FMT "%" PRIu32
3219

3320
#if SIZEOF_TIME_T == 8
3421
# define PRI_TIME PRIi64

src/basic/process-util.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ int fork_agent(const char *name, const int except[], size_t n_except, pid_t *pid
172172

173173
int set_oom_score_adjust(int value);
174174

175-
#if SIZEOF_PID_T == 4
176175
/* The highest possibly (theoretic) pid_t value on this architecture. */
177176
#define PID_T_MAX ((pid_t) INT32_MAX)
178177
/* 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);
182181
* these values are documented in proc(5) we feel quite confident that they are stable enough for the near future at
183182
* least to define them here too. */
184183
#define TASKS_MAX 4194303U
185-
#elif SIZEOF_PID_T == 2
186-
#define PID_T_MAX ((pid_t) INT16_MAX)
187-
#define TASKS_MAX 32767U
188-
#else
189-
#error "Unknown pid_t size"
190-
#endif
191184

192185
assert_cc(TASKS_MAX <= (unsigned long) PID_T_MAX);
193186

src/core/dbus-manager.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1663,7 +1663,7 @@ static int method_lookup_dynamic_user_by_uid(sd_bus_message *message, void *user
16631663
assert(message);
16641664
assert(m);
16651665

1666-
assert_cc(sizeof(uid) == sizeof(uint32_t));
1666+
assert_cc(sizeof(uid_t) == sizeof(uint32_t));
16671667
r = sd_bus_message_read_basic(message, 'u', &uid);
16681668
if (r < 0)
16691669
return r;

src/test/test-process-util.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,10 +572,8 @@ static void test_pid_to_ptr(void) {
572572
assert_se(PTR_TO_PID(PID_TO_PTR(INT16_MAX)) == INT16_MAX);
573573
assert_se(PTR_TO_PID(PID_TO_PTR(INT16_MIN)) == INT16_MIN);
574574

575-
#if SIZEOF_PID_T >= 4
576575
assert_se(PTR_TO_PID(PID_TO_PTR(INT32_MAX)) == INT32_MAX);
577576
assert_se(PTR_TO_PID(PID_TO_PTR(INT32_MIN)) == INT32_MIN);
578-
#endif
579577
}
580578

581579
static void test_ioprio_class_from_to_string_one(const char *val, int expected) {

0 commit comments

Comments
 (0)
X Tutup