]> git.ipfire.org Git - thirdparty/util-linux.git/log
thirdparty/util-linux.git
10 years agocfdisk: improve menu clean function
Karel Zak [Mon, 5 Jan 2015 11:42:24 +0000 (12:42 +0100)] 
cfdisk: improve menu clean function

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agocfdisk: detect too small partition sizes
Karel Zak [Mon, 5 Jan 2015 11:13:25 +0000 (12:13 +0100)] 
cfdisk: detect too small partition sizes

References: https://github.com/karelzak/util-linux/issues/136
Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agochfn: fix compilation without libuser
Karel Zak [Fri, 19 Dec 2014 14:05:04 +0000 (15:05 +0100)] 
chfn: fix compilation without libuser

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agomore: fix compiler warnings
Karel Zak [Fri, 19 Dec 2014 13:34:03 +0000 (14:34 +0100)] 
more: fix compiler warnings

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agoMerge remote-tracking branch 'sami/2014wk49'
Karel Zak [Fri, 19 Dec 2014 13:28:42 +0000 (14:28 +0100)] 
Merge remote-tracking branch 'sami/2014wk49'

* sami/2014wk49:
  chfn: make command to obey login.defs CHFN_RESTRICT instructions
  chfn: remove set_changed_data() and add add_missing()
  chfn: rename prompt() to ask_new_field()
  chfn: move new and old finger structs to chfn control struct
  chfn: clean up parse_argv()
  chfn: add minimalistic struct chfn_control
  chfn: simplify parse_passwd() by using strsep()
  chfn: fix usage() regression
  chfn: use xasprintf() rather than bunch of strlen() and malloc() calls
  chfn: rewrite prompt() to use strutils
  chfn: remove function prototypes
  lslogins: use hardcoded paths from pathnames.h
  lslogins: add space to systemd journal header and message
  lslogins: reject unknown time format arguments
  lslogins: fix short options
  lslogins: tell why command failed
  lslogins: make journald last logs time stamps to honor --time-format
  lslogins: allow changing password changed and expiration time formats

10 years agoipcs: fix shmctl() usage
Karel Zak [Fri, 19 Dec 2014 12:42:41 +0000 (13:42 +0100)] 
ipcs: fix shmctl() usage

The function shmctl() has to be called with 'struct shmid_ds', and if
you need 'struct shminfo' then the right way is to cast:

bad way:
  struct shm_info info;

  shmctl(0, SHM_INFO, &info);

right way:
  struct shmid_ds buf;
  struct shm_info *info;

  shmctl(0, SHM_INFO, &buf);
  info = (struct shm_info *) &buf);

The patch also fixes bug in ipc_shm_get_limits() where is missing
lim->shmmax in code based on shmctl().

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agotests: don't check the current ipcs limits
Karel Zak [Fri, 19 Dec 2014 12:36:07 +0000 (13:36 +0100)] 
tests: don't check the current ipcs limits

The ipcs/limit test checks the current kernel limits, but we have no
clue about the current setting, so on on 64bit system it may overflow.

It's better to test for well known limits only. For the random setting
is there ipcs/limit2 test.

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agomore: blacklist unsigned integer overflow [AddressSanitizer]
Sami Kerola [Wed, 17 Dec 2014 22:57:02 +0000 (22:57 +0000)] 
more: blacklist unsigned integer overflow [AddressSanitizer]

The mbrtowc() return values are overflowing by design.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agoipcs: fix two data type errors [AddressSanitizer]
Sami Kerola [Tue, 25 Nov 2014 20:04:44 +0000 (20:04 +0000)] 
ipcs: fix two data type errors [AddressSanitizer]

==3218==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fffa577e2b0 at pc 0x4501f9 bp 0x7fffa577e130 sp 0x7fffa577e108
WRITE of size 112 at 0x7fffa577e2b0 thread T0
    #0 0x4501f8 in shmctl /home/users/aadgrand/LLVM/releases/ubuntu/final/llvm.src/projects/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc:2502
    #1 0x48bd13 in ipc_shm_get_info /home/travis/build/kerolasa/lelux-utiliteetit/sys-utils/ipcutils.c:157
    #2 0x488884 in do_shm /home/travis/build/kerolasa/lelux-utiliteetit/sys-utils/ipcs.c:279
    #3 0x4844a8 in main /home/travis/build/kerolasa/lelux-utiliteetit/sys-utils/ipcs.c:175
    #4 0x2afb3f8c176c (/lib/x86_64-linux-gnu/libc.so.6+0x2176c)
    #5 0x48408c in _start (/home/travis/build/kerolasa/lelux-utiliteetit/ipcs+0x48408c)

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agolscpu: blacklist vmware_bdoor() AddressSanitizer check
Sami Kerola [Sat, 22 Nov 2014 09:01:36 +0000 (09:01 +0000)] 
lscpu: blacklist vmware_bdoor() AddressSanitizer check

AddressSanitizer is identifying the __asm__ segment as suspicious.

==1215==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000
(pc 0x0000004ccffd bp 0x7fff9b7184f0 sp 0x7fff9b7184e0 T0)
    #0 0x4ccffc in vmware_bdoor /home/src/util-linux/sys-utils/lscpu.c:660

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agoinclude/c: define UL_ASAN_BLACKLIST address_sanitizer function attribute
Sami Kerola [Sat, 22 Nov 2014 08:49:34 +0000 (08:49 +0000)] 
include/c: define UL_ASAN_BLACKLIST address_sanitizer function attribute

The UL_ASAN_BLACKLIST allows AddressSanitizer to be switched off for
functions that cannot be checked.

Reference: http://dxr.mozilla.org/mozilla-central/source/mfbt/Attributes.h
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agochfn: make command to obey login.defs CHFN_RESTRICT instructions
Sami Kerola [Sun, 14 Dec 2014 16:45:50 +0000 (16:45 +0000)] 
chfn: make command to obey login.defs CHFN_RESTRICT instructions

Reference: http://man7.org/linux/man-pages/man5/login.defs.5.html
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=138519
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agochfn: remove set_changed_data() and add add_missing()
Sami Kerola [Wed, 17 Dec 2014 22:28:49 +0000 (22:28 +0000)] 
chfn: remove set_changed_data() and add add_missing()

The add_missing() and find_field() functions are needed when input data
is incomplete, such as in case when chfn is instructed to change only
selected fields with command line options.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agochfn: rename prompt() to ask_new_field()
Sami Kerola [Wed, 17 Dec 2014 22:28:03 +0000 (22:28 +0000)] 
chfn: rename prompt() to ask_new_field()

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agochfn: move new and old finger structs to chfn control struct
Sami Kerola [Sun, 14 Dec 2014 17:44:11 +0000 (17:44 +0000)] 
chfn: move new and old finger structs to chfn control struct

This change is a little bit messy, and requires a comment the struct
finfo should not have 'struct passwd *pw' as it's member.  The earlier
struct design would have been burden to maintain, and confusing to use.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agochfn: clean up parse_argv()
Sami Kerola [Sun, 14 Dec 2014 13:56:32 +0000 (13:56 +0000)] 
chfn: clean up parse_argv()

Use switch() case ?: for all option parsing, as in most of the other
source files.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agochfn: add minimalistic struct chfn_control
Sami Kerola [Sun, 14 Dec 2014 13:48:17 +0000 (13:48 +0000)] 
chfn: add minimalistic struct chfn_control

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agochfn: simplify parse_passwd() by using strsep()
Sami Kerola [Sun, 14 Dec 2014 13:28:57 +0000 (13:28 +0000)] 
chfn: simplify parse_passwd() by using strsep()

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agochfn: fix usage() regression
Sami Kerola [Sun, 14 Dec 2014 12:31:11 +0000 (12:31 +0000)] 
chfn: fix usage() regression

Commit db433bf737a5fd4e1c7cca5e3603934743eebd1c changed -u for --help to
-h, that is not true.  The -h is short hand for --home-phone.  And the
--version is accompanied with -v not -V.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agochfn: use xasprintf() rather than bunch of strlen() and malloc() calls
Sami Kerola [Sun, 14 Dec 2014 12:28:26 +0000 (12:28 +0000)] 
chfn: use xasprintf() rather than bunch of strlen() and malloc() calls

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agochfn: rewrite prompt() to use strutils
Sami Kerola [Sun, 14 Dec 2014 11:37:03 +0000 (11:37 +0000)] 
chfn: rewrite prompt() to use strutils

The left and right white space trimming can be done with strutils.h
[lr]trim_whitespace() functions.

As a minor fix when user input exceeds maxium allowed gecos field length
the remaining characters in stdin are purged so that re-prompting works
correctly.

Additionally the prompt() is made to add message to check_gecos_string(),
so that there are less similar strings for translation project to deal.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agochfn: remove function prototypes
Sami Kerola [Sat, 13 Dec 2014 22:16:21 +0000 (22:16 +0000)] 
chfn: remove function prototypes

Requires resuffling functions order they work without issues.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agolslogins: use hardcoded paths from pathnames.h
Sami Kerola [Sat, 13 Dec 2014 18:07:44 +0000 (18:07 +0000)] 
lslogins: use hardcoded paths from pathnames.h

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agolslogins: add space to systemd journal header and message
Sami Kerola [Sat, 13 Dec 2014 17:49:20 +0000 (17:49 +0000)] 
lslogins: add space to systemd journal header and message

This commit changes journal messages in individual user printout the
following way.

Dec 13 16:02:05 systemd[324]:Time has been changed (old)
Dec 13 16:02:05 systemd[324]: Time has been changed (new)

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agolslogins: reject unknown time format arguments
Sami Kerola [Sat, 13 Dec 2014 17:11:04 +0000 (17:11 +0000)] 
lslogins: reject unknown time format arguments

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agolslogins: fix short options
Sami Kerola [Sat, 13 Dec 2014 16:58:37 +0000 (16:58 +0000)] 
lslogins: fix short options

Usage is promising -e is an option alias of --export, so make it work.
And get rid of -x that was accepted, but not in use.

Long only enum member OPT_VER was probably a development time idea, that
never got to be used.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agolslogins: tell why command failed
Sami Kerola [Sat, 13 Dec 2014 16:41:06 +0000 (16:41 +0000)] 
lslogins: tell why command failed

Printing usage() without hint what is wrong does not help an user.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agolslogins: make journald last logs time stamps to honor --time-format
Sami Kerola [Fri, 12 Dec 2014 23:07:28 +0000 (23:07 +0000)] 
lslogins: make journald last logs time stamps to honor --time-format

This makes by default the last logs to have year in output when necessary.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agolslogins: allow changing password changed and expiration time formats
Sami Kerola [Fri, 12 Dec 2014 22:46:04 +0000 (22:46 +0000)] 
lslogins: allow changing password changed and expiration time formats

The password change and expiry has are marked with resolution of a day,
so add a new short iso-8601 format.  With this system admins can easily
find users has not updated their password lately

$ lslogins --time-format=iso --user --output=pwd-change,user | sort -n

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agostrutils: fix unsigned integer overflows [AddressSanitizer]
Sami Kerola [Sat, 22 Nov 2014 08:18:17 +0000 (08:18 +0000)] 
strutils: fix unsigned integer overflows [AddressSanitizer]

include/strutils.h:174:10: runtime error: unsigned integer overflow: 0 -
1 cannot be represented in type 'size_t' (aka 'unsigned long')

include/strutils.h:178:6: runtime error: unsigned integer overflow:
18446744073709551615 + 1 cannot be represented in type 'size_t' (aka
'unsigned long')

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agofdisk: (sgi) fix unsigned integer overflow [AddressSanitizer]
Sami Kerola [Sat, 22 Nov 2014 08:13:59 +0000 (08:13 +0000)] 
fdisk: (sgi) fix unsigned integer overflow [AddressSanitizer]

include/pt-sgi.h:103:7: runtime error: unsigned integer overflow: 0 -
1186450447 cannot be represented in type 'unsigned int'

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agolib: fix crc32 and crc64 interger overflows [AddressSanitizer]
Sami Kerola [Sat, 22 Nov 2014 00:31:07 +0000 (00:31 +0000)] 
lib: fix crc32 and crc64 interger overflows [AddressSanitizer]

lib/crc32.c:111:11: runtime error: unsigned integer overflow: 0 - 1
cannot be represented in type 'size_t' (aka 'unsigned long')

lib/crc64.c:101:12: runtime error: unsigned integer overflow: 0 - 1
cannot be represented in type 'size_t' (aka 'unsigned long')

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agocal: fix signed integer overflow [AddressSanitizer]
Sami Kerola [Fri, 21 Nov 2014 23:33:33 +0000 (23:33 +0000)] 
cal: fix signed integer overflow [AddressSanitizer]

misc-utils/cal.c:811:16: runtime error: signed integer overflow:
2147483645 + 536870911 cannot be represented in type 'int'

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agolib/mbalign: fix unsigned integer overflow [AddressSanitizer]
Sami Kerola [Fri, 21 Nov 2014 23:11:31 +0000 (23:11 +0000)] 
lib/mbalign: fix unsigned integer overflow [AddressSanitizer]

This error was reported 155 times.

lib/mbsalign.c:322:18: runtime error: unsigned integer overflow: 0 - 1
cannot be represented in type 'size_t' (aka 'unsigned long')

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agosfdisk: in the usage text show -v for --version instead of -V
Benno Schulenberg [Sun, 14 Dec 2014 19:45:33 +0000 (20:45 +0100)] 
sfdisk: in the usage text show -v for --version instead of -V

In sfdisk -V is taken by --verify.  Use for the description of --version
the same indentation as for --help, not that of the other options.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
10 years agodocs: fix the grammar and formatting in the man page of sfdisk
Benno Schulenberg [Sun, 14 Dec 2014 19:45:32 +0000 (20:45 +0100)] 
docs: fix the grammar and formatting in the man page of sfdisk

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
10 years agodocs: adjust some formatting and wordings in a handful of man pages
Benno Schulenberg [Sun, 14 Dec 2014 19:45:31 +0000 (20:45 +0100)] 
docs: adjust some formatting and wordings in a handful of man pages

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
10 years agodocs: adjust the grammar, text, sorting and formatting of logger man page
Benno Schulenberg [Sun, 14 Dec 2014 19:45:30 +0000 (20:45 +0100)] 
docs: adjust the grammar, text, sorting and formatting of logger man page

The message argument is not an option and should not be listed among
those.  Describe the optional argument of --rfc5424 better.  Use the
= and no space for optional option arguments.  Don't italicize words
unnecessarily.  Use bold for literal things.  And sort the options
alphabetically (apart from -V and -h).

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
10 years agodocs: don't use bold or italics for "[option]" in synopsis of man pages
Benno Schulenberg [Sun, 14 Dec 2014 19:45:29 +0000 (20:45 +0100)] 
docs: don't use bold or italics for "[option]" in synopsis of man pages

As per the convention shown in Documentation/howto-man-page.txt.
Also make a few other tiny adjustments along the way.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
10 years agodocs: improve the sorting of the options in the man page of getopt
Benno Schulenberg [Sun, 14 Dec 2014 19:45:28 +0000 (20:45 +0100)] 
docs: improve the sorting of the options in the man page of getopt

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
10 years agotextual: do not start option descriptions with a capital
Benno Schulenberg [Sun, 14 Dec 2014 19:45:27 +0000 (20:45 +0100)] 
textual: do not start option descriptions with a capital

This normalizes the help text of getopt, clarifies one description,
and also adjust two comments.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
10 years agodocs: fix the grammar of the recent comment about comments
Benno Schulenberg [Sun, 14 Dec 2014 19:45:26 +0000 (20:45 +0100)] 
docs: fix the grammar of the recent comment about comments

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
10 years agologin: Fix unused variables in login.c if _HAVE_UT_TV isn't defined
Will Johansson [Mon, 15 Dec 2014 11:51:29 +0000 (03:51 -0800)] 
login: Fix unused variables in login.c if _HAVE_UT_TV isn't defined

Wrap around the variable declaration for `tv' with ifdef so the compilers
don't warn about unused variables if we're compiling without UT_TV. This
happens with the musl libc, since it doesn't define _HAVE_UT_TV, even
though it _does_ have the ut_tv field in the utmp struct.

Signed-off-by: Will Johansson <will.johansson@gmail.com>
10 years agolibmount: allow unspecified source on remount
Karel Zak [Thu, 18 Dec 2014 09:30:14 +0000 (10:30 +0100)] 
libmount: allow unspecified source on remount

kernel does not require mount source (e.g. device name) on remount, it
means that fstab/mtab/mountinfo should be optional in this case.
For example:

 mount -o rw,remount /

has to work on system without mounted /proc.

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agologin-utils: Enable building util-linux against OpenPAM
Will Johansson [Wed, 10 Dec 2014 02:40:31 +0000 (18:40 -0800)] 
login-utils: Enable building util-linux against OpenPAM

OpenPAM is compatible with util-linux, with a few changes, namely
using OpenPAM's conversation function, openpam_ttyconv.

We check for Linux-PAM by querying for security/pam_misc.h, and OpenPAM
by querying for security/openpam.h.

Signed-off-by: Will Johansson <will.johansson@gmail.com>
10 years agolslogins: fix -l -g logic
Karel Zak [Fri, 12 Dec 2014 14:17:19 +0000 (15:17 +0100)] 
lslogins: fix -l -g logic

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agoterminal-colors.d: add note about comments to man page
Karel Zak [Fri, 12 Dec 2014 13:02:21 +0000 (14:02 +0100)] 
terminal-colors.d: add note about comments to man page

Reported-by: Jan Pokorný <jpokorny@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agogetopt: cleanup add_log_options()
Karel Zak [Tue, 9 Dec 2014 11:21:33 +0000 (12:21 +0100)] 
getopt: cleanup add_log_options()

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agogetopt: rename function to keep code readable
Karel Zak [Tue, 9 Dec 2014 11:17:57 +0000 (12:17 +0100)] 
getopt: rename function to keep code readable

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agogetopt: fix compiler warning
Karel Zak [Tue, 9 Dec 2014 11:17:22 +0000 (12:17 +0100)] 
getopt: fix compiler warning

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agoMerge branch '2014wk48' of git://github.com/kerolasa/lelux-utiliteetit
Karel Zak [Tue, 9 Dec 2014 10:53:39 +0000 (11:53 +0100)] 
Merge branch '2014wk48' of git://github.com/kerolasa/lelux-utiliteetit

* '2014wk48' of git://github.com/kerolasa/lelux-utiliteetit:
  getopt: avoid re-terminating long_option list at every update
  getopt: change --shell argument parsing function
  getopt: prefer switch-case rather than long if statement
  getopt: remove unnecessary code
  getopt: make normalize() print strings
  getopt: use xstrdup rather than malloc + strcpy
  getopt: add struct getopt_control and remove global variables
  getopt: remove function prototypes
  getopt: make nonoptions optstring comment correct
  tests: add more getopt tests
  tests: copy test-suite from Frodo Looijaard's getopt
  getopt: sync with 1.1.6 release
  line: use util-linux conventions
  textual: improve error messages
  login-utils: use libc error printing facility

10 years agolslogins: align usage() and manual with struct option longopts
Sami Kerola [Mon, 8 Dec 2014 22:20:56 +0000 (22:20 +0000)] 
lslogins: align usage() and manual with struct option longopts

Short option -G goes together with long option --supp-groups, while
neither of -m or --groups-info has worked in a release so remove them
from usage() and manual.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agolslogins: fix assertion failure for none existing logins
Sami Kerola [Mon, 8 Dec 2014 22:20:55 +0000 (22:20 +0000)] 
lslogins: fix assertion failure for none existing logins

This cange makes the following to retun none-zero value instead of a core
dump.

$ lslogins qwertyuiopasdfghjklzxcvbnm1234567
lslogins: libsmartcols/src/line.c:362: scols_line_get_cell: Assertion `ln' failed.
Aborted (core dumped)

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agobuild-sys: hwclock requires -lm
Cristian Rodríguez [Mon, 8 Dec 2014 20:30:10 +0000 (17:30 -0300)] 
build-sys: hwclock requires -lm

hwclock uses fabs and therefore needs libm, otherwise a linking
error ocurrs when building with -fno-builtin.

10 years agoline: use util-linux conventions
Sami Kerola [Sun, 7 Dec 2014 10:13:04 +0000 (10:13 +0000)] 
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>
10 years agotextual: improve error messages
Sami Kerola [Sun, 7 Dec 2014 10:13:03 +0000 (10:13 +0000)] 
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>
10 years agologin-utils: use libc error printing facility
Sami Kerola [Sun, 7 Dec 2014 10:13:02 +0000 (10:13 +0000)] 
login-utils: use libc error printing facility

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agogetopt: avoid re-terminating long_option list at every update
Sami Kerola [Sun, 7 Dec 2014 09:55:08 +0000 (09:55 +0000)] 
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>
10 years agogetopt: change --shell argument parsing function
Sami Kerola [Sun, 7 Dec 2014 00:40:11 +0000 (00:40 +0000)] 
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>
10 years agogetopt: prefer switch-case rather than long if statement
Sami Kerola [Sun, 7 Dec 2014 00:16:56 +0000 (00:16 +0000)] 
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>
10 years agogetopt: remove unnecessary code
Sami Kerola [Sat, 6 Dec 2014 18:21:56 +0000 (18:21 +0000)] 
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>
10 years agogetopt: make normalize() print strings
Sami Kerola [Sat, 6 Dec 2014 17:58:16 +0000 (17:58 +0000)] 
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>
10 years agogetopt: use xstrdup rather than malloc + strcpy
Sami Kerola [Sat, 6 Dec 2014 11:50:03 +0000 (11:50 +0000)] 
getopt: use xstrdup rather than malloc + strcpy

CC: Frodo Looijaard <frodo@frodo.looijaard.name>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agogetopt: add struct getopt_control and remove global variables
Sami Kerola [Sat, 6 Dec 2014 11:32:46 +0000 (11:32 +0000)] 
getopt: add struct getopt_control and remove global variables

CC: Frodo Looijaard <frodo@frodo.looijaard.name>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agogetopt: remove function prototypes
Sami Kerola [Sat, 6 Dec 2014 16:48:57 +0000 (16:48 +0000)] 
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>
10 years agogetopt: make nonoptions optstring comment correct
Sami Kerola [Sat, 6 Dec 2014 10:47:53 +0000 (10:47 +0000)] 
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>
10 years agotests: add more getopt tests
Sami Kerola [Fri, 5 Dec 2014 22:49:48 +0000 (22:49 +0000)] 
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>
10 years agotests: copy test-suite from Frodo Looijaard's getopt
Sami Kerola [Thu, 4 Dec 2014 22:39:21 +0000 (22:39 +0000)] 
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>
10 years agogetopt: sync with 1.1.6 release
Sami Kerola [Thu, 4 Dec 2014 22:04:08 +0000 (22:04 +0000)] 
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>
10 years agoline: use util-linux conventions
Sami Kerola [Thu, 4 Dec 2014 21:49:13 +0000 (21:49 +0000)] 
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>
10 years agotextual: improve error messages
Sami Kerola [Thu, 4 Dec 2014 21:10:44 +0000 (21:10 +0000)] 
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>
10 years agologin-utils: use libc error printing facility
Sami Kerola [Sun, 30 Nov 2014 18:10:57 +0000 (18:10 +0000)] 
login-utils: use libc error printing facility

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
10 years agolibmount: add new libmnt_monitor API
Karel Zak [Fri, 5 Dec 2014 14:30:04 +0000 (15:30 +0100)] 
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>
10 years agolibblkid: fix potential bufer overflows
Sebastian Krahmer [Fri, 5 Dec 2014 09:06:42 +0000 (10:06 +0100)] 
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>
10 years agolibfdisk: fix bug in cmp_numbers() and partitions sorting
Karel Zak [Thu, 4 Dec 2014 12:06:03 +0000 (13:06 +0100)] 
libfdisk: fix bug in cmp_numbers() and partitions sorting

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1170191
Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agolibfdisk: remove 'end' from struct fdisk_partition
Karel Zak [Thu, 4 Dec 2014 11:24:31 +0000 (12:24 +0100)] 
libfdisk: remove 'end' from struct fdisk_partition

This struct member duplicate "start+size".

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agolibfdisk: rename sector_t to fdisk_sector_t
Karel Zak [Thu, 4 Dec 2014 10:41:51 +0000 (11:41 +0100)] 
libfdisk: rename sector_t to fdisk_sector_t

.. just to avoid too generic names for public API.

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agolibfdisk: fix cfdisk freespace analyze
Karel Zak [Thu, 4 Dec 2014 09:27:39 +0000 (10:27 +0100)] 
libfdisk: fix cfdisk freespace analyze

The problem is how fdisk_partition_cmp_start() compare numbers, the
function returns result from "a->start - b->start", unfortunately the
numbers are uint64, but function returns "int".

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1170191
Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agolsblk: add SUBSYSTEMS column
Karel Zak [Tue, 2 Dec 2014 10:38:15 +0000 (11:38 +0100)] 
lsblk: add SUBSYSTEMS column

 $ lsblk -oNAME,SIZE,TYPE,SUBSYSTEMS /dev/sr0
 NAME  SIZE TYPE SUBSYSTEMS
 sr0   7.8M rom  block:scsi:usb:pci

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agodocs: update TODO file
Karel Zak [Tue, 2 Dec 2014 10:09:31 +0000 (11:09 +0100)] 
docs: update TODO file

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agolsblk: add HOTPLUG column
Karel Zak [Tue, 2 Dec 2014 10:09:04 +0000 (11:09 +0100)] 
lsblk: add HOTPLUG column

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agoeject: use sysfs API to detect hotplug
Karel Zak [Tue, 2 Dec 2014 10:00:19 +0000 (11:00 +0100)] 
eject: use sysfs API to detect hotplug

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agolib/sysfs: add subsystem and hotplug detection
Karel Zak [Tue, 2 Dec 2014 09:59:48 +0000 (10:59 +0100)] 
lib/sysfs: add subsystem and hotplug detection

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agodocs: update TODO file
Karel Zak [Fri, 28 Nov 2014 12:29:15 +0000 (13:29 +0100)] 
docs: update TODO file

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agolibblkid: care about unsafe chars in cache
Karel Zak [Thu, 27 Nov 2014 12:39:35 +0000 (13:39 +0100)] 
libblkid: care about unsafe chars in cache

The high-level libblkid API uses /run/blkid/blkid.tab cache to
store probing results. The cache format is

   <device NAME="value" ...>devname</device>

and unfortunately the cache code does not escape quotation marks:

   # mkfs.ext4 -L 'AAA"BBB'

   # cat /run/blkid/blkid.tab
   ...
   <device ... LABEL="AAA"BBB" ...>/dev/sdb1</device>

such string is later incorrectly parsed and blkid(8) returns
nonsenses. And for use-cases like

   # eval $(blkid -o export /dev/sdb1)

it's also insecure.

Note that mount, udevd and blkid -p are based on low-level libblkid
API, it bypass the cache and directly read data from the devices.

The current udevd upstream does not depend on blkid(8) output at all,
it's directly linked with the library and all unsafe chars are encoded by
\x<hex> notation.

   # mkfs.ext4 -L 'X"`/tmp/foo` "' /dev/sdb1
   # udevadm info --export-db | grep LABEL
   ...
   E: ID_FS_LABEL=X__/tmp/foo___
   E: ID_FS_LABEL_ENC=X\x22\x60\x2ftmp\x2ffoo\x60\x20\x22

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agoinclude/carefulputc: encode also ' and $ in fputs_quoted() output
Karel Zak [Thu, 27 Nov 2014 12:36:09 +0000 (13:36 +0100)] 
include/carefulputc: encode also ' and $ in fputs_quoted() output

This change is important for commands linked with libsmartcols (e.g. lsblk(1))
to make it more safe for crazy scenarios like

   eval $(lsblk --fs --pairs /dev/sdb1)

where the command returns NAME="value" from filesystem LABELS (etc.)

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agolibfdisk: add API docs
Karel Zak [Wed, 26 Nov 2014 18:13:57 +0000 (19:13 +0100)] 
libfdisk: add API docs

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agolibfdisk: rename and move function
Karel Zak [Wed, 26 Nov 2014 16:33:07 +0000 (17:33 +0100)] 
libfdisk: rename and move function

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agolibsmartcols: fix docs namespace
Karel Zak [Wed, 26 Nov 2014 15:53:48 +0000 (16:53 +0100)] 
libsmartcols: fix docs namespace

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agobuild-sys: add fdisk.pc
Karel Zak [Wed, 26 Nov 2014 12:20:16 +0000 (13:20 +0100)] 
build-sys: add fdisk.pc

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agobuild-sys: add fdiskP.h to sources
Karel Zak [Wed, 26 Nov 2014 11:51:15 +0000 (12:51 +0100)] 
build-sys: add fdiskP.h to sources

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agobuild-sys: create a regular shared libfdisk.so
Karel Zak [Wed, 26 Nov 2014 11:45:24 +0000 (12:45 +0100)] 
build-sys: create a regular shared libfdisk.so

- symbols versioning
- SONAME from configure.ac
- library version to header file
- modify build-sys to compile and install shared lib

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agoblkdiscard: fix compiler warning
Karel Zak [Wed, 26 Nov 2014 11:38:53 +0000 (12:38 +0100)] 
blkdiscard: fix compiler warning

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agobuild-sys: cleanup in libmount Makemodule
Karel Zak [Wed, 26 Nov 2014 11:14:18 +0000 (12:14 +0100)] 
build-sys: cleanup in libmount Makemodule

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agolibfdisk: add comments to header file
Karel Zak [Wed, 26 Nov 2014 10:55:45 +0000 (11:55 +0100)] 
libfdisk: add comments to header file

Signed-off-by: Karel Zak <kzak@redhat.com>
10 years agolibfdisk: add docs for SGI functions
Karel Zak [Wed, 26 Nov 2014 10:45:00 +0000 (11:45 +0100)] 
libfdisk: add docs for SGI functions

10 years agolibfdisk: add docs for SUN functions
Karel Zak [Wed, 26 Nov 2014 10:34:57 +0000 (11:34 +0100)] 
libfdisk: add docs for SUN functions

10 years agolibfdisk: cleanup fdisk_partition_to_string() comment
Karel Zak [Wed, 26 Nov 2014 10:26:31 +0000 (11:26 +0100)] 
libfdisk: cleanup fdisk_partition_to_string() comment

10 years agolibfdisk: fix typo
Karel Zak [Wed, 26 Nov 2014 10:23:27 +0000 (11:23 +0100)] 
libfdisk: fix typo

10 years agolibfdisk: add docs for iterator
Karel Zak [Wed, 26 Nov 2014 10:21:16 +0000 (11:21 +0100)] 
libfdisk: add docs for iterator