blob: a6fcd2f5dae2cf813a5a6a0b48d4105b2b627e63 [file] [log] [blame]
Andrew Geissler706d5aa2021-02-12 15:55:30 -06001From 4aa91347ae975051dbe4dd2f98a1f4f459f2604f Mon Sep 17 00:00:00 2001
Brad Bishop19323692019-04-05 15:28:33 -04002From: Chen Qi <Qi.Chen@windriver.com>
3Date: Mon, 25 Feb 2019 15:12:41 +0800
Andrew Geissler706d5aa2021-02-12 15:55:30 -06004Subject: [PATCH] Use uintmax_t for handling rlim_t
Brad Bishop19323692019-04-05 15:28:33 -04005
6PRIu{32,64} is not right format to represent rlim_t type
7therefore use %ju and typecast the rlim_t variables to
8uintmax_t.
9
10Fixes portablility errors like
11
12execute.c:3446:36: error: format '%lu' expects argument of type 'long unsigned int', but argument 5 has type 'rlim_t {aka long long unsigned int}' [-Werror=format=]
13| fprintf(f, "%s%s: " RLIM_FMT "\n",
14| ^~~~~~~~
15| prefix, rlimit_to_string(i), c->rlimit[i]->rlim_max);
16| ~~~~~~~~~~~~~~~~~~~~~~
17
18Upstream-Status: Denied [https://github.com/systemd/systemd/pull/7199]
19
20Signed-off-by: Khem Raj <raj.khem@gmail.com>
21[Rebased for v241]
22Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
Andrew Geissler706d5aa2021-02-12 15:55:30 -060023
Brad Bishop19323692019-04-05 15:28:33 -040024---
25 src/basic/format-util.h | 8 +-------
26 src/basic/rlimit-util.c | 10 +++++-----
27 src/core/execute.c | 4 ++--
28 3 files changed, 8 insertions(+), 14 deletions(-)
29
Andrew Geissler706d5aa2021-02-12 15:55:30 -060030Index: systemd-stable/src/basic/format-util.h
31===================================================================
32--- systemd-stable.orig/src/basic/format-util.h
33+++ systemd-stable/src/basic/format-util.h
34@@ -32,13 +32,7 @@ assert_cc(sizeof(gid_t) == sizeof(uint32
Brad Bishop19323692019-04-05 15:28:33 -040035 # define PRI_TIMEX "li"
36 #endif
37
38-#if SIZEOF_RLIM_T == 8
39-# define RLIM_FMT "%" PRIu64
40-#elif SIZEOF_RLIM_T == 4
41-# define RLIM_FMT "%" PRIu32
42-#else
43-# error Unknown rlim_t size
44-#endif
45+#define RLIM_FMT "%ju"
46
47 #if SIZEOF_DEV_T == 8
48 # define DEV_FMT "%" PRIu64
Andrew Geissler706d5aa2021-02-12 15:55:30 -060049Index: systemd-stable/src/basic/rlimit-util.c
50===================================================================
51--- systemd-stable.orig/src/basic/rlimit-util.c
52+++ systemd-stable/src/basic/rlimit-util.c
53@@ -306,13 +306,13 @@ int rlimit_format(const struct rlimit *r
Brad Bishop19323692019-04-05 15:28:33 -040054 if (rl->rlim_cur >= RLIM_INFINITY && rl->rlim_max >= RLIM_INFINITY)
55 s = strdup("infinity");
56 else if (rl->rlim_cur >= RLIM_INFINITY)
57- (void) asprintf(&s, "infinity:" RLIM_FMT, rl->rlim_max);
58+ (void) asprintf(&s, "infinity:" RLIM_FMT, (uintmax_t)rl->rlim_max);
59 else if (rl->rlim_max >= RLIM_INFINITY)
60- (void) asprintf(&s, RLIM_FMT ":infinity", rl->rlim_cur);
61+ (void) asprintf(&s, RLIM_FMT ":infinity", (uintmax_t)rl->rlim_cur);
62 else if (rl->rlim_cur == rl->rlim_max)
63- (void) asprintf(&s, RLIM_FMT, rl->rlim_cur);
64+ (void) asprintf(&s, RLIM_FMT, (uintmax_t)rl->rlim_cur);
65 else
66- (void) asprintf(&s, RLIM_FMT ":" RLIM_FMT, rl->rlim_cur, rl->rlim_max);
67+ (void) asprintf(&s, RLIM_FMT ":" RLIM_FMT, (uintmax_t)rl->rlim_cur, (uintmax_t)rl->rlim_max);
68
69 if (!s)
70 return -ENOMEM;
Andrew Geissler82c905d2020-04-13 13:39:40 -050071@@ -403,7 +403,7 @@ int rlimit_nofile_safe(void) {
Brad Bishop19323692019-04-05 15:28:33 -040072
73 rl.rlim_cur = FD_SETSIZE;
74 if (setrlimit(RLIMIT_NOFILE, &rl) < 0)
75- return log_debug_errno(errno, "Failed to lower RLIMIT_NOFILE's soft limit to " RLIM_FMT ": %m", rl.rlim_cur);
76+ return log_debug_errno(errno, "Failed to lower RLIMIT_NOFILE's soft limit to " RLIM_FMT ": %m", (uintmax_t)rl.rlim_cur);
77
78 return 1;
79 }
Andrew Geissler706d5aa2021-02-12 15:55:30 -060080Index: systemd-stable/src/core/execute.c
81===================================================================
82--- systemd-stable.orig/src/core/execute.c
83+++ systemd-stable/src/core/execute.c
84@@ -4686,9 +4686,9 @@ void exec_context_dump(const ExecContext
85 for (i = 0; i < RLIM_NLIMITS; i++)
Brad Bishop19323692019-04-05 15:28:33 -040086 if (c->rlimit[i]) {
87 fprintf(f, "%sLimit%s: " RLIM_FMT "\n",
88- prefix, rlimit_to_string(i), c->rlimit[i]->rlim_max);
89+ prefix, rlimit_to_string(i), (uintmax_t)c->rlimit[i]->rlim_max);
90 fprintf(f, "%sLimit%sSoft: " RLIM_FMT "\n",
91- prefix, rlimit_to_string(i), c->rlimit[i]->rlim_cur);
92+ prefix, rlimit_to_string(i), (uintmax_t)c->rlimit[i]->rlim_cur);
93 }
94
95 if (c->ioprio_set) {