- make --system switch compatible with udev/systemd scheme
OBS-URL: https://build.opensuse.org/package/show/Base:System/procps?expand=0&rev=52
This commit is contained in:
parent
6c4076f27e
commit
96ecb2706c
@ -1,50 +1,109 @@
|
||||
From 45915cfc03fb82b68425445063a0bcebab1ff230 Mon Sep 17 00:00:00 2001
|
||||
From f09de20e534804464d89d76c607ac877573ad9fe Mon Sep 17 00:00:00 2001
|
||||
From: Ludwig Nussel <ludwig.nussel@suse.de>
|
||||
Date: Wed, 18 May 2011 08:16:39 +0200
|
||||
Subject: [PATCH procps 1/3] add --system switch
|
||||
Date: Fri, 26 Aug 2011 11:11:50 +0200
|
||||
Subject: [PATCH 1/3] add --system switch
|
||||
|
||||
instead of requiring distributions to construct a loop around sysctl
|
||||
in boot scripts just scan a set of default directories if the --system
|
||||
switch is used.
|
||||
Config files are applied in alphabetic order of their base name.
|
||||
Each base name is only applied once according to the directory
|
||||
preference. /etc/sysctl.conf is always applied last.
|
||||
---
|
||||
sysctl.c | 35 +++++++++++++++++++++++++++++++++++
|
||||
1 files changed, 35 insertions(+), 0 deletions(-)
|
||||
sysctl.8 | 5 ++++
|
||||
sysctl.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
2 files changed, 79 insertions(+), 0 deletions(-)
|
||||
|
||||
diff --git a/sysctl.8 b/sysctl.8
|
||||
index e26c4fb..d2b0ceb 100644
|
||||
--- a/sysctl.8
|
||||
+++ b/sysctl.8
|
||||
@@ -64,6 +64,11 @@ Display all values currently available.
|
||||
.TP
|
||||
.B "-A"
|
||||
Display all values currently available in table form.
|
||||
+.TP
|
||||
+.B "--system"
|
||||
+Load settings from system configuration files (/lib/sysctl.d/*.conf,
|
||||
+/usr/lib/sysctl.d/*.conf, /usr/local/lib/sysctl.d/*.conf,
|
||||
+/etc/sysctl.d/*.conf, /run/sysctl.d/*.conf, /etc/sysctl.conf)
|
||||
.SH EXAMPLES
|
||||
.TP
|
||||
/sbin/sysctl -a
|
||||
diff --git a/sysctl.c b/sysctl.c
|
||||
index 9be79ce..3445efe 100644
|
||||
index 9be79ce..bf4e529 100644
|
||||
--- a/sysctl.c
|
||||
+++ b/sysctl.c
|
||||
@@ -453,6 +453,37 @@ static int Preload(const char *restrict const filename) {
|
||||
@@ -453,6 +453,76 @@ static int Preload(const char *restrict const filename) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
+static int PreloadSystem(void) {
|
||||
+ unsigned i;
|
||||
+ const char* dirs[] = {
|
||||
+ "/lib/sysctl.d",
|
||||
+ "/usr/lib/sysctl.d",
|
||||
+ "/usr/local/lib/sysctl.d",
|
||||
+ "/etc/sysctl.d",
|
||||
+struct pair {
|
||||
+ char* name;
|
||||
+ char* value;
|
||||
+};
|
||||
+ for (i=0; i < sizeof(dirs)/sizeof(dirs[0]); ++i) {
|
||||
+
|
||||
+static int sortpairs(const void* A, const void* B)
|
||||
+{
|
||||
+ const struct pair* a = *(struct pair* const*)A;
|
||||
+ const struct pair* b = *(struct pair* const*)B;
|
||||
+ return strcmp(a->name, b->name);
|
||||
+}
|
||||
+
|
||||
+static int PreloadSystem(void) {
|
||||
+ unsigned di, i;
|
||||
+ const char* dirs[] = {
|
||||
+ "/run/sysctl.d",
|
||||
+ "/etc/sysctl.d",
|
||||
+ "/usr/local/lib/sysctl.d",
|
||||
+ "/usr/lib/sysctl.d",
|
||||
+ "/lib/sysctl.d",
|
||||
+ };
|
||||
+ struct pair** cfgs = NULL;
|
||||
+ unsigned ncfgs = 0;
|
||||
+ enum { nprealloc = 16 };
|
||||
+
|
||||
+ for (di=0; di < sizeof(dirs)/sizeof(dirs[0]); ++di) {
|
||||
+ struct dirent* de;
|
||||
+ DIR* dp = opendir(dirs[i]);
|
||||
+ DIR* dp = opendir(dirs[di]);
|
||||
+ if (!dp)
|
||||
+ continue;
|
||||
+ while (( de = readdir(dp) )) {
|
||||
+ char buf[PATH_MAX];
|
||||
+ if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) {
|
||||
+ continue;
|
||||
+ }
|
||||
+ if (strlen(de->d_name) < 6 || !strcmp(de->d_name+strlen(de->d_name)-6, ".conf"))
|
||||
+ continue;
|
||||
+ snprintf(buf, sizeof(buf), "%s/%s", dirs[i], de->d_name);
|
||||
+ if (!Quiet)
|
||||
+ printf("* Applying %s ...\n", buf);
|
||||
+ Preload(buf);
|
||||
+ /* check if config already known */
|
||||
+ for (i = 0; i < ncfgs; ++i) {
|
||||
+ if (!strcmp(cfgs[i]->name, de->d_name))
|
||||
+ break;
|
||||
+ }
|
||||
+ if (i < ncfgs) // already in
|
||||
+ continue;
|
||||
+
|
||||
+ if (ncfgs % nprealloc == 0) {
|
||||
+ cfgs = realloc(cfgs, sizeof(struct pair*)*(ncfgs+nprealloc));
|
||||
+ }
|
||||
+ cfgs[ncfgs] = malloc(sizeof(struct pair) + strlen(de->d_name)*2+2 + strlen(dirs[di])+1);
|
||||
+ cfgs[ncfgs]->name = (char*)cfgs[ncfgs]+sizeof(struct pair);
|
||||
+ strcpy(cfgs[ncfgs]->name, de->d_name);
|
||||
+ cfgs[ncfgs]->value = (char*)cfgs[ncfgs]+sizeof(struct pair) + strlen(cfgs[ncfgs]->name)+1;
|
||||
+ sprintf(cfgs[ncfgs]->value, "%s/%s", dirs[di], de->d_name);
|
||||
+ ncfgs++;
|
||||
+
|
||||
+ }
|
||||
+ closedir(dp);
|
||||
+ }
|
||||
+
|
||||
+ qsort(cfgs, ncfgs, sizeof(struct cfg*), sortpairs);
|
||||
+
|
||||
+ for (i = 0; i < ncfgs; ++i) {
|
||||
+ if (!Quiet)
|
||||
+ printf("* Applying %s ...\n", cfgs[i]->value);
|
||||
+ Preload(cfgs[i]->value);
|
||||
+ }
|
||||
+
|
||||
+ if (!Quiet)
|
||||
+ printf("* Applying %s ...\n", DEFAULT_PRELOAD);
|
||||
+ return Preload(DEFAULT_PRELOAD);
|
||||
@ -52,7 +111,7 @@ index 9be79ce..3445efe 100644
|
||||
|
||||
|
||||
/*
|
||||
@@ -488,6 +519,10 @@ int main(int argc, char *argv[]) {
|
||||
@@ -488,6 +558,10 @@ int main(int argc, char *argv[]) {
|
||||
fprintf(stdout, "sysctl (%s)\n",procps_version);
|
||||
exit(0);
|
||||
}
|
||||
|
@ -1,28 +1,23 @@
|
||||
From b73ff507f616c74ac94e7b1bef2ce51fa9bb2806 Mon Sep 17 00:00:00 2001
|
||||
From 596511f915e210d27c84eaca0a5b4c7c48ec96e0 Mon Sep 17 00:00:00 2001
|
||||
From: Ludwig Nussel <ludwig.nussel@suse.de>
|
||||
Date: Wed, 18 May 2011 08:20:09 +0200
|
||||
Subject: [PATCH procps 2/3] implement --pattern option
|
||||
Date: Fri, 26 Aug 2011 11:31:39 +0200
|
||||
Subject: [PATCH 2/3] implement --pattern option
|
||||
|
||||
Useful for e.g network hook scripts together with --system to only apply
|
||||
sysctls for a specific network interface.
|
||||
---
|
||||
sysctl.8 | 14 ++++++++++++++
|
||||
sysctl.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
2 files changed, 66 insertions(+), 0 deletions(-)
|
||||
sysctl.8 | 10 ++++++++-
|
||||
sysctl.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
|
||||
2 files changed, 67 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/sysctl.8 b/sysctl.8
|
||||
index e26c4fb..9f6de65 100644
|
||||
index d2b0ceb..406bb59 100644
|
||||
--- a/sysctl.8
|
||||
+++ b/sysctl.8
|
||||
@@ -64,6 +64,16 @@ Display all values currently available.
|
||||
.TP
|
||||
.B "-A"
|
||||
Display all values currently available in table form.
|
||||
+.TP
|
||||
+.B "--system"
|
||||
+Load settings from system configuration files (/lib/sysctl.d/*.conf,
|
||||
+/usr/lib/sysctl.d/*.conf, /usr/local/lib/sysctl.d/*.conf,
|
||||
+/etc/sysctl.d/*.conf, /etc/sysctl.conf)
|
||||
@@ -69,6 +69,11 @@ Display all values currently available in table form.
|
||||
Load settings from system configuration files (/lib/sysctl.d/*.conf,
|
||||
/usr/lib/sysctl.d/*.conf, /usr/local/lib/sysctl.d/*.conf,
|
||||
/etc/sysctl.d/*.conf, /run/sysctl.d/*.conf, /etc/sysctl.conf)
|
||||
+.TP
|
||||
+.B "--pattern" PATTERN
|
||||
+Ignore settings that don't patch PATTERN. A star '*' is recognized
|
||||
@ -31,10 +26,11 @@ index e26c4fb..9f6de65 100644
|
||||
.SH EXAMPLES
|
||||
.TP
|
||||
/sbin/sysctl -a
|
||||
@@ -73,6 +83,10 @@ Display all values currently available in table form.
|
||||
@@ -77,7 +82,10 @@ Load settings from system configuration files (/lib/sysctl.d/*.conf,
|
||||
.TP
|
||||
/sbin/sysctl -w kernel.domainname="example.com"
|
||||
.TP
|
||||
/sbin/sysctl -p /etc/sysctl.conf
|
||||
-/sbin/sysctl -p /etc/sysctl.conf
|
||||
+.TP
|
||||
+/sbin/sysctl --pattern 'net.ipv4.conf.*.forwarding' -a
|
||||
+.TP
|
||||
@ -43,7 +39,7 @@ index e26c4fb..9f6de65 100644
|
||||
.I /proc/sys
|
||||
.I /etc/sysctl.conf
|
||||
diff --git a/sysctl.c b/sysctl.c
|
||||
index 3445efe..b68170b 100644
|
||||
index bf4e529..1867777 100644
|
||||
--- a/sysctl.c
|
||||
+++ b/sysctl.c
|
||||
@@ -50,6 +50,7 @@ static bool PrintName;
|
||||
@ -62,21 +58,37 @@ index 3445efe..b68170b 100644
|
||||
|
||||
static void slashdot(char *restrict p, char old, char new){
|
||||
p = strpbrk(p,"/.");
|
||||
@@ -145,6 +147,10 @@ static int ReadSetting(const char *restrict const name) {
|
||||
outname = strdup(name);
|
||||
slashdot(outname,'/','.'); /* change / to . */
|
||||
@@ -135,16 +137,21 @@ static int ReadSetting(const char *restrict const name) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
+ /* used to display the output */
|
||||
+ outname = strdup(name);
|
||||
+ slashdot(outname,'/','.'); /* change / to . */
|
||||
+
|
||||
+ if (pattern && !pattern_match(outname)){
|
||||
+ goto out;
|
||||
+ free(outname);
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
/* used to open the file */
|
||||
tmpname = malloc(strlen(name)+strlen(PROC_PATH)+2);
|
||||
strcpy(tmpname, PROC_PATH);
|
||||
strcat(tmpname, name);
|
||||
slashdot(tmpname+strlen(PROC_PATH),'.','/'); /* change . to / */
|
||||
|
||||
- /* used to display the output */
|
||||
- outname = strdup(name);
|
||||
- slashdot(outname,'/','.'); /* change / to . */
|
||||
-
|
||||
if (stat(tmpname, &ts) < 0) {
|
||||
if (!IgnoreError) {
|
||||
perror(tmpname);
|
||||
@@ -391,7 +397,39 @@ out:
|
||||
@@ -391,7 +398,39 @@ out:
|
||||
return rc;
|
||||
}
|
||||
|
||||
-
|
||||
+static int pattern_match(const char* name) {
|
||||
+ const char* p = pattern;
|
||||
+ if (!p || !name)
|
||||
@ -101,7 +113,7 @@ index 3445efe..b68170b 100644
|
||||
+ }
|
||||
+ if (*p != *name)
|
||||
+ return 0;
|
||||
|
||||
+
|
||||
+ ++p;
|
||||
+ ++name;
|
||||
+ continue;
|
||||
@ -113,7 +125,7 @@ index 3445efe..b68170b 100644
|
||||
|
||||
/*
|
||||
* Preload the sysctl's from the conf file
|
||||
@@ -435,6 +473,10 @@ static int Preload(const char *restrict const filename) {
|
||||
@@ -435,6 +474,10 @@ static int Preload(const char *restrict const filename) {
|
||||
|
||||
StripLeadingAndTrailingSpaces(name);
|
||||
|
||||
@ -124,7 +136,7 @@ index 3445efe..b68170b 100644
|
||||
value = strtok(NULL, "\n\r");
|
||||
if (!value || !*value) {
|
||||
fprintf(stderr, WARN_BAD_LINE, filename, n);
|
||||
@@ -523,6 +565,16 @@ int main(int argc, char *argv[]) {
|
||||
@@ -562,6 +605,16 @@ int main(int argc, char *argv[]) {
|
||||
IgnoreError = true;
|
||||
return PreloadSystem();
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
From 40c2bfe16c9a9e9562c686afa9d6b7f754a5c8d9 Mon Sep 17 00:00:00 2001
|
||||
From 0925e01c49599c541ea3d40a7e30a313bb77efce Mon Sep 17 00:00:00 2001
|
||||
From: Ludwig Nussel <ludwig.nussel@suse.de>
|
||||
Date: Tue, 17 May 2011 16:35:18 +0200
|
||||
Subject: [PATCH procps 3/3] read sysctls also from /boot/sysctl.conf-$kernelversion
|
||||
Subject: [PATCH 3/3] read sysctls also from /boot/sysctl.conf-$kernelversion
|
||||
|
||||
---
|
||||
sysctl.c | 10 ++++++++++
|
||||
1 files changed, 10 insertions(+), 0 deletions(-)
|
||||
sysctl.c | 11 +++++++++++
|
||||
1 files changed, 11 insertions(+), 0 deletions(-)
|
||||
|
||||
diff --git a/sysctl.c b/sysctl.c
|
||||
index b68170b..6967ca8 100644
|
||||
index 1867777..a41539b 100644
|
||||
--- a/sysctl.c
|
||||
+++ b/sysctl.c
|
||||
@@ -27,6 +27,7 @@
|
||||
@ -19,17 +19,18 @@ index b68170b..6967ca8 100644
|
||||
#include <dirent.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
@@ -497,12 +498,21 @@ static int Preload(const char *restrict const filename) {
|
||||
@@ -510,6 +511,7 @@ static int sortpairs(const void* A, const void* B)
|
||||
|
||||
static int PreloadSystem(void) {
|
||||
unsigned i;
|
||||
unsigned di, i;
|
||||
+ struct utsname uts;
|
||||
const char* dirs[] = {
|
||||
"/lib/sysctl.d",
|
||||
"/usr/lib/sysctl.d",
|
||||
"/usr/local/lib/sysctl.d",
|
||||
"/run/sysctl.d",
|
||||
"/etc/sysctl.d",
|
||||
};
|
||||
@@ -556,6 +558,15 @@ static int PreloadSystem(void) {
|
||||
|
||||
qsort(cfgs, ncfgs, sizeof(struct cfg*), sortpairs);
|
||||
|
||||
+ if (uname(&uts) == 0) {
|
||||
+ char buf[PATH_MAX];
|
||||
+ snprintf(buf, sizeof(buf), "/boot/sysctl.conf-%s", uts.release);
|
||||
@ -38,9 +39,10 @@ index b68170b..6967ca8 100644
|
||||
+ Preload(buf);
|
||||
+ }
|
||||
+ }
|
||||
for (i=0; i < sizeof(dirs)/sizeof(dirs[0]); ++i) {
|
||||
struct dirent* de;
|
||||
DIR* dp = opendir(dirs[i]);
|
||||
+
|
||||
for (i = 0; i < ncfgs; ++i) {
|
||||
if (!Quiet)
|
||||
printf("* Applying %s ...\n", cfgs[i]->value);
|
||||
--
|
||||
1.7.3.4
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
-------------------------------------------------------------------
|
||||
Fri Aug 26 09:36:03 UTC 2011 - lnussel@suse.de
|
||||
|
||||
- make --system switch compatible with udev/systemd scheme
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Wed Aug 24 10:09:36 UTC 2011 - werner@suse.de
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user