0010-Use-uintmax_t-for-handling-rlim_t.patch 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. From 48a791aae7a47a2a08e9e60c18054071a43b8cda 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] Use uintmax_t for handling rlim_t
  5. PRIu{32,64} is not right format to represent rlim_t type
  6. therefore use %ju and typecast the rlim_t variables to
  7. uintmax_t.
  8. Fixes portablility errors like
  9. 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=]
  10. | fprintf(f, "%s%s: " RLIM_FMT "\n",
  11. | ^~~~~~~~
  12. | prefix, rlimit_to_string(i), c->rlimit[i]->rlim_max);
  13. | ~~~~~~~~~~~~~~~~~~~~~~
  14. Upstream-Status: Denied [https://github.com/systemd/systemd/pull/7199]
  15. Signed-off-by: Khem Raj <raj.khem@gmail.com>
  16. [Rebased for v241]
  17. Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
  18. ---
  19. src/basic/format-util.h | 8 +-------
  20. src/basic/rlimit-util.c | 12 ++++++------
  21. src/core/execute.c | 4 ++--
  22. 3 files changed, 9 insertions(+), 15 deletions(-)
  23. --- a/src/basic/format-util.h
  24. +++ b/src/basic/format-util.h
  25. @@ -34,13 +34,7 @@ assert_cc(sizeof(gid_t) == sizeof(uint32
  26. # error Unknown timex member size
  27. #endif
  28. -#if SIZEOF_RLIM_T == 8
  29. -# define RLIM_FMT "%" PRIu64
  30. -#elif SIZEOF_RLIM_T == 4
  31. -# define RLIM_FMT "%" PRIu32
  32. -#else
  33. -# error Unknown rlim_t size
  34. -#endif
  35. +#define RLIM_FMT "%ju"
  36. #if SIZEOF_DEV_T == 8
  37. # define DEV_FMT "%" PRIu64
  38. --- a/src/basic/rlimit-util.c
  39. +++ b/src/basic/rlimit-util.c
  40. @@ -44,7 +44,7 @@ int setrlimit_closest(int resource, cons
  41. fixed.rlim_max == highest.rlim_max)
  42. return 0;
  43. - 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);
  44. + 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);
  45. return RET_NERRNO(setrlimit(resource, &fixed));
  46. }
  47. @@ -307,13 +307,13 @@ int rlimit_format(const struct rlimit *r
  48. if (rl->rlim_cur >= RLIM_INFINITY && rl->rlim_max >= RLIM_INFINITY)
  49. r = free_and_strdup(&s, "infinity");
  50. else if (rl->rlim_cur >= RLIM_INFINITY)
  51. - r = asprintf(&s, "infinity:" RLIM_FMT, rl->rlim_max);
  52. + r = asprintf(&s, "infinity:" RLIM_FMT, (uintmax_t)rl->rlim_max);
  53. else if (rl->rlim_max >= RLIM_INFINITY)
  54. - r = asprintf(&s, RLIM_FMT ":infinity", rl->rlim_cur);
  55. + r = asprintf(&s, RLIM_FMT ":infinity", (uintmax_t)rl->rlim_cur);
  56. else if (rl->rlim_cur == rl->rlim_max)
  57. - r = asprintf(&s, RLIM_FMT, rl->rlim_cur);
  58. + r = asprintf(&s, RLIM_FMT, (uintmax_t)rl->rlim_cur);
  59. else
  60. - r = asprintf(&s, RLIM_FMT ":" RLIM_FMT, rl->rlim_cur, rl->rlim_max);
  61. + r = asprintf(&s, RLIM_FMT ":" RLIM_FMT, (uintmax_t)rl->rlim_cur, (uintmax_t)rl->rlim_max);
  62. if (r < 0)
  63. return -ENOMEM;
  64. @@ -403,7 +403,7 @@ int rlimit_nofile_safe(void) {
  65. rl.rlim_cur = FD_SETSIZE;
  66. if (setrlimit(RLIMIT_NOFILE, &rl) < 0)
  67. - return log_debug_errno(errno, "Failed to lower RLIMIT_NOFILE's soft limit to " RLIM_FMT ": %m", rl.rlim_cur);
  68. + return log_debug_errno(errno, "Failed to lower RLIMIT_NOFILE's soft limit to " RLIM_FMT ": %m", (uintmax_t)rl.rlim_cur);
  69. return 1;
  70. }
  71. --- a/src/core/execute.c
  72. +++ b/src/core/execute.c
  73. @@ -5869,9 +5869,9 @@ void exec_context_dump(const ExecContext
  74. for (unsigned i = 0; i < RLIM_NLIMITS; i++)
  75. if (c->rlimit[i]) {
  76. fprintf(f, "%sLimit%s: " RLIM_FMT "\n",
  77. - prefix, rlimit_to_string(i), c->rlimit[i]->rlim_max);
  78. + prefix, rlimit_to_string(i), (uintmax_t)c->rlimit[i]->rlim_max);
  79. fprintf(f, "%sLimit%sSoft: " RLIM_FMT "\n",
  80. - prefix, rlimit_to_string(i), c->rlimit[i]->rlim_cur);
  81. + prefix, rlimit_to_string(i), (uintmax_t)c->rlimit[i]->rlim_cur);
  82. }
  83. if (c->ioprio_set) {