setarch: do not use -1 as array index [cppcheck]

Negative array index does technically work, but looks awkward and
can confuse static analyser such as cppcheck.

[sys-utils/setarch.c:267]: (error) Array index -1 is out of bounds

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
blkid: fix realloc memory leak [cppcheck]

[misc-utils/blkid.c:367]: (error) Common realloc mistake: 'str' nulled but not freed upon failure

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
uuidd: use output redirection which works [checkbashisms]

possible bashism in misc-utils/uuidd.rc line 52 (should be >word 2>&1):
	if pidofproc -p $PIDFILE $DAEMON >& /dev/null ; then

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
include: fix spurious list.h warnings

include/list.h:224:17: warning: ISO C forbids omitting the middle term of a ?: expression [-pedantic]
include/list.h:255:19: warning: ISO C forbids omitting the middle term of a ?: expression [-pedantic]

Compilation warned about that at least 110 times.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
build: fix redundant redeclaration warnings

env.c:24:15: warning: redundant redeclaration of 'environ' [-Wredundant-decls]
su.c:81:15: warning: redundant redeclaration of 'environ' [-Wredundant-decls]

fstab.c:581:14: warning: redundant redeclaration of 'strsignal' [-Wredundant-decls]

kill.h:1:13: note: previous declaration of 'get_pids' was here
kill.c:152:13: warning: redundant redeclaration of 'get_pids' [-Wredundant-decls]

kill.c:142:5: warning: redundant redeclaration of 'main' [-Wredundant-decls]
getopt.c:89:5: warning: redundant redeclaration of 'main' [-Wredundant-decls]

agetty.c:536:15: warning: redundant redeclaration of 'optarg' [-Wredundant-decls]
agetty.c:537:13: warning: redundant redeclaration of 'optind' [-Wredundant-decls]
script.c:161:13: warning: redundant redeclaration of 'optind' [-Wredundant-decls]
wall.c:96:13: warning: redundant redeclaration of 'optind' [-Wredundant-decls]

libmount.h:362:26: note: previous declaration of 'mnt_update_get_fs' was here
libmount.h:454:26: note: previous declaration of 'mnt_context_get_fs' was here
mountP.h:383:26: warning: redundant redeclaration of 'mnt_context_get_fs' [-Wredundant-decls]
mountP.h:398:26: warning: redundant redeclaration of 'mnt_update_get_fs' [-Wredundant-decls]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
build: fix unused parameter warnings

pager.c:203:14: warning: unused parameter 'argc' [-Wunused-parameter]
pager.c:203:26: warning: unused parameter 'argv' [-Wunused-parameter]

randutils.c:108:14: warning: unused parameter 'argc' [-Wunused-parameter]
randutils.c:108:26: warning: unused parameter 'argv' [-Wunused-parameter]

optstr.c:774:37: warning: unused parameter 'optstr' [-Wunused-parameter]
optstr.c:774:51: warning: unused parameter 'value' [-Wunused-parameter]
optstr.c:774:65: warning: unused parameter 'valsz' [-Wunused-parameter]
optstr.c:774:79: warning: unused parameter 'next' [-Wunused-parameter]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
sysfs: fix printf format warnings

sysfs.c:93:3: warning: format '%u' expects argument of type 'unsigned
	int *', but argument 3 has type 'int *' [-Wformat]
sysfs.c:93:3: warning: format '%u' expects argument of type 'unsigned
	int *', but argument 4 has type 'int *' [-Wformat]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
include: fix void pointer arithmetics warnings

all-io.h:18:9: warning: pointer of type 'void *' used in arithmetic [-pedantic]
all-io.h:38:9: warning: pointer of type 'void *' used in arithmetic [-pedantic]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
docs: clean up partx.8 manual

* Remove bold & italic noise.
* Reformat text to be 70 characters wide.
* Use option and option argument highlights consistently.
* Indent option argument list for --nr.
* Squeeze examples where the same is done multiple different ways.
* Use URL and email macros where appropriate.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
eject: inform if CD-ROM drive is not ready

Include file (see linux/cdrom.h lines 395 and 398) suggests ioctl() can
return CDS_NO_INFO and CDS_DRIVE_NOT_READY, which where ignored.  This
commit will tell user what is going on.

The commit will also make eject to crash in ioctl() will return
unexpected value.

Reference: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/linux/cdrom.h;h=dfd7f187c351440d2ffa81050e46ed2602877f73;hb=HEAD
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
wipefs: use symbolic value for markup mode

In case mode value is found to be out of bounds program will crash.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
blkdev: add blkdev_scsi_type_to_name()

Add a function, and necessary symbols, to convert scsi type id's
to name strings.

Reference: http://permalink.gmane.org/gmane.linux.utilities.util-linux-ng/5994
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
lsblk: use blkdev_scsi_type_to_name()

Replace inline version of similar, but less complete, functionality
with the lib/blkdev.c function.  The function will inform if a type is
unknown, which appears as hex string value.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
flock: user-configurable exit code

When locking the file fails with -n or -w option, caller has no way
to distinguish between the exit code 1 of the -c command,
and the exit code 1 of flock(1) caused by the conflicting lock.

Add a new -E <exitcode> (--conflict-exit-code) option to set
the exit code for the case of locking failure to any value.
su: remove unimplemented options -u and -v

Signed-off-by: Bernhard Voelker <mail@bernhard-voelker.de>
setsid: fix off-by-one error in execvp call

Bug introduced during --ctty implementation by v2.21-112-g8a2f04d.

Signed-off-by: Bernhard Voelker <mail@bernhard-voelker.de>
libblkid: update dm-verity scan

New superblock now contains UUID. Old version is not going to be used.

Signed-off-by: Milan Broz <mbroz@redhat.com>
libmount: plug a memory leak in exec_helper()

valgrind --leak-check=full ./sys-utils/mount -t cifs //127.0.0.1/users /mnt/smb -o user=root,password=linux
....
==21359== 28 bytes in 1 blocks are definitely lost in loss record 1 of 1
==21359==    at 0x4C298B2: realloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21359==    by 0x415780: __mnt_optstr_append_option (optstr.c:188)
==21359==    by 0x415CB5: mnt_optstr_set_option (optstr.c:387)
==21359==    by 0x40D778: do_mount (context_mount.c:192)
==21359==    by 0x40E6A9: mnt_context_do_mount (context_mount.c:685)
==21359==    by 0x40EB7B: mnt_context_mount (context_mount.c:786)
==21359==    by 0x4058B0: main (mount.c:918)

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
libmount: fix read before allocated buffer

valgrind --leak-check=full ./sys-utils/mount -t cifs //127.0.0.1/users /mnt/smb -o user=root,password=linux
....
==21359== Invalid read of size 1
==21359==    at 0x415AC6: mnt_optstr_remove_option_at (optstr.c:310)
==21359==    by 0x416358: mnt_optstr_apply_flags (optstr.c:716)
==21359==    by 0x40DFBF: mnt_context_prepare_mount (context_mount.c:86)
==21359==    by 0x40EB5A: mnt_context_mount (context_mount.c:782)
==21359==    by 0x4058B0: main (mount.c:918)
==21359==  Address 0x51cd5bf is 1 bytes before a block of size 10 alloc'd
==21359==    at 0x4C297CD: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21359==    by 0x4C29957: realloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21359==    by 0x415780: __mnt_optstr_append_option (optstr.c:188)
==21359==    by 0x412822: mnt_fs_append_options (fs.c:764)
==21359==    by 0x409288: mnt_context_append_options (context.c:733)
==21359==    by 0x4053F0: main (mount.c:776)

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
libmount: fix trivial typos

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>