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,9 +290,16 @@ static int WriteSetting(const char *setting) {
break; break;
} }
} else { } else {
fprintf(fp, "%s\n", value); rc = fprintf(fp, "%s\n", value);
if (rc < 0) {
fprintf(stderr, ERR_UNKNOWN_WRITING, errno, outname);
fclose(fp); fclose(fp);
} else {
rc=fclose(fp);
if (rc != 0)
fprintf(stderr, ERR_UNKNOWN_WRITING, errno, outname);
}
if (rc==0 && !Quiet) {
if (PrintName) { if (PrintName) {
fprintf(stdout, "%s = %s\n", outname, value); fprintf(stdout, "%s = %s\n", outname, value);
} else { } else {
@ -299,6 +309,7 @@ static int WriteSetting(const char *setting) {
fprintf(stdout, "%s", value); fprintf(stdout, "%s", value);
} }
} }
}
free(tmpname); free(tmpname);
free(outname); free(outname);
@ -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 */