libblkid: fix potential bufer overflows

While digging deeper into libblk probing, I found that some
computations might wrap and allocate too few buffer space which then
overflows. In particular on 32bit systems (chromebook) where size_t is
32bit, this is problematic (for 64bit the result fits into the calloc
size_t).

Signed-off-by: Karel Zak <kzak@redhat.com>
libmount: add new libmnt_monitor API

It's usually enough to us [e]poll() to monitor kernel mount table, but
there is no way how to monitor changes in userspace mount options
(e.g. _netdev). The management of these mount options is completely
hidden in libmount and /rub/mount/utab is private libmount file.

This patch introduces new libmnt_mount API to monitor also userspace
mount table.

Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils: use libc error printing facility

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
textual: improve error messages

Use error printing facilities that add command name in front of the error
message, and add explanation that is part of existing translations.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
line: use util-linux conventions

This change add --help and --version print outs, checking at exit the
stdout write was successful, and as a minor thing the command is made to
use wide char functions to read and write inputs.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
getopt: sync with 1.1.6 release

Reference: http://www.spinics.net/lists/util-linux-ng/msg10556.html
CC: Frodo Looijaard <frodo@frodo.looijaard.name>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
tests: copy test-suite from Frodo Looijaard's getopt

The test cases and their names are the same, but the surrounding testing
facility with Frodo's svn and util-linux are pretty different so this is
not exactly 1:1 copy.

Reference: svn://svn.frodo.looijaard.name/public/getopt/trunk/tests
CC: Frodo Looijaard <frodo@frodo.looijaard.name>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
tests: add more getopt tests

After importing Frodo's tests I ran coverage to see if something had
remained unchecked, and there were couple tests that could be done.

CC: Frodo Looijaard <frodo@frodo.looijaard.name>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
getopt: make nonoptions optstring comment correct

From manual page: 'If the first character of optstring is '-', then each
nonoption argv-element is handled as if it were the argument of an option
with character code 1.'

Reference: http://man7.org/linux/man-pages/man3/getopt.3.html
CC: Frodo Looijaard <frodo@frodo.looijaard.name>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
getopt: remove function prototypes

Functions are in right order so they do not need prototypes, with effect
of not needing to keep function argument changes in sync in two locations.

CC: Frodo Looijaard <frodo@frodo.looijaard.name>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
getopt: add struct getopt_control and remove global variables

CC: Frodo Looijaard <frodo@frodo.looijaard.name>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
getopt: use xstrdup rather than malloc + strcpy

CC: Frodo Looijaard <frodo@frodo.looijaard.name>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
getopt: make normalize() print strings

A change towards less indirection, and a change to free allocated memory.

CC: Frodo Looijaard <frodo@frodo.looijaard.name>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
getopt: remove unnecessary code

The control structure is initialized in main().

CC: Frodo Looijaard <frodo@frodo.looijaard.name>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
getopt: prefer switch-case rather than long if statement

And avoid testing same thing time after time.

CC: Frodo Looijaard <frodo@frodo.looijaard.name>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
getopt: change --shell argument parsing function

Avoid passing getopt_control stucture in when returning a value is enough.

CC: Frodo Looijaard <frodo@frodo.looijaard.name>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
getopt: avoid re-terminating long_option list at every update

Terminating the ctl->long_options list once when adding options is
completed is enough.  This also allows moving ctl->long_options_nr
increment to more appropriate location.

CC: Frodo Looijaard <frodo@frodo.looijaard.name>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>