tree-wide: have_effective_cap() may return negative errno

This commit is contained in:
Yu Watanabe
2022-12-23 22:11:00 +09:00
parent d7301331e8
commit 26c45a6c1d
7 changed files with 30 additions and 17 deletions
+5 -2
View File
@@ -79,6 +79,7 @@ bool argv_looks_like_help(int argc, char **argv) {
static int update_argv(const char name[], size_t l) {
static int can_do = -1;
int r;
if (can_do == 0)
return 0;
@@ -86,13 +87,15 @@ static int update_argv(const char name[], size_t l) {
/* Calling prctl() with PR_SET_MM_ARG_{START,END} requires CAP_SYS_RESOURCE so let's use this as quick bypass
* check, to avoid calling mmap() should PR_SET_MM_ARG_{START,END} fail with EPERM later on anyway. */
if (!have_effective_cap(CAP_SYS_RESOURCE))
r = have_effective_cap(CAP_SYS_RESOURCE);
if (r < 0)
return log_debug_errno(r, "Failed to check if we have enough privileges: %m");
if (r == 0)
return log_debug_errno(SYNTHETIC_ERRNO(EPERM),
"Skipping PR_SET_MM, as we don't have privileges.");
static size_t mm_size = 0;
static char *mm = NULL;
int r;
if (mm_size < l+1) {
size_t nn_size;