blob: aeacd865aef92fa2014b0b883050076fcb78cf0f [file] [log] [blame]
Andrew Geisslerd1e89492021-02-12 15:35:20 -06001From e45bb02174812e4935214f42a18725be320770d5 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 Geisslerd1e89492021-02-12 15:35:20 -06004Subject: [PATCH 10/26] 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>
23---
24 src/basic/format-util.h | 8 +-------
25 src/basic/rlimit-util.c | 10 +++++-----
26 src/core/execute.c | 4 ++--
27 3 files changed, 8 insertions(+), 14 deletions(-)
28
Andrew Geisslerd1e89492021-02-12 15:35:20 -060029diff --git a/src/basic/format-util.h b/src/basic/format-util.h
30index b7e18768e3..3195ab205d 100644
31--- a/src/basic/format-util.h
32+++ b/src/basic/format-util.h
33@@ -32,13 +32,7 @@ assert_cc(sizeof(gid_t) == sizeof(uint32_t));
Brad Bishop19323692019-04-05 15:28:33 -040034 # define PRI_TIMEX "li"
35 #endif
36
37-#if SIZEOF_RLIM_T == 8
38-# define RLIM_FMT "%" PRIu64
39-#elif SIZEOF_RLIM_T == 4
40-# define RLIM_FMT "%" PRIu32
41-#else
42-# error Unknown rlim_t size
43-#endif
44+#define RLIM_FMT "%ju"
45
46 #if SIZEOF_DEV_T == 8
47 # define DEV_FMT "%" PRIu64
Andrew Geisslerd1e89492021-02-12 15:35:20 -060048diff --git a/src/basic/rlimit-util.c b/src/basic/rlimit-util.c
49index 880976312c..9e1b61cd4a 100644
50--- a/src/basic/rlimit-util.c
51+++ b/src/basic/rlimit-util.c
52@@ -306,13 +306,13 @@ int rlimit_format(const struct rlimit *rl, char **ret) {
Brad Bishop19323692019-04-05 15:28:33 -040053 if (rl->rlim_cur >= RLIM_INFINITY && rl->rlim_max >= RLIM_INFINITY)
54 s = strdup("infinity");
55 else if (rl->rlim_cur >= RLIM_INFINITY)
56- (void) asprintf(&s, "infinity:" RLIM_FMT, rl->rlim_max);
57+ (void) asprintf(&s, "infinity:" RLIM_FMT, (uintmax_t)rl->rlim_max);
58 else if (rl->rlim_max >= RLIM_INFINITY)
59- (void) asprintf(&s, RLIM_FMT ":infinity", rl->rlim_cur);
60+ (void) asprintf(&s, RLIM_FMT ":infinity", (uintmax_t)rl->rlim_cur);
61 else if (rl->rlim_cur == rl->rlim_max)
62- (void) asprintf(&s, RLIM_FMT, rl->rlim_cur);
63+ (void) asprintf(&s, RLIM_FMT, (uintmax_t)rl->rlim_cur);
64 else
65- (void) asprintf(&s, RLIM_FMT ":" RLIM_FMT, rl->rlim_cur, rl->rlim_max);
66+ (void) asprintf(&s, RLIM_FMT ":" RLIM_FMT, (uintmax_t)rl->rlim_cur, (uintmax_t)rl->rlim_max);
67
68 if (!s)
69 return -ENOMEM;
Andrew Geissler82c905d2020-04-13 13:39:40 -050070@@ -403,7 +403,7 @@ int rlimit_nofile_safe(void) {
Brad Bishop19323692019-04-05 15:28:33 -040071
72 rl.rlim_cur = FD_SETSIZE;
73 if (setrlimit(RLIMIT_NOFILE, &rl) < 0)
74- return log_debug_errno(errno, "Failed to lower RLIMIT_NOFILE's soft limit to " RLIM_FMT ": %m", rl.rlim_cur);
75+ return log_debug_errno(errno, "Failed to lower RLIMIT_NOFILE's soft limit to " RLIM_FMT ": %m", (uintmax_t)rl.rlim_cur);
76
77 return 1;
78 }
Andrew Geisslerd1e89492021-02-12 15:35:20 -060079diff --git a/src/core/execute.c b/src/core/execute.c
80index 89632e0582..335283776c 100644
81--- a/src/core/execute.c
82+++ b/src/core/execute.c
83@@ -5288,9 +5288,9 @@ void exec_context_dump(const ExecContext *c, FILE* f, const char *prefix) {
84 for (unsigned i = 0; i < RLIM_NLIMITS; i++)
Brad Bishop19323692019-04-05 15:28:33 -040085 if (c->rlimit[i]) {
86 fprintf(f, "%sLimit%s: " RLIM_FMT "\n",
87- prefix, rlimit_to_string(i), c->rlimit[i]->rlim_max);
88+ prefix, rlimit_to_string(i), (uintmax_t)c->rlimit[i]->rlim_max);
89 fprintf(f, "%sLimit%sSoft: " RLIM_FMT "\n",
90- prefix, rlimit_to_string(i), c->rlimit[i]->rlim_cur);
91+ prefix, rlimit_to_string(i), (uintmax_t)c->rlimit[i]->rlim_cur);
92 }
93
94 if (c->ioprio_set) {
Andrew Geisslerd1e89492021-02-12 15:35:20 -060095--
962.27.0
97