From cdca71e94506fbb921ab2c626be3ad05c4287498 Mon Sep 17 00:00:00 2001 From: Craig Small Date: Fri, 20 Sep 2013 22:34:32 +1000 Subject: [PATCH] sysctl --system ignores missing /etc/sysctl.conf sysctl --system would not correctly return the RC for files in subdirectories and would insist on having /etc/sysctl.conf This update makes two changes when using sysctl --system: - The RC status is ORed for each config file, meaning an error in any file is propated to the RC - If /etc/sysctl.conf doesn't exist we just don't load it References: https://bbs.archlinux.org/viewtopic.php?id=170005 http://www.freelists.org/post/procps/wrong-defaults-for-sysctl-on-arch-linux --- sysctl.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/sysctl.c b/sysctl.c index 14257098..ca3992ee 100644 --- a/sysctl.c +++ b/sysctl.c @@ -578,6 +578,8 @@ static int PreloadSystem(void) }; struct pair **cfgs = NULL; unsigned ncfgs = 0; + int rc = 0; + struct stat ts; enum { nprealloc = 16 }; for (di = 0; di < sizeof(dirs) / sizeof(dirs[0]); ++di) { @@ -634,12 +636,16 @@ static int PreloadSystem(void) for (i = 0; i < ncfgs; ++i) { if (!Quiet) printf(_("* Applying %s ...\n"), cfgs[i]->value); - Preload(cfgs[i]->value); + rc |= Preload(cfgs[i]->value); } - if (!Quiet) - printf(_("* Applying %s ...\n"), DEFAULT_PRELOAD); - return Preload(DEFAULT_PRELOAD); + + if (stat(DEFAULT_PRELOAD, &ts) < 0 && S_ISREG(ts.st_mode)) { + if (!Quiet) + printf(_("* Applying %s ...\n"), DEFAULT_PRELOAD); + rc |= Preload(DEFAULT_PRELOAD); + } + return rc; } /*