blob: 2071f4fb2063b52e7036c5ed17677e886533d61b [file] [log] [blame]
Patrick Williamsda295312023-12-05 16:48:56 -06001From 60f7d2c62bc3718023df93c01688d3ee1625d64d Mon Sep 17 00:00:00 2001
Andrew Geissler595f6302022-01-24 19:11:47 +00002From: Chen Qi <Qi.Chen@windriver.com>
3Date: Mon, 25 Feb 2019 15:12:41 +0800
4Subject: [PATCH] Use uintmax_t for handling rlim_t
5
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 Geissler595f6302022-01-24 19:11:47 +000023---
24 src/basic/format-util.h | 8 +-------
25 src/basic/rlimit-util.c | 12 ++++++------
26 src/core/execute.c | 4 ++--
27 3 files changed, 9 insertions(+), 15 deletions(-)
28
29--- a/src/basic/format-util.h
30+++ b/src/basic/format-util.h
31@@ -34,13 +34,7 @@ assert_cc(sizeof(gid_t) == sizeof(uint32
32 # error Unknown timex member size
33 #endif
34
35-#if SIZEOF_RLIM_T == 8
36-# define RLIM_FMT "%" PRIu64
37-#elif SIZEOF_RLIM_T == 4
38-# define RLIM_FMT "%" PRIu32
39-#else
40-# error Unknown rlim_t size
41-#endif
42+#define RLIM_FMT "%ju"
43
44 #if SIZEOF_DEV_T == 8
45 # define DEV_FMT "%" PRIu64
46--- a/src/basic/rlimit-util.c
47+++ b/src/basic/rlimit-util.c
48@@ -44,7 +44,7 @@ int setrlimit_closest(int resource, cons
49 fixed.rlim_max == highest.rlim_max)
50 return 0;
51
52- log_debug("Failed at setting rlimit " RLIM_FMT " for resource RLIMIT_%s. Will attempt setting value " RLIM_FMT " instead.", rlim->rlim_max, rlimit_to_string(resource), fixed.rlim_max);
53+ log_debug("Failed at setting rlimit " RLIM_FMT " for resource RLIMIT_%s. Will attempt setting value " RLIM_FMT " instead.", (uintmax_t)rlim->rlim_max, rlimit_to_string(resource), (uintmax_t)fixed.rlim_max);
54
55 return RET_NERRNO(setrlimit(resource, &fixed));
56 }
57@@ -307,13 +307,13 @@ int rlimit_format(const struct rlimit *r
58 if (rl->rlim_cur >= RLIM_INFINITY && rl->rlim_max >= RLIM_INFINITY)
59 r = free_and_strdup(&s, "infinity");
60 else if (rl->rlim_cur >= RLIM_INFINITY)
61- r = asprintf(&s, "infinity:" RLIM_FMT, rl->rlim_max);
62+ r = asprintf(&s, "infinity:" RLIM_FMT, (uintmax_t)rl->rlim_max);
63 else if (rl->rlim_max >= RLIM_INFINITY)
64- r = asprintf(&s, RLIM_FMT ":infinity", rl->rlim_cur);
65+ r = asprintf(&s, RLIM_FMT ":infinity", (uintmax_t)rl->rlim_cur);
66 else if (rl->rlim_cur == rl->rlim_max)
67- r = asprintf(&s, RLIM_FMT, rl->rlim_cur);
68+ r = asprintf(&s, RLIM_FMT, (uintmax_t)rl->rlim_cur);
69 else
70- r = asprintf(&s, RLIM_FMT ":" RLIM_FMT, rl->rlim_cur, rl->rlim_max);
71+ r = asprintf(&s, RLIM_FMT ":" RLIM_FMT, (uintmax_t)rl->rlim_cur, (uintmax_t)rl->rlim_max);
72 if (r < 0)
73 return -ENOMEM;
74
Patrick Williamsda295312023-12-05 16:48:56 -060075@@ -407,7 +407,7 @@ int rlimit_nofile_safe(void) {
76 rl.rlim_max = MIN(rl.rlim_max, (rlim_t) read_nr_open());
77 rl.rlim_cur = MIN((rlim_t) FD_SETSIZE, rl.rlim_max);
Andrew Geissler595f6302022-01-24 19:11:47 +000078 if (setrlimit(RLIMIT_NOFILE, &rl) < 0)
79- return log_debug_errno(errno, "Failed to lower RLIMIT_NOFILE's soft limit to " RLIM_FMT ": %m", rl.rlim_cur);
80+ return log_debug_errno(errno, "Failed to lower RLIMIT_NOFILE's soft limit to " RLIM_FMT ": %m", (uintmax_t)rl.rlim_cur);
81
82 return 1;
83 }
84--- a/src/core/execute.c
85+++ b/src/core/execute.c
Patrick Williamsda295312023-12-05 16:48:56 -060086@@ -6707,9 +6707,9 @@ void exec_context_dump(const ExecContext
Andrew Geissler595f6302022-01-24 19:11:47 +000087 for (unsigned i = 0; i < RLIM_NLIMITS; i++)
88 if (c->rlimit[i]) {
89 fprintf(f, "%sLimit%s: " RLIM_FMT "\n",
90- prefix, rlimit_to_string(i), c->rlimit[i]->rlim_max);
91+ prefix, rlimit_to_string(i), (uintmax_t)c->rlimit[i]->rlim_max);
92 fprintf(f, "%sLimit%sSoft: " RLIM_FMT "\n",
93- prefix, rlimit_to_string(i), c->rlimit[i]->rlim_cur);
94+ prefix, rlimit_to_string(i), (uintmax_t)c->rlimit[i]->rlim_cur);
95 }
96
97 if (c->ioprio_set) {