Commit Graph

47 Commits

Author SHA1 Message Date
Sami Kerola
2c99a09e52 sysctl: fix compiler warnings
sysctl.c:293:5: warning: no previous declaration for 'is_deprecated' [-Wmissing-declarations]
sysctl.c:472:58: warning: declaration of 'pattern' shadows a global declaration [-Wshadow]
sysctl.c:67:14: warning: shadowed declaration is here [-Wshadow]
sysctl.c:650:7: warning: variable 'SwitchesAllowed' set but not used [-Wunused-but-set-variable]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-11-06 22:30:01 +11:00
Sami Kerola
b2c08d1d41 sysctl: avoid crash when -p file has unexpected input
Commit e01765d30b added is_deprecated(), which
crashed when user had input without without /proc/sys/ subdirectory.  The below
should illustrate how exactly the bug got to be trickered.

$ cat ~/foo
cause = crash
$ ./sysctl -p ~/foo
Segmentation fault

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-05-07 09:01:10 +02:00
Mike Frysinger
e2987888e2 sysctl: restore old -p handling
The previous version of sysctl had the form:
	sysctl -p [file]
In other words, it required a space between the -p and the [file].
Omitting the space would lead to an error.

The new version though is the opposite:
	sysctl -p[file]
In other words, it requires there to not be a space.

Considering the old behavior has been around for a decade, and runtime
checking for this mismatch in behavior is silly, and supporting the old
syntax is trivial, add support for it.

When '-p regexp' is glob is used to make reqular expression to be
expanded to argument list, which also means that -p option will
allow multiple files being specified as input.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2012-05-07 09:01:10 +02:00
Mike Frysinger
156dd0b5a3 sysctl: fix broken .conf suffix matching
There's an off-by-one error in the count (".conf" is 5 bytes, not 6),
and the logic is inverted for the strcmp return value -- we want to
skip the files when they *don't* end in .conf, not when they *do*.

Also fix the off-by-one len check.

Bug-Debian: http://bugs.debian.org/669128
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2012-05-07 09:00:38 +02:00
Mike Frysinger
dbefb4476a sysctl: use stdbool.h
The stdbool.h header is part of C99 and has been usable on systems for
more than a decade.  Let's drop these manual hacks.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2012-05-03 09:16:34 +02:00
Sami Kerola
bf47d16095 sysctl: simplify file close error checking
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-04-06 15:32:45 +02:00
Sami Kerola
52269d22f3 all: check stdout and stderr status at exit
If stream status is not checked at the end of execution below problem
would not report error, or non-zero exit code.  The uptime is just an
example same was true with all commands of the project.

$ uptime >&- ; echo $?
uptime: write error: Bad file descriptor
1
$ uptime >/dev/full ; echo $?
uptime: write error: No space left on device
1

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-23 15:57:53 +01:00
Jim Warner
18c08390da sysctl: fix argument parsing regression
Any key=value pair following the first one are dropped after
commit 81df8e2630, due to changing
from the while loop to using getopt.

Broken behavior:
  sysctl net.ipv6.conf.tun0.optimistic_dad net.ipv6.conf.tun0.mc_forwarding
  net.ipv6.conf.tun0.optimistic_dad = 0

Good behavior:
  sysctl net.ipv6.conf.tun0.optimistic_dad net.ipv6.conf.tun0.mc_forwarding
  net.ipv6.conf.tun0.optimistic_dad = 0
  net.ipv6.conf.tun0.mc_forwarding = 0

Reference: http://www.freelists.org/post/procps/BUG-Commit-81df8e2-allows-only-one-keyvalue-arg
Reported-By: Sven Ulland <sveniu@opera.com>
Signed-off-by: Jim Warner <james.warner@comcast.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-08 08:40:02 +11:00
Sami Kerola
ce61089059 docs: clarification to license headers in files
Add license header to all files.  The summary of licensing is below,
taken from Craig Small's email which is referred in commit message
tail.

sysctl and pgrep are GPL 2+
The rest is LGPL 2.1+

Reference: http://www.freelists.org/post/procps/Incorrect-FSF-address-in-the-license-files,8
Bug-Redhat: https://bugzilla.redhat.com/show_bug.cgi?id=797962
CC: Craig Small <csmall@enc.com.au>
CC: Jaromir Capik <jcapik@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-03 18:41:11 +11:00
Sami Kerola
f5e2277a2e sysctl: print new line explicitely
In some cases sysctl does not print new line after the last line.
This commit fixes that behavior.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-03 18:40:58 +11:00
Sami Kerola
e01765d30b sysctl: deprecate parameters
According to arp(7) manual page base_reachable_time and retrans_time
are obsolete since kernel 2.6.12. Based on that the print all listing
will not show these two parameters, and attempt to set them will fail.

Reported-by: Alexandre Cavalcante Alencar <alexandre.alencar@gmail.com>
Bug-Debian: http://bugs.debian.org/599556
Reference: http://www.mail-archive.com/bk-commits-head@vger.kernel.org/msg03396.html
Reference: http://www.opensubscriber.com/message/linux-kernel@vger.kernel.org/7344177.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-02-14 11:22:15 +01:00
Sami Kerola
1689e769e6 sysctl: fix potential null derefence [smatch scan]
sysctl.c:560 PreloadSystem(29) error: potential null derefence 'cfgs'.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-02-05 21:02:34 +01:00
Sami Kerola
8fe81caa42 sysctl: fix coding style
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-01-25 09:18:38 +01:00
Sami Kerola
79ceb30b5c ps: unify cases and remove trailing dots in messages
Strings with lower caps & no trailing dots have greater change to
have multiple occurences, meaning less effort for translators, than
strings with them.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-01-15 20:52:58 +01:00
Craig Small
fb11e1fe0a Changed the err and warns to macros
err and warn are BSD format but they are not recommended by library
developers.  However their consiseness is useful!

The solution is to use some macros that create xerr etc which then
just map to the error() function.  The next problem is error() uses
program_invocation_name so we set this to program_invovation_short_name

This is a global set but seems to be the convention (or at least errors
are on the short name only) used everywhere else.
2012-01-03 18:48:43 +11:00
Sami Kerola
c3405fab1a translations: group usage texts
Reference: http://www.freelists.org/post/procps/backporting,5
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-01-02 16:29:03 +11:00
Sami Kerola
a10282422b sysctl: enable pattern matching with path
Pattern matching support in `sysctl: implement --pattern option'
commit did not work when variable path was defined, for example

$ sysctl net.ipv4 -r arp.ignore

gave no output. Reason being was tht the pattern was matched agains
the specified argument and not the output variable list.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-20 17:30:55 +01:00
Sami Kerola
7f99096ded sysctl: exit with error message instead of usage()
Printing usage() output at error is too noisy.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-20 17:30:54 +01:00
Sami Kerola
0022b6ec5d nls: improve translations and provide translator help comments
Reference: http://www.freelists.org/post/procps/backporting,1
Reported-by: Jim Warner <james.warner@comcast.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-20 17:30:54 +01:00
Sami Kerola
c862a4caa5 nls: add functions which take translations to be used
Add the following three functions to most of the commands.

setlocale (LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);

Reference: http://www.freelists.org/post/procps/backporting,1
Reported-by: Jim Warner <james.warner@comcast.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-20 17:30:53 +01:00
Sami Kerola
8795154eac sysctl: warn when separators are repeated
For some reason sysctl earlier allowed quite strange separators.

% sysctl kernel./.pty.nr
kernel./.pty.nr = 6
% sysctl kernel///pty//////////nr
kernel...pty..........nr = 6

This commit does not disallow that sort of constructs, but will warn
about them. In future disallowing these might be reasonable thing to
do.

% sysctl kernel./.pty.nr
sysctl: separators should not be repeated: ./.pty.nr
kernel./.pty.nr = 6

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-20 17:30:51 +01:00
Sami Kerola
9f89e336c3 sysctl: use libc error printing facilities
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-20 17:30:50 +01:00
Sami Kerola
1ef14f4bf9 includes: add xalloc.h to unify memory allocations
The xalloc.h provides necessary error checking.

Signed-off-by: Jim Warner <james.warner@comcast.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-20 17:30:50 +01:00
Sami Kerola
44f5745d7e sysctl: add gettext support
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-20 17:17:04 +01:00
Ludwig Nussel
7393599f73 sysctl: implement --pattern option
Useful for e.g network hook scripts together with --system to only apply
sysctls for a specific network interface.

Signed-off-by: Ludwig Nussel <ludwig.nussel@suse.de>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-20 17:17:03 +01:00
Ludwig Nussel
100959274c sysctl: 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.

Signed-off-by: Ludwig Nussel <ludwig.nussel@suse.de>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-20 17:17:03 +01:00
Sami Kerola
81df8e2630 sysctl: options handling & usage output
The sysctl now uses getopt_long and has help screen which be user
friendly. Rest of the modernization is left later, since this is
a command is used in scripts, and changing for instance error
printing to use warn & warnx could break stuff.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-20 17:17:01 +01:00
Craig Small
ff211c2f2e sysctl: fix up some option processing
A patch from Debian.

Backported-by: Sami Kerola <kerolasa@iki.fi>
2011-12-18 22:53:08 +11:00
Steven J. Hill
dd03003edd sysctl: remove index() for buildroot
The uClibc does not support index() function.

A patch from Buildroot.

Reference: http://git.buildroot.net/buildroot/patch/?id=f460603f02092b4f514d108dd8b4167a7a056213
Backported-by: Sami Kerola <kerolasa@iki.fi>
2011-12-18 10:28:21 +11:00
Sami Kerola
72da1d663a sysctl.c: crash due missing include
Missinc include made help printing to crash.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-06-04 17:22:44 +02:00
Werner Fink
4736dad559 Do not let sysctl abort due a missed file or directory under /proc.
Include signal.h for compiling w.

Signed-off-by: Werner Fink <werner@suse.de>
2011-01-19 12:26:01 +01:00
albert
7ed102fd76 sysctl: fix crash -- thanks Steinar Gunderson #423704 2007-05-28 01:59:28 +00:00
albert
a791f8034f sysctl: use - for stdin 2006-06-24 21:17:51 +00:00
albert
0edb6a86fb better error messages 2005-01-05 21:21:58 +00:00
albert
deae025969 new packager guidelines 2004-07-17 15:25:45 +00:00
albert
b357452770 sysctl -N 2004-07-15 15:22:23 +00:00
albert
aae2db6f9b Debian and Red Hat sysctl patches 2004-07-15 04:44:42 +00:00
albert
6b4f2559c6 from Folkert van Heusden's code review 2002-12-28 23:57:10 +00:00
albert
3e67b58ec2 satisfy GPL section 2a and LGPL section 2b name+date requirement 2002-12-15 00:30:17 +00:00
albert
78d2adaa15 add --version and --help 2002-12-12 04:49:39 +00:00
albert
c0e2e83dbd sysctl -e 2002-12-11 22:55:42 +00:00
albert
ade43a692b c99 -- ugh, this is HARD 2002-11-27 08:21:30 +00:00
albert
1572abd03e part 1 2002-11-25 23:24:40 +00:00
albert
3f6928c4fb move functions 2002-11-25 21:42:17 +00:00
albert
af89241571 coding style 2002-10-09 21:32:33 +00:00
albert
c785a0e34a slashdot fix 2002-10-09 06:23:58 +00:00
csmall
03a9b5a30f procps 010114 2002-02-01 22:47:29 +00:00