sysctl: ignore errors from lines starting with -
The systemd sysctl ignores errors from preload files that start with a hyphen. This change brings the procps sysctl into line with their change. References: procps-ng/procps#138 https://github.com/systemd/systemd/pull/13191 https://github.com/systemd/systemd/pull/13141
This commit is contained in:
20
sysctl.c
20
sysctl.c
@@ -378,6 +378,7 @@ static int WriteSetting(const char *setting)
|
||||
char *tmpname;
|
||||
char *outname;
|
||||
char *last_dot;
|
||||
bool ignore_failure;
|
||||
|
||||
FILE *fp;
|
||||
struct stat ts;
|
||||
@@ -402,6 +403,10 @@ static int WriteSetting(const char *setting)
|
||||
return -2;
|
||||
}
|
||||
|
||||
ignore_failure = name[0] == '-';
|
||||
if (ignore_failure)
|
||||
name++;
|
||||
|
||||
/* used to open the file */
|
||||
tmpname = xmalloc(equals - name + 1 + strlen(PROC_PATH));
|
||||
strcpy(tmpname, PROC_PATH);
|
||||
@@ -446,19 +451,22 @@ static int WriteSetting(const char *setting)
|
||||
switch (errno) {
|
||||
case ENOENT:
|
||||
if (!IgnoreError) {
|
||||
xwarnx(_("\"%s\" is an unknown key"), outname);
|
||||
rc = -1;
|
||||
xwarnx(_("\"%s\" is an unknown key%s"), outname, (ignore_failure?_(", ignoring"):""));
|
||||
if (!ignore_failure)
|
||||
rc = -1;
|
||||
}
|
||||
break;
|
||||
case EPERM:
|
||||
case EROFS:
|
||||
case EACCES:
|
||||
xwarnx(_("permission denied on key '%s'"), outname);
|
||||
rc = -1;
|
||||
xwarnx(_("permission denied on key \"%s\"%s"), outname, (ignore_failure?_(", ignoring"):""));
|
||||
break;
|
||||
default:
|
||||
xwarn(_("setting key \"%s\""), outname);
|
||||
rc = -1;
|
||||
xwarn(_("setting key \"%s\"%s"), outname, (ignore_failure?_(", ignoring"):""));
|
||||
break;
|
||||
}
|
||||
if (!ignore_failure && errno != ENOENT)
|
||||
rc = -1;
|
||||
} else {
|
||||
rc = fprintf(fp, "%s\n", value);
|
||||
if (0 < rc)
|
||||
|
Reference in New Issue
Block a user