From aae2db6f9be5fa586518c70a84ea27584174deb1 Mon Sep 17 00:00:00 2001 From: albert <> Date: Thu, 15 Jul 2004 04:44:42 +0000 Subject: [PATCH] Debian and Red Hat sysctl patches --- .cvsignore | 3 +++ NEWS | 2 ++ sysctl.8 | 7 +++++-- sysctl.c | 37 ++++++++++++++++++++++++++----------- 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/.cvsignore b/.cvsignore index 89ca7d36..42469bf7 100644 --- a/.cvsignore +++ b/.cvsignore @@ -7,6 +7,9 @@ kill oldps pgrep pkill +slabtop +patches +test proc ps skill diff --git a/NEWS b/NEWS index d3dc30df..56a0e2f7 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,8 @@ move striping from install command to CFLAGS now using gcc -fweb and -frename-registers options avoid warning about -lncurses when not linking -- thanks FLWM watch: allow sub-second intervals -- thanks Thomas Stewart +sysctl: -q option +sysctl: better error handling of failed writes ps: personality-specific -x support (HP-UX and SVR4-MP) ps: k option, same as --sort vmstat: fixed -d diff --git a/sysctl.8 b/sysctl.8 index 94926d38..7d0ed9fe 100644 --- a/sysctl.8 +++ b/sysctl.8 @@ -12,9 +12,9 @@ sysctl \- configure kernel parameters at runtime .SH SYNOPSIS .B "sysctl [-n] [-e] variable ..." .br -.B "sysctl [-n] [-e] -w variable=value ..." +.B "sysctl [-n] [-e] [-q] -w variable=value ..." .br -.B "sysctl [-n] [-e] -p " +.B "sysctl [-n] [-e] [-q] -p " .br .B "sysctl [-n] [-e] -a" .br @@ -45,6 +45,9 @@ Use this option to disable printing of the key name when printing values. .B "-e" Use this option to ignore errors about unknown keys. .TP +.B "-q" +Use this option to not display the values set to stdout. +.TP .B "-w" Use this option when you want to change a sysctl setting. .TP diff --git a/sysctl.c b/sysctl.c index 613688cd..022694a7 100644 --- a/sysctl.c +++ b/sysctl.c @@ -15,6 +15,8 @@ * Changelog: * v1.01: * - added -p to preload values from a file + * Horms: + * - added -q to be quiet when modifying values * * Changes by Albert Cahalan, 2002. */ @@ -46,6 +48,7 @@ static const char DEFAULT_PRELOAD[] = "/etc/sysctl.conf"; static bool PrintName; static bool PrintNewline; static bool IgnoreError; +static bool Quiet; /* error messages */ static const char ERR_UNKNOWN_PARAMETER[] = "error: Unknown parameter '%s'\n"; @@ -80,9 +83,9 @@ static void slashdot(char *restrict p, char old, char new){ */ static int Usage(const char *restrict const name) { printf("usage: %s [-n] [-e] variable ... \n" - " %s [-n] [-e] -w variable=value ... \n" + " %s [-n] [-e] [-q] -w variable=value ... \n" " %s [-n] [-e] -a \n" - " %s [-n] [-e] -p (default /etc/sysctl.conf) \n" + " %s [-n] [-e] [-q] -p (default /etc/sysctl.conf) \n" " %s [-n] [-e] -A\n", name, name, name, name, name); return -1; } @@ -287,16 +290,24 @@ static int WriteSetting(const char *setting) { break; } } else { - fprintf(fp, "%s\n", value); - fclose(fp); - - if (PrintName) { - fprintf(stdout, "%s = %s\n", outname, value); + rc = fprintf(fp, "%s\n", value); + if (rc < 0) { + fprintf(stderr, ERR_UNKNOWN_WRITING, errno, outname); + fclose(fp); } else { - if (PrintNewline) - fprintf(stdout, "%s\n", value); - else - fprintf(stdout, "%s", value); + rc=fclose(fp); + if (rc != 0) + fprintf(stderr, ERR_UNKNOWN_WRITING, errno, outname); + } + if (rc==0 && !Quiet) { + if (PrintName) { + fprintf(stdout, "%s = %s\n", outname, value); + } else { + if (PrintNewline) + fprintf(stdout, "%s\n", value); + else + fprintf(stdout, "%s", value); + } } } @@ -377,6 +388,7 @@ int main(int argc, char **argv) { PrintName = true; PrintNewline = true; IgnoreError = false; + Quiet = false; if (argc < 2) { return Usage(me); @@ -419,6 +431,9 @@ int main(int argc, char **argv) { preloadfile = *argv; } return Preload(preloadfile); + case 'q': + Quiet = true; + break; case 'a': /* string and integer values (for Linux, all of them) */ case 'A': /* the above, including "opaques" (would be unprintable) */ case 'X': /* the above, with opaques completly printed in hex */