blob: 2071f4fb2063b52e7036c5ed17677e886533d61b [file] [log] [blame]
Andrew Geisslerfc113ea2023-03-31 09:59:46 -05001From 60f7d2c62bc3718023df93c01688d3ee1625d64d 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
William A. Kennington IIIac69b482021-06-02 12:28:27 -07004Subject: [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>
23---
24 src/basic/format-util.h | 8 +-------
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050025 src/basic/rlimit-util.c | 12 ++++++------
Brad Bishop19323692019-04-05 15:28:33 -040026 src/core/execute.c | 4 ++--
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050027 3 files changed, 9 insertions(+), 15 deletions(-)
Brad Bishop19323692019-04-05 15:28:33 -040028
Andrew Geisslerd1e89492021-02-12 15:35:20 -060029--- a/src/basic/format-util.h
30+++ b/src/basic/format-util.h
Andrew Geissler220dafd2023-10-04 10:18:08 -050031@@ -34,13 +34,7 @@ assert_cc(sizeof(gid_t) == sizeof(uint32
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000032 # error Unknown timex member size
Brad Bishop19323692019-04-05 15:28:33 -040033 #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
Andrew Geisslerd1e89492021-02-12 15:35:20 -060046--- a/src/basic/rlimit-util.c
47+++ b/src/basic/rlimit-util.c
Andrew Geissler220dafd2023-10-04 10:18:08 -050048@@ -44,7 +44,7 @@ int setrlimit_closest(int resource, cons
Andrew Geissler09036742021-06-25 14:25:14 -050049 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
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000055 return RET_NERRNO(setrlimit(resource, &fixed));
56 }
Andrew Geissler220dafd2023-10-04 10:18:08 -050057@@ -307,13 +307,13 @@ int rlimit_format(const struct rlimit *r
Brad Bishop19323692019-04-05 15:28:33 -040058 if (rl->rlim_cur >= RLIM_INFINITY && rl->rlim_max >= RLIM_INFINITY)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000059 r = free_and_strdup(&s, "infinity");
Brad Bishop19323692019-04-05 15:28:33 -040060 else if (rl->rlim_cur >= RLIM_INFINITY)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000061- r = asprintf(&s, "infinity:" RLIM_FMT, rl->rlim_max);
62+ r = asprintf(&s, "infinity:" RLIM_FMT, (uintmax_t)rl->rlim_max);
Brad Bishop19323692019-04-05 15:28:33 -040063 else if (rl->rlim_max >= RLIM_INFINITY)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000064- r = asprintf(&s, RLIM_FMT ":infinity", rl->rlim_cur);
65+ r = asprintf(&s, RLIM_FMT ":infinity", (uintmax_t)rl->rlim_cur);
Brad Bishop19323692019-04-05 15:28:33 -040066 else if (rl->rlim_cur == rl->rlim_max)
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000067- r = asprintf(&s, RLIM_FMT, rl->rlim_cur);
68+ r = asprintf(&s, RLIM_FMT, (uintmax_t)rl->rlim_cur);
Brad Bishop19323692019-04-05 15:28:33 -040069 else
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000070- 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)
Brad Bishop19323692019-04-05 15:28:33 -040073 return -ENOMEM;
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000074
Andrew Geissler220dafd2023-10-04 10:18:08 -050075@@ -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);
Brad Bishop19323692019-04-05 15:28:33 -040078 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 }
Andrew Geisslerd1e89492021-02-12 15:35:20 -060084--- a/src/core/execute.c
85+++ b/src/core/execute.c
Andrew Geissler220dafd2023-10-04 10:18:08 -050086@@ -6707,9 +6707,9 @@ void exec_context_dump(const ExecContext
Andrew Geisslerd1e89492021-02-12 15:35:20 -060087 for (unsigned i = 0; i < RLIM_NLIMITS; i++)
Brad Bishop19323692019-04-05 15:28:33 -040088 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) {