tail: avoid rare error-path FD leak

* src/tail.c (tail_forever): Close FD to avoid leak after a
failed fstat.
split: plug nominal leaks

* src/split.c (lines_rr) [IF_LINT]: Plug a harmless leak.
(main) [IF_LINT]: Free a usually-small (~70KB) buffer
just before exit, mainly to take this off the radar of
leak-detecting tools.

Improved-by: Pádraig Brady.
tests: avoid FP ulimit failure with valgrind-wrapped tools

* tests/init.cfg (require_ulimit_): Raise VM limit from 10MiB to
20MiB, to accommodate overhead of a valgrind-wrapped date program.
Also declare this function's local variables "local".
truncate: don't leak a file descriptor with --ref=PIPE

* src/truncate.c (main): For a user who makes the mistake of
using a non-seekable file as a reference for the desired length,
truncate would open that file, attempt to seek to its end, but
upon seek failure would neglect to close the file descriptor.
Close the file descriptor even when lseek fails.
In addition, ignore failure to close that reference FD, since as
long as the lseek succeeds, a close failure doesn't matter.
Coverity spotted the potential FD leak.

Improved-by: Pádraig Brady.
df: fix exit code and error messages with --total

When the combination of the file system options with given files or
devices does not lead to output, "df --total" would exit successfully
although it should not.

Examples:
  $ df --total --type=xfs /          # when / is not an XFS file system
  $ df --total --local -t nfs  DIR   # nfs is remote per se ...
  $ df --total -t qwerty /dev/sdb5   # typo in file system type

Furthermore, "df --total" would not print the error message "no file
systems processed" when the file argument does not exist or is otherwise
not accessible.

Example:
  $ df --total __not_exist__

These 2 bugs are present since --total was added by commit
v6.12-166-gea2887b.

* src/df.c (get_dev): Do not set file_systems_processed to true when
force_fsu is true, i.e. when the row for the "total" line is processed.
(main): Don't print totals unless we've processed a file system.
Also only print the "no FS processed" message if there was no
preceding diagnostic.
* tests/df/total-unprocessed: Add a new test.
* tests/Makefile.am: Reference the new test.
* NEWS: Mention the fix.

Improved-by: Jim Meyering
build: avoid sort link failure on Solaris 10

* src/Makefile.am (sort_LDADD): Sort uses euidaccess, which may require
whatever library configure deemed necessary to resolve the eaccess
function, but no one told sort to link with that library.
(sort_LDADD): Add $(LIB_EACCESS).
tests: printf-surprise: avoid unwarranted failure on FreeBSD 9.0

* tests/misc/printf-surprise: A VM size of 10,000KiB was too
little in which to run "env printf ..." on FreeBSD 9.0-p3.
Increase it to 15,000.
build: update gnulib submodule to latest
tests: fix validation of local file systems

* tests/init.cfg (require_mount_list_): A new function
to ensure we can read the list of file systems.
(require_local_dir_): Call the above function, as otherwise
the check is invalid.
* tests/df/total-unprocessed: Ensure df can read the
list of mounted file systems so that --local can be honored.
gitignore: ignore 'am-ng' directory in build-aux

Rather than the '.mk' directory in $(top_srcdir).  This is to reflect
the change of location and name of the directory used by Automake-NG
to install makefile fragments used by its generated Makefiles.

Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com>
Merge branch 'master' into automake-ng

* master:
  tests: fix validation of local file systems
  build: update gnulib submodule to latest
  tests: printf-surprise: avoid unwarranted failure on FreeBSD 9.0
  build: avoid sort link failure on Solaris 10
  df: fix exit code and error messages with --total
  truncate: don't leak a file descriptor with --ref=PIPE
  tests: avoid FP ulimit failure with valgrind-wrapped tools
  split: plug nominal leaks
  tail: avoid rare error-path FD leak
.gitignore: add lib/spawn.h, reorder

Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com>
version 8.18

* NEWS: Record release date.
maint: post-release administrivia

* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
df: fail when the mount list is required but cannot be read

* src/df.c (main): Add conditions to fail when the mount list cannot
be read: this includes the cases when a file name argument is given
and any of -a, -l, -t or -x is used.
* doc/coreutils.texi: Document the additional error conditions.
* tests/df/no-mtab-status: Add a new test.
* tests/Makefile.am: Reference the new test.
* NEWS: Mention the fix.
rm: new option --dir (-d) to remove empty directories

Add new option to rm (-d/--dir), which allows removal of
empty directories, while still safely disallowing removal
of non-empty ones.

This improves compatibility with Mac OS X and BSD systems,
which honor the -d option.

* src/remove.c (rm_fts): Remove empty directories when requested.
* src/remove.h (rm_options) [remove_empty_directories]: New member.
* src/rm.c (long_opts, usage, main): Update usage and option parsing.
(rm_option_init): Initialize the new member.
* src/mv.c (rm_option_init): Initialize the new member.
* tests/rm/d-1: New test case - successfully delete empty dir.
* tests/rm/d-2: New test case - refuse to delete nonempty dir.
* tests/Makefile.am (TESTS): Add them.
maint: use 'AM_DIST_FORMATS', not 'dist-*' options

Automake-NG has changed the API to specify which distribution
formats to use.  Adjust accordingly.

* configure.ac (AM_INIT_AUTOMAKE): Drop 'dist-xz' and 'no-dist-gzip'
option.
* Makefile.am (AM_DIST_FORMATS): Define to 'xz'.

Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com>
build: no need to activate parallel-tests and color-tests automake opts

They are on by default with Automake-NG.

* configure.ac (AM_INIT_AUTOMAKE): Drop those options.

Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com>
Merge branch 'master' into automake-ng

* master:
  rm: new option --dir (-d) to remove empty directories
  df: fail when the mount list is required but cannot be read
  maint: post-release administrivia
  version 8.18