* resource.c (sprint_rlim64, sprint_rlim32): Remove.
(print_rlim64_t, print_rlim32_t): New functions.
(print_rlimit64, print_rlimit32): Use them.
* tests/setrlimit-Xabbrev.c: New file.
* tests/setrlimit-Xraw.c: Likewise.
* tests/setrlimit-Xverbose.c: Likewise.
* tests/setrlimit.c (main): Handle XLAT_ABBREV, XLAT_RAW,
and XLAT_VERBOSE macros.
* tests/xgetrlimit.c (sprint_rlim): Likewise.
* tests/gen_tests.in (setrlimit-Xabbrev, setrlimit-Xraw,
setrlimit-Xverbose): New tests.
* tests/pure_executables.list: Add setrlimit-Xabbrev, setrlimit-Xraw,
and setrlimit-Xverbose.
* tests/.gitignore: Likewise.
Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
#include "xlat/resources.h"
-static const char *
-sprint_rlim64(uint64_t lim)
-{
- static char buf[sizeof(uint64_t)*3 + sizeof("*1024")];
+static void
+print_rlim64_t(uint64_t lim) {
+ const char *str = NULL;
if (lim == UINT64_MAX)
- return "RLIM64_INFINITY";
+ str = "RLIM64_INFINITY";
+ else if (lim > 1024 && lim % 1024 == 0) {
+ static char buf[sizeof(lim) * 3 + sizeof("*1024")];
- if (lim > 1024 && lim % 1024 == 0)
xsprintf(buf, "%" PRIu64 "*1024", lim / 1024);
- else
- xsprintf(buf, "%" PRIu64, lim);
- return buf;
+ str = buf;
+ }
+
+ if (!str || xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
+ tprintf("%" PRIu64, lim);
+
+ if (!str || xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
+ return;
+
+ (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE
+ ? tprints_comment : tprints)(str);
}
static void
} rlim;
if (!umove_or_printaddr(tcp, addr, &rlim)) {
- tprintf("{rlim_cur=%s,", sprint_rlim64(rlim.rlim_cur));
- tprintf(" rlim_max=%s}", sprint_rlim64(rlim.rlim_max));
+ tprints("{rlim_cur=");
+ print_rlim64_t(rlim.rlim_cur);
+ tprints(", rlim_max=");
+ print_rlim64_t(rlim.rlim_max);
+ tprints("}");
}
}
#if !defined(current_wordsize) || current_wordsize == 4
-static const char *
-sprint_rlim32(uint32_t lim)
-{
- static char buf[sizeof(uint32_t)*3 + sizeof("*1024")];
+static void
+print_rlim32_t(uint32_t lim) {
+ const char *str = NULL;
if (lim == UINT32_MAX)
- return "RLIM_INFINITY";
+ str = "RLIM_INFINITY";
+ else if (lim > 1024 && lim % 1024 == 0) {
+ static char buf[sizeof(lim) * 3 + sizeof("*1024")];
- if (lim > 1024 && lim % 1024 == 0)
xsprintf(buf, "%" PRIu32 "*1024", lim / 1024);
- else
- xsprintf(buf, "%" PRIu32, lim);
- return buf;
+ str = buf;
+ }
+
+ if (!str || xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
+ tprintf("%" PRIu32, lim);
+
+ if (!str || xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
+ return;
+
+ (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE
+ ? tprints_comment : tprints)(str);
}
static void
} rlim;
if (!umove_or_printaddr(tcp, addr, &rlim)) {
- tprintf("{rlim_cur=%s,", sprint_rlim32(rlim.rlim_cur));
- tprintf(" rlim_max=%s}", sprint_rlim32(rlim.rlim_max));
+ tprints("{rlim_cur=");
+ print_rlim32_t(rlim.rlim_cur);
+ tprints(", rlim_max=");
+ print_rlim32_t(rlim.rlim_max);
+ tprints("}");
}
}
setreuid
setreuid32
setrlimit
+setrlimit-Xabbrev
+setrlimit-Xraw
+setrlimit-Xverbose
setuid
setuid32
shmxt
setreuid -a15
setreuid32 -a17
setrlimit -a27
+setrlimit-Xabbrev -a27 -e trace=setrlimit -Xabbrev
+setrlimit-Xraw -a19 -e trace=setrlimit -Xraw
+setrlimit-Xverbose -a36 -e trace=setrlimit -Xverbose
setuid -a10
setuid32 -a12
shmxt -a11 -e trace='/(osf_)?shmat,shmdt'
setreuid
setreuid32
setrlimit
+setrlimit-Xabbrev
+setrlimit-Xraw
+setrlimit-Xverbose
setuid
setuid32
shmxt
--- /dev/null
+#include "setrlimit.c"
--- /dev/null
+#define XLAT_RAW 1
+#include "setrlimit.c"
--- /dev/null
+#define XLAT_VERBOSE 1
+#include "setrlimit.c"
for (xlat = resources; xlat->str; ++xlat) {
unsigned long res = 0xfacefeed00000000ULL | xlat->val;
long rc = syscall(__NR_setrlimit, res, 0);
+# if XLAT_RAW
+ printf("setrlimit(%#x, NULL) = %s\n",
+ (unsigned int) xlat->val, sprintrc(rc));
+# elif XLAT_VERBOSE
+ printf("setrlimit(%#x /* %s */, NULL) = %s\n",
+ (unsigned int) xlat->val,
+ xlat->str, sprintrc(rc));
+# else
printf("setrlimit(%s, NULL) = %s\n", xlat->str, sprintrc(rc));
+# endif
struct rlimit libc_rlim = {};
if (getrlimit((int) res, &libc_rlim))
rc = syscall(__NR_setrlimit, res, rlimit);
const char *errstr = sprintrc(rc);
+# if XLAT_RAW
+ printf("setrlimit(%#x, {rlim_cur=%s, rlim_max=%s}) = %s\n",
+ (unsigned int) xlat->val,
+ sprint_rlim(rlimit[0]), sprint_rlim(rlimit[1]),
+ errstr);
+# elif XLAT_VERBOSE
+ printf("setrlimit(%#x /* %s */,"
+ " {rlim_cur=%s, rlim_max=%s}) = %s\n",
+ (unsigned int) xlat->val, xlat->str,
+ sprint_rlim(rlimit[0]), sprint_rlim(rlimit[1]),
+ errstr);
+# else
printf("setrlimit(%s, {rlim_cur=%s, rlim_max=%s}) = %s\n",
xlat->str,
sprint_rlim(rlimit[0]), sprint_rlim(rlimit[1]),
errstr);
+# endif
}
puts("+++ exited with 0 +++");
const char *
sprint_rlim(kernel_ulong_t lim)
{
+ static char buf[2][ /* space for 2 llu strings */
+ 2*sizeof(lim)*3 +
+ /* space for XLAT_STYLE_ABBREV decoding */
+ sizeof("*1024") + sizeof("RLIM64_INFINITY") +
+ /* space for C style comments */
+ 6];
+ static unsigned int i;
+
+ i &= 1;
+
+#if XLAT_RAW
+ sprintf(buf[i], "%llu", (unsigned long long) lim);
+ return buf[i++];
+#else
if (sizeof(lim) == sizeof(uint64_t)) {
- if (lim == (kernel_ulong_t) -1ULL)
+ if (lim == (kernel_ulong_t) -1ULL) {
+# if XLAT_VERBOSE
+ sprintf(buf[i], "%llu /* RLIM64_INFINITY */",
+ (unsigned long long) lim);
+ return buf[i++];
+# else /* XLAT_ABBREV */
return "RLIM64_INFINITY";
+# endif
+ }
} else {
- if (lim == (kernel_ulong_t) -1U)
+ if (lim == (kernel_ulong_t) -1U) {
+# if XLAT_VERBOSE
+ sprintf(buf[i], "%llu /* RLIM_INFINITY */",
+ (unsigned long long) lim);
+ return buf[i++];
+# else /* XLAT_ABBREV */
return "RLIM_INFINITY";
+# endif
+ }
}
- static char buf[2][sizeof(lim)*3 + sizeof("*1024")];
- static int i;
- i &= 1;
if (lim > 1024 && lim % 1024 == 0)
+# if XLAT_VERBOSE
+ sprintf(buf[i], "%llu /* %llu*1024 */",
+ (unsigned long long) lim,
+ (unsigned long long) lim / 1024);
+# else /* XLAT_ABBREV */
sprintf(buf[i], "%llu*1024", (unsigned long long) lim / 1024);
+# endif
else
sprintf(buf[i], "%llu", (unsigned long long) lim);
return buf[i++];
+#endif /* !XLAT_RAW */
}
#ifdef NR_GETRLIMIT