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:
parent
97e1264525
commit
a6c0795d49
20
sysctl.c
20
sysctl.c
@ -375,6 +375,7 @@ static int WriteSetting(const char *setting)
|
|||||||
char *tmpname;
|
char *tmpname;
|
||||||
char *outname;
|
char *outname;
|
||||||
char *last_dot;
|
char *last_dot;
|
||||||
|
bool ignore_failure;
|
||||||
|
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
struct stat ts;
|
struct stat ts;
|
||||||
@ -399,6 +400,10 @@ static int WriteSetting(const char *setting)
|
|||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ignore_failure = name[0] == '-';
|
||||||
|
if (ignore_failure)
|
||||||
|
name++;
|
||||||
|
|
||||||
/* used to open the file */
|
/* used to open the file */
|
||||||
tmpname = xmalloc(equals - name + 1 + strlen(PROC_PATH));
|
tmpname = xmalloc(equals - name + 1 + strlen(PROC_PATH));
|
||||||
strcpy(tmpname, PROC_PATH);
|
strcpy(tmpname, PROC_PATH);
|
||||||
@ -443,19 +448,22 @@ static int WriteSetting(const char *setting)
|
|||||||
switch (errno) {
|
switch (errno) {
|
||||||
case ENOENT:
|
case ENOENT:
|
||||||
if (!IgnoreError) {
|
if (!IgnoreError) {
|
||||||
xwarnx(_("\"%s\" is an unknown key"), outname);
|
xwarnx(_("\"%s\" is an unknown key%s"), outname, (ignore_failure?_(", ignoring"):""));
|
||||||
rc = -1;
|
if (!ignore_failure)
|
||||||
|
rc = -1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case EPERM:
|
||||||
|
case EROFS:
|
||||||
case EACCES:
|
case EACCES:
|
||||||
xwarnx(_("permission denied on key '%s'"), outname);
|
xwarnx(_("permission denied on key \"%s\"%s"), outname, (ignore_failure?_(", ignoring"):""));
|
||||||
rc = -1;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
xwarn(_("setting key \"%s\""), outname);
|
xwarn(_("setting key \"%s\"%s"), outname, (ignore_failure?_(", ignoring"):""));
|
||||||
rc = -1;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (!ignore_failure && errno != ENOENT)
|
||||||
|
rc = -1;
|
||||||
} else {
|
} else {
|
||||||
rc = fprintf(fp, "%s\n", value);
|
rc = fprintf(fp, "%s\n", value);
|
||||||
if (0 < rc)
|
if (0 < rc)
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
|
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
.\" GNU General Public License for more details."
|
.\" GNU General Public License for more details."
|
||||||
.TH SYSCTL.CONF "5" "January 2012" "procps-ng" "File Formats"
|
.TH SYSCTL.CONF "5" "2019-09-21" "procps-ng" "File Formats"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
sysctl.conf \- sysctl preload/configuration file
|
sysctl.conf \- sysctl preload/configuration file
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
@ -28,6 +28,10 @@ token = value
|
|||||||
Note that blank lines are ignored, and whitespace before and after a token or
|
Note that blank lines are ignored, and whitespace before and after a token or
|
||||||
value is ignored, although a value can contain whitespace within. Lines which
|
value is ignored, although a value can contain whitespace within. Lines which
|
||||||
begin with a # or ; are considered comments and ignored.
|
begin with a # or ; are considered comments and ignored.
|
||||||
|
|
||||||
|
If a line begins with a single \-, any attempts to set the value that fail will be
|
||||||
|
ignored.
|
||||||
|
|
||||||
.SH NOTES
|
.SH NOTES
|
||||||
As the
|
As the
|
||||||
.BR /etc/sysctl.conf
|
.BR /etc/sysctl.conf
|
||||||
|
Loading…
Reference in New Issue
Block a user