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
pgrep
pkill
slabtop
patches
test
proc
ps
skill

2
NEWS
View File

@ -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

View File

@ -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 <filename>"
.B "sysctl [-n] [-e] [-q] -p <filename>"
.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

View File

@ -15,6 +15,8 @@
* Changelog:
* v1.01:
* - added -p <preload> 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 <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);
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 */