Debian and Red Hat sysctl patches

This commit is contained in:
albert 2004-07-15 04:44:42 +00:00
parent 8300609ba9
commit aae2db6f9b
4 changed files with 36 additions and 13 deletions

View File

@ -7,6 +7,9 @@ kill
oldps oldps
pgrep pgrep
pkill pkill
slabtop
patches
test
proc proc
ps ps
skill skill

2
NEWS
View File

@ -4,6 +4,8 @@ move striping from install command to CFLAGS
now using gcc -fweb and -frename-registers options now using gcc -fweb and -frename-registers options
avoid warning about -lncurses when not linking -- thanks FLWM avoid warning about -lncurses when not linking -- thanks FLWM
watch: allow sub-second intervals -- thanks Thomas Stewart 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: personality-specific -x support (HP-UX and SVR4-MP)
ps: k option, same as --sort ps: k option, same as --sort
vmstat: fixed -d vmstat: fixed -d

View File

@ -12,9 +12,9 @@ sysctl \- configure kernel parameters at runtime
.SH SYNOPSIS .SH SYNOPSIS
.B "sysctl [-n] [-e] variable ..." .B "sysctl [-n] [-e] variable ..."
.br .br
.B "sysctl [-n] [-e] -w variable=value ..." .B "sysctl [-n] [-e] [-q] -w variable=value ..."
.br .br
.B "sysctl [-n] [-e] -p <filename>" .B "sysctl [-n] [-e] [-q] -p <filename>"
.br .br
.B "sysctl [-n] [-e] -a" .B "sysctl [-n] [-e] -a"
.br .br
@ -45,6 +45,9 @@ Use this option to disable printing of the key name when printing values.
.B "-e" .B "-e"
Use this option to ignore errors about unknown keys. Use this option to ignore errors about unknown keys.
.TP .TP
.B "-q"
Use this option to not display the values set to stdout.
.TP
.B "-w" .B "-w"
Use this option when you want to change a sysctl setting. Use this option when you want to change a sysctl setting.
.TP .TP

View File

@ -15,6 +15,8 @@
* Changelog: * Changelog:
* v1.01: * v1.01:
* - added -p <preload> to preload values from a file * - added -p <preload> to preload values from a file
* Horms:
* - added -q to be quiet when modifying values
* *
* Changes by Albert Cahalan, 2002. * Changes by Albert Cahalan, 2002.
*/ */
@ -46,6 +48,7 @@ static const char DEFAULT_PRELOAD[] = "/etc/sysctl.conf";
static bool PrintName; static bool PrintName;
static bool PrintNewline; static bool PrintNewline;
static bool IgnoreError; static bool IgnoreError;
static bool Quiet;
/* error messages */ /* error messages */
static const char ERR_UNKNOWN_PARAMETER[] = "error: Unknown parameter '%s'\n"; 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) { static int Usage(const char *restrict const name) {
printf("usage: %s [-n] [-e] variable ... \n" 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] -a \n"
" %s [-n] [-e] -p <file> (default /etc/sysctl.conf) \n" " %s [-n] [-e] [-q] -p <file> (default /etc/sysctl.conf) \n"
" %s [-n] [-e] -A\n", name, name, name, name, name); " %s [-n] [-e] -A\n", name, name, name, name, name);
return -1; return -1;
} }
@ -287,16 +290,24 @@ static int WriteSetting(const char *setting) {
break; break;
} }
} else { } else {
fprintf(fp, "%s\n", value); rc = fprintf(fp, "%s\n", value);
fclose(fp); if (rc < 0) {
fprintf(stderr, ERR_UNKNOWN_WRITING, errno, outname);
if (PrintName) { fclose(fp);
fprintf(stdout, "%s = %s\n", outname, value);
} else { } else {
if (PrintNewline) rc=fclose(fp);
fprintf(stdout, "%s\n", value); if (rc != 0)
else fprintf(stderr, ERR_UNKNOWN_WRITING, errno, outname);
fprintf(stdout, "%s", value); }
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; PrintName = true;
PrintNewline = true; PrintNewline = true;
IgnoreError = false; IgnoreError = false;
Quiet = false;
if (argc < 2) { if (argc < 2) {
return Usage(me); return Usage(me);
@ -419,6 +431,9 @@ int main(int argc, char **argv) {
preloadfile = *argv; preloadfile = *argv;
} }
return Preload(preloadfile); return Preload(preloadfile);
case 'q':
Quiet = true;
break;
case 'a': /* string and integer values (for Linux, all of them) */ case 'a': /* string and integer values (for Linux, all of them) */
case 'A': /* the above, including "opaques" (would be unprintable) */ case 'A': /* the above, including "opaques" (would be unprintable) */
case 'X': /* the above, with opaques completly printed in hex */ case 'X': /* the above, with opaques completly printed in hex */