Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 1 | From e3f847bd0338d27aff3335b42661d8a4b66b965e Mon Sep 17 00:00:00 2001 |
| 2 | From: Chen Qi <Qi.Chen@windriver.com> |
| 3 | Date: Mon, 25 Feb 2019 15:12:41 +0800 |
| 4 | Subject: [PATCH 11/24] Use uintmax_t for handling rlim_t |
| 5 | |
| 6 | PRIu{32,64} is not right format to represent rlim_t type |
| 7 | therefore use %ju and typecast the rlim_t variables to |
| 8 | uintmax_t. |
| 9 | |
| 10 | Fixes portablility errors like |
| 11 | |
| 12 | execute.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 | |
| 18 | Upstream-Status: Denied [https://github.com/systemd/systemd/pull/7199] |
| 19 | |
| 20 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 21 | [Rebased for v241] |
| 22 | Signed-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 | |
| 29 | diff --git a/src/basic/format-util.h b/src/basic/format-util.h |
| 30 | index dece5d3..dbb87bc 100644 |
| 31 | --- a/src/basic/format-util.h |
| 32 | +++ b/src/basic/format-util.h |
| 33 | @@ -42,13 +42,7 @@ |
| 34 | # 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 |
| 48 | diff --git a/src/basic/rlimit-util.c b/src/basic/rlimit-util.c |
| 49 | index 74b3a02..b02c03c 100644 |
| 50 | --- a/src/basic/rlimit-util.c |
| 51 | +++ b/src/basic/rlimit-util.c |
| 52 | @@ -307,13 +307,13 @@ int rlimit_format(const struct rlimit *rl, char **ret) { |
| 53 | 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; |
| 70 | @@ -404,7 +404,7 @@ int rlimit_nofile_safe(void) { |
| 71 | |
| 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 | } |
| 79 | diff --git a/src/core/execute.c b/src/core/execute.c |
| 80 | index a708231..e2b8748 100644 |
| 81 | --- a/src/core/execute.c |
| 82 | +++ b/src/core/execute.c |
| 83 | @@ -4220,9 +4220,9 @@ void exec_context_dump(const ExecContext *c, FILE* f, const char *prefix) { |
| 84 | for (i = 0; i < RLIM_NLIMITS; i++) |
| 85 | 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) { |
| 95 | -- |
| 96 | 2.7.4 |
| 97 | |