Compare commits

...

130 Commits
v8.0 ... v8.1

Author SHA1 Message Date
Jim Meyering
447d245551 version 8.1
* NEWS: Record release date.
2009-11-18 19:38:50 +01:00
Jim Meyering
fee722471c build: update gnulib for Solaris utimens workaround 2009-11-18 15:58:20 +01:00
Jim Meyering
630f4ba107 build: update gnulib submodule to latest 2009-11-18 07:33:02 +01:00
Jim Meyering
2fccfaab19 maint: remove local gnulib-related patches
* gl/lib/printf-args.c.diff: Remove file.  No longer needed.
* gl/lib/vasnprintf.c.diff: Likewise.
2009-11-17 21:44:37 +01:00
Jim Meyering
2b18a4c138 build: update gnulib for Solaris 10 unsetenv work-around 2009-11-17 21:44:30 +01:00
Jim Meyering
6609ccbf87 doc: mention the du/fts vs. NFSv4 mount-point work-around
* NEWS (Changes in behavior): Mention it.
2009-11-17 08:56:12 +01:00
Jim Meyering
d863533752 build: update from gnulib for (un)setenv fixes 2009-11-17 08:48:15 +01:00
Jim Meyering
bf5af9aef8 build: update gnulib submodule to latest 2009-11-16 11:37:09 +01:00
Jim Meyering
161e5120d4 true, false: perform initialization only when argc == 2
* src/true.c (main): There is no reason to examine argv[0],
call atexit, etc., in the usual case in which we're about to exit.
This has the side effect of making it so that these programs
no longer segfault when subjected to execve abuse.
Before this change, these commands would make "true" segfault:
  printf '%s\n' '#include <unistd.h>' 'int main(int c, char**v)' \
    '{ execve (v[1], 0, 0); }' > k.c && gcc k.c && ./a.out $PWD/true
Now it succeeds.  Reported by Tetsuo Handa and Bart Van Assche
via Ondřej Vašík in http://bugzilla.redhat.com/537684.
2009-11-16 09:30:50 +01:00
Jim Meyering
3b997a9bcb tail -F can fail to track a file after it's been rotated
Tailing forever and by-name (--follow=name, -F), tail would
sometimes fail to follow a file that had been removed via rename.
If you can't apply this patch and have tail 7.6 or newer, you can
work around the bug via the undocumented --disable-inotify option.
* src/tail.c (tail_forever_inotify): When tailing by name (-F),
do not un-watch a file upon receipt of the IN_MOVE_SELF event.
Reported by Arjan Opmeer in http://bugs.debian.org/548439.
* NEWS (Bug fixes): Mention it.
Also see http://marc.info/?l=coreutils-bug&m=125829031916515
* tests/Makefile.am (TESTS): Add tail-2/inotify-rotate.
* tests/tail-2/inotify-rotate: New test.
2009-11-16 09:30:43 +01:00
Jim Meyering
00f0cabaec tests: help-version: exit nonzero when $built_programs is empty
* tests/misc/help-version: Use "Exit 1", rather than "Exit $fail"
with fail defined to 0 when $built_programs is empty.
2009-11-14 15:01:44 +01:00
Jim Meyering
5cf6fb3b12 build: do use AM_GNU_GETTEXT's "need-formatstring-macros" option
* configure.ac: Revert commit 49741b61 and add a comment.
Reported by Eric Blake.
2009-11-14 15:01:44 +01:00
Pádraig Brady
9ed5048148 tests: avoid a spurious failure on a loaded system
* tests/misc/timeout-parameters: This test could fail due to
the 1-second timeout expiring before a command of "no_such"
could be exec'd and fail.  Increase to 10 seconds.
2009-11-14 13:53:17 +00:00
Jim Meyering
c3744b25f2 build: require gettext-0.17
* configure.ac: Require gettext-0.17; it was released two years ago.
2009-11-13 17:54:07 +01:00
Jim Meyering
49741b61b7 build: correct gettext configure-time support
* configure.ac: Use AM_GNU_GETTEXT([external], [need-ngettext]),
rather than AM_GNU_GETTEXT([external], [need-formatstring-macros]).
Reported by Martin Jacobs in
http://thread.gmane.org/gmane.comp.parsers.bison.bugs/3181
* THANKS: Add his name.
2009-11-13 17:54:07 +01:00
Jim Meyering
9a91b2a928 build: update gnulib to latest, for fixed test-getgroups.c 2009-11-13 16:39:11 +01:00
Jim Meyering
4c9e7e01fa tests: avoid a spurious timeout on a heavily-loaded system
* tests/misc/timeout-parameters: This test would fail due to
the 1-second timeout expiring before a command of "." could
be exec'd and fail.  Increase to 10 seconds.
2009-11-13 16:38:20 +01:00
Eric Blake
6a31fd8d73 build: update gnulib, for getgroups improvements
A replacement getgroups is now guaranteed to exist, but it may
fail with ENOSYS.  mgetgroups is moved to gnulib, and now takes
gid_t instead of GETGROUPS_T (but setgroups still needs GETGROUPS_T).

* gnulib: Update to latest.
* gl/modules/mgetgroups: Delete, moved to gnulib.
* gl/m4/mgetgroups.m4: Likewise.
* gl/lib/mgetgroups.h: Likewise.
* gl/lib/mgetgroups.c: Likewise.
* src/group-list.c (print_group_list): Adjust callers.
* src/id.c (print_full_info): Likewise.
2009-11-13 07:50:20 -07:00
Jim Meyering
719a95aa9d build: bootstrap: add a comment; generalize autoheader check
* bootstrap: Sync from gnulib and diff.
2009-11-12 09:51:54 +01:00
Jim Meyering
1313107c5c build: update gnulib to latest; more *BSD and Solaris work-arounds 2009-11-12 07:53:42 +01:00
Jim Meyering
cf1bc9810d bootstrap: use git_modules_config in one more place
* bootstrap: Make bootstrap's --gnulib-srcdir more useful (for testing).
2009-11-11 19:07:37 +01:00
Eric Blake
622cf39be6 doc: fix typo
* doc/coreutils.texi (mktemp invocation): Quote shell variable.
2009-11-10 05:56:22 -07:00
Jim Meyering
3aff3ed137 build: update gnulib submodule to latest for its FreeBSD fixes 2009-11-09 11:00:42 +01:00
Pádraig Brady
10d97b3191 ls: fix capability coloring
Capability checking was incorrectly done on just the base name
rather than on the whole path.  Consequently there could be both
false positives and negatives when coloring files with capabilities.
Also capability checking was not done at all in certain cases for
non executable files.  Note passing absolute rather than relative
names to cap_get_file() reduces the has_capability() overhead
from around 33% to 30%.  I.E. ls --color is now around 3% faster.

* src/ls.c (struct fileinfo): Add a has_capability member.
(print_color_indicator): Refactor to pass just a fileinfo pointer
and a flag to say if we're dealing with a symlink target.
(print_name_with_quoting): Likewise.
(gobble_file): Set has_capability in the fileinfo struct.  Also do
a capability check even if executable coloring is disabled.
Ditto for SETUID and SETUID coloring.
Comment on how expensive has_capability() is.
(print_long_format): Adjust to refactored print_name_with_quoting.
(quote_name): Likewise.
(print_file_name_and_frills): Likewise.
* tests/ls/capability: Test the various false positive and negatives.
* THANKS: Add reporter (Ivan Labath).
* NEWS: Mention the fix.
2009-11-09 08:16:20 +00:00
Eric Blake
56b85e035b build: consistently use freopen-safer
cat, head, ptx, shuf, tac, tail, tee, tr, and uniq used freopen
on stdout, and were potentially vulnerable.  dircolors, du, and
tsort only used it on stdin, which is unaffected by freopen_safer,
but this covers all uses for consistency.

* cfg.mk (sc_require_stdio_safer): New rule.
* gl/modules/xfreopen (Depends-on): Add freopen-safer.
* gl/lib/xfreopen.c (includes): Use stdio--.h.
* src/ptx.c (includes): Likewise.
* src/shuf.c (includes): Likewise.
* src/uniq.c (includes): Likewise.
* src/dircolors.c (includes): Likewise.
* src/du.c (includes): Likewise.
* src/tsort.c (includes): Likewise.
2009-11-07 10:10:28 -07:00
Eric Blake
c768e2231b mktemp: fix bug with -q and closed stdout
If stdin or stdout is closed, then freopen(,stderr) can violate
the premise that STDERR_FILENO==fileno(stderr), which in turn
breaks mktemp -q.

* bootstrap.conf (gnulib_modules): Add freopen-safer.
* src/mktemp.c (includes): Use stdio--.h.
* tests/misc/close-stdout: Enhance test to catch bug.
2009-11-07 10:10:25 -07:00
Jim Meyering
9a8d8f46a5 maint: make du's cycle-detection code consistent
* src/du.c (process_file): Revert the du.c-changing part of
commit 8ba5d1a7. Use cycle_warning_required instead.
2009-11-07 08:43:05 +01:00
Jim Meyering
d9dbbb9a45 chcon, chgrp, chmod and chown now diagnose a directory cycle
* lib/xfts.c (cycle_warning_required): New function.
* lib/xfts.h: Declare it.
* src/chown-core.c (change_file_owner): Diagnose a cycle.
* src/chmod.c (process_file): Likewise.
* src/chcon.c (process_file): Likewise.
* NEWS (Bug fixes): Mention this.
2009-11-07 08:43:00 +01:00
Giuseppe Scrivano
74cf4cb26d nproc: A new program to count the available processors
* AUTHORS: Add my name.
* NEWS: Mention it.
* README: Likewise.
* bootstrap.conf (gnulib_modules): Add nproc.
* doc/coreutils.texi (nproc invocation): Add nproc info.
* man/Makefile.am (nproc.1): Add dependency.
* man/nproc.x: New template.
* man/.gitignore: Ignore generated man page.
* po/POTFILES.in: Add src/nproc.c.
* src/.gitignore: Exclude nproc.
* src/Makefile.am (EXTRA_PROGRAMS): Add nproc.
* src/nproc.c: New file.
* tests/Makefile.am (TESTS): Add misc/nproc-{avail,positive}.
* tests/misc/nproc-avail: New file.
* tests/misc/nproc-positive: New file.
2009-11-06 16:54:12 +00:00
Jim Meyering
41456fac8a build: move do-release-commit-and-tag to gnulib
* bootstrap.conf (gnulib_modules): Add do-release-commit-and-tag.
* build-aux/do-release-commit-and-tag: Remove file.  Now it's in gnulib.
* gnulib: Update submodule to the latest, to get the just-moved script.
2009-11-06 11:20:16 +01:00
Eric Blake
dde83c27b4 mktemp: use more robust means to avoid double-close of stdout
Reverts earlier patch - fflush() can succeed but fclose() fail for
some cases of write failures, and we want to catch those.

* src/mktemp.c (stdout_closed): New variable.
(maybe_close_stdout): New function, borrowed from dd.c.
(main): Track whether stdout has been closed.
2009-11-05 13:12:35 -07:00
Eric Blake
20e5a0d562 mktemp: enhance test to catch just-fixed typo behavior
Penance for botching the conflict resolution while rebasing my series.

* tests/misc/mktemp (check_tmp): Test for the bug when wrong parameter
is used.
2009-11-05 13:12:33 -07:00
Jim Meyering
22e4276ed1 mktemp: don't try to close stdout twice
* src/mktemp.c (main): Rather than calling close_stream (which would
make atexit-called close_stdout try to close it a second time),
check for write failure via ferror and fflush.
2009-11-05 16:32:52 +01:00
Jim Meyering
25d2460ae3 mktemp: don't use suff_len in place of #-of-`X's variable
* src/mktemp.c (mkstemp_len, mkdtemp_len): Pass x_len as final
argument, and not suff_len.
2009-11-05 16:23:59 +01:00
Eric Blake
31a9937081 mktemp: add suffix handling
Now that mkstemps is supported, we might as well use it.

* src/mktemp.c (TMPDIR_OPTION): New enum value.
(longopts): Add new option.
(usage): Document it.
(count_trailing_X_s): Rename...
(count_consecutive_X_s): ...to this, and add parameter.
(mkstemp_len, mkdtemp_len): Add parameter.
(main): Implement new option.
(AUTHORS): Add myself.
* AUTHORS (mktemp): Likewise.
* tests/misc/mktemp: Test new option.
* doc/coreutils.texi (mktemp invocation): Document it.
* NEWS: Likewise.
Fixes http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=548316.
2009-11-05 07:10:40 -07:00
Eric Blake
d431c61873 build: reflect gnulib changes to tempname
In glibc 2.11 and gnulib, gen_tempname added a parameter
suffixlen (unfortunately, it is typed as int rather than
size_t, for historical compatibility to a poor choice by BSD).

* gnulib: Import latest changes.
* gl/lib/tempname.h.diff: Accommodate new suffixlen parameter.
* gl/lib/tempname.c.diff (check_x_suffix): Allow for X in suffix
beyond x_suffix_len.
(gen_tempname_len): Add suffixlen parameter.
(__gen_tempname): Update caller.
* src/mktemp.c (mkstemp_len, mkdtemp_len): Update callers.
2009-11-05 07:00:52 -07:00
Eric Blake
5f29d118df build: override gnulib tempname via diff
Diffs are more robust than wholesale replacement, because bootstrap
will inform us of any incompatible changes made in upstream gnulib.

* gl/lib/tempname.h: Change...
* gl/lib/tempname.h.diff: ...to diff.
* gl/lib/tempname.c: Change...
* gl/lib/tempname.c.diff: ...to diff.
2009-11-05 06:59:21 -07:00
Eric Blake
0c5ae3a8ac mktemp: rearrange --help output
* src/mktemp.c (usage): Align indentation and sort by long
options.  Describe valid templates.
Suggested by http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=548316.
2009-11-05 06:59:03 -07:00
Eric Blake
e89a5e9b13 tests: enhance mktemp test
* tests/misc/mktemp: Add more coverage.
2009-11-05 06:54:56 -07:00
Eric Blake
bcca26e838 doc: document mktemp
* doc/coreutils.texi (mktemp invocation): New node.
* TODO: Delete completed task.
2009-11-05 06:54:50 -07:00
Eric Blake
41b3a8ed8b mktemp: don't leave file behind on write failure
* src/mktemp.c (main): Remove just-created file if stdout had
problems.
* bootstrap.conf (gnulib_modules): Add remove.
* tests/misc/close-stdout: Test it.
* NEWS: Document it.
2009-11-05 06:53:21 -07:00
Jim Meyering
cd65f11c4f du: cleanup: remove dead-code vestige of already-removed option
* src/du.c (MEGABYTES_LONG_OPTION, main): Remove vestiges
of already-removed long option, --megabytes.
2009-11-05 08:37:12 +01:00
Jim Meyering
8ba5d1a70c du now diagnoses cycles, rather than ignoring them
* src/du.c (symlink_deref_bits): New global, decl moved from ...
(main): ...here.
(process_file): When fts detects a directory cycle that can't
be due to symlinks, report it and arrange to exit nonzero.
* NEWS (Bug fixes): Mention it.
2009-11-05 08:32:31 +01:00
Jim Meyering
38cb824673 maint: factor out cycle warning, now that du will use it, too
* src/system.h (emit_cycle_warning): Define.  Factored out of...
* src/remove.c (rm_fts): ...here.  Use the new macro.
2009-11-05 08:32:31 +01:00
Jim Meyering
d4b96c26ce tests: rm: add test for today's change in behavior
* tests/Makefile.am (root_tests): Add rm/read-only to the list.
* tests/rm/read-only: New file.
2009-11-03 14:48:10 +01:00
Jim Meyering
7bf2e3db23 rm -f: ignore EROFS when it's really ENOENT
rm -f must not print a diagnostic for a nonexistent file.  However,
most linux-based kernel unlinkat functions set errno to EROFS when
the named file (regardless of whether it exists) would lie on a
read-only file system.  remove.c now performs an extra fstatat call
in that case, to determine whether the file exists.
* src/remove.c (excise): Map EROFS to ENOENT, if a file is nonexistent.
Reported by Steven Drake in <http://savannah.gnu.org/bugs/?27923>.
* NEWS (Changes in behavior): Mention it.
2009-11-03 14:14:00 +01:00
Jim Meyering
87bf834dd3 tests: inotify-race: don't let malfunctioning gdb hang the test
* tests/tail-2/inotify-race: Apply timeout to each gdb invocation.
2009-11-03 14:14:00 +01:00
Eric Blake
8fe40b84bd build: avoid some warnings
* gl/lib/mbsalign.c (mbsalign): Mark unused parameter.
* bootstrap.conf (gnulib_modules): Remove obsolete
rename-dest-slash.
* gnulib-tests/Makefile.am (AM_CFLAGS): Reduce set of warnings for
gnulib tests.
* gl/modules/rename-tests.diff (Makefile.am): New file, to add
LIBINTL to LDADD, since we avoid canonicalize-lgpl module.
* gl/lib/regcomp.c.diff (regerror, calc_next)
(build_collating_symbol, parse_bracket_element, build_equiv_class)
(free_tree): Mark unused parameters.
* gl/lib/regex_internal.h.diff (re_string_elem_size_at): New file,
to mark unused parameters.
* gl/lib/printf-args.c.diff (PRINTF_FETCHARGS): New file, to avoid
type mismatch.
* gl/lib/vasnprintf.c (VASNPRINTF): New file, to avoid shadowing
local variable name.
* .gitignore: Ignore temporary build artifacts.
2009-11-02 06:34:24 -07:00
Eric Blake
565e5f6827 build: update gnulib submodule to latest, for fewer compiler warnings 2009-11-02 06:26:55 -07:00
Jim Meyering
6eb457eaba admin: automate one more part of the release process
This script automates the process of updating NEWS, performs
the resulting final commit (thus with a consistent log message),
and applies a signed tag (v$VERSION) to the result.
* build-aux/do-release-commit-and-tag: New script.
* README-release: Document it.
2009-10-31 11:08:03 +01:00
Jim Meyering
a276ba2dd4 admin: fix typo in release procedure
* README-release: s/gzip/coreutils/
2009-10-31 08:49:46 +01:00
Jim Meyering
71c2f88155 tests: prohibit fail=0 initialization
* cfg.mk (sc_prohibit_fail_0): New rule.
* .x-sc_prohibit_fail_0: New file.
* Makefile.am (syntax_check_exceptions): Distribute the new file.
2009-10-30 12:50:31 +01:00
Jim Meyering
3c88587b2e tests: factor 350 fail=0 initializations into test-lib.sh
Run this command to remove the factored-out "fail=0" lines.
perl -ni -e '/^fail=0$/ or print' $(g grep -l '^fail=0$')
* tests/test-lib.sh: Initialize fail=0 here, not in 300+ scripts.
* tests/...: nearly all bourne shell scripts
Suggested by Eric Blake.
2009-10-30 12:50:12 +01:00
Jim Meyering
12a0a583f6 tests: remove the less-regular fail=0 assignments manually
* tests/tail-2/assert-2:
* tests/tail-2/assert:
* tests/cp/file-perm-race:
* tests/misc/df:
* tests/misc/truncate-dir-fail:
2009-10-30 10:49:22 +01:00
Jim Meyering
39da66f979 tests: don't let a fail=1 env. setting induce unwarranted test failure
* cfg.mk (sc_fail_is_initialized): New rule.
Fix the offenders:
* tests/cp/acl: Set fail=0
* tests/cp/backup-is-src: Likewise.
* tests/cp/file-perm-race: Likewise.
* tests/cp/reflink-auto: Likewise.
* tests/cp/same-file: Likewise.
* tests/ln/backup-1: Likewise.
* tests/misc/su-fail: Likewise.
* tests/misc/truncate-owned-by-other: Likewise.
* tests/mkdir/p-3: Likewise.
* tests/mkdir/selinux: Likewise.
* tests/mkdir/special-1: Likewise.
* tests/mv/acl: Likewise.
* tests/mv/backup-is-src: Likewise.
* tests/mv/diag: Likewise.
* tests/mv/force: Likewise.
* tests/mv/hard-link-1: Likewise.
* tests/mv/into-self-3: Likewise.
* tests/mv/sticky-to-xpart: Likewise.
* tests/touch/now-owned-by-other: Likewise.
2009-10-29 16:51:07 +01:00
Jim Meyering
22776f84cb remove stray closing comment delimiter, "*/", in previous change
* gl/lib/regexec.c.diff: Fix a typo.
2009-10-29 14:53:45 +01:00
Eric Blake
17b7d09bf2 maint: avoid exiting with magic number
Cope with gnulib's new sc_prohibit_magic_number_exit rule.

* .x-sc_prohibit_magic_number_exit: New file, to add exemptions.
* Makefile.am (syntax_check_exceptions): Distribute it.
* lib/euidaccess-stat.c (main): Fix culprits.
* src/chcon.c (main): Likewise.
* src/runcon.c (main): Likewise.
* src/setuidgid.c (main): Likewise.
2009-10-29 07:31:23 -06:00
Jim Meyering
f2859424cb build (--enable-gcc-warnings): enable gcc's -Werror also in lib/
* configure.ac (GNULIB_WARN_CFLAGS): Define.
* lib/Makefile.am (AM_CFLAGS): Use $(GNULIB_WARN_CFLAGS)
rather than $(WARN_CFLAGS) and add $(WERROR_CFLAGS).
* gl/lib/regcomp.c.diff: New file.
* gl/lib/regex_internal.c.diff: New file.
* gl/lib/regexec.c.diff: New file.
2009-10-29 08:14:42 +01:00
Jim Meyering
56a66d78ff build: update gnulib submodule to latest 2009-10-29 08:14:42 +01:00
Jim Meyering
e26cb21e6b build: allow whitespace violations in gl/lib/*.diff files
* .gitattributes: Exempt gl/lib/*.diff.
* .x-sc_prohibit_tab_based_indentation: Likewise.
* .x-sc_space_tab:Likewise.
2009-10-29 08:14:42 +01:00
Eric Blake
1c59bb3cef nice, nohup, su: detect write failure to stderr
These programs can print non-fatal diagnostics to stderr prior to
exec'ing a subsidiary program.  However, if we thought the situation
warranted a diagnostic, we insist that the diagnostic be printed
without error, rather than blindly exec, as it may be a security risk.

For an example, try 'nice -n -1 nice 2>/dev/full'.  Failure to raise
priority (by lowering niceness) is not fatal, but failure to inform
the user about failure to change priority is dangerous.

* src/nice.c (main): Declare failure if writing advisory message
to stderr fails.
* src/nohup.c (main): Likewise.
* src/su.c (main): Likewise.
* tests/misc/nice: Test this.
* tests/misc/nohup: Likewise.
* NEWS: Document this.
2009-10-28 21:12:41 -06:00
Jim Meyering
536a1fbe5f doc: tell --enable-gcc-warnings users where to report problems
* README-hacking: Add a caveat for --enable-gcc-warnings.
2009-10-28 18:13:44 +01:00
Jim Meyering
ce22916610 build: make doc checks more user-friendly
* doc/Makefile.am (check-texinfo): Begin moving each individual test
into its own rules.
(sc-avoid-builtin, sc-avoid-path): New rules.
Extracted from check-texinfo.
(syntax_checks): Add them.
2009-10-28 18:07:22 +01:00
Jim Meyering
da17f99b20 doc: avoid failing "make check"
* doc/coreutils.texi (env invocation): s/builtin/built-in/
2009-10-28 18:07:21 +01:00
Pádraig Brady
c07b181396 doc: improve the echo and printf help on escapes
* src/printf.c (usage): Merge strings with echo.c to
aid translators.  Move the description for \NNN beside
the other numeric escape codes.  Don't mention
"character" as that suggests character conversion.
* src/echo.c (usage): Likewise.
Also mention the \xHH escape sequence.
2009-10-28 17:01:29 +00:00
Pádraig Brady
2904d675a4 echo, printf: interpret \e as the Escape character
Match gcc, perl, bash, ksh, tcsh, ... in supporting \e.
* src/printf.c (print_escape_char): Output \x1B when \e encountered.
* src/echo.c (main): Likewise.
* src/stat.c (print_escape_char): Likewise.
* doc/coreutils.texi (echo invocation): Add \e to the list.
* tests/misc/printf: Verify that \e outputs \x1B.
* NEWS: Mention the change in behaviour.
2009-10-28 16:37:07 +00:00
Eric Blake
54491d2751 printenv: ignore bogus variable names
Exposed by env a=b=c printenv a=b.

* src/printenv.c (main): Silently reject = in names.
* tests/misc/printenv: Test for it.
* NEWS: Document this.
2009-10-28 06:24:52 -06:00
Pádraig Brady
42d12b45d3 maint: avoid "make syntax-check" failure
* src/printenv.c: Remove unused "long-options.h"
2009-10-28 11:50:54 +00:00
Eric Blake
75efc921b0 doc: turn env comments into documentation
* src/env.c: Convert introductory comments...
* doc/coreutils.texi (env invocation): ...into documentation.
Suggested by Jim Meyering.
2009-10-27 19:55:37 -06:00
Eric Blake
d6de2f198e env, printenv: add -0/--null option
Allows for unambiguous processing when environment values (or even
non-portable names!) contain newline.

* src/env.c (longopts): Add new option.
(usage): Document it.
(main): Implement it.
* src/printenv.c (longopts): New variable.
(usage): Document new option.
(main): Implement it.
* doc/coreutils.texi (Common options): New macro optNull.
(du invocation, env invocation, printenv invocation): Use it.
* NEWS: Mention this.
* tests/misc/env-null: New test.
* tests/Makefile.am (TESTS): Run it.
2009-10-27 19:55:35 -06:00
Eric Blake
1a81342089 tests: add printenv coverage
* tests/misc/printenv: New test.
* tests/Makefile.am (TESTS): Run it.
* .gitignore: Ignore more cruft.
2009-10-27 19:53:37 -06:00
Eric Blake
0cc0424119 tests: fix PATH problems on cygwin
* tests/misc/sort-compress: Remove non-portable over-restriction
of PATH; besides, commit 3ea177e changed sort to no longer default
to gzip.
* tests/rm/fail-eperm: Untaint, rather than clear, PATH.
* tests/misc/pwd-long: Likewise.  Also skip test if long path
cannot be created.
(normalize_to_cwd_relative): Use eq rather than ==, since cygwin
perl doesn't properly handle 64-bit ino_t numerically.
2009-10-27 18:53:44 -06:00
Eric Blake
f00bbe33e4 tests: clean up tests of env -- handling
The comment in env.c about -- handling has not matched the behavior
in the code since the initial commit back in 1992.

* src/env.c: Fix bogus comment.
* tests/misc/env: Further tweaks, avoiding PATH problems inherent
in testing -i, and testing program name containing =.
* doc/coreutils.texi (env invocation): Mention that intermediate
program is needed to invoke program with name containing =.
2009-10-26 21:30:34 -06:00
Eric Blake
0f3f6bf6bf doc: document PATH interactions with env
* doc/coreutils.texi (env invocation): Mention that PATH is
modified prior to exec.
* tests/misc/env: Test this.
2009-10-26 21:30:32 -06:00
Eric Blake
243f1b1c71 env: reject bogus -u arguments
* src/env.c (main): Use unsetenv rather than putenv to remove
items from environ, and check for failure.
* bootstrap.conf (gnulib_modules): Add unsetenv.
* tests/misc/env: Test this.
* NEWS: Document it.
2009-10-26 21:30:30 -06:00
Eric Blake
c6900474ef maint: let gnulib provide environ
* bootstrap.conf (gnulib_modules): Add environ.
* src/env.c (environ): Delete declaration.
* src/printenv.c (environ): Likewise.
* src/stdbuf.c (environ): Likewise.
* src/su.c (environ): Likewise.
2009-10-26 21:30:28 -06:00
Eric Blake
dae24f5ffc tests: avoid file name not portable to cygwin
* tests/misc/chroot-fail: Use 'no_such', not '...', since cygwin
1.5 silently strips trailing dots.
* tests/misc/nice-fail: Likewise.
* tests/misc/stdbuf: Likewise.
* tests/misc/timeout-parameters: Likewise.
2009-10-26 06:05:44 -06:00
Jim Meyering
c695781753 tests: rm/one-file-system: work around umount failure
* tests/rm/one-file-system (cleanup_): Unmount a/b, rather than
"$other_partition_tmpdir", to accommodate those who link /etc/mtab
to /proc/mounts.  Reported by Gilles Espinasse in
http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/18508
2009-10-26 10:21:25 +01:00
Jim Meyering
d9cf7c911f tests: adjust new env test not to fail
* tests/misc/env: Create ./-i as a link to our "echo" binary,
rather than as a bourne shell script, so that env can exec it.
Set PATH to ".".
2009-10-26 09:59:32 +01:00
Jim Meyering
50e837b1c4 tests: nice: adjust new tests to work more portably
* tests/misc/nice (tests): Accommodate a nice program for which
"nice -n -1 nice" prints nothing.  It should print -1 or (usually) 0.
Otherwise, we'd get syntax errors.
2009-10-26 08:25:34 +01:00
Jim Meyering
501bf7b589 nice: execute program even when setpriority fails due to EACCES
* src/nice.c (perm_related_errno): New function.
(main): Use it, rather than testing only errno == EPERM.
* NEWS (Bug fixes): Mention it.
2009-10-26 08:25:34 +01:00
Pádraig Brady
69fbfd400c timeout: don't orphan monitored programs if they ignore specified signals
* src/timeout.c (install_signal_handlers): Handle any user
specified signal, so that if it does not cause the child
to exit then we don't exit and orphan the child. Previously this
for example, would leave an orphan dd process running:
timeout -sUSR1 1s dd if=/dev/zero of=/dev/null
* NEWS: Mention the fix.
2009-10-25 23:28:38 +00:00
Eric Blake
30e4b6e84b tests: test recent status changes
* tests/misc/nice: Enhance test.
* tests/misc/chroot-fail: New test.
* tests/misc/env: Likewise.
* tests/misc/nice-fail: Likewise.
* tests/misc/su-fail: Likewise.
* tests/Makefile.am (TESTS): Run new tests.
2009-10-23 16:32:26 -06:00
Eric Blake
2122247aca maint: move chroot test
* tests/chroot/credentials: Move...
* tests/misc/chroot-credentials: ...here, to reduce number of
directories.
* tests/Makefile.am (root_tests): Reflect rename.
2009-10-23 16:31:34 -06:00
Eric Blake
bd933c1250 tests: enhance stdbuf and timeout tests
* tests/misc/timeout-parameters: Validate exact exit status.
* tests/misc/stdbuf: Likewise.
* tests/misc/timeout: Likewise.  Use require_built_.
* tests/misc/arch: Likewise.
2009-10-23 16:31:23 -06:00
Eric Blake
1ce9e1e5ca nohup: use EXIT_CANCELED if not POSIXLY_CORRECT
* src/nohup.c (NOHUP_FAILURE): Rename...
(POSIX_NOHUP_FAILURE): ...to this.
(main): Pay attention to POSIXLY_CORRECT, to determine whether to
use status 125 or 127.
* doc/coreutils.texi (nohup invocation): Document this.
* NEWS: Likewise.
* tests/misc/invalid-opt (exit_status): Adjust expected results.
* tests/misc/help-version (expected_failure_status): Likewise.
* tests/misc/nohup: Likewise.
2009-10-23 16:24:08 -06:00
Eric Blake
b6540b96ba chroot, env, nice, su: use EXIT_CANCELED for internal failure
* src/chroot.c (main): Use EXIT_CANCELED, not EXIT_FAILURE.
* src/env.c (main): Likewise.
* src/nice.c (main): Likewise.
* src/su.c (change_identity, main): Likewise.
* doc/coreutils.texi (chroot invocation, env invocation)
(nice invocation, su invocation): Document this.
* NEWS: Likewise.
* tests/misc/invalid-opt (exit_status): Adjust expected results.
* tests/misc/help-version (expected_failure_status): Likewise.
2009-10-23 16:24:05 -06:00
Eric Blake
97777f559a tests: accommodate BSD getopt
* tests/misc/invalid-opt (err_subst): Support alternate spelling.
2009-10-23 16:24:02 -06:00
Eric Blake
c0dcf3238b build: prohibit improper use of stat and lstat
* cfg.mk (sc_prohibit_stat_macro_address): New rule.
* src/ln.c (do_link): Adjust comment to avoid false positive.
* src/stat.c (do_stat): Likewise.
* src/touch.c (main): Likewise.
2009-10-23 06:29:54 -06:00
Eric Blake
a08e13a0fb build: update gnulib submodule to latest, for test cleanups 2009-10-22 21:25:39 -06:00
Eric Blake
5e361387d0 maint: turn on compiler warnings for gnulib tests
* gnulib-tests/Makefile.am (AM_CFLAGS): Add WARN_CFLAGS.
* configure.ac (enable-gcc-warnings): Also use -funit-at-a-time,
to silence gcc 4.3.4 -Wdisabled-optimization.
* .gitignore: Ignore some more files.
2009-10-22 08:05:09 -06:00
Jim Meyering
cbf36952d8 build: prohibit direct use of readlink or readlinkat
* cfg.mk (sc_prohibit_readlink): New rule.
Suggested by Eric Blake.
2009-10-22 12:12:24 +02:00
Giuseppe Scrivano
029b6b14c5 tests: add a test for the `tail -f' race condition bug
If new data becomes available between the initial read and when tail
registers the inotify watch descriptors, ensure that it is read
before a new event happens on the file.
* tests/Makefile.am (TESTS): Add tail-2/inotify-race.
* tests/tail-2/inotify-race: New file.
2009-10-22 10:25:58 +02:00
Giuseppe Scrivano
cd0f3036f6 tail -f: avoid a race condition
* NEWS (Bug fixes): Mention it.
* src/tail.c (check_fspec): New function.
(tail_forever_inotify): Ensure there is no new data before entering the
inotify events wait loop.
2009-10-22 09:11:24 +02:00
Eric Blake
9abbe32c2e build: update gnulib submodule to latest, for utimens enhancements 2009-10-21 21:44:56 -06:00
Eric Blake
54645c195c tests: ensure touch honors trailing slash
* tests/touch/trailing-slash: New test.
* tests/Makefile.am (TESTS): Run it.
2009-10-21 20:45:27 -06:00
Pádraig Brady
710fe413fe md5sum, sha*sum, sum: line-buffer the printed checksums
* src/md5sum.c (main): Set stdout to line buffered mode
to ensure parallel running instances don't intersperse
their output.  This adds 5% to the run time in the worst case
of many zero length files, or 2% with standard file sizes.
* src/sum.c (main): Likewise.
* tests/misc/md5sum-parallel: New test for atomic output.
* tests/Makefile.am: Reference it.
* NEWS: Mention the fix
2009-10-21 16:56:00 +01:00
Pádraig Brady
71adb516de maint: issue warnings for more missing optional libraries
* README-hacking: Suggest to use ./configure --quiet so that
any warnings are easily noticed.
* m4/gmp.m4 (cu_GMP): Warn if libgmp is not available.
* m4/jm-macros.m4 (coreutils_MACROS): Normalize the libcap warning.
* m4/xattr.m4 (gl_FUNC_XATTR): Warn if libattr is not available.
2009-10-20 17:11:00 +01:00
Jim Meyering
6ac6c7e4b7 build: use gnulib's isblank module
* bootstrap.conf (gnulib_modules): Add isblank.
* src/system.h (isblank): Don't define.
* m4/check-decl.m4: Don't check for isblank declaration.
* gnulib: Update submodule to latest.
2009-10-19 07:57:15 +02:00
Jim Meyering
f26508204b maint: factor out duplication in currently unused rules
* src/Makefile.am (fs_normalize_perl_subst): Define.
(fs-magic, fs-kernel-magic): Use it.
2009-10-18 10:26:15 +02:00
Eric Blake
9e13b6a0b4 touch: add -h to change symlink timestamps, where supported
* src/touch.c (no_dereference): New flag variable.
(longopts): Add -h/--no-dereference.
(touch): Add symlink handling.
(usage): Document new option.
(main): Accept new option.
* NEWS: Document it.
* doc/coreutils.texi (touch invocation): Likewise.  Also mention
birthtime.
* tests/touch/no-dereference: New test.
* tests/Makefile.am (TESTS): Run it.
2009-10-17 14:36:28 -06:00
Jim Meyering
527fb951de tests: abmon-align: avoid test failure
* tests/ls/abmon-align: Don't remove (1d;) the first line of output.
That was making the test consider only 11 of 12 month names.
Rewrite not to use \(.*\), as that provoked a malfunction in GNU sed
on powerpc Mac OS X (though we don't know yet whether this is due to a
sed bug, or to miscompilation).  Nelson Beebe reported the test failure.
2009-10-17 12:21:52 +02:00
Jim Meyering
f8653f2af3 build: update gnulib submodule to latest 2009-10-17 12:20:41 +02:00
Jim Meyering
2fa407885c build: don't let environment settings perturb build
Setting the envvars, LIB_FDATASYNC, LIB_XATTR or LIB_CRYPT
could cause a configure-time and/or build-time malfunction.
Typically, a configure-time function-in-library test is performed
via code like this:

  LIB_VAR=
  AC_SUBST([LIB_VAR])
  prefix_saved_LIBS=$LIBS
    AC_SEARCH_LIBS([FUNC], [LIB_NAME],
                   [test "$ac_cv_search_FUNC" = "none required" ||
                    LIB_VAR=$ac_cv_search_FUNC])
  LIBS=$prefix_saved_LIBS

However, in each of the files affected by this change, the LIB_VAR=
initialization was omitted.  Thus, when set in the environment, its
value would propagate into generated Makefiles when FUNC is not found
in LIB_NAME.
* m4/jm-macros.m4 (coreutils_MACROS): Initialize AC_SUBST'd var
* m4/lib-check.m4 (cu_LIB_CHECK): Likewise.
* m4/xattr.m4 (gl_FUNC_XATTR): Likewise.
2009-10-15 21:03:40 +02:00
C de-Avillez
b3cfa712ca tail: add add missing backslash at the end of a line in usage
* src/tail.c (usage): Add missing backslash at the end of a line.
2009-10-13 11:20:20 +02:00
Eric Blake
f25273d7f1 tail: tweak usage for more clarity
* src/tail.c (usage): Spell out -n +K.
* THANKS: Update.
Reported by Jan-Pawel Wrozstinski.
2009-10-12 07:00:12 -06:00
Eric Blake
26e8e602a8 touch: optimize use of utimens
* src/touch.c (main): Use UTIME_NOW rather than calling gettime.
(touch): Use UTIME_OMIT rather than stat.
2009-10-10 15:16:55 -06:00
Eric Blake
7280a913a1 copy: allow symlink timestamp preservation on more systems
* src/copy.c (utimens_symlink): Simplify by using lutimens.
* m4/jm-macros.m4 (coreutils_MACROS): Drop utimensat; gnulib does
this for us.
* tests/cp/preserve-slink-time: Recognize lutimes support.
2009-10-10 15:16:52 -06:00
Eric Blake
7ff00ca82f build: update gnulib submodule to latest, for utimens improvements 2009-10-10 15:16:50 -06:00
Jim Meyering
f7b1873805 tests: adjust tail-2/pid to work around FreeBSD 6.1 failure
* tests/tail-2/pid: Run tail -f --pid=... on an actual file, not on
/dev/null, to avoid this failure on FreeBSD 6.1: tail: /dev/null:
cannot change nonblocking mode: Inappropriate ioctl for device
2009-10-10 15:05:09 +02:00
Eric Blake
c2bebf63ed maint: touch up previous LDADD patch
* src/Makefile.am (dir_LDADD): Delete; the ls_LDADD line covers this.
2009-10-10 06:28:40 -06:00
Jim Meyering
d74a1b005c build: build uname(1) unconditionally
Before, on a system without the uname function, the build
system would detect that and not build/install a uname program.
Now that gnulib guarantees a uname function, ...
* configure.ac: Don't check for the uname function.
* src/Makefile.am (build_if_possible__progs): Move uname...
(EXTRA_PROGRAMS): ...to this list.
2009-10-10 09:03:15 +02:00
Jim Meyering
4f1a3eda10 maint: list program names one per line
* src/Makefile.am (EXTRA_PROGRAMS): List them one per line.
(build_if_possible__progs): Likewise.
2009-10-10 08:58:43 +02:00
Jim Meyering
c9e7b8844b build: ls: fix link failure due to missing -lacl
* src/Makefile.am (ls_LDADD): Re-add $(LIB_ACL).
Inadvertently-removed by commit 78c93601.
2009-10-10 08:24:02 +02:00
Eric Blake
219f2f0538 maint: touch up previous LDADD patch
* src/Makefile.am (stdbuf_LDADD): Add missing primer.
(hostname_LDADD, uname_LDADD): Add GETHOSTNAME_LIB.
* bootstrap.conf (gnulib_modules): Add uname.
2009-10-09 20:08:03 -06:00
Eric Blake
78c9360178 maint: improve additional library tracking
* src/Makefile.am (LDADD): Refactor, to make per-library additions
to individual programs easier to maintain.
2009-10-09 19:28:07 -06:00
Jim Meyering
0023f65fd7 chcon: don't disable just because SELinux is disabled
* src/chcon.c (main): Now that gnulib provides getfilecon wrappers,
we can revert most of the 2009-10-05 commit 3a97d664, "chcon: exit
immediately if SELinux is disabled", since chcon is still useful as
long as the file system provides handlers for the security.*
name space.  gnulib's getfilecon wrappers ensure that an offending
context now evokes a return value of -1.
Prompted by comments from Stephen Smalley in
http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/18378/focus=18394
* NEWS (Bug fixes): Mention it.
2009-10-09 14:33:10 +02:00
Jim Meyering
57d9263ca5 ls: remove explicit getfilecon work-around
* src/ls.c (gobble_file): Remove l?getfilecon work-around,
now that the gnulib wrappers handle it for us.
2009-10-09 14:33:10 +02:00
Jim Meyering
e11a0319b3 build: update gnulib submodule to latest, for getfilecon wrappers 2009-10-09 14:33:10 +02:00
Eric Blake
c039c96449 maint: use X2NREALLOC in more places
* src/chroot.c (set_additional_groups): Use X2NREALLOC rather than
x2nrealloc.
* src/factor.c (emit_factor): Likewise.
* src/setuidgid.c (main): Likewise.
2009-10-08 20:30:08 -06:00
Eric Blake
aa092ccf6a maint: remove unused macros and declarations
* src/system.h (EDQUOT, EISDIR, ENOSYS, EOVERFLOW, F_OK, X_OK)
(W_OK, R_OK): Delete; macros provided by gnulib.
(includes): Gnulib guarantees both <time.h> and <sys/time.h>, in
either order.
(free, malloc, memchr, realloc, getenv, lseek): Delete, gnulib
guarantees these declarations.
* m4/check-decl.m4 (gl_CHECK_DECLS): Delete checks now done by
gnulib.
2009-10-08 20:30:06 -06:00
Eric Blake
2a876d901d maint: move timeout exit statuses
* src/timeout.c (EXIT_TIMEDOUT, EXIT_CANCELED): Remove as
macros...
* src/system.h (EXIT_TIMEDOUT, EXIT_CANCELED): ...and provide as
enum values instead.
* src/stdbuf.c (EXIT_CANCELED): Delete.
2009-10-08 20:30:03 -06:00
Eric Blake
a797c4d7d3 stat: test recent patch
* tests/misc/stat-slash: New test.
* tests/Makefile.am (TESTS): Run it.
2009-10-08 20:30:00 -06:00
Eric Blake
7a3bc1bf27 stdbuf: improve path search
* src/stdbuf.c (set_program_path): Use gnulib methods for better
file name handling.
* bootstrap.conf (gnulib_modules): Add xreadlink.
2009-10-08 06:52:18 -06:00
Eric Blake
00674c7475 stat: work with recent gnulib changes
* src/stat.c (do_stat): Don't mask function-like stat macro.
2009-10-08 06:52:15 -06:00
Jim Meyering
eb5f06f2a6 stat: add support for many more file system types
* src/stat.c (human_fstype): Add the following FS types,
from <linux/magic.h>: afs, anon-inode FS, btrfs, cgroupfs,
cramfs-wend, debugfs, futexfs, inotifyfs, minux3, securityfs,
selinux, xenfs.
Also add "nilfs".
* src/Makefile.am (fs-kernel-magic): New rule.
* NEWS (Bug fixes): Mention this.
2009-10-08 10:18:28 +02:00
Jim Meyering
8e32390716 stat: recognize CIFS and HFS file system types
* src/stat.c (human_fstype) [CIFS, HFS]: Add new file system types.
Prompted by a report from Stuart Kemp.
Normalize the form of a few hexadecimal magic numbers.
Alphabetize on S_MAGIC_ case names.
* src/Makefile.am (fs-magic-compare, fs-def, fs-magic): New rules, to
automate comparison of our list with that in the Linux statfs man page.
* NEWS (Bug fixes): Mention it.
2009-10-08 09:07:12 +02:00
Guenter Knauf
b95be30e3f md5sum, sha*sum: also accept openssl checksum syntax
* src/md5sum.c (split_3): Accept openssl checksum syntax, which
differs only by two spaces from that of the bsd checksum tools:
openssl: MD5(f)= d41d8cd98f00b204e9800998ecf8427e
bsd:     MD5 (f) = d41d8cd98f00b204e9800998ecf8427e
2009-10-07 09:31:27 +02:00
Jim Meyering
d183a15cbb maint: make release-making instructions more generic
* README-release: Make instructions more generic.
2009-10-06 16:49:36 +02:00
Jim Meyering
96829a9ff0 post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2009-10-06 13:20:18 +02:00
438 changed files with 3319 additions and 1571 deletions

2
.gitattributes vendored
View File

@@ -5,3 +5,5 @@
# # Derived from the regexp in emacs' lisp/add-log.el.
# [diff "texinfo"]
# funcname = "^@node[ \t][ \t]*\\([^,][^,]*\\)"
gl/lib/*.diff -whitespace

5
.gitignore vendored
View File

@@ -3,6 +3,7 @@
*.o
*/.deps
*~
._bootmp
.gdb-history
.kludge-stamp
.tarball-version
@@ -47,11 +48,13 @@ lib/arpa
lib/binary-io.h
lib/charset.alias
lib/configmake.h
lib/glthread
lib/libcoreutils.a
lib/printf.c
lib/progname.c
lib/progname.h
lib/selinux
lib/unistr
lib/uniwidth
m4/.cvsignore
m4/.gitignore
@@ -72,3 +75,5 @@ src/version.c
src/version.h
stamp-h1
tests/*/*.log
tests/t?
tests/test-suite.log

View File

@@ -1 +1 @@
7.6
8.0

3
.x-sc_prohibit_fail_0 Normal file
View File

@@ -0,0 +1,3 @@
\.mk$
/Makefile\.am$
^tests/test-lib\.sh$

View File

@@ -0,0 +1,3 @@
configure.ac
*.m4
ChangeLog*

View File

@@ -4,3 +4,4 @@ Makefile\.am$
^tests/pr/
ChangeLog.*
^man/help2man$
^gl/lib/.*\.c\.diff$

View File

@@ -9,3 +9,4 @@ m4/lib-prefix.m4
m4/po.m4
aclocal.m4
src/c99-to-c89.diff
^gl/lib/.*\.c\.diff$

View File

@@ -46,11 +46,12 @@ md5sum: Ulrich Drepper, Scott Miller, David Madore
mkdir: David MacKenzie
mkfifo: David MacKenzie
mknod: David MacKenzie
mktemp: Jim Meyering
mktemp: Jim Meyering, Eric Blake
mv: Mike Parker, David MacKenzie, Jim Meyering
nice: David MacKenzie
nl: Scott Bartram, David MacKenzie
nohup: Jim Meyering
nproc: Giuseppe Scrivano
od: Jim Meyering
paste: David M. Ihnat, David MacKenzie
pathchk: Paul Eggert, David MacKenzie, Jim Meyering

View File

@@ -47,6 +47,8 @@ syntax_check_exceptions = \
.x-sc_po_check \
.x-sc_program_name \
.x-sc_prohibit_atoi_atof \
.x-sc_prohibit_fail_0 \
.x-sc_prohibit_magic_number_exit \
.x-sc_prohibit_stat_st_blocks \
.x-sc_prohibit_strcmp \
.x-sc_prohibit_tab_based_indentation \

97
NEWS
View File

@@ -1,5 +1,102 @@
GNU coreutils NEWS -*- outline -*-
* Noteworthy changes in release 8.1 (2009-11-18) [stable]
** Bug fixes
chcon no longer exits immediately just because SELinux is disabled.
Even then, chcon may still be useful.
[bug introduced in coreutils-8.0]
chcon, chgrp, chmod, chown and du now diagnose an ostensible directory cycle
and arrange to exit nonzero. Before, they would silently ignore the
offending directory and all "contents."
env -u A=B now fails, rather than silently adding A to the
environment. Likewise, printenv A=B silently ignores the invalid
name. [the bugs date back to the initial implementation]
ls --color now handles files with capabilities correctly. Previously
files with capabilities were often not colored, and also sometimes, files
without capabilites were colored in error. [bug introduced in coreutils-7.0]
md5sum now prints checksums atomically so that concurrent
processes will not intersperse their output.
This also affected sum, sha1sum, sha224sum, sha384sum and sha512sum.
[the bug dates back to the initial implementation]
mktemp no longer leaves a temporary file behind if it was unable to
output the name of the file to stdout.
[the bug dates back to the initial implementation]
nice -n -1 PROGRAM now runs PROGRAM even when its internal setpriority
call fails with errno == EACCES.
[the bug dates back to the initial implementation]
nice, nohup, and su now refuse to execute the subsidiary program if
they detect write failure in printing an otherwise non-fatal warning
message to stderr.
stat -f recognizes more file system types: afs, cifs, anon-inode FS,
btrfs, cgroupfs, cramfs-wend, debugfs, futexfs, hfs, inotifyfs, minux3,
nilfs, securityfs, selinux, xenfs
tail -f (inotify-enabled) now avoids a race condition.
Before, any data appended in the tiny interval between the initial
read-to-EOF and the inotify watch initialization would be ignored
initially (until more data was appended), or forever, if the file
were first renamed or unlinked or never modified.
[The race was introduced in coreutils-7.5]
tail -F (inotify-enabled) now consistently tails a file that has been
replaced via renaming. That operation provokes either of two sequences
of inotify events. The less common sequence is now handled as well.
[The bug came with the implementation change in coreutils-7.5]
timeout now doesn't exit unless the command it is monitoring does,
for any specified signal. [bug introduced in coreutils-7.0].
** Changes in behavior
chroot, env, nice, and su fail with status 125, rather than 1, on
internal error such as failure to parse command line arguments; this
is for consistency with stdbuf and timeout, and avoids ambiguity
with the invoked command failing with status 1. Likewise, nohup
fails with status 125 instead of 127.
du (due to a change in gnulib's fts) can now traverse NFSv4 automounted
directories in which the stat'd device number of the mount point differs
during a traversal. Before, it would fail, because such a mismatch would
usually represent a serious error or a subversion attempt.
echo and printf now interpret \e as the Escape character (0x1B).
rm -f /read-only-fs/nonexistent now succeeds and prints no diagnostic
on systems with an unlinkat syscall that sets errno to EROFS in that case.
Before, it would fail with a "Read-only file system" diagnostic.
Also, "rm /read-only-fs/nonexistent" now reports "file not found" rather
than the less precise "Read-only file system" error.
** New programs
nproc: Print the number of processing units available to a process.
** New features
env and printenv now accept the option --null (-0), as a means to
avoid ambiguity with newlines embedded in the environment.
md5sum --check now also accepts openssl-style checksums.
So do sha1sum, sha224sum, sha384sum and sha512sum.
mktemp now accepts the option --suffix to provide a known suffix
after the substitution in the template. Additionally, uses such as
"mktemp fileXXXXXX.txt" are able to infer an appropriate --suffix.
touch now accepts the option --no-dereference (-h), as a means to
change symlink timestamps on platforms with enough support.
* Noteworthy changes in release 8.0 (2009-10-06) [beta]
** Bug fixes

2
README
View File

@@ -11,7 +11,7 @@ The programs that can be built with this package are:
csplit cut date dd df dir dircolors dirname du echo env expand expr
factor false fmt fold groups head hostid hostname id install join kill
link ln logname ls md5sum mkdir mkfifo mknod mktemp mv nice nl nohup
od paste pathchk pinky pr printenv printf ptx pwd readlink rm rmdir
nproc od paste pathchk pinky pr printenv printf ptx pwd readlink rm rmdir
runcon seq sha1sum sha224sum sha256sum sha384sum sha512sum shred shuf
sleep sort split stat stdbuf stty su sum sync tac tail tee test timeout
touch tr true truncate tsort tty uname unexpand uniq unlink uptime users

View File

@@ -35,7 +35,7 @@ which are extracted from other source packages:
And there you are! Just
$ ./configure #[--enable-gcc-warnings]
$ ./configure --quiet #[--enable-gcc-warnings] [*]
$ make
$ make check
@@ -48,6 +48,12 @@ should output no difference.
Enjoy!
[*] The --enable-gcc-warnings option is useful only with glibc
and with a very recent version of gcc. You'll probably also have
to use recent system headers. If you configure with this option,
and spot a problem, please be sure to send the report to the bug
reporting address of this package, and not to that of gnulib, even
if the problem seems to originate in a gnulib-provided file.
-----
Copyright (C) 2002-2009 Free Software Foundation, Inc.

View File

@@ -7,18 +7,18 @@ Here are most of the steps we (maintainers) follow when making a release.
* Run ./configure && make maintainer-clean
* Ensure that the desired versions of autoconf, automake, bison, etc.
are in your PATH. See HACKING for the complete list.
are in your PATH. See the buildreq list in bootstrap.conf for
the complete list.
* Ensure that you're on "master" with no uncommitted diffs.
This should produce no output: git checkout master; git diff
* Make sure your local gnulib directory is up to date.
* Run bootstrap: ./bootstrap
FIXME: enable excluded programs like arch? to get their manual pages?
* Pre-release testing:
Ensure that make check syntax-check succeeds.
On at least one SELinux-enabled (enforcing) and one non-SELinux system,
run all tests, both root-only and regular.
Run *all* non-root tests, including expensive and very expensive ones i.e.,
@@ -29,19 +29,17 @@ FIXME: enable excluded programs like arch? to get their manual pages?
* Run "make distcheck"
* Manually set the date, version number, and [stable/alpha/beta] on
line 3 of NEWS, then do e.g.,:
* Set the date, version number, and release type [stable/alpha/beta] on
line 3 of NEWS, commit that, and tag the release by running e.g.,
v=7.3
git commit -F <(printf 'version '$v'\n\n* NEWS: Record release date.\n') -a
git tag -s -m "coreutils $v" v$v HEAD
build-aux/do-release-commit-and-tag 8.1 beta
* Run the following to create release tarballs. Your choice selects the
corresponding upload-to destination in the emitted gnupload command.
The different destinations are specified in cfg.mk. See the definitions
of gnu_ftp_host-{alpha,beta,major}.
of gnu_ftp_host-{alpha,beta,stable}.
# "TYPE" must be major, beta or alpha
# "TYPE" must be stable, beta or alpha
make TYPE
* Test the tarball. copy it to a few odd-ball systems and ensure that
@@ -59,12 +57,15 @@ Once all the builds and tests have passed,
that they're all valid.
* Push the new tag:
git push origin tag v<JUST_RELEASED_VERSION_NUMBER>
v=$(cat .prev-version)
git push origin tag v$v
* Send the gpg-signed announcement mail, e.g.,
To: info-gnu@gnu.org, coreutils-announce@gnu.org
Cc: coordinator@translationproject.org, bug-coreutils@gnu.org
Subject: coreutils-7.1 released [stable]
Subject: coreutils-8.0 released [beta]
* Approve the announcement here:
http://lists.gnu.org/mailman/admindb/coreutils-announce
@@ -73,10 +74,13 @@ Once all the builds and tests have passed,
From here:
https://savannah.gnu.org/projects/coreutils/
click on the "submit news", then write something like the following:
(If there is no such button, then enable "News" for the project via
the Main -> "Select Features" menu item, or via this link:
https://savannah.gnu.org/project/admin/editgroupfeatures.php?group=coreutils)
Subject: coreutils-7.2 released [stable]
Subject: coreutils-0.0 released [beta]
The announcement is here:
http://article.gmane.org/gmane.comp.gnu.core-utils.announce/49
http://article.gmane.org/gmane.comp.gnu.core-utils.announce/54
Then go here to approve it:
https://savannah.gnu.org/news/approve.php?group=coreutils
@@ -85,4 +89,6 @@ Once all the builds and tests have passed,
http://www.gnu.org/software/coreutils/manual/
by running the gnu-web-doc-update script.
by running this:
build-aux/gnu-web-doc-update

8
THANKS
View File

@@ -52,6 +52,7 @@ Andy Longton alongton@metamark.com
Anthony Thyssen anthony@griffith.edu.au
Antonio Rendas ajrendas@yahoo.com
Ariel Faigon ariel@cthulhu.engr.sgi.com
Arjan Opmeer arjan.opmeer@gmail.com
Arne H. Juul arnej@solan.unit.no
Arne Henrik Juul arnej@imf.unit.no
Arnold Robbins arnold@skeeve.com
@@ -210,6 +211,7 @@ Geoff Whale geoffw@cse.unsw.EDU.AU
Gerald Pfeifer gerald@pfeifer.com
Gerhard Poul gpoul@gnu.org
Germano Leichsenring germano@jedi.cs.kobe-u.ac.jp
Gilles Espinasse g.esp@free.fr
Glen Lenker glen.lenker@gmail.com
Göran Uddeborg goeran@uddeborg.se
Guochun Shi gshi@ncsa.uiuc.edu
@@ -246,6 +248,7 @@ Ian Turner vectro@pipeline.com
Iida Yosiaki iida@gnu.org
Ilya N. Golubev gin@mo.msk.ru
Ingo Saitz ingo@debian.org
Ivan Labath labath3@st.fmph.uniba.sk
Ivo Timmermans ivo@debian.org
James james@albion.glarp.com
James Antill jmanti%essex.ac.uk@seralph21.essex.ac.uk
@@ -262,6 +265,7 @@ Jan Engelhardt jengelh@medozas.de
Jan Fedak J.Fedak@sh.cvut.cz
Jan Moringen jan.moringen@uni-bielefeld.de
Jan Nieuwenhuizen janneke@gnu.org
Jan-Pawel Wrozstinski jpwroz@gmail.com
Janos Farkas chexum@shadow.banki.hu
Jarkko Hietaniemi jhi@epsilon.hut.fi
Jarod Wilson jwilson@redhat.com
@@ -368,6 +372,7 @@ Martin martin@dresden.nacamar.de
Martin Buck martin.buck@ascom.ch
Martin Gallant martyg@goodbit.net
Martin Hippe martin.hippe@schlund.de
Martin Jacobs martin.jacobs@arcor.de
Martin Michlmayr tbm@cyrius.com
Martin Mitchell martin@debian.org
Martin P.J. Zinser zinser@decus.de
@@ -397,7 +402,7 @@ Max Chang maxchang@ucla.edu
Meelis Roos mroos@tartu.cyber.ee
Michael michael@aplatform.com
Michael ??? michael@roka.net
Michael Bacarella mbac@netgraft.com>
Michael Bacarella mbac@netgraft.com
Michael Deutschmann michael@talamasca.ocis.net
Michael Elizabeth Chastain mec.gnu@mindspring.com
Michael Gaughen mgaughen@polyserve.com
@@ -539,6 +544,7 @@ Stephen Smoogen smooge@mindspring.com
Steve McConnel steve@acadcomp.sil.org
Steve McIntyre steve@einval.com
Steve Ward planet36@gmail.com
Steven Drake sbd@users.sourceforge.net
Steven G. Johnson stevenj@alum.mit.edu
Steven Mocking ufo@quicknet.nl
Steven Parkes smparkes@smparkes.net

1
TODO
View File

@@ -12,7 +12,6 @@ Modify chmod so that it does not change an inode's st_ctime
Discussed more recently on <http://bugs.debian.org/497514>.
document the following in coreutils.texi:
mktemp
[
pinky

View File

@@ -71,6 +71,7 @@ gnulib_modules=
gnulib_files=
# A function to be called after everything else in this script.
# Override it via your own definition in bootstrap.conf.
bootstrap_epilogue() { :; }
# The command to download all .po files for a specified domain into
@@ -416,7 +417,7 @@ case ${GNULIB_SRCDIR--} in
git_modules_config submodule.gnulib.url >/dev/null; then
git submodule init
GNULIB_SRCDIR=`cd $GNULIB_SRCDIR && pwd`
git config --replace-all submodule.gnulib.url $GNULIB_SRCDIR
git_modules_config --replace-all submodule.gnulib.url $GNULIB_SRCDIR
echo "$0: getting gnulib files..."
git submodule update || exit $?
GNULIB_SRCDIR=gnulib
@@ -733,7 +734,7 @@ find "$m4_base" "$source_base" \
# Reconfigure, getting other files.
# Skip autoheader if it's not needed.
grep '^[ ]*AC_CONFIG_HEADERS\>' configure.ac >/dev/null ||
grep -E '^[ ]*AC_CONFIG_HEADERS?\>' configure.ac >/dev/null ||
AUTOHEADER=true
for command in \

View File

@@ -71,7 +71,9 @@ gnulib_modules="
diacrit
dirfd
dirname
do-release-commit-and-tag
dup2
environ
error
euidaccess
exclude
@@ -90,6 +92,7 @@ gnulib_modules="
fopen-safer
fprintftime
freopen
freopen-safer
fseeko
fsusage
fsync
@@ -127,6 +130,7 @@ gnulib_modules="
inttostr
inttypes
isapipe
isblank
lchmod
lchown
lib-ignore
@@ -156,6 +160,7 @@ gnulib_modules="
modechange
mountlist
mpsort
nproc
obstack
pathmax
perl
@@ -178,8 +183,8 @@ gnulib_modules="
readutmp
realloc
regex
remove
rename
rename-dest-slash
rmdir
root-dev-ino
rpmatch
@@ -210,10 +215,12 @@ gnulib_modules="
sys_stat
timespec
tzset
uname
unicodeio
unistd-safer
unlink-busy
unlocked-io
unsetenv
update-copyright
uptime
useless-if-before-free
@@ -238,6 +245,7 @@ gnulib_modules="
xnanosleep
xprintf
xprintf-posix
xreadlink
xstrtod
xstrtoimax
xstrtol

33
cfg.mk
View File

@@ -39,7 +39,7 @@ bootstrap-tools = autoconf,automake,gnulib,bison
# Now that we have better tests, make this the default.
export VERBOSE = yes
old_NEWS_hash = 0d22ab4ad3fedd9cf283b256b61e8080
old_NEWS_hash = 785e51bc9af87e7eb004f9ba24a0ca27
# Ensure that the list of O_ symbols used to compute O_FULLBLOCK is complete.
dd = $(srcdir)/src/dd.c
@@ -191,6 +191,18 @@ sc_no_exec_perl_coreutils:
exit 1; } || :; \
fi
# Don't use "readlink" or "readlinkat" directly
sc_prohibit_readlink:
@re='\<readlink(at)? \(' \
msg='do not use readlink(at); use via xreadlink or areadlink*' \
$(_prohibit_regexp)
# Don't use address of "stat" or "lstat" functions
sc_prohibit_stat_macro_address:
@re='\<l?stat '':|&l?stat\>' \
msg='stat() and lstat() may be function-like macros' \
$(_prohibit_regexp)
# Ensure that date's --help output stays in sync with the info
# documentation for GNU strftime. The only exception is %N,
# which date accepts but GNU strftime does not.
@@ -218,4 +230,23 @@ sc_prohibit_emacs__indent_tabs_mode__setting:
msg='use of emacs indent-tabs-mode: setting' \
$(_prohibit_regexp)
# Ensure that each file that contains fail=1 also contains fail=0.
# Otherwise, setting file=1 in the environment would make tests fail unexpectedly.
sc_prohibit_fail_0:
@re='\<fail=0\>' \
msg='fail=0 initialization' \
$(_prohibit_regexp)
# Ensure that "stdio--.h" is used where appropriate.
sc_require_stdio_safer:
@if $(VC_LIST_EXCEPT) | grep -l '\.[ch]$$' > /dev/null; then \
files=$$(grep -l '\bfreopen \?(' $$($(VC_LIST_EXCEPT) \
| grep '\.[ch]$$')); \
test -n "$$files" && grep -LE 'include "stdio--.h"' $$files \
| grep . && \
{ echo '$(ME): the above files should use "stdio--.h"' \
1>&2; exit 1; } || :; \
else :; \
fi
include $(srcdir)/dist-check.mk

View File

@@ -106,6 +106,7 @@ if test "$gl_gcc_warnings" = yes; then
gl_WARN_ADD([-Wno-logical-op])
gl_WARN_ADD([-fdiagnostics-show-option])
gl_WARN_ADD([-funit-at-a-time])
AC_SUBST([WARN_CFLAGS])
@@ -113,13 +114,21 @@ if test "$gl_gcc_warnings" = yes; then
AC_DEFINE([_FORTIFY_SOURCE], [2],
[enable compile-time and run-time bounds-checking, and some warnings])
AC_DEFINE([GNULIB_PORTCHECK], [1], [enable some gnulib portability checks])
# We use a slightly smaller set of warning options for lib/.
# Remove the following and save the result in GNULIB_WARN_CFLAGS.
nw=
nw="$nw -Wuninitialized"
nw="$nw -Wunused-macros"
nw="$nw -Wmissing-prototypes"
nw="$nw -Wold-style-definition"
gl_MANYWARN_COMPLEMENT([GNULIB_WARN_CFLAGS], [$WARN_CFLAGS], [$nw])
AC_SUBST([GNULIB_WARN_CFLAGS])
fi
AC_FUNC_FORK
optional_bin_progs=
AC_CHECK_FUNCS([uname],
gl_ADD_PROG([optional_bin_progs], [uname]))
AC_CHECK_FUNCS([chroot],
gl_ADD_PROG([optional_bin_progs], [chroot]))
AC_CHECK_FUNCS([gethostid],
@@ -420,8 +429,10 @@ CONFIG_STATUS_DEPENDENCIES='$(top_srcdir)/src/Makefile.am'
AC_SUBST([CONFIG_STATUS_DEPENDENCIES])
############################################################################
# As long as "grep 'PRI[diouxX]' po/*.pot" reports matches in
# translatable strings, we must use need-formatstring-macros here.
AM_GNU_GETTEXT([external], [need-formatstring-macros])
AM_GNU_GETTEXT_VERSION([0.15])
AM_GNU_GETTEXT_VERSION([0.17])
# For a test of uniq: it uses the $LOCALE_FR envvar.
gt_LOCALE_FR

View File

@@ -48,8 +48,10 @@ _W = (^|[^A-Za-z0-9_])
W_ = ([^A-Za-z0-9_]|$$)
syntax_checks = \
sc-avoid-builtin \
sc-avoid-io \
sc-avoid-non-zero \
sc-avoid-path \
sc-avoid-timezone \
sc-avoid-zeroes \
sc-exponent-grouping \
@@ -70,9 +72,18 @@ check-texinfo: $(syntax_checks)
$(PERL) -e 1 2> /dev/null && { $(PERL) -ne \
'/\bPOSIX\b/ && !/\@acronym{POSIX}/ && !/^\* / || /{posix}/ and print,exit 1' \
$(srcdir)/*.texi 2> /dev/null || fail=1; }; \
$(EGREP) -i '$(_W)builtins?$(W_)' $(srcdir)/*.texi && fail=1; \
exit $$fail
sc-avoid-builtin:
$(AM_V_GEN)$(EGREP) -i '$(_W)builtins?$(W_)' $(srcdir)/*.texi \
&& exit 1 || :
sc-avoid-path:
$(AM_V_GEN)fail=0; \
$(EGREP) -i '$(_W)path(name)?s?$(W_)' $(srcdir)/*.texi \
| $(EGREP) -v 'search path|@vindex PATH$$|@env[{]PATH[}]' && fail=1; \
| $(EGREP) -v \
'PATH=|path search|search path|@vindex PATH$$|@env[{]PATH[}]' \
&& fail=1; \
exit $$fail
# Use `time zone', not `timezone'.

View File

@@ -31,7 +31,6 @@
@c FIXME: the following need documentation
@c * [: (coreutils)[ invocation. File/string tests.
@c * pinky: (coreutils)pinky invocation. FIXME.
@c * mktemp: (coreutils)mktemp invocation. FIXME.
@dircategory Individual utilities
@direntry
@@ -80,10 +79,12 @@
* mkdir: (coreutils)mkdir invocation. Create directories.
* mkfifo: (coreutils)mkfifo invocation. Create FIFOs (named pipes).
* mknod: (coreutils)mknod invocation. Create special files.
* mktemp: (coreutils)mktemp invocation. Create temporary files.
* mv: (coreutils)mv invocation. Rename files.
* nice: (coreutils)nice invocation. Modify niceness.
* nl: (coreutils)nl invocation. Number lines and write files.
* nohup: (coreutils)nohup invocation. Immunize to hangups.
* nproc: (coreutils)nproc invocation. Print the number of processors.
* od: (coreutils)od invocation. Dump files in octal, etc.
* paste: (coreutils)paste invocation. Merge lines of files.
* pathchk: (coreutils)pathchk invocation. Check file name portability.
@@ -193,7 +194,7 @@ Free Documentation License''.
* Printing text:: echo printf yes
* Conditions:: false true test expr
* Redirection:: tee
* File name manipulation:: dirname basename pathchk
* File name manipulation:: dirname basename pathchk mktemp
* Working context:: pwd stty printenv tty
* User information:: id logname whoami groups users who
* System context:: date arch uname hostname hostid uptime
@@ -378,6 +379,7 @@ File name manipulation
* basename invocation:: Strip directory and suffix from a file name
* dirname invocation:: Strip non-directory suffix from a file name
* pathchk invocation:: Check file name validity and portability
* mktemp invocation:: Create temporary file or directory
Working context
@@ -409,6 +411,7 @@ System context
* arch invocation:: Print machine hardware name
* date invocation:: Print or set system date and time
* nproc invocation:: Print the number of processors
* uname invocation:: Print system information
* hostname invocation:: Print or set system name
* hostid invocation:: Print numeric host identifier
@@ -574,6 +577,18 @@ Do not treat the last operand specially when it is a directory or a
symbolic link to a directory. @xref{Target directory}.
@end macro
@macro optNull{cmd}
@item -0
@opindex -0
@itemx --null
@opindex --null
@cindex output @sc{nul}-byte-terminated lines
Output a zero byte (@acronym{ASCII} @sc{nul}) at the end of each line,
rather than a newline. This option enables other programs to parse the
output of @command{\cmd\} even when that output would contain data
with embedded newlines.
@end macro
@macro optSi
@itemx --si
@opindex --si
@@ -9855,7 +9870,9 @@ touch [@var{option}]@dots{} @var{file}@dots{}
@end example
@cindex empty files, creating
Any @var{file} argument that does not exist is created empty.
Any @var{file} argument that does not exist is created empty, unless
option @option{--no-create} (@option{-c}) or @option{--no-dereference}
(@option{-h}) was in effect.
A @var{file} argument string of @samp{-} is handled specially and
causes @command{touch} to change the times of the file associated with
@@ -9869,8 +9886,8 @@ user must own the files.
Although @command{touch} provides options for changing two of the times---the
times of last access and modification---of a file, there is actually
a third one as well: the inode change time. This is often referred to
as a file's @code{ctime}.
a standard third one as well: the inode change time. This is often
referred to as a file's @code{ctime}.
The inode change time represents the time when the file's meta-information
last changed. One common example of this is when the permissions of a
file change. Changing the permissions doesn't access the file, so
@@ -9882,6 +9899,9 @@ fresh copy of the file, including the new permissions value.
Another operation that modifies a file's ctime without affecting
the others is renaming. In any case, it is not possible, in normal
operations, for a user to change the ctime field to a user-specified value.
Some operating systems and file systems support a fourth time: the
birth time, when the file was first created; by definition, this
timestamp never changes.
@vindex TZ
Time stamps assume the time zone rules specified by the @env{TZ}
@@ -9910,7 +9930,7 @@ Change the access time only.
@itemx --no-create
@opindex -c
@opindex --no-create
Do not create files that do not exist.
Do not warn about or create files that do not exist.
@item -d
@itemx --date=@var{time}
@@ -9931,6 +9951,24 @@ silently ignore any excess precision here.
@cindex BSD @command{touch} compatibility
Ignored; for compatibility with BSD versions of @command{touch}.
@item -h
@itemx --no-dereference
@opindex -h
@opindex --no-dereference
@cindex symbolic links, changing time
@findex lutimes
Attempt to change the timestamps of a symbolic link, rather than what
the link refers to. When using this option, empty files are not
created, but option @option{-c} must also be used to avoid warning
about files that do not exist. Not all systems support changing the
timestamps of symlinks, since underlying system support for this
action was not required until @acronym{POSIX} 2008. Also, on some
systems, the mere act of examining a symbolic link changes the access
time, such that only changes to the modification time will persist
long enough to be observable. When coupled with option @option{-r}, a
reference timestamp is taken from a symbolic link rather than the file
it refers to.
@item -m
@itemx --time=mtime
@itemx --time=modify
@@ -9950,6 +9988,8 @@ If this option is combined with the @option{--date=@var{time}}
the origin for any relative @var{time}s given, but is otherwise ignored.
For example, @samp{-r foo -d '-5 seconds'} specifies a time stamp
equal to five seconds before the corresponding time stamp for @file{foo}.
If @var{file} is a symbolic link, the reference timestamp is taken
from the target of the symlink, unless @option{-h} was also in effect.
@item -t [[@var{cc}]@var{yy}]@var{mmddhhmm}[.@var{ss}]
Use the argument (optional four-digit or two-digit years, months,
@@ -10351,15 +10391,7 @@ Show the total for each directory (and file if --all) that is at
most MAX_DEPTH levels down from the root of the hierarchy. The root
is at level 0, so @code{du --max-depth=0} is equivalent to @code{du -s}.
@item -0
@opindex -0
@itemx --null
@opindex --null
@cindex output null-byte-terminated lines
Output a zero byte (@acronym{ASCII} @sc{nul}) at the end of each line,
rather than a newline. This option enables other programs to parse the
output of @command{du} even when that output would contain file names
with embedded newlines.
@optNull{du}
@optSi
@@ -10771,6 +10803,8 @@ alert (bell)
backspace
@item \c
produce no further output
@item \e
escape
@item \f
form feed
@item \n
@@ -11845,6 +11879,7 @@ This section describes commands that manipulate file names.
* basename invocation:: Strip directory and suffix from a file name.
* dirname invocation:: Strip non-directory suffix from a file name.
* pathchk invocation:: Check file name validity and portability.
* mktemp invocation:: Create temporary file or directory.
@end menu
@@ -12019,6 +12054,180 @@ Exit status:
1 otherwise.
@end display
@node mktemp invocation
@section @command{mktemp}: Create temporary file or directory
@pindex mktemp
@cindex file names, creating temporary
@cindex directory, creating temporary
@cindex temporary files and directories
@command{mktemp} manages the creation of temporary files and
directories. Synopsis:
@example
mktemp [@var{option}]@dots{} [@var{template}]
@end example
Safely create a temporary file or directory based on @var{template},
and print its name. If given, @var{template} must include at least
three consecutive @samp{X}s in the last component. If omitted, the template
@samp{tmp.XXXXXXXXXX} is used, and option @option{--tmpdir} is
implied. The final run of @samp{X}s in the @var{template} will be replaced
by alpha-numeric characters; thus, on a case-sensitive file system,
and with a @var{template} including a run of @var{n} instances of @samp{X},
there are @samp{62**@var{n}} potential file names.
Older scripts used to create temporary files by simply joining the
name of the program with the process id (@samp{$$}) as a suffix.
However, that naming scheme is easily predictable, and suffers from a
race condition where the attacker can create an appropriately named
symbolic link, such that when the script then opens a handle to what
it thought was an unused file, it is instead modifying an existing
file. Using the same scheme to create a directory is slightly safer,
since the @command{mkdir} will fail if the target already exists, but
it is still inferior because it allows for denial of service attacks.
Therefore, modern scripts should use the @command{mktemp} command to
guarantee that the generated name will be unpredictable, and that
knowledge of the temporary file name implies that the file was created
by the current script and cannot be modified by other users.
When creating a file, the resulting file has read and write
permissions for the current user, but no permissions for the group or
others; these permissions are reduced if the current umask is more
restrictive.
Here are some examples (although note that if you repeat them, you
will most likely get different file names):
@itemize @bullet
@item
Create a temporary file in the current directory.
@example
$ mktemp file.XXXX
file.H47c
@end example
@item
Create a temporary file with a known suffix.
@example
$ mktemp --suffix=.txt file-XXXX
file-H08W.txt
$ mktemp file-XXXX-XXXX.txt
file-XXXX-eI9L.txt
@end example
@item
Create a secure fifo relative to the user's choice of @env{TMPDIR},
but falling back to the current directory rather than @file{/tmp}.
Note that @command{mktemp} does not create fifos, but can create a
secure directory in which the fifo can live. Exit the shell if the
directory or fifo could not be created.
@example
$ dir=$(mktemp -p "$@{TMPDIR:-.@}" -d dir-XXXX) || exit 1
$ fifo=$dir/fifo
$ mkfifo "$fifo" || @{ rmdir "$dir"; exit 1; @}
@end example
@item
Create and use a temporary file if possible, but ignore failure. The
file will reside in the directory named by @env{TMPDIR}, if specified,
or else in @file{/tmp}.
@example
$ file=$(mktemp -q) && @{
> # Safe to use $file only within this block. Use quotes,
> # since $TMPDIR, and thus $file, may contain whitespace.
> echo ... > "$file"
> rm "$file"
> @}
@end example
@item
Act as a semi-random character generator (it is not fully random,
since it is impacted by the contents of the current directory). To
avoid security holes, do not use the resulting names to create a file.
@example
$ mktemp -u XXX
Gb9
$ mktemp -u XXX
nzC
@end example
@end itemize
The program accepts the following options. Also see @ref{Common options}.
@table @samp
@item -d
@itemx --directory
@opindex -d
@opindex --directory
Create a directory rather than a file. The directory will have read,
write, and search permissions for the current user, but no permissions
for the group or others; these permissions are reduced if the current
umask is more restrictive.
@item -q
@itemx --quiet
@opindex -q
@opindex --quiet
Suppress diagnostics about failure to create a file or directory. The
exit status will still reflect whether a file was created.
@item -u
@itemx --dry-run
@opindex -u
@opindex --dry-run
Generate a temporary name that does not name an existing file, without
changing the file system contents. Using the output of this command
to create a new file is inherently unsafe, as there is a window of
time between generating the name and using it where another process
can create an object by the same name.
@item -p @var{dir}
@itemx --tmpdir[=@var{dir}]
@opindex -p
@opindex --tmpdir
Treat @var{template} relative to the directory @var{dir}. If
@var{dir} is not specified (only possible with the long option
@option{--tmpdir}) or is the empty string, use the value of
@env{TMPDIR} if available, otherwise use @samp{/tmp}. If this is
specified, @var{template} must not be absolute. However,
@var{template} can still contain slashes, although intermediate
directories must already exist.
@item --suffix=@var{suffix}
@opindex --suffix
Append @var{suffix} to the @var{template}. @var{suffix} must not
contain slash. If @option{--suffix} is specified, @var{template} must
end in @samp{X}; if it is not specified, then an appropriate
@option{--suffix} is inferred by finding the last @samp{X} in
@var{template}. This option exists for use with the default
@var{template} and for the creation of a @var{suffix} that starts with
@samp{X}.
@item -t
@opindex -t
Treat @var{template} as a single file relative to the value of
@env{TMPDIR} if available, or to the directory specified by
@option{-p}, otherwise to @samp{/tmp}. @var{template} must not
contain slashes. This option is deprecated; the use of @option{-p}
without @option{-t} offers better defaults (by favoring the command
line over @env{TMPDIR}) and more flexibility (by allowing intermediate
directories).
@end table
@cindex exit status of @command{mktemp}
Exit status:
@display
0 if the file was created,
1 otherwise.
@end display
@node Working context
@chapter Working context
@@ -12781,8 +12990,13 @@ If no @var{variable}s are specified, @command{printenv} prints the value of
every environment variable. Otherwise, it prints the value of each
@var{variable} that is set, and nothing for those that are not set.
The only options are a lone @option{--help} or @option{--version}.
@xref{Common options}.
The program accepts the following option. Also see @ref{Common options}.
@table @samp
@optNull{printenv}
@end table
@cindex exit status of @command{printenv}
Exit status:
@@ -13196,6 +13410,7 @@ information.
@menu
* date invocation:: Print or set system date and time.
* arch invocation:: Print machine hardware name.
* nproc invocation:: Print the number of processors.
* uname invocation:: Print system information.
* hostname invocation:: Print or set system name.
* hostid invocation:: Print numeric host identifier.
@@ -13855,6 +14070,43 @@ The program accepts the @ref{Common options} only.
@exitstatus
@node nproc invocation
@section @command{nproc}: Print the number of available processors
@pindex nproc
@cindex Print the number of processors
@cindex system information, printing
Print the number of processing units available to the current process,
which may be less than the number of online processors.
If this information is not accessible, then print the number of
processors installed. If the @env{OMP_NUM_THREADS} environment variable is
set, then it will determine the returned value. The result is guaranteed to be
greater than zero. Synopsis:
@example
nproc [@var{option}]
@end example
The program accepts the following options. Also see @ref{Common options}.
@table @samp
@item --all
@opindex --all
Print the number of installed processors on the system, which may
be greater than the number online or available to the current process.
The @env{OMP_NUM_THREADS} environment variable is not honored in this case.
@item --ignore=@var{number}
@opindex --ignore
If possible, exclude this @var{number} of processing units.
@end table
@exitstatus
@node uname invocation
@section @command{uname}: Print system information
@@ -14338,7 +14590,7 @@ device files), copy them into place, too.
Exit status:
@display
1 if @command{chroot} itself fails
125 if @command{chroot} itself fails
126 if @var{command} is found but cannot be invoked
127 if @var{command} cannot be found
the exit status of @var{command} otherwise
@@ -14383,17 +14635,89 @@ remaining arguments are passed as arguments to that program.
The program should not be a special built-in utility
(@pxref{Special built-in utilities}).
Modifications to @env{PATH} take effect prior to searching for
@var{command}. Use caution when reducing @env{PATH}; behavior is
not portable when @env{PATH} is undefined or omits key directories
such as @file{/bin}.
In the rare case that a utility contains a @samp{=} in the name, the
only way to disambiguate it from a variable assignment is to use an
intermediate command for @var{command}, and pass the problematic
program name via @var{args}. For example, if @file{./prog=} is an
executable in the current @env{PATH}:
@example
env prog= true # runs 'true', with prog= in environment
env ./prog= true # runs 'true', with ./prog= in environment
env -- prog= true # runs 'true', with prog= in environment
env sh -c '\prog= true' # runs 'prog=' with argument 'true'
env sh -c 'exec "$@@"' sh prog= true # also runs 'prog='
@end example
@cindex environment, printing
If no command name is specified following the environment
specifications, the resulting environment is printed. This is like
specifying the @command{printenv} program.
For some examples, suppose the environment passed to @command{env}
contains @samp{LOGNAME=rms}, @samp{EDITOR=emacs}, and
@samp{PATH=.:/gnubin:/hacks}:
@itemize @bullet
@item
Output the current environment.
@example
$ env | LC_ALL=C sort
EDITOR=emacs
LOGNAME=rms
PATH=.:/gnubin:/hacks
@end example
@item
Run @command{foo} with a reduced environment, preserving only the
original @env{PATH} to avoid problems in locating @command{foo}.
@example
env - PATH="$PATH" foo
@end example
@item
Run @command{foo} with the environment containing @samp{LOGNAME=rms},
@samp{EDITOR=emacs}, and @samp{PATH=.:/gnubin:/hacks}, and guarantees
that @command{foo} was found in the file system rather than as a shell
built-in.
@example
env foo
@end example
@item
Run @command{nemacs} with the environment containing @samp{LOGNAME=foo},
@samp{EDITOR=emacs}, @samp{PATH=.:/gnubin:/hacks}, and
@samp{DISPLAY=gnu:0}.
@example
env DISPLAY=gnu:0 LOGNAME=foo nemacs
@end example
@item
Attempt to run the program @command{/energy/--} (as that is the only
possible path search result); if the command exists, the environment
will contain @samp{LOGNAME=rms} and @samp{PATH=/energy}, and the
arguments will be @samp{e=mc2}, @samp{bar}, and @samp{baz}.
@example
env -u EDITOR PATH=/energy -- e=mc2 bar baz
@end example
@end itemize
The program accepts the following options. Also see @ref{Common options}.
Options must precede operands.
@table @samp
@optNull{env}
@item -u @var{name}
@itemx --unset=@var{name}
@opindex -u
@@ -14416,7 +14740,7 @@ Exit status:
@display
0 if no @var{command} is specified and the environment is output
1 if @command{env} itself fails
125 if @command{env} itself fails
126 if @var{command} is found but cannot be invoked
127 if @var{command} cannot be found
the exit status of @var{command} otherwise
@@ -14491,7 +14815,7 @@ Exit status:
@display
0 if no @var{command} is specified and the niceness is output
1 if @command{nice} itself fails
125 if @command{nice} itself fails
126 if @var{command} is found but cannot be invoked
127 if @var{command} cannot be found
the exit status of @var{command} otherwise
@@ -14609,11 +14933,15 @@ options}. Options must precede operands.
Exit status:
@display
125 if @command{nohup} itself fails, and @env{POSIXLY_CORRECT} is not set
126 if @var{command} is found but cannot be invoked
127 if @command{nohup} itself fails or if @var{command} cannot be found
127 if @var{command} cannot be found
the exit status of @var{command} otherwise
@end display
If @env{POSIXLY_CORRECT} is set, internal failures give status 127
instead of 125.
@node stdbuf invocation
@section @command{stdbuf}: Run a command with modified I/O stream buffering
@@ -14818,7 +15146,7 @@ shell is restricted (see @option{-m} just above).
Exit status:
@display
1 if @command{su} itself fails
125 if @command{su} itself fails
126 if subshell is found but cannot be invoked
127 if subshell cannot be found
the exit status of the subshell otherwise

View File

@@ -129,7 +129,7 @@ mbs_align_pad (char *dest, const char* dest_end, size_t n_spaces)
size_t
mbsalign (const char *src, char *dest, size_t dest_size,
size_t *width, mbs_align_t align, int flags)
size_t *width, mbs_align_t align, int flags _UNUSED_PARAMETER_)
{
size_t ret = -1;
size_t src_size = strlen (src) + 1;

View File

@@ -1,142 +0,0 @@
/* mgetgroups.c -- return a list of the groups a user is in
Copyright (C) 2007-2009 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Extracted from coreutils' src/id.c. */
#include <config.h>
#include "mgetgroups.h"
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#if HAVE_GETGROUPLIST
# include <grp.h>
#endif
#include "getugroups.h"
#include "xalloc.h"
static GETGROUPS_T *
realloc_groupbuf (GETGROUPS_T *g, size_t num)
{
if (xalloc_oversized (num, sizeof (*g)))
{
errno = ENOMEM;
return NULL;
}
return realloc (g, num * sizeof (*g));
}
/* Like getugroups, but store the result in malloc'd storage.
Set *GROUPS to the malloc'd list of all group IDs of which USERNAME
is a member. If GID is not -1, store it first. GID should be the
group ID (pw_gid) obtained from getpwuid, in case USERNAME is not
listed in the groups database (e.g., /etc/groups). Upon failure,
don't modify *GROUPS, set errno, and return -1. Otherwise, return
the number of groups. */
int
mgetgroups (char const *username, gid_t gid, GETGROUPS_T **groups)
{
int max_n_groups;
int ng;
GETGROUPS_T *g;
#if HAVE_GETGROUPLIST
/* We prefer to use getgrouplist if available, because it has better
performance characteristics.
In glibc 2.3.2, getgrouplist is buggy. If you pass a zero as the
length of the output buffer, getgrouplist will still write to the
buffer. Contrary to what some versions of the getgrouplist
manpage say, this doesn't happen with nonzero buffer sizes.
Therefore our usage here just avoids a zero sized buffer. */
if (username)
{
enum { N_GROUPS_INIT = 10 };
max_n_groups = N_GROUPS_INIT;
g = realloc_groupbuf (NULL, max_n_groups);
if (g == NULL)
return -1;
while (1)
{
GETGROUPS_T *h;
int last_n_groups = max_n_groups;
/* getgrouplist updates max_n_groups to num required. */
ng = getgrouplist (username, gid, g, &max_n_groups);
/* Some systems (like Darwin) have a bug where they
never increase max_n_groups. */
if (ng < 0 && last_n_groups == max_n_groups)
max_n_groups *= 2;
if ((h = realloc_groupbuf (g, max_n_groups)) == NULL)
{
int saved_errno = errno;
free (g);
errno = saved_errno;
return -1;
}
g = h;
if (0 <= ng)
{
*groups = g;
/* On success some systems just return 0 from getgrouplist,
so return max_n_groups rather than ng. */
return max_n_groups;
}
}
}
/* else no username, so fall through and use getgroups. */
#endif
max_n_groups = (username
? getugroups (0, NULL, username, gid)
: getgroups (0, NULL));
/* If we failed to count groups with NULL for a buffer,
try again with a non-NULL one, just in case. */
if (max_n_groups < 0)
max_n_groups = 5;
g = realloc_groupbuf (NULL, max_n_groups);
if (g == NULL)
return -1;
ng = (username
? getugroups (max_n_groups, g, username, gid)
: getgroups (max_n_groups, g));
if (ng < 0)
{
int saved_errno = errno;
free (g);
errno = saved_errno;
return -1;
}
*groups = g;
return ng;
}

View File

@@ -1,19 +0,0 @@
/* Get a list of all group IDs associated with a specified user ID.
Copyright (C) 2007, 2009 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <sys/types.h>
int mgetgroups (const char *username, gid_t gid, GETGROUPS_T **groups);

82
gl/lib/regcomp.c.diff Normal file
View File

@@ -0,0 +1,82 @@
diff --git c/lib/regcomp.c i/lib/regcomp.c
index 6472ff6..665b2ab 100644
--- c/lib/regcomp.c
+++ i/lib/regcomp.c
@@ -18,6 +18,8 @@
with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+#include "intprops.h"
+#include "verify.h"
static reg_errcode_t re_compile_internal (regex_t *preg, const char * pattern,
size_t length, reg_syntax_t syntax);
static void re_compile_fastmap_iter (regex_t *bufp,
@@ -541,7 +543,7 @@ regerror (errcode, preg, errbuf, errbuf_size)
size_t errbuf_size;
#else /* size_t might promote */
size_t
-regerror (int errcode, const regex_t *_Restrict_ preg,
+regerror (int errcode, const regex_t *_Restrict_ preg _UNUSED_PARAMETER_,
char *_Restrict_ errbuf, size_t errbuf_size)
#endif
{
@@ -1375,7 +1377,7 @@ calc_first (void *extra, bin_tree_t *node)
/* Pass 2: compute NEXT on the tree. Preorder visit. */
static reg_errcode_t
-calc_next (void *extra, bin_tree_t *node)
+calc_next (void *extra _UNUSED_PARAMETER_, bin_tree_t *node)
{
switch (node->token.type)
{
@@ -2571,7 +2573,8 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
/* This loop is actually executed only when end != REG_MISSING,
to rewrite <re>{0,n} as (<re>(<re>...<re>?)?)?... We have
already created the start+1-th copy. */
- if ((Idx) -1 < 0 || end != REG_MISSING)
+ verify (! TYPE_SIGNED (Idx));
+ if (end != REG_MISSING)
for (i = start + 2; i <= end; ++i)
{
elem = duplicate_tree (elem, dfa);
@@ -2731,7 +2734,8 @@ static reg_errcode_t
internal_function
build_collating_symbol (bitset_t sbcset,
# ifdef RE_ENABLE_I18N
- re_charset_t *mbcset, Idx *coll_sym_alloc,
+ re_charset_t *mbcset _UNUSED_PARAMETER_,
+ Idx *coll_sym_alloc _UNUSED_PARAMETER_,
# endif
const unsigned char *name)
{
@@ -3309,7 +3313,8 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
static reg_errcode_t
parse_bracket_element (bracket_elem_t *elem, re_string_t *regexp,
- re_token_t *token, int token_len, re_dfa_t *dfa,
+ re_token_t *token, int token_len,
+ re_dfa_t *dfa _UNUSED_PARAMETER_,
reg_syntax_t syntax, bool accept_hyphen)
{
#ifdef RE_ENABLE_I18N
@@ -3396,8 +3401,9 @@ parse_bracket_symbol (bracket_elem_t *elem, re_string_t *regexp,
static reg_errcode_t
#ifdef RE_ENABLE_I18N
-build_equiv_class (bitset_t sbcset, re_charset_t *mbcset,
- Idx *equiv_class_alloc, const unsigned char *name)
+build_equiv_class (bitset_t sbcset, re_charset_t *mbcset _UNUSED_PARAMETER_,
+ Idx *equiv_class_alloc _UNUSED_PARAMETER_,
+ const unsigned char *name)
#else /* not RE_ENABLE_I18N */
build_equiv_class (bitset_t sbcset, const unsigned char *name)
#endif /* not RE_ENABLE_I18N */
@@ -3798,7 +3804,7 @@ free_token (re_token_t *node)
and its children. */
static reg_errcode_t
-free_tree (void *extra, bin_tree_t *node)
+free_tree (void *extra _UNUSED_PARAMETER_, bin_tree_t *node)
{
free_token (&node->token);
return REG_NOERROR;

View File

@@ -0,0 +1,25 @@
diff --git a/lib/regex_internal.c b/lib/regex_internal.c
index 904b88e..61c8d9d 100644
--- a/lib/regex_internal.c
+++ b/lib/regex_internal.c
@@ -18,6 +18,8 @@
with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+#include "verify.h"
+#include "intprops.h"
static void re_string_construct_common (const char *str, Idx len,
re_string_t *pstr,
RE_TRANSLATE_TYPE trans, bool icase,
@@ -1390,7 +1392,10 @@ static void
internal_function
re_node_set_remove_at (re_node_set *set, Idx idx)
{
- if (idx < 0 || idx >= set->nelem)
+ verify (! TYPE_SIGNED (Idx));
+ /* if (idx < 0)
+ return; */
+ if (idx >= set->nelem)
return;
--set->nelem;
for (; idx < set->nelem; idx++)

View File

@@ -0,0 +1,14 @@
diff --git i/lib/regex_internal.h w/lib/regex_internal.h
index 859832f..3c7fe06 100644
--- i/lib/regex_internal.h
+++ w/lib/regex_internal.h
@@ -826,7 +826,8 @@ re_string_wchar_at (const re_string_t *pstr, Idx idx)
static int
internal_function __attribute ((pure))
-re_string_elem_size_at (const re_string_t *pstr, Idx idx)
+re_string_elem_size_at (const re_string_t *pstr _UNUSED_PARAMETER_,
+ Idx idx _UNUSED_PARAMETER_)
{
# ifdef _LIBC
const unsigned char *p, *extra;

45
gl/lib/regexec.c.diff Normal file
View File

@@ -0,0 +1,45 @@
diff --git a/lib/regexec.c b/lib/regexec.c
index 21a8166..7762437 100644
--- a/lib/regexec.c
+++ b/lib/regexec.c
@@ -18,6 +18,8 @@
with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+#include "verify.h"
+#include "intprops.h"
static reg_errcode_t match_ctx_init (re_match_context_t *cache, int eflags,
Idx n) internal_function;
static void match_ctx_clean (re_match_context_t *mctx) internal_function;
@@ -378,8 +380,11 @@ re_search_2_stub (struct re_pattern_buffer *bufp,
Idx len = length1 + length2;
char *s = NULL;
- if (BE (length1 < 0 || length2 < 0 || stop < 0 || len < length1, 0))
- return -2;
+ verify (! TYPE_SIGNED (Idx));
+ if (BE (len < length1, 0))
+ return -2;
+ /* if (BE (length1 < 0 || length2 < 0 || stop < 0, 0))
+ return -2; */
/* Concatenate the strings. */
if (length2 > 0)
@@ -431,11 +436,14 @@ re_search_stub (struct re_pattern_buffer *bufp,
Idx last_start = start + range;
/* Check for out-of-range. */
- if (BE (start < 0 || start > length, 0))
- return -1;
+ verify (! TYPE_SIGNED (Idx));
+ /* if (BE (start < 0, 0))
+ return -1; */
+ if (BE (start > length, 0))
+ return -1;
if (BE (length < last_start || (0 <= range && last_start < start), 0))
last_start = length;
- else if (BE (last_start < 0 || (range < 0 && start <= last_start), 0))
+ else if (BE (/* last_start < 0 || */ (range < 0 && start <= last_start), 0))
last_start = 0;
__libc_lock_lock (dfa->lock);

View File

@@ -1,294 +0,0 @@
/* tempname.c - generate the name of a temporary file.
Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
2000, 2001, 2002, 2003, 2005, 2006, 2007, 2009 Free Software Foundation,
Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Extracted from glibc sysdeps/posix/tempname.c. See also tmpdir.c. */
#if !_LIBC
# include <config.h>
# include "tempname.h"
# include "randint.h"
#endif
#include <sys/types.h>
#include <assert.h>
#include <errno.h>
#ifndef __set_errno
# define __set_errno(Val) errno = (Val)
#endif
#include <stdio.h>
#ifndef P_tmpdir
# define P_tmpdir "/tmp"
#endif
#ifndef TMP_MAX
# define TMP_MAX 238328
#endif
#ifndef __GT_FILE
# define __GT_FILE 1
# define __GT_DIR 2
# define __GT_NOCREATE 3
#endif
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/time.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/stat.h>
#if _LIBC
# define struct_stat64 struct stat64
#else
# define struct_stat64 struct stat
# define __open open
# define __gen_tempname gen_tempname
# define __getpid getpid
# define __gettimeofday gettimeofday
# define __mkdir mkdir
# define __lxstat64(version, file, buf) lstat (file, buf)
# define __xstat64(version, file, buf) stat (file, buf)
#endif
#if ! (HAVE___SECURE_GETENV || _LIBC)
# define __secure_getenv getenv
#endif
#if _LIBC
/* Return nonzero if DIR is an existent directory. */
static int
direxists (const char *dir)
{
struct_stat64 buf;
return __xstat64 (_STAT_VER, dir, &buf) == 0 && S_ISDIR (buf.st_mode);
}
/* Path search algorithm, for tmpnam, tmpfile, etc. If DIR is
non-null and exists, uses it; otherwise uses the first of $TMPDIR,
P_tmpdir, /tmp that exists. Copies into TMPL a template suitable
for use with mk[s]temp. Will fail (-1) if DIR is non-null and
doesn't exist, none of the searched dirs exists, or there's not
enough space in TMPL. */
int
__path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx,
int try_tmpdir)
{
const char *d;
size_t dlen, plen;
if (!pfx || !pfx[0])
{
pfx = "file";
plen = 4;
}
else
{
plen = strlen (pfx);
if (plen > 5)
plen = 5;
}
if (try_tmpdir)
{
d = __secure_getenv ("TMPDIR");
if (d != NULL && direxists (d))
dir = d;
else if (dir != NULL && direxists (dir))
/* nothing */ ;
else
dir = NULL;
}
if (dir == NULL)
{
if (direxists (P_tmpdir))
dir = P_tmpdir;
else if (strcmp (P_tmpdir, "/tmp") != 0 && direxists ("/tmp"))
dir = "/tmp";
else
{
__set_errno (ENOENT);
return -1;
}
}
dlen = strlen (dir);
while (dlen > 1 && dir[dlen - 1] == '/')
dlen--; /* remove trailing slashes */
/* check we have room for "${dir}/${pfx}XXXXXX\0" */
if (tmpl_len < dlen + 1 + plen + 6 + 1)
{
__set_errno (EINVAL);
return -1;
}
sprintf (tmpl, "%.*s/%.*sXXXXXX", (int) dlen, dir, (int) plen, pfx);
return 0;
}
#endif /* _LIBC */
static inline bool
check_x_suffix (char const *s, size_t len)
{
return strspn (s, "X") == len;
}
/* These are the characters used in temporary file names. */
static const char letters[] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
/* Generate a temporary file name based on TMPL. TMPL must end in a
a sequence of at least X_SUFFIX_LEN "X"s. The name constructed
does not exist at the time of the call to __gen_tempname. TMPL is
overwritten with the result.
KIND may be one of:
__GT_NOCREATE: simply verify that the name does not exist
at the time of the call.
__GT_FILE: create the file using open(O_CREAT|O_EXCL)
and return a read-write fd. The file is mode 0600.
__GT_DIR: create a directory, which will be mode 0700.
We use a clever algorithm to get hard-to-predict names. */
int
gen_tempname_len (char *tmpl, int flags, int kind, size_t x_suffix_len)
{
size_t len;
char *XXXXXX;
unsigned int count;
int fd = -1;
int save_errno = errno;
struct_stat64 st;
struct randint_source *rand_src;
/* A lower bound on the number of temporary files to attempt to
generate. The maximum total number of temporary file names that
can exist for a given template is 62**6. It should never be
necessary to try all these combinations. Instead if a reasonable
number of names is tried (we define reasonable as 62**3) fail to
give the system administrator the chance to remove the problems. */
#define ATTEMPTS_MIN (62 * 62 * 62)
/* The number of times to attempt to generate a temporary file. To
conform to POSIX, this must be no smaller than TMP_MAX. */
#if ATTEMPTS_MIN < TMP_MAX
unsigned int attempts = TMP_MAX;
#else
unsigned int attempts = ATTEMPTS_MIN;
#endif
len = strlen (tmpl);
if (len < x_suffix_len || ! check_x_suffix (&tmpl[len - x_suffix_len],
x_suffix_len))
{
__set_errno (EINVAL);
return -1;
}
rand_src = randint_all_new (NULL, 8);
if (! rand_src)
return -1;
/* This is where the Xs start. */
XXXXXX = &tmpl[len - x_suffix_len];
for (count = 0; count < attempts; ++count)
{
size_t i;
for (i = 0; i < x_suffix_len; i++)
{
XXXXXX[i] = letters[randint_genmax (rand_src, sizeof letters - 2)];
}
switch (kind)
{
case __GT_FILE:
fd = __open (tmpl,
(flags & ~0777) | O_RDWR | O_CREAT | O_EXCL,
S_IRUSR | S_IWUSR);
break;
case __GT_DIR:
fd = __mkdir (tmpl, S_IRUSR | S_IWUSR | S_IXUSR);
break;
case __GT_NOCREATE:
/* This case is backward from the other three. This function
succeeds if __xstat fails because the name does not exist.
Note the continue to bypass the common logic at the bottom
of the loop. */
if (__lxstat64 (_STAT_VER, tmpl, &st) < 0)
{
if (errno == ENOENT)
{
__set_errno (save_errno);
fd = 0;
goto done;
}
else
{
/* Give up now. */
fd = -1;
goto done;
}
}
continue;
default:
assert (! "invalid KIND in __gen_tempname");
}
if (fd >= 0)
{
__set_errno (save_errno);
goto done;
}
else if (errno != EEXIST)
{
fd = -1;
goto done;
}
}
randint_all_free (rand_src);
/* We got out of the loop because we ran out of combinations to try. */
__set_errno (EEXIST);
return -1;
done:
{
int saved_errno = errno;
randint_all_free (rand_src);
__set_errno (saved_errno);
}
return fd;
}
int
__gen_tempname (char *tmpl, int flags, int kind)
{
return gen_tempname_len (tmpl, flags, kind, 6);
}

193
gl/lib/tempname.c.diff Normal file
View File

@@ -0,0 +1,193 @@
diff --git c/lib/tempname.c i/lib/tempname.c
index 2da5afe..562955a 100644
--- c/lib/tempname.c
+++ i/lib/tempname.c
@@ -22,6 +22,7 @@
#if !_LIBC
# include <config.h>
# include "tempname.h"
+# include "randint.h"
#endif
#include <sys/types.h>
@@ -49,6 +50,7 @@
# error report this to bug-gnulib@gnu.org
#endif
+#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
@@ -179,14 +181,21 @@ __path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx,
}
#endif /* _LIBC */
+static inline bool
+check_x_suffix (char const *s, size_t len)
+{
+ return len <= strspn (s, "X");
+}
+
/* These are the characters used in temporary file names. */
static const char letters[] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
/* Generate a temporary file name based on TMPL. TMPL must match the
- rules for mk[s]temp (i.e. end in "XXXXXX", possibly with a suffix).
+ rules for mk[s]temp (i.e. end in at least X_SUFFIX_LEN "X"s,
+ possibly with a suffix).
The name constructed does not exist at the time of the call to
- __gen_tempname. TMPL is overwritten with the result.
+ this function. TMPL is overwritten with the result.
KIND may be one of:
__GT_NOCREATE: simply verify that the name does not exist
@@ -197,23 +206,24 @@ static const char letters[] =
We use a clever algorithm to get hard-to-predict names. */
int
-__gen_tempname (char *tmpl, int suffixlen, int flags, int kind)
+gen_tempname_len (char *tmpl, int suffixlen, int flags, int kind,
+ size_t x_suffix_len)
{
- int len;
+ size_t len;
char *XXXXXX;
- static uint64_t value;
- uint64_t random_time_bits;
unsigned int count;
int fd = -1;
int save_errno = errno;
struct_stat64 st;
+ struct randint_source *rand_src;
/* A lower bound on the number of temporary files to attempt to
generate. The maximum total number of temporary file names that
can exist for a given template is 62**6. It should never be
necessary to try all these combinations. Instead if a reasonable
number of names is tried (we define reasonable as 62**3) fail to
- give the system administrator the chance to remove the problems. */
+ give the system administrator the chance to remove the problems.
+ This value requires that X_SUFFIX_LEN be at least 3. */
#define ATTEMPTS_MIN (62 * 62 * 62)
/* The number of times to attempt to generate a temporary file. To
@@ -225,43 +235,28 @@ __gen_tempname (char *tmpl, int suffixlen, int flags, int kind)
#endif
len = strlen (tmpl);
- if (len < 6 + suffixlen || memcmp (&tmpl[len - 6 - suffixlen], "XXXXXX", 6))
+ if (len < x_suffix_len + suffixlen
+ || ! check_x_suffix (&tmpl[len - x_suffix_len - suffixlen],
+ x_suffix_len))
{
__set_errno (EINVAL);
return -1;
}
/* This is where the Xs start. */
- XXXXXX = &tmpl[len - 6 - suffixlen];
+ XXXXXX = &tmpl[len - x_suffix_len - suffixlen];
/* Get some more or less random data. */
-#ifdef RANDOM_BITS
- RANDOM_BITS (random_time_bits);
-#else
- {
- struct timeval tv;
- __gettimeofday (&tv, NULL);
- random_time_bits = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec;
- }
-#endif
- value += random_time_bits ^ __getpid ();
+ rand_src = randint_all_new (NULL, 8);
+ if (! rand_src)
+ return -1;
- for (count = 0; count < attempts; value += 7777, ++count)
+ for (count = 0; count < attempts; ++count)
{
- uint64_t v = value;
-
- /* Fill in the random bits. */
- XXXXXX[0] = letters[v % 62];
- v /= 62;
- XXXXXX[1] = letters[v % 62];
- v /= 62;
- XXXXXX[2] = letters[v % 62];
- v /= 62;
- XXXXXX[3] = letters[v % 62];
- v /= 62;
- XXXXXX[4] = letters[v % 62];
- v /= 62;
- XXXXXX[5] = letters[v % 62];
+ size_t i;
+
+ for (i = 0; i < x_suffix_len; i++)
+ XXXXXX[i] = letters[randint_genmax (rand_src, sizeof letters - 2)];
switch (kind)
{
@@ -276,7 +271,7 @@ __gen_tempname (char *tmpl, int suffixlen, int flags, int kind)
break;
case __GT_NOCREATE:
- /* This case is backward from the other three. __gen_tempname
+ /* This case is backward from the other three. This function
succeeds if __xstat fails because the name does not exist.
Note the continue to bypass the common logic at the bottom
of the loop. */
@@ -285,11 +280,15 @@ __gen_tempname (char *tmpl, int suffixlen, int flags, int kind)
if (errno == ENOENT)
{
__set_errno (save_errno);
- return 0;
+ fd = 0;
+ goto done;
}
else
- /* Give up now. */
- return -1;
+ {
+ /* Give up now. */
+ fd = -1;
+ goto done;
+ }
}
continue;
@@ -301,13 +300,32 @@ __gen_tempname (char *tmpl, int suffixlen, int flags, int kind)
if (fd >= 0)
{
__set_errno (save_errno);
- return fd;
+ goto done;
}
else if (errno != EEXIST)
- return -1;
+ {
+ fd = -1;
+ goto done;
+ }
}
+ randint_all_free (rand_src);
+
/* We got out of the loop because we ran out of combinations to try. */
__set_errno (EEXIST);
return -1;
+
+ done:
+ {
+ int saved_errno = errno;
+ randint_all_free (rand_src);
+ __set_errno (saved_errno);
+ }
+ return fd;
+}
+
+int
+__gen_tempname (char *tmpl, int suffixlen, int flags, int kind)
+{
+ return gen_tempname_len (tmpl, suffixlen, flags, kind, 6);
}

View File

@@ -1,42 +0,0 @@
/* Create a temporary file or directory.
Copyright (C) 2006, 2007, 2009 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* header written by Eric Blake */
/* In gnulib, always prefer large files. GT_FILE maps to
__GT_BIGFILE, not __GT_FILE, for a reason. */
#define GT_FILE 1
#define GT_DIR 2
#define GT_NOCREATE 3
/* Generate a temporary file name based on TMPL. TMPL must match the
rules for mk[s]temp (i.e. end in "XXXXXX"). The name constructed
does not exist at the time of the call to gen_tempname. TMPL is
overwritten with the result.
KIND may be one of:
GT_NOCREATE: simply verify that the name does not exist
at the time of the call.
GT_FILE: create a large file using open(O_CREAT|O_EXCL)
and return a read-write fd. The file is mode 0600.
GT_DIR: create a directory, which will be mode 0700.
We use a clever algorithm to get hard-to-predict names. */
#include <stddef.h>
extern int gen_tempname (char *tmpl, int flags, int kind);
extern int gen_tempname_len (char *tmpl, int flags, int kind,
size_t x_suffix_len);

12
gl/lib/tempname.h.diff Normal file
View File

@@ -0,0 +1,12 @@
diff --git c/lib/tempname.h i/lib/tempname.h
index cd69e7d..9757db2 100644
--- c/lib/tempname.h
+++ i/lib/tempname.h
@@ -46,5 +46,7 @@
We use a clever algorithm to get hard-to-predict names. */
extern int gen_tempname (char *tmpl, int suffixlen, int flags, int kind);
+extern int gen_tempname_len (char *tmpl, int suffixlen, int flags, int kind,
+ size_t x_suffix_len);
#endif /* GL_TEMPNAME_H */

View File

@@ -21,6 +21,7 @@
#include "error.h"
#include "exitfail.h"
#include "quote.h"
#include "stdio--.h"
#include "gettext.h"
#define _(msgid) gettext (msgid)

View File

@@ -1,11 +0,0 @@
#serial 3
dnl Copyright (C) 2007-2009 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_MGETGROUPS],
[
AC_CHECK_FUNCS([getgrouplist])
AC_LIBOBJ([mgetgroups])
])

View File

@@ -1,24 +0,0 @@
Description:
Return the group IDs of a user in malloc'd storage.
Files:
lib/mgetgroups.c
lib/mgetgroups.h
m4/mgetgroups.m4
Depends-on:
getugroups
xalloc
configure.ac:
gl_MGETGROUPS
Makefile.am:
Include:
License:
LGPL
Maintainer:
Jim Meyering

View File

@@ -0,0 +1,9 @@
diff --git a/modules/rename-tests b/modules/rename-tests
index be1b423..fea330a 100644
--- a/modules/rename-tests
+++ b/modules/rename-tests
@@ -14,3 +14,4 @@ configure.ac:
Makefile.am:
TESTS += test-rename
check_PROGRAMS += test-rename
+test_rename_LDADD = $(LDADD) @LIBINTL@

View File

@@ -8,6 +8,7 @@ lib/xfreopen.h
Depends-on:
error
exitfail
freopen-safer
quote
configure.ac:

2
gnulib

Submodule gnulib updated: 6f6420cc97...0883405cc7

View File

@@ -1 +1,3 @@
include gnulib.mk
AM_CFLAGS = $(GNULIB_WARN_CFLAGS) # $(WERROR_CFLAGS)

View File

@@ -17,7 +17,7 @@
include gnulib.mk
AM_CFLAGS += $(WARN_CFLAGS) # $(WERROR_CFLAGS)
AM_CFLAGS += $(GNULIB_WARN_CFLAGS) $(WERROR_CFLAGS)
libcoreutils_a_SOURCES += \
buffer-lcm.c buffer-lcm.h \

View File

@@ -130,6 +130,6 @@ main (int argc, char **argv)
ok = euidaccess_stat (&st, mode);
printf ("%s: %s\n", file, ok ? "y" : "n");
exit (0);
return 0;
}
#endif

View File

@@ -61,3 +61,22 @@ xfts_open (char * const *argv, int options,
return fts;
}
/* When fts_read returns FTS_DC to indicate a directory cycle,
it may or may not indicate a real problem. When a program like
chgrp performs a recursive traversal that requires traversing
symbolic links, it is *not* a problem. However, when invoked
with "-P -R", it deserves a warning. The fts_options member
records the options that control this aspect of fts's behavior,
so test that. */
bool
cycle_warning_required (FTS const *fts, FTSENT const *ent)
{
#define ISSET(Fts,Opt) ((Fts)->fts_options & (Opt))
/* When dereferencing no symlinks, or when dereferencing only
those listed on the command line and we're not processing
a command-line argument, then a cycle is a serious problem. */
return ((ISSET (fts, FTS_PHYSICAL) && !ISSET (fts, FTS_COMFOLLOW))
|| (ISSET (fts, FTS_PHYSICAL) && ISSET (fts, FTS_COMFOLLOW)
&& ent->fts_level != FTS_ROOTLEVEL));
}

View File

@@ -1,5 +1,9 @@
#include <stdbool.h>
#include "fts_.h"
FTS *
xfts_open (char * const *, int options,
int (*) (const FTSENT **, const FTSENT **));
bool
cycle_warning_required (FTS const *fts, FTSENT const *ent);

View File

@@ -1,4 +1,4 @@
#serial 24
#serial 26
# Check declarations for this package.
dnl Copyright (C) 1997-2001, 2003-2006, 2008-2009 Free Software
@@ -35,15 +35,7 @@ AC_DEFUN([gl_CHECK_DECLS],
getpwuid,
ttyname], , , $headers)
AC_CHECK_DECLS([isblank], [], [], [#include <ctype.h>])
AC_CHECK_DECLS_ONCE([free])
AC_CHECK_DECLS_ONCE([getenv])
AC_CHECK_DECLS_ONCE([geteuid])
AC_CHECK_DECLS_ONCE([getlogin])
AC_CHECK_DECLS_ONCE([getuid])
AC_CHECK_DECLS_ONCE([lseek])
AC_CHECK_DECLS_ONCE([malloc])
AC_CHECK_DECLS_ONCE([memchr])
AC_CHECK_DECLS_ONCE([realloc])
])

View File

@@ -30,7 +30,9 @@ AC_DEFUN([cu_GMP],
LIB_GMP=$ac_cv_search___gmpz_init
AC_DEFINE([HAVE_GMP], [1],
[Define if you have GNU libgmp (or replacement)])
}])
}],
[AC_MSG_WARN([libgmp development library was not found or not usable.])
AC_MSG_WARN([AC_PACKAGE_NAME will be built without GMP support.])])
LIBS=$cu_saved_libs
fi
])

View File

@@ -89,14 +89,12 @@ AC_DEFUN([coreutils_MACROS],
tcgetpgrp \
)
# for cp.c
AC_CHECK_FUNCS_ONCE([utimensat])
dnl This can't use AC_REQUIRE; I'm not quite sure why.
cu_PREREQ_STAT_PROG
# for dd.c and shred.c
coreutils_saved_libs=$LIBS
LIB_FDATASYNC=
AC_SEARCH_LIBS([fdatasync], [rt posix4],
[test "$ac_cv_search_fdatasync" = "none required" ||
LIB_FDATASYNC=$ac_cv_search_fdatasync])
@@ -118,7 +116,8 @@ AC_DEFUN([coreutils_MACROS],
if test "X$enable_libcap" = "Xyes"; then
AC_MSG_ERROR([libcap library was not found or not usable])
else
AC_MSG_WARN([libcap library was not found or not usable, support for libcap will not be built])
AC_MSG_WARN([libcap library was not found or not usable.])
AC_MSG_WARN([AC_PACKAGE_NAME will be built without capability support.])
fi
fi
else

View File

@@ -51,6 +51,7 @@ $ac_includes_default
# SCO-ODT-3.0 is reported to need -lufc for crypt.
# NetBSD needs -lcrypt for crypt.
LIB_CRYPT=
cu_saved_libs="$LIBS"
AC_SEARCH_LIBS([crypt], [ufc crypt],
[test "$ac_cv_search_crypt" = "none required" ||

View File

@@ -22,9 +22,12 @@ AC_DEFUN([gl_FUNC_XATTR],
use_xattr=1
else
use_xattr=0
AC_MSG_WARN([libattr development library was not found or not usable.])
AC_MSG_WARN([AC_PACKAGE_NAME will be built without xattr support.])
fi
AC_DEFINE_UNQUOTED([USE_XATTR], [$use_xattr],
[Define if you want extended attribute support.])
LIB_XATTR=
xattr_saved_LIBS=$LIBS
AC_SEARCH_LIBS([attr_copy_file], [attr],
[test "$ac_cv_search_attr_copy_file" = "none required" ||

1
man/.gitignore vendored
View File

@@ -48,6 +48,7 @@ mv.1
nice.1
nl.1
nohup.1
nproc.1
od.1
paste.1
pathchk.1

View File

@@ -80,6 +80,7 @@ mv.1: $(common_dep) $(srcdir)/mv.x ../src/mv.c
nice.1: $(common_dep) $(srcdir)/nice.x ../src/nice.c
nl.1: $(common_dep) $(srcdir)/nl.x ../src/nl.c
nohup.1: $(common_dep) $(srcdir)/nohup.x ../src/nohup.c
nproc.1: $(common_dep) $(srcdir)/nproc.x ../src/nproc.c
od.1: $(common_dep) $(srcdir)/od.x ../src/od.c
paste.1: $(common_dep) $(srcdir)/paste.x ../src/paste.c
pathchk.1: $(common_dep) $(srcdir)/pathchk.x ../src/pathchk.c

4
man/nproc.x Normal file
View File

@@ -0,0 +1,4 @@
[NAME]
nproc \- print the number of processing units available
[DESCRIPTION]
.\" Add any additional description here

View File

@@ -89,6 +89,7 @@ src/mv.c
src/nice.c
src/nl.c
src/nohup.c
src/nproc.c
src/od.c
src/operand2sig.c
src/paste.c

1
src/.gitignore vendored
View File

@@ -56,6 +56,7 @@ mv
nice
nl
nohup
nproc
od
paste
pathchk

View File

@@ -24,25 +24,115 @@ no_install__progs = \
arch hostname su
build_if_possible__progs = \
chroot df hostid nice pinky stdbuf libstdbuf.so stty su uname uptime users who
chroot \
df \
hostid \
libstdbuf.so \
nice \
pinky \
stdbuf \
stty \
su \
uptime \
users \
who
AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS)
EXTRA_PROGRAMS = \
$(no_install__progs) \
$(build_if_possible__progs) \
[ chcon chgrp chown chmod cp dd dircolors du \
ginstall link ln dir vdir ls mkdir \
mkfifo mknod mktemp \
mv nohup readlink rm rmdir shred stat sync touch unlink \
cat cksum comm csplit cut expand fmt fold head join groups md5sum \
nl od paste pr ptx sha1sum sha224sum sha256sum sha384sum sha512sum \
shuf sort split sum tac tail tr tsort unexpand uniq wc \
basename date dirname echo env expr factor false \
id kill logname pathchk printenv printf pwd \
runcon seq sleep tee \
test timeout true truncate tty whoami yes \
base64
[ \
base64 \
basename \
cat \
chcon \
chgrp \
chmod \
chown \
cksum \
comm \
cp \
csplit \
cut \
date \
dd \
dir \
dircolors \
dirname \
du \
echo \
env \
expand \
expr \
factor \
false \
fmt \
fold \
ginstall \
groups \
head \
id \
join \
kill \
link \
ln \
logname \
ls \
md5sum \
mkdir \
mkfifo \
mknod \
mktemp \
mv \
nl \
nproc \
nohup \
od \
paste \
pathchk \
pr \
printenv \
printf \
ptx \
pwd \
readlink \
rm \
rmdir \
runcon \
seq \
sha1sum \
sha224sum \
sha256sum \
sha384sum \
sha512sum \
shred \
shuf \
sleep \
sort \
split \
stat \
sum \
sync \
tac \
tail \
tee \
test \
timeout \
touch \
tr \
true \
truncate \
tsort \
tty \
uname \
unexpand \
uniq \
unlink \
vdir \
wc \
whoami \
yes
bin_PROGRAMS = $(OPTIONAL_BIN_PROGS)
@@ -50,20 +140,20 @@ noinst_PROGRAMS = setuidgid getlimits
pkglib_PROGRAMS = $(OPTIONAL_PKGLIB_PROGS)
noinst_HEADERS = \
chown-core.h \
copy.h \
cp-hash.h \
dircolors.h \
fs.h \
group-list.h \
ls.h \
operand2sig.h \
prog-fprintf.h \
remove.h \
system.h \
wheel-size.h \
wheel.h \
noinst_HEADERS = \
chown-core.h \
copy.h \
cp-hash.h \
dircolors.h \
fs.h \
group-list.h \
ls.h \
operand2sig.h \
prog-fprintf.h \
remove.h \
system.h \
wheel-size.h \
wheel.h \
uname.h
EXTRA_DIST = dcgen dircolors.hin tac-pipe.c \
@@ -87,99 +177,217 @@ nodist_libver_a_SOURCES = version.c version.h
# replacement functions defined in libcoreutils.a.
LDADD = libver.a ../lib/libcoreutils.a $(LIBINTL) ../lib/libcoreutils.a
# First, list all programs, to make listing per-program libraries easier.
# See [ below.
arch_LDADD = $(LDADD)
base64_LDADD = $(LDADD)
basename_LDADD = $(LDADD)
cat_LDADD = $(LDADD)
chcon_LDADD = $(LDADD)
chgrp_LDADD = $(LDADD)
chmod_LDADD = $(LDADD)
chown_LDADD = $(LDADD)
chroot_LDADD = $(LDADD)
cksum_LDADD = $(LDADD)
comm_LDADD = $(LDADD)
nproc_LDADD = $(LDADD)
cp_LDADD = $(LDADD)
csplit_LDADD = $(LDADD)
cut_LDADD = $(LDADD)
date_LDADD = $(LDADD)
dd_LDADD = $(LDADD)
df_LDADD = $(LDADD)
# See dir_LDADD below
dircolors_LDADD = $(LDADD)
dirname_LDADD = $(LDADD)
du_LDADD = $(LDADD)
echo_LDADD = $(LDADD)
env_LDADD = $(LDADD)
expand_LDADD = $(LDADD)
expr_LDADD = $(LDADD)
factor_LDADD = $(LDADD)
false_LDADD = $(LDADD)
fmt_LDADD = $(LDADD)
fold_LDADD = $(LDADD)
getlimits_LDADD = $(LDADD)
ginstall_LDADD = $(LDADD)
groups_LDADD = $(LDADD)
head_LDADD = $(LDADD)
hostid_LDADD = $(LDADD)
hostname_LDADD = $(LDADD)
id_LDADD = $(LDADD)
join_LDADD = $(LDADD)
kill_LDADD = $(LDADD)
link_LDADD = $(LDADD)
ln_LDADD = $(LDADD)
logname_LDADD = $(LDADD)
ls_LDADD = $(LDADD)
md5sum_LDADD = $(LDADD)
mkdir_LDADD = $(LDADD)
mkfifo_LDADD = $(LDADD)
mknod_LDADD = $(LDADD)
mktemp_LDADD = $(LDADD)
mv_LDADD = $(LDADD)
nice_LDADD = $(LDADD)
nl_LDADD = $(LDADD)
nohup_LDADD = $(LDADD)
od_LDADD = $(LDADD)
paste_LDADD = $(LDADD)
pathchk_LDADD = $(LDADD)
pinky_LDADD = $(LDADD)
pr_LDADD = $(LDADD)
printenv_LDADD = $(LDADD)
printf_LDADD = $(LDADD)
ptx_LDADD = $(LDADD)
pwd_LDADD = $(LDADD)
readlink_LDADD = $(LDADD)
rm_LDADD = $(LDADD)
rmdir_LDADD = $(LDADD)
runcon_LDADD = $(LDADD)
seq_LDADD = $(LDADD)
setuidgid_LDADD = $(LDADD)
sha1sum_LDADD = $(LDADD)
sha224sum_LDADD = $(LDADD)
sha256sum_LDADD = $(LDADD)
sha384sum_LDADD = $(LDADD)
sha512sum_LDADD = $(LDADD)
shred_LDADD = $(LDADD)
shuf_LDADD = $(LDADD)
sleep_LDADD = $(LDADD)
sort_LDADD = $(LDADD)
split_LDADD = $(LDADD)
stat_LDADD = $(LDADD)
stdbuf_LDADD = $(LDADD)
stty_LDADD = $(LDADD)
su_LDADD = $(LDADD)
sum_LDADD = $(LDADD)
sync_LDADD = $(LDADD)
tac_LDADD = $(LDADD)
tail_LDADD = $(LDADD)
tee_LDADD = $(LDADD)
test_LDADD = $(LDADD)
timeout_LDADD = $(LDADD)
touch_LDADD = $(LDADD)
tr_LDADD = $(LDADD)
true_LDADD = $(LDADD)
truncate_LDADD = $(LDADD)
tsort_LDADD = $(LDADD)
tty_LDADD = $(LDADD)
uname_LDADD = $(LDADD)
unexpand_LDADD = $(LDADD)
uniq_LDADD = $(LDADD)
unlink_LDADD = $(LDADD)
uptime_LDADD = $(LDADD)
users_LDADD = $(LDADD)
# See vdir_LDADD below
wc_LDADD = $(LDADD)
who_LDADD = $(LDADD)
whoami_LDADD = $(LDADD)
yes_LDADD = $(LDADD)
# for eaccess in lib/euidaccess.c.
chcon_LDADD = $(LDADD) $(LIB_SELINUX)
cp_LDADD = $(LDADD) $(LIB_EACCESS) $(LIB_SELINUX)
ginstall_LDADD = $(LDADD) $(LIB_EACCESS) $(LIB_SELINUX)
mkdir_LDADD = $(LDADD) $(LIB_SELINUX)
mkfifo_LDADD = $(LDADD) $(LIB_SELINUX)
mknod_LDADD = $(LDADD) $(LIB_SELINUX)
mv_LDADD = $(LDADD) $(LIB_EACCESS) $(LIB_SELINUX)
runcon_LDADD = $(LDADD) $(LIB_SELINUX)
pathchk_LDADD = $(LDADD) $(LIB_EACCESS)
rm_LDADD = $(LDADD) $(LIB_EACCESS)
test_LDADD = $(LDADD) $(LIB_EACCESS)
# This is for the '[' program. Automake transliterates '[' to '_'.
__LDADD = $(LDADD) $(LIB_EACCESS)
# Synonyms. Recall that Automake transliterates '[' to '_'.
__LDADD = $(test_LDADD)
dir_LDADD = $(ls_LDADD)
vdir_LDADD = $(ls_LDADD)
# for clock_gettime and fdatasync
dd_LDADD = $(LDADD) $(LIB_GETHRXTIME) $(LIB_FDATASYNC)
dir_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX) $(LIB_CAP)
id_LDADD = $(LDADD) $(LIB_SELINUX)
ls_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX) $(LIB_CAP)
mktemp_LDADD = $(LDADD) $(LIB_GETHRXTIME)
pr_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
shred_LDADD = $(LDADD) $(LIB_GETHRXTIME) $(LIB_FDATASYNC)
shuf_LDADD = $(LDADD) $(LIB_GETHRXTIME)
tac_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
vdir_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME) $(LIB_SELINUX) $(LIB_CAP)
# Shared files
copy_LDADD =
cp_LDADD += $(copy_LDADD)
ginstall_LDADD += $(copy_LDADD)
mv_LDADD += $(copy_LDADD)
## If necessary, add -lm to resolve use of pow in lib/strtod.c.
sort_LDADD = $(LDADD) $(POW_LIB) $(LIB_GETHRXTIME)
remove_LDADD =
mv_LDADD += $(remove_LDADD)
rm_LDADD += $(remove_LDADD)
# for get_date and gettime
date_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
touch_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
# for eaccess, euidaccess
copy_LDADD += $(LIB_EACCESS)
remove_LDADD += $(LIB_EACCESS)
test_LDADD += $(LIB_EACCESS)
# If necessary, add -lm to resolve use of pow in lib/strtod.c.
# If necessary, add -liconv to resolve use of iconv in lib/unicodeio.c.
printf_LDADD = $(LDADD) $(POW_LIB) $(LIBICONV)
# for selinux use
chcon_LDADD += $(LIB_SELINUX)
copy_LDADD += $(LIB_SELINUX)
ginstall_LDADD += $(LIB_SELINUX)
id_LDADD += $(LIB_SELINUX)
ls_LDADD += $(LIB_SELINUX)
mkdir_LDADD += $(LIB_SELINUX)
mkfifo_LDADD += $(LIB_SELINUX)
mknod_LDADD += $(LIB_SELINUX)
runcon_LDADD += $(LIB_SELINUX)
stat_LDADD += $(LIB_SELINUX)
# If necessary, add -lm to resolve use of pow in lib/strtod.c.
seq_LDADD = $(LDADD) $(POW_LIB)
# for gettime, settime, utimecmp, utimens
copy_LDADD += $(LIB_CLOCK_GETTIME)
date_LDADD += $(LIB_CLOCK_GETTIME)
ginstall_LDADD += $(LIB_CLOCK_GETTIME)
ls_LDADD += $(LIB_CLOCK_GETTIME)
pr_LDADD += $(LIB_CLOCK_GETTIME)
touch_LDADD += $(LIB_CLOCK_GETTIME)
# If necessary, add libraries to resolve the `pow' reference in lib/strtod.c
# and the `nanosleep' reference in lib/xnanosleep.c.
nanosec_libs = $(LDADD) $(POW_LIB) $(LIB_NANOSLEEP)
# for gethrxtime, randint, randread, gen_tempname
dd_LDADD += $(LIB_GETHRXTIME)
mktemp_LDADD += $(LIB_GETHRXTIME)
shred_LDADD += $(LIB_GETHRXTIME)
shuf_LDADD += $(LIB_GETHRXTIME)
sort_LDADD += $(LIB_GETHRXTIME)
# for cap_get_file
ls_LDADD += $(LIB_CAP)
# for fdatasync
dd_LDADD += $(LIB_FDATASYNC)
shred_LDADD += $(LIB_FDATASYNC)
# for strtod, strtold
printf_LDADD += $(POW_LIB)
seq_LDADD += $(POW_LIB)
sleep_LDADD += $(POW_LIB)
sort_LDADD += $(POW_LIB)
tail_LDADD += $(POW_LIB)
uptime_LDADD += $(POW_LIB)
# for xnanosleep
sleep_LDADD += $(LIB_NANOSLEEP)
tail_LDADD += $(LIB_NANOSLEEP)
# for various GMP functions
expr_LDADD = $(LDADD) $(LIB_GMP)
expr_LDADD += $(LIB_GMP)
factor_LDADD += $(LIB_GMP)
# for various GMP functions
factor_LDADD = $(LDADD) $(LIB_GMP)
# for getloadavg
uptime_LDADD += $(GETLOADAVG_LIBS)
sleep_LDADD = $(nanosec_libs)
tail_LDADD = $(nanosec_libs)
# for crypt
su_LDADD += $(LIB_CRYPT)
# If necessary, add -lm to resolve use of pow in lib/strtod.c.
uptime_LDADD = $(LDADD) $(POW_LIB) $(GETLOADAVG_LIBS)
su_LDADD = $(LDADD) $(LIB_CRYPT)
dir_LDADD += $(LIB_ACL)
# for various ACL functions
copy_LDADD += $(LIB_ACL)
ls_LDADD += $(LIB_ACL)
vdir_LDADD += $(LIB_ACL)
cp_LDADD += $(LIB_ACL) $(LIB_XATTR)
mv_LDADD += $(LIB_ACL) $(LIB_XATTR)
ginstall_LDADD += $(LIB_ACL) $(LIB_XATTR)
stat_LDADD = $(LDADD) $(LIB_SELINUX)
# for various xattr functions
copy_LDADD += $(LIB_XATTR)
# Append $(LIBICONV) to each program that uses proper_name_utf8.
# for print_unicode_char, proper_name_utf8
cat_LDADD += $(LIBICONV)
cp_LDADD += $(LIBICONV)
df_LDADD += $(LIBICONV)
du_LDADD += $(LIBICONV)
getlimits_LDADD += $(LIBICONV)
printf_LDADD += $(LIBICONV)
ptx_LDADD += $(LIBICONV)
split_LDADD += $(LIBICONV)
stdbuf_LDADD += $(LIBICONV)
timeout_LDADD += $(LIBICONV)
truncate_LDADD += $(LIBICONV)
# programs that use getaddrinfo (e.g., via canon_host)
pinky_LDADD = $(LDADD) $(GETADDRINFO_LIB)
who_LDADD = $(LDADD) $(GETADDRINFO_LIB)
# for canon_host
pinky_LDADD += $(GETADDRINFO_LIB)
who_LDADD += $(GETADDRINFO_LIB)
# for gethostname, uname
hostname_LDADD += $(GETHOSTNAME_LIB)
uname_LDADD += $(GETHOSTNAME_LIB)
$(PROGRAMS): ../lib/libcoreutils.a
@@ -274,6 +482,7 @@ rmdir_SOURCES = rmdir.c prog-fprintf.c
uname_SOURCES = uname.c uname-uname.c
arch_SOURCES = uname.c uname-arch.c
nproc_SOURCES = nproc.c
md5sum_SOURCES = md5sum.c
md5sum_CPPFLAGS = -DHASH_ALGO_MD5=1 $(AM_CPPFLAGS)
@@ -330,6 +539,59 @@ wheel.h: wheel-gen.pl Makefile.am
# Tell automake to exempt then from that installcheck test.
AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false test
# Compare fs.h with the list of file system names/magic-numbers in the
# Linux statfs man page. This target prints any new name/number pairs.
# Also compare against /usr/include/linux/magic.h
.PHONY: fs-magic-compare
fs-magic-compare: fs-magic fs-kernel-magic fs-def
join -v1 -t@ fs-magic fs-def
join -v1 -t@ fs-kernel-magic fs-def
CLEANFILES += fs-def
fs-def: fs.h
grep '^# *define ' $< > $@-t && mv $@-t $@
# Massage bits of the statfs man page and definitions from
# /usr/include/linux/magic.h to be in a form consistent with what's in fs.h.
fs_normalize_perl_subst = \
-e 's/MINIX_SUPER_MAGIC\b/MINIX/;' \
-e 's/MINIX_SUPER_MAGIC2\b/MINIX_30/;' \
-e 's/MINIX2_SUPER_MAGIC\b/MINIX_V2/;' \
-e 's/MINIX2_SUPER_MAGIC2\b/MINIX_V2_30/;' \
-e 's/MINIX3_SUPER_MAGIC\b/MINIX_V3/;' \
-e 's/CIFS_MAGIC_NUMBER/CIFS/;' \
-e 's/(_SUPER)?_MAGIC//;' \
-e 's/\s+0x(\S+)/" 0x" . uc $$1/e;' \
-e 's/(\s+0x)(\X{3})\b/$${1}0$$2/;' \
-e 's/(\s+0x)(\X{6})\b/$${1}00$$2/;' \
-e 's/(\s+0x)(\X{7})\b/$${1}0$$2/;' \
-e 's/^\s+//;' \
-e 's/^\#define\s+//;' \
-e 's/^_(XIAFS)/$$1/;' \
-e 's/^USBDEVICE/USBDEVFS/;' \
-e 's/NTFS_SB/NTFS/;' \
-e 's/^/\# define S_MAGIC_/;' \
-e 's,\s*/\* .*? \*/,,;'
CLEANFILES += fs-magic
fs-magic: Makefile
man statfs \
|perl -ne '/File system types:/.../Nobody kno/ and print' \
|grep 0x | perl -p \
$(fs_normalize_perl_subst) \
| grep -Ev 'S_MAGIC_EXT[34]|STACK_END' \
| LC_ALL=C sort \
> $@-t && mv $@-t $@
CLEANFILES += fs-kernel-magic
fs-kernel-magic: Makefile
perl -ne '/^#define.*0x/ and print' /usr/include/linux/magic.h \
| perl -p \
$(fs_normalize_perl_subst) \
| grep -Ev 'S_MAGIC_EXT[34]|STACK_END' \
| LC_ALL=C sort \
> $@-t && mv $@-t $@
BUILT_SOURCES += fs.h
fs.h: stat.c extract-magic
$(AM_V_GEN)rm -f $@

View File

@@ -267,6 +267,14 @@ process_file (FTS *fts, FTSENT *ent)
ok = false;
break;
case FTS_DC: /* directory that causes cycles */
if (cycle_warning_required (fts, ent))
{
emit_cycle_warning (file_full_name);
return false;
}
break;
default:
break;
}
@@ -519,10 +527,6 @@ main (int argc, char **argv)
usage (EXIT_FAILURE);
}
if (is_selinux_enabled () != 1)
error (EXIT_FAILURE, 0,
_("%s may be used only on a SELinux kernel"), program_name);
if (reference_file)
{
if (getfilecon (reference_file, &ref_context) < 0)
@@ -550,7 +554,7 @@ main (int argc, char **argv)
if (reference_file && component_specified)
{
error (0, 0, _("conflicting security context specifiers given"));
usage (1);
usage (EXIT_FAILURE);
}
if (recurse && preserve_root)

View File

@@ -228,6 +228,15 @@ process_file (FTS *fts, FTSENT *ent)
error (0, 0, _("cannot operate on dangling symlink %s"),
quote (file_full_name));
ok = false;
break;
case FTS_DC: /* directory that causes cycles */
if (cycle_warning_required (fts, ent))
{
emit_cycle_warning (file_full_name);
return false;
}
break;
default:
break;

View File

@@ -316,6 +316,14 @@ change_file_owner (FTS *fts, FTSENT *ent,
ok = false;
break;
case FTS_DC: /* directory that causes cycles */
if (cycle_warning_required (fts, ent))
{
emit_cycle_warning (file_full_name);
return false;
}
break;
default:
break;
}

View File

@@ -91,7 +91,7 @@ set_additional_groups (char const *groups)
}
if (n_gids == n_gids_allocated)
gids = x2nrealloc (gids, &n_gids_allocated, sizeof *gids);
gids = X2NREALLOC (gids, &n_gids_allocated);
gids[n_gids++] = value;
}
@@ -160,7 +160,7 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
initialize_exit_failure (EXIT_FAILURE);
initialize_exit_failure (EXIT_CANCELED);
atexit (close_stdout);
parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version,
@@ -177,22 +177,22 @@ main (int argc, char **argv)
groups = optarg;
break;
default:
usage (EXIT_FAILURE);
usage (EXIT_CANCELED);
}
}
if (argc <= optind)
{
error (0, 0, _("missing operand"));
usage (EXIT_FAILURE);
usage (EXIT_CANCELED);
}
if (chroot (argv[optind]) != 0)
error (EXIT_FAILURE, errno, _("cannot change root directory to %s"),
error (EXIT_CANCELED, errno, _("cannot change root directory to %s"),
argv[optind]);
if (chdir ("/"))
error (EXIT_FAILURE, errno, _("cannot chdir to root directory"));
error (EXIT_CANCELED, errno, _("cannot chdir to root directory"));
if (argc == optind + 1)
{
@@ -223,7 +223,7 @@ main (int argc, char **argv)
char const *err = parse_user_spec (userspec, &uid, &gid, &user, &group);
if (err)
error (EXIT_FAILURE, errno, "%s", err);
error (EXIT_CANCELED, errno, "%s", err);
free (user);
free (group);
@@ -254,7 +254,7 @@ main (int argc, char **argv)
}
if (fail)
exit (EXIT_FAILURE);
exit (EXIT_CANCELED);
/* Execute the given command. */
execvp (argv[0], argv);

View File

@@ -123,20 +123,12 @@ static char const *top_level_dst_name;
static inline int
utimens_symlink (char const *file, struct timespec const *timespec)
{
int err = 0;
#if HAVE_UTIMENSAT
err = utimensat (AT_FDCWD, file, timespec, AT_SYMLINK_NOFOLLOW);
int err = lutimens (file, timespec);
/* When configuring on a system with new headers and libraries, and
running on one with a kernel that is old enough to lack the syscall,
utimensat fails with ENOSYS. Ignore that. */
if (err && errno == ENOSYS)
err = 0;
#else
(void) file;
(void) timespec;
#endif
return err;
}

View File

@@ -19,7 +19,6 @@
#include <sys/types.h>
#include <getopt.h>
#include <stdio.h>
#include "system.h"
#include "dircolors.h"
@@ -27,6 +26,7 @@
#include "error.h"
#include "obstack.h"
#include "quote.h"
#include "stdio--.h"
#include "xstrndup.h"
/* The official name of this program (e.g., no `g' prefix). */

View File

@@ -24,7 +24,6 @@
Rewritten to use nftw, then to use fts by Jim Meyering. */
#include <config.h>
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
#include <assert.h>
@@ -40,6 +39,7 @@
#include "quotearg.h"
#include "same.h"
#include "stat-time.h"
#include "stdio--.h"
#include "xfts.h"
#include "xstrtol.h"
@@ -67,7 +67,6 @@ extern bool fts_debug;
/* Hash structure for inode and device numbers. The separate entry
structure makes it easier to rehash "in place". */
struct entry
{
ino_t st_ino;
@@ -194,7 +193,6 @@ enum
FILES0_FROM_OPTION,
HUMAN_SI_OPTION,
MAX_DEPTH_OPTION,
MEGABYTES_LONG_OPTION,
TIME_OPTION,
TIME_STYLE_OPTION
};
@@ -495,6 +493,15 @@ process_file (FTS *fts, FTSENT *ent)
ok = false;
break;
case FTS_DC: /* directory that causes cycles */
if (cycle_warning_required (fts, ent))
{
emit_cycle_warning (file);
return false;
}
ok = true;
break;
default:
ok = true;
break;
@@ -755,10 +762,6 @@ main (int argc, char **argv)
}
break;
case MEGABYTES_LONG_OPTION: /* FIXME: remove in 2009 */
error (0, 0,
_("the --megabytes option is deprecated; use -m instead"));
/* fall through */
case 'm':
human_output_opts = 0;
output_block_size = 1024 * 1024;

View File

@@ -63,18 +63,22 @@ Echo the STRING(s) to standard output.\n\
\n\
If -e is in effect, the following sequences are recognized:\n\
\n\
\\0NNN the character whose ASCII code is NNN (octal)\n\
\\\\ backslash\n\
\\a alert (BEL)\n\
\\b backspace\n\
"), stdout);
fputs (_("\
\\c produce no further output\n\
\\f form feed\n\
\\n new line\n\
\\r carriage return\n\
\\t horizontal tab\n\
\\v vertical tab\n\
\\\\ backslash\n\
\\a alert (BEL)\n\
\\b backspace\n\
\\c produce no further output\n\
\\e escape\n\
\\f form feed\n\
\\n new line\n\
\\r carriage return\n\
\\t horizontal tab\n\
\\v vertical tab\n\
"), stdout);
fputs (_("\
\\0NNN byte with octal value NNN (1 to 3 digits)\n\
\\xHH byte with hexadecimal value HH (1 to 2 digits)\n\
"), stdout);
printf (USAGE_BUILTIN_WARNING, PROGRAM_NAME);
emit_ancillary_info ();
@@ -203,6 +207,7 @@ just_echo:
case 'a': c = '\a'; break;
case 'b': c = '\b'; break;
case 'c': exit (EXIT_SUCCESS);
case 'e': c = '\x1B'; break;
case 'f': c = '\f'; break;
case 'n': c = '\n'; break;
case 'r': c = '\r'; break;

100
src/env.c
View File

@@ -16,66 +16,6 @@
/* Richard Mlynarik and David MacKenzie */
/* Options:
-
-i
--ignore-environment
Construct a new environment from scratch; normally the
environment is inherited from the parent process, except as
modified by other options.
-u variable
--unset=variable
Unset variable VARIABLE (remove it from the environment).
If VARIABLE was not set, does nothing.
variable=value (an arg containing a "=" character)
Set the environment variable VARIABLE to value VALUE. VALUE
may be of zero length ("variable="). Setting a variable to a
zero-length value is different from unsetting it.
--
Indicate that the following argument is the program
to invoke. This is necessary when the program's name
begins with "-" or contains a "=".
The first remaining argument specifies a program to invoke;
it is searched for according to the specification of the PATH
environment variable. Any arguments following that are
passed as arguments to that program.
If no command name is specified following the environment
specifications, the resulting environment is printed.
This is like specifying a command name of "printenv".
Examples:
If the environment passed to "env" is
{ LOGNAME=rms EDITOR=emacs PATH=.:/gnubin:/hacks }
env - foo
runs "foo" in a null environment.
env foo
runs "foo" in the environment
{ LOGNAME=rms EDITOR=emacs PATH=.:/gnubin:/hacks }
env DISPLAY=gnu:0 nemacs
runs "nemacs" in the environment
{ LOGNAME=rms EDITOR=emacs PATH=.:/gnubin:/hacks DISPLAY=gnu:0 }
env - LOGNAME=foo /hacks/hack bar baz
runs the "hack" program on arguments "bar" and "baz" in an
environment in which the only variable is "LOGNAME". Note that
the "-" option clears out the PATH variable, so one should be
careful to specify in which directory to find the program to
call.
env -u EDITOR LOGNAME=foo PATH=/energy -- e=mc2 bar baz
runs the program "/energy/e=mc2" with environment
{ LOGNAME=foo PATH=/energy }
*/
#include <config.h>
#include <stdio.h>
#include <sys/types.h>
@@ -83,6 +23,7 @@
#include "system.h"
#include "error.h"
#include "quote.h"
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME "env"
@@ -91,11 +32,10 @@
proper_name ("Richard Mlynarik"), \
proper_name ("David MacKenzie")
extern char **environ;
static struct option const longopts[] =
{
{"ignore-environment", no_argument, NULL, 'i'},
{"null", no_argument, NULL, '0'},
{"unset", required_argument, NULL, 'u'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
@@ -116,8 +56,9 @@ Usage: %s [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]\n"),
fputs (_("\
Set each NAME to VALUE in the environment and run COMMAND.\n\
\n\
-i, --ignore-environment start with an empty environment\n\
-u, --unset=NAME remove variable from the environment\n\
-i, --ignore-environment start with an empty environment\n\
-0, --null end each output line with 0 byte rather than newline\n\
-u, --unset=NAME remove variable from the environment\n\
"), stdout);
fputs (HELP_OPTION_DESCRIPTION, stdout);
fputs (VERSION_OPTION_DESCRIPTION, stdout);
@@ -135,6 +76,7 @@ main (int argc, char **argv)
{
int optc;
bool ignore_environment = false;
bool opt_nul_terminate_output = false;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
@@ -142,10 +84,10 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
initialize_exit_failure (EXIT_FAILURE);
initialize_exit_failure (EXIT_CANCELED);
atexit (close_stdout);
while ((optc = getopt_long (argc, argv, "+iu:", longopts, NULL)) != -1)
while ((optc = getopt_long (argc, argv, "+iu:0", longopts, NULL)) != -1)
{
switch (optc)
{
@@ -154,10 +96,13 @@ main (int argc, char **argv)
break;
case 'u':
break;
case '0':
opt_nul_terminate_output = true;
break;
case_GETOPT_HELP_CHAR;
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
default:
usage (EXIT_FAILURE);
usage (EXIT_CANCELED);
}
}
@@ -171,25 +116,36 @@ main (int argc, char **argv)
}
optind = 0; /* Force GNU getopt to re-initialize. */
while ((optc = getopt_long (argc, argv, "+iu:", longopts, NULL)) != -1)
if (optc == 'u')
putenv (optarg); /* Requires GNU putenv. */
while ((optc = getopt_long (argc, argv, "+iu:0", longopts, NULL)) != -1)
if (optc == 'u' && unsetenv (optarg))
error (EXIT_CANCELED, errno, _("cannot unset %s"), quote (optarg));
if (optind < argc && STREQ (argv[optind], "-"))
++optind;
while (optind < argc && strchr (argv[optind], '='))
putenv (argv[optind++]);
if (putenv (argv[optind++]))
{
char *name = argv[optind - 1];
*(strchr (name, '=')) = '\0';
error (EXIT_CANCELED, errno, _("cannot set %s"), quote (name));
}
/* If no program is specified, print the environment and exit. */
if (argc <= optind)
{
char *const *e = environ;
while (*e)
puts (*e++);
printf ("%s%c", *e++, opt_nul_terminate_output ? '\0' : '\n');
exit (EXIT_SUCCESS);
}
if (opt_nul_terminate_output)
{
error (0, errno, _("cannot specify --null (-0) with command"));
usage (EXIT_CANCELED);
}
execvp (argv[optind], &argv[optind]);
{

View File

@@ -67,7 +67,7 @@ static void
emit_factor (mpz_t n)
{
if (nfactors_found == nfactors_allocated)
factor = x2nrealloc (factor, &nfactors_allocated, sizeof *factor);
factor = X2NREALLOC (factor, &nfactors_allocated);
mpz_init (factor[nfactors_found]);
mpz_set (factor[nfactors_found], n);
++nfactors_found;

View File

@@ -54,14 +54,13 @@ print_group_list (const char *username,
ok = false;
}
#if HAVE_GETGROUPS
{
GETGROUPS_T *groups;
gid_t *groups;
int i;
int n_groups = mgetgroups (username, (pwd ? pwd->pw_gid : (gid_t) -1),
&groups);
if (n_groups < 0)
if (n_groups < 0 && errno != ENOSYS)
{
if (username)
{
@@ -84,7 +83,6 @@ print_group_list (const char *username,
}
free (groups);
}
#endif /* HAVE_GETGROUPS */
return ok;
}

View File

@@ -292,14 +292,13 @@ print_full_info (const char *username)
printf ("(%s)", grp->gr_name);
}
#if HAVE_GETGROUPS
{
GETGROUPS_T *groups;
gid_t *groups;
int i;
int n_groups = mgetgroups (username, (pwd ? pwd->pw_gid : (gid_t) -1),
&groups);
if (n_groups < 0)
if (n_groups < 0 && errno != ENOSYS)
{
if (username)
{
@@ -327,7 +326,6 @@ print_full_info (const char *username)
}
free (groups);
}
#endif /* HAVE_GETGROUPS */
/* POSIX mandates the precise output format, and that it not include
any context=... part, so skip that if POSIXLY_CORRECT is set. */

View File

@@ -138,7 +138,7 @@ do_link (const char *source, const char *dest)
{
/* Which stat to use depends on whether linkat will follow the
symlink. We can't use the shorter
(logical ? stat : lstat) (source, &source_stats)
(logical?stat:lstat) (source, &source_stats)
since stat might be a function-like macro. */
if ((logical ? stat (source, &source_stats)
: lstat (source, &source_stats))

159
src/ls.c
View File

@@ -214,6 +214,9 @@ struct fileinfo
/* For long listings, true if the file has an access control list,
or an SELinux security context. */
enum acl_type acl_type;
/* For color listings, true if a regular file has capability info. */
bool has_capability;
};
#define LEN_STR_PAIR(s) sizeof (s) - 1, s
@@ -241,9 +244,8 @@ static bool file_ignored (char const *name);
static uintmax_t gobble_file (char const *name, enum filetype type,
ino_t inode, bool command_line_arg,
char const *dirname);
static bool print_color_indicator (const char *name, mode_t mode, int linkok,
bool stat_ok, enum filetype type,
nlink_t nlink);
static bool print_color_indicator (const struct fileinfo *f,
bool symlink_target);
static void put_indicator (const struct bin_str *ind);
static void add_ignore_pattern (const char *pattern);
static void attach (char *dest, const char *dirname, const char *name);
@@ -264,11 +266,9 @@ static int format_user_width (uid_t u);
static int format_group_width (gid_t g);
static void print_long_format (const struct fileinfo *f);
static void print_many_per_line (void);
static size_t print_name_with_quoting (const char *p, mode_t mode,
int linkok, bool stat_ok,
enum filetype type,
static size_t print_name_with_quoting (const struct fileinfo *f,
bool symlink_target,
struct obstack *stack,
nlink_t nlink,
size_t start_col);
static void prep_non_filename_text (void);
static bool print_type_indicator (bool stat_ok, mode_t mode,
@@ -2637,6 +2637,37 @@ unsigned_file_size (off_t size)
return size + (size < 0) * ((uintmax_t) OFF_T_MAX - OFF_T_MIN + 1);
}
#ifdef HAVE_CAP
/* Return true if NAME has a capability (see linux/capability.h) */
static bool
has_capability (char const *name)
{
char *result;
bool has_cap;
cap_t cap_d = cap_get_file (name);
if (cap_d == NULL)
return false;
result = cap_to_text (cap_d, NULL);
cap_free (cap_d);
if (!result)
return false;
/* check if human-readable capability string is empty */
has_cap = !!*result;
cap_free (result);
return has_cap;
}
#else
static bool
has_capability (char const *name ATTRIBUTE_UNUSED)
{
return false;
}
#endif
/* Enter and remove entries in the table `cwd_file'. */
/* Empty the table of files. */
@@ -2718,11 +2749,16 @@ gobble_file (char const *name, enum filetype type, ino_t inode,
to see if it's executable. */
|| (type == normal && (indicator_style == classify
/* This is so that --color ends up
highlighting files with the executable
bit set even when options like -F are
not specified. */
highlighting files with these mode
bits set even when options like -F are
not specified. Note we do a redundant
stat in the very unlikely case where
C_CAP is set but not the others. */
|| (print_with_color
&& is_colored (C_EXEC))
&& (is_colored (C_EXEC)
|| is_colored (C_SETUID)
|| is_colored (C_SETGID)
|| is_colored (C_CAP)))
)))))
{
@@ -2793,6 +2829,11 @@ gobble_file (char const *name, enum filetype type, ino_t inode,
f->stat_ok = true;
/* Note has_capability() adds around 30% runtime to `ls --color` */
if ((type == normal || S_ISREG (f->stat.st_mode))
&& print_with_color && is_colored (C_CAP))
f->has_capability = has_capability (absolute_name);
if (format == long_format || print_scontext)
{
bool have_selinux = false;
@@ -2802,17 +2843,6 @@ gobble_file (char const *name, enum filetype type, ino_t inode,
: lgetfilecon (absolute_name, &f->scontext));
err = (attr_len < 0);
/* Contrary to its documented API, getfilecon may return 0,
yet set f->scontext to NULL (on at least Debian's libselinux1
2.0.15-2+b1), so work around that bug.
FIXME: remove this work-around in 2011, or whenever affected
versions of libselinux are long gone. */
if (attr_len == 0)
{
err = 0;
f->scontext = xstrdup ("unlabeled");
}
if (err == 0)
have_selinux = ! STREQ ("unlabeled", f->scontext);
else
@@ -3772,18 +3802,14 @@ print_long_format (const struct fileinfo *f)
}
DIRED_FPUTS (buf, stdout, p - buf);
size_t w = print_name_with_quoting (f->name, FILE_OR_LINK_MODE (f), f->linkok,
f->stat_ok, f->filetype, &dired_obstack,
f->stat.st_nlink, p - buf);
size_t w = print_name_with_quoting (f, false, &dired_obstack, p - buf);
if (f->filetype == symbolic_link)
{
if (f->linkname)
{
DIRED_FPUTS_LITERAL (" -> ", stdout);
print_name_with_quoting (f->linkname, f->linkmode, f->linkok - 1,
f->stat_ok, f->filetype, NULL,
f->stat.st_nlink, (p - buf) + w + 4);
print_name_with_quoting (f, true, NULL, (p - buf) + w + 4);
if (indicator_style != none)
print_type_indicator (true, f->linkmode, unknown);
}
@@ -3959,19 +3985,20 @@ quote_name (FILE *out, const char *name, struct quoting_options const *options,
}
static size_t
print_name_with_quoting (const char *p, mode_t mode, int linkok,
bool stat_ok, enum filetype type,
struct obstack *stack, nlink_t nlink,
print_name_with_quoting (const struct fileinfo *f,
bool symlink_target,
struct obstack *stack,
size_t start_col)
{
const char* name = symlink_target ? f->linkname : f->name;
bool used_color_this_time
= (print_with_color
&& print_color_indicator (p, mode, linkok, stat_ok, type, nlink));
= (print_with_color && print_color_indicator (f, symlink_target));
if (stack)
PUSH_CURRENT_DIRED_POS (stack);
size_t width = quote_name (stdout, p, filename_quoting_options, NULL);
size_t width = quote_name (stdout, name, filename_quoting_options, NULL);
dired_pos += width;
if (stack)
@@ -4023,9 +4050,7 @@ print_file_name_and_frills (const struct fileinfo *f, size_t start_col)
if (print_scontext)
printf ("%*s ", format == with_commas ? 0 : scontext_width, f->scontext);
size_t width = print_name_with_quoting (f->name, FILE_OR_LINK_MODE (f),
f->linkok, f->stat_ok, f->filetype,
NULL, f->stat.st_nlink, start_col);
size_t width = print_name_with_quoting (f, false, NULL, start_col);
if (indicator_style != none)
width += print_type_indicator (f->stat_ok, f->stat.st_mode, f->filetype);
@@ -4076,55 +4101,38 @@ print_type_indicator (bool stat_ok, mode_t mode, enum filetype type)
return !!c;
}
#ifdef HAVE_CAP
/* Return true if NAME has a capability (see linux/capability.h) */
static bool
has_capability (char const *name)
{
char *result;
bool has_cap;
cap_t cap_d = cap_get_file (name);
if (cap_d == NULL)
return false;
result = cap_to_text (cap_d, NULL);
cap_free (cap_d);
if (!result)
return false;
/* check if human-readable capability string is empty */
has_cap = !!*result;
cap_free (result);
return has_cap;
}
#else
static bool
has_capability (char const *name ATTRIBUTE_UNUSED)
{
return false;
}
#endif
/* Returns whether any color sequence was printed. */
static bool
print_color_indicator (const char *name, mode_t mode, int linkok,
bool stat_ok, enum filetype filetype,
nlink_t nlink)
print_color_indicator (const struct fileinfo *f, bool symlink_target)
{
enum indicator_no type;
struct color_ext_type *ext; /* Color extension */
size_t len; /* Length of name */
const char* name;
mode_t mode;
int linkok;
if (symlink_target)
{
name = f->linkname;
mode = f->linkmode;
linkok = f->linkok - 1;
}
else
{
name = f->name;
mode = FILE_OR_LINK_MODE (f);
linkok = f->linkok;
}
/* Is this a nonexistent file? If so, linkok == -1. */
if (linkok == -1 && color_indicator[C_MISSING].string != NULL)
type = C_MISSING;
else if (! stat_ok)
else if (!f->stat_ok)
{
static enum indicator_no filetype_indicator[] = FILETYPE_INDICATORS;
type = filetype_indicator[filetype];
type = filetype_indicator[f->filetype];
}
else
{
@@ -4136,12 +4144,11 @@ print_color_indicator (const char *name, mode_t mode, int linkok,
type = C_SETUID;
else if ((mode & S_ISGID) != 0 && is_colored (C_SETGID))
type = C_SETGID;
/* has_capability() called second for performance. */
else if (is_colored (C_CAP) && has_capability (name))
else if (is_colored (C_CAP) && f->has_capability)
type = C_CAP;
else if ((mode & S_IXUGO) != 0 && is_colored (C_EXEC))
type = C_EXEC;
else if ((1 < nlink) && is_colored (C_MULTIHARDLINK))
else if ((1 < f->stat.st_nlink) && is_colored (C_MULTIHARDLINK))
type = C_MULTIHARDLINK;
}
else if (S_ISDIR (mode))

View File

@@ -251,11 +251,10 @@ static bool
split_3 (char *s, size_t s_len,
unsigned char **hex_digest, int *binary, char **file_name)
{
size_t i;
bool escaped_filename = false;
size_t algo_name_len;
i = 0;
size_t i = 0;
while (ISWHITE (s[i]))
++i;
@@ -263,11 +262,13 @@ split_3 (char *s, size_t s_len,
algo_name_len = strlen (DIGEST_TYPE_STRING);
if (strncmp (s + i, DIGEST_TYPE_STRING, algo_name_len) == 0)
{
if (strncmp (s + i + algo_name_len, " (", 2) == 0)
if (s[i + algo_name_len] == ' ')
++i;
if (s[i + algo_name_len] == '(')
{
*binary = 0;
return bsd_split_3 (s + i + algo_name_len + 2,
s_len - (i + algo_name_len + 2),
return bsd_split_3 (s + i + algo_name_len + 1,
s_len - (i + algo_name_len + 1),
hex_digest, file_name);
}
}
@@ -512,7 +513,6 @@ digest_check (const char *checkfile_name)
if (!status_only)
{
printf (_("%s: FAILED open or read\n"), filename);
fflush (stdout);
}
}
else
@@ -538,7 +538,6 @@ digest_check (const char *checkfile_name)
printf ("%s: %s\n", filename, _("FAILED"));
else if (!quiet)
printf ("%s: %s\n", filename, _("OK"));
fflush (stdout);
}
}
}
@@ -618,6 +617,10 @@ main (int argc, char **argv)
atexit (close_stdout);
/* Line buffer stdout to ensure lines are written atomically and immediately
so that processes running in parallel do not intersperse their output. */
setvbuf (stdout, NULL, _IOLBF, 0);
while ((opt = getopt_long (argc, argv, "bctw", long_options, NULL)) != -1)
switch (opt)
{

View File

@@ -14,24 +14,27 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by Jim Meyering. */
/* Written by Jim Meyering and Eric Blake. */
#include <config.h>
#include <stdio.h>
#include <sys/types.h>
#include <getopt.h>
#include "system.h"
#include "close-stream.h"
#include "error.h"
#include "filenamecat.h"
#include "quote.h"
#include "stdio--.h"
#include "tempname.h"
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME "mktemp"
#define AUTHORS proper_name ("Jim Meyering")
#define AUTHORS \
proper_name ("Jim Meyering"), \
proper_name ("Eric Blake")
static const char *default_template = "tmp.XXXXXXXXXX";
@@ -39,7 +42,8 @@ static const char *default_template = "tmp.XXXXXXXXXX";
non-character as a pseudo short option, starting with CHAR_MAX + 1. */
enum
{
TMPDIR_OPTION = CHAR_MAX + 1
SUFFIX_OPTION = CHAR_MAX + 1,
TMPDIR_OPTION
};
static struct option const longopts[] =
@@ -47,6 +51,7 @@ static struct option const longopts[] =
{"directory", no_argument, NULL, 'd'},
{"quiet", no_argument, NULL, 'q'},
{"dry-run", no_argument, NULL, 'u'},
{"suffix", required_argument, NULL, SUFFIX_OPTION},
{"tmpdir", optional_argument, NULL, TMPDIR_OPTION},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
@@ -64,33 +69,32 @@ usage (int status)
printf (_("Usage: %s [OPTION]... [TEMPLATE]\n"), program_name);
fputs (_("\
Create a temporary file or directory, safely, and print its name.\n\
If TEMPLATE is not specified, use tmp.XXXXXXXXXX.\n\
TEMPLATE must contain at least 3 consecutive `X's in last component.\n\
If TEMPLATE is not specified, use tmp.XXXXXXXXXX, and --tmpdir is implied.\n\
"), stdout);
fputs ("\n", stdout);
fputs (_("\
-d, --directory create a directory, not a file\n\
-d, --directory create a directory, not a file\n\
-u, --dry-run do not create anything; merely print a name (unsafe)\n\
-q, --quiet suppress diagnostics about file/dir-creation failure\n\
"), stdout);
fputs (_("\
-q, --quiet suppress diagnostics about file/dir-creation failure\n\
--suffix=SUFF append SUFF to TEMPLATE. SUFF must not contain slash.\n\
This option is implied if TEMPLATE does not end in X.\n\
"), stdout);
fputs (_("\
-u, --dry-run do not create anything; merely print a name (unsafe)\n\
"), stdout);
fputs (_("\
--tmpdir[=DIR] interpret TEMPLATE relative to DIR. If DIR is\n\
not specified, use $TMPDIR if set, else /tmp.\n\
With this option, TEMPLATE must not be an absolute name.\n\
Unlike with -t, TEMPLATE may contain slashes, but even\n\
here, mktemp still creates only the final component.\n\
--tmpdir[=DIR] interpret TEMPLATE relative to DIR. If DIR is not\n\
specified, use $TMPDIR if set, else /tmp. With\n\
this option, TEMPLATE must not be an absolute name.\n\
Unlike with -t, TEMPLATE may contain slashes, but\n\
mktemp creates only the final component.\n\
"), stdout);
fputs ("\n", stdout);
fputs (_("\
-p DIR use DIR as a prefix; implies -t [deprecated]\n\
"), stdout);
fputs (_("\
-t interpret TEMPLATE as a single file name component,\n\
relative to a directory: $TMPDIR, if set; else the\n\
directory specified via -p; else /tmp [deprecated]\n\
-p DIR use DIR as a prefix; implies -t [deprecated]\n\
-t interpret TEMPLATE as a single file name component,\n\
relative to a directory: $TMPDIR, if set; else the\n\
directory specified via -p; else /tmp [deprecated]\n\
"), stdout);
fputs ("\n", stdout);
fputs (HELP_OPTION_DESCRIPTION, stdout);
@@ -102,9 +106,8 @@ If TEMPLATE is not specified, use tmp.XXXXXXXXXX.\n\
}
static size_t
count_trailing_X_s (const char *s)
count_consecutive_X_s (const char *s, size_t len)
{
size_t len = strlen (s);
size_t n = 0;
for ( ; len && s[len-1] == 'X'; len--)
++n;
@@ -112,15 +115,33 @@ count_trailing_X_s (const char *s)
}
static int
mkstemp_len (char *tmpl, size_t suff_len, bool dry_run)
mkstemp_len (char *tmpl, size_t suff_len, size_t x_len, bool dry_run)
{
return gen_tempname_len (tmpl, 0, dry_run ? GT_NOCREATE : GT_FILE, suff_len);
return gen_tempname_len (tmpl, suff_len, 0, dry_run ? GT_NOCREATE : GT_FILE,
x_len);
}
static int
mkdtemp_len (char *tmpl, size_t suff_len, bool dry_run)
mkdtemp_len (char *tmpl, size_t suff_len, size_t x_len, bool dry_run)
{
return gen_tempname_len (tmpl, 0, dry_run ? GT_NOCREATE : GT_DIR, suff_len);
return gen_tempname_len (tmpl, suff_len, 0, dry_run ? GT_NOCREATE : GT_DIR,
x_len);
}
/* True if we have already closed standard output. */
static bool stdout_closed;
/* Avoid closing stdout twice. Since we conditionally call
close_stream (stdout) in order to decide whether to clean up a
temporary file, the exit hook needs to know whether to do all of
close_stdout or just the stderr half. */
static void
maybe_close_stdout (void)
{
if (!stdout_closed)
close_stdout ();
else if (close_stream (stderr) != 0)
_exit (EXIT_FAILURE);
}
int
@@ -132,12 +153,14 @@ main (int argc, char **argv)
int c;
unsigned int n_args;
char *template;
char *suffix = NULL;
bool use_dest_dir = false;
bool deprecated_t_option = false;
bool create_directory = false;
bool dry_run = false;
int status = EXIT_SUCCESS;
size_t x_count;
size_t suffix_len;
char *dest_name;
initialize_main (&argc, &argv);
@@ -146,7 +169,7 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
atexit (close_stdout);
atexit (maybe_close_stdout);
while ((c = getopt_long (argc, argv, "dp:qtuV", longopts, NULL)) != -1)
{
@@ -175,9 +198,13 @@ main (int argc, char **argv)
dest_dir_arg = optarg;
break;
case SUFFIX_OPTION:
suffix = optarg;
break;
case_GETOPT_HELP_CHAR;
case 'V':
case 'V': /* Undocumented alias. FIXME: remove in 2011. */
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
default:
usage (EXIT_FAILURE);
@@ -210,7 +237,41 @@ main (int argc, char **argv)
template = argv[optind];
}
x_count = count_trailing_X_s (template);
if (suffix)
{
size_t len = strlen (template);
if (!len || template[len - 1] != 'X')
{
error (EXIT_FAILURE, 0,
_("with --suffix, template %s must end in X"),
quote (template));
}
suffix_len = strlen (suffix);
dest_name = xcharalloc (len + suffix_len + 1);
memcpy (dest_name, template, len);
memcpy (dest_name + len, suffix, suffix_len + 1);
template = dest_name;
suffix = dest_name + len;
}
else
{
template = xstrdup (template);
suffix = strrchr (template, 'X');
if (!suffix)
suffix = strchr (template, '\0');
else
suffix++;
suffix_len = strlen (suffix);
}
/* At this point, template is malloc'd, and suffix points into template. */
if (suffix_len && last_component (suffix) != suffix)
{
error (EXIT_FAILURE, 0,
_("invalid suffix %s, contains directory separator"),
quote (suffix));
}
x_count = count_consecutive_X_s (template, suffix - template);
if (x_count < 3)
error (EXIT_FAILURE, 0, _("too few X's in template %s"), quote (template));
@@ -244,11 +305,10 @@ main (int argc, char **argv)
quote (template));
}
template = file_name_concat (dest_dir, template, NULL);
}
else
{
template = xstrdup (template);
dest_name = file_name_concat (dest_dir, template, NULL);
free (template);
template = dest_name;
/* Note that suffix is now invalid. */
}
/* Make a copy to be used in case of diagnostic, since failing
@@ -257,7 +317,7 @@ main (int argc, char **argv)
if (create_directory)
{
int err = mkdtemp_len (dest_name, x_count, dry_run);
int err = mkdtemp_len (dest_name, suffix_len, x_count, dry_run);
if (err != 0)
{
error (0, errno, _("failed to create directory via template %s"),
@@ -267,7 +327,7 @@ main (int argc, char **argv)
}
else
{
int fd = mkstemp_len (dest_name, x_count, dry_run);
int fd = mkstemp_len (dest_name, suffix_len, x_count, dry_run);
if (fd < 0 || (!dry_run && close (fd) != 0))
{
error (0, errno, _("failed to create file via template %s"),
@@ -277,7 +337,17 @@ main (int argc, char **argv)
}
if (status == EXIT_SUCCESS)
puts (dest_name);
{
puts (dest_name);
/* If we created a file, but then failed to output the file
name, we should clean up the mess before failing. */
if (!dry_run && (stdout_closed = true) && close_stream (stdout) != 0)
{
int saved_errno = errno;
remove (dest_name);
error (EXIT_FAILURE, saved_errno, _("write error"));
}
}
#ifdef lint
free (dest_name);

View File

@@ -86,6 +86,12 @@ With no COMMAND, print the current niceness. Nicenesses range from\n\
exit (status);
}
static bool
perm_related_errno (int err)
{
return err == EACCES || err == EPERM;
}
int
main (int argc, char **argv)
{
@@ -101,7 +107,7 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
initialize_exit_failure (EXIT_FAILURE);
initialize_exit_failure (EXIT_CANCELED);
atexit (close_stdout);
parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version,
@@ -132,7 +138,7 @@ main (int argc, char **argv)
i += optind - 1;
if (optc == '?')
usage (EXIT_FAILURE);
usage (EXIT_CANCELED);
else if (optc == 'n')
adjustment_given = optarg;
else /* optc == -1 */
@@ -148,7 +154,7 @@ main (int argc, char **argv)
enum { MIN_ADJUSTMENT = 1 - 2 * NZERO, MAX_ADJUSTMENT = 2 * NZERO - 1 };
long int tmp;
if (LONGINT_OVERFLOW < xstrtol (adjustment_given, NULL, 10, &tmp, ""))
error (EXIT_FAILURE, 0, _("invalid adjustment %s"),
error (EXIT_CANCELED, 0, _("invalid adjustment %s"),
quote (adjustment_given));
adjustment = MAX (MIN_ADJUSTMENT, MIN (tmp, MAX_ADJUSTMENT));
}
@@ -158,13 +164,13 @@ main (int argc, char **argv)
if (adjustment_given)
{
error (0, 0, _("a command must be given with an adjustment"));
usage (EXIT_FAILURE);
usage (EXIT_CANCELED);
}
/* No command given; print the niceness. */
errno = 0;
current_niceness = GET_NICENESS ();
if (current_niceness == -1 && errno != 0)
error (EXIT_FAILURE, errno, _("cannot get niceness"));
error (EXIT_CANCELED, errno, _("cannot get niceness"));
printf ("%d\n", current_niceness);
exit (EXIT_SUCCESS);
}
@@ -175,11 +181,21 @@ main (int argc, char **argv)
#else
current_niceness = GET_NICENESS ();
if (current_niceness == -1 && errno != 0)
error (EXIT_FAILURE, errno, _("cannot get niceness"));
error (EXIT_CANCELED, errno, _("cannot get niceness"));
ok = (setpriority (PRIO_PROCESS, 0, current_niceness + adjustment) == 0);
#endif
if (!ok)
error (errno == EPERM ? 0 : EXIT_FAILURE, errno, _("cannot set niceness"));
{
error (perm_related_errno (errno) ? 0
: EXIT_CANCELED, errno, _("cannot set niceness"));
/* error() flushes stderr, but does not check for write failure.
Normally, we would catch this via our atexit() hook of
close_stdout, but execvp() gets in the way. If stderr
encountered a write failure, there is no need to try calling
error() again. */
if (ferror (stderr))
exit (EXIT_CANCELED);
}
execvp (argv[i], &argv[i]);

View File

@@ -40,7 +40,7 @@
enum
{
/* `nohup' itself failed. */
NOHUP_FAILURE = 127
POSIX_NOHUP_FAILURE = 127
};
void
@@ -85,6 +85,7 @@ main (int argc, char **argv)
bool redirecting_stdout;
bool stdout_is_closed;
bool redirecting_stderr;
int exit_internal_failure;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
@@ -92,18 +93,24 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
initialize_exit_failure (NOHUP_FAILURE);
/* POSIX 2008 requires that internal failure give status 127; unlike
for env, exec, nice, time, and xargs where it requires internal
failure give something in the range 1-125. For consistency with
other tools, fail with EXIT_CANCELED unless POSIXLY_CORRECT. */
exit_internal_failure = (getenv ("POSIXLY_CORRECT")
? POSIX_NOHUP_FAILURE : EXIT_CANCELED);
initialize_exit_failure (exit_internal_failure);
atexit (close_stdout);
parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version,
usage, AUTHORS, (char const *) NULL);
if (getopt_long (argc, argv, "+", NULL, NULL) != -1)
usage (NOHUP_FAILURE);
usage (exit_internal_failure);
if (argc <= optind)
{
error (0, 0, _("missing operand"));
usage (NOHUP_FAILURE);
usage (exit_internal_failure);
}
ignoring_input = isatty (STDIN_FILENO);
@@ -154,7 +161,7 @@ main (int argc, char **argv)
if (in_home)
error (0, saved_errno2, _("failed to open %s"),
quote (in_home));
exit (NOHUP_FAILURE);
exit (exit_internal_failure);
}
file = in_home;
}
@@ -179,7 +186,7 @@ main (int argc, char **argv)
if (0 <= saved_stderr_fd
&& set_cloexec_flag (saved_stderr_fd, true) != 0)
error (NOHUP_FAILURE, errno,
error (exit_internal_failure, errno,
_("failed to set the copy of stderr to close on exec"));
if (!redirecting_stdout)
@@ -189,12 +196,22 @@ main (int argc, char **argv)
: N_("redirecting stderr to stdout")));
if (dup2 (out_fd, STDERR_FILENO) < 0)
error (NOHUP_FAILURE, errno, _("failed to redirect standard error"));
error (exit_internal_failure, errno,
_("failed to redirect standard error"));
if (stdout_is_closed)
close (out_fd);
}
/* error() flushes stderr, but does not check for write failure.
Normally, we would catch this via our atexit() hook of
close_stdout, but execvp() gets in the way. If stderr
encountered a write failure, there is no need to try calling
error() again, particularly since we may have just changed the
underlying fd out from under stderr. */
if (ferror (stderr))
exit (exit_internal_failure);
signal (SIGHUP, SIG_IGN);
{

127
src/nproc.c Normal file
View File

@@ -0,0 +1,127 @@
/* nproc - print the number of processors.
Copyright (C) 2009 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by Giuseppe Scrivano. */
#include <config.h>
#include <getopt.h>
#include <stdio.h>
#include <sys/types.h>
#include "system.h"
#include "error.h"
#include "nproc.h"
#include "xstrtol.h"
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME "nproc"
#define AUTHORS proper_name ("Giuseppe Scrivano")
enum
{
ALL_OPTION = CHAR_MAX + 1,
IGNORE_OPTION
};
static struct option const longopts[] =
{
{"all", no_argument, NULL, ALL_OPTION},
{"ignore", required_argument, NULL, IGNORE_OPTION},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
{NULL, 0, NULL, 0}
};
void
usage (int status)
{
if (status != EXIT_SUCCESS)
fprintf (stderr, _("Try `%s --help' for more information.\n"),
program_name);
else
{
printf (_("Usage: %s [OPTION]...\n"), program_name);
fputs (_("\
Print the number of processing units available to the current process,\n\
which may be less than the number of online processors\n\
\n\
"), stdout);
fputs (_("\
--all print the number of installed processors\n\
--ignore=N if possible, exclude N processing units\n\
"), stdout);
fputs (HELP_OPTION_DESCRIPTION, stdout);
fputs (VERSION_OPTION_DESCRIPTION, stdout);
emit_ancillary_info ();
}
exit (status);
}
int
main (int argc, char **argv)
{
unsigned long nproc, ignore = 0;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
atexit (close_stdout);
enum nproc_query mode = NPROC_CURRENT_OVERRIDABLE;
while (1)
{
int c = getopt_long (argc, argv, "", longopts, NULL);
if (c == -1)
break;
switch (c)
{
case_GETOPT_HELP_CHAR;
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
case ALL_OPTION:
mode = NPROC_ALL;
break;
case IGNORE_OPTION:
if (xstrtoul (optarg, NULL, 10, &ignore, "") != LONGINT_OK)
{
error (0, 0, _("%s: invalid number to ignore"), optarg);
usage (EXIT_FAILURE);
}
break;
default:
usage (EXIT_FAILURE);
}
}
nproc = num_processors (mode);
if (ignore < nproc)
nproc -= ignore;
else
nproc = 1;
printf ("%lu\n", nproc);
exit (EXIT_SUCCESS);
}

View File

@@ -33,7 +33,6 @@
#include <getopt.h>
#include "system.h"
#include "long-options.h"
/* Exit status for syntax errors, etc. */
enum { PRINTENV_FAILURE = 2 };
@@ -45,7 +44,13 @@ enum { PRINTENV_FAILURE = 2 };
proper_name ("David MacKenzie"), \
proper_name ("Richard Mlynarik")
extern char **environ;
static struct option const longopts[] =
{
{"null", no_argument, NULL, '0'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
{NULL, 0, NULL, 0}
};
void
usage (int status)
@@ -56,13 +61,15 @@ usage (int status)
else
{
printf (_("\
Usage: %s [VARIABLE]...\n\
or: %s OPTION\n\
Usage: %s [OPTION]... [VARIABLE]...\n\
Print the values of the specified environment VARIABLE(s).\n\
If no VARIABLE is specified, print name and value pairs for them all.\n\
\n\
"),
program_name, program_name);
program_name);
fputs (_("\
-0, --null end each output line with 0 byte rather than newline\n\
"), stdout);
fputs (HELP_OPTION_DESCRIPTION, stdout);
fputs (VERSION_OPTION_DESCRIPTION, stdout);
printf (USAGE_BUILTIN_WARNING, PROGRAM_NAME);
@@ -78,6 +85,8 @@ main (int argc, char **argv)
char *ep, *ap;
int i;
bool ok;
int optc;
bool opt_nul_terminate_output = false;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
@@ -88,15 +97,24 @@ main (int argc, char **argv)
initialize_exit_failure (PRINTENV_FAILURE);
atexit (close_stdout);
parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version,
usage, AUTHORS, (char const *) NULL);
if (getopt_long (argc, argv, "+", NULL, NULL) != -1)
usage (PRINTENV_FAILURE);
while ((optc = getopt_long (argc, argv, "+iu:0", longopts, NULL)) != -1)
{
switch (optc)
{
case '0':
opt_nul_terminate_output = true;
break;
case_GETOPT_HELP_CHAR;
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
default:
usage (PRINTENV_FAILURE);
}
}
if (optind >= argc)
{
for (env = environ; *env != NULL; ++env)
puts (*env);
printf ("%s%c", *env, opt_nul_terminate_output ? '\0' : '\n');
ok = true;
}
else
@@ -107,6 +125,10 @@ main (int argc, char **argv)
{
bool matched = false;
/* 'printenv a=b' is silent, even if 'a=b=c' is in environ. */
if (strchr (argv[i], '='))
continue;
for (env = environ; *env; ++env)
{
ep = *env;
@@ -115,7 +137,8 @@ main (int argc, char **argv)
{
if (*ep == '=' && *ap == '\0')
{
puts (ep + 1);
printf ("%s%c", ep + 1,
opt_nul_terminate_output ? '\0' : '\n');
matched = true;
break;
}

View File

@@ -25,6 +25,7 @@
\a = alert (bell)
\b = backspace
\c = produce no further output
\e = escape
\f = form feed
\n = new line
\r = carriage return
@@ -101,22 +102,21 @@ Print ARGUMENT(s) according to FORMAT, or execute according to OPTION:\n\
FORMAT controls the output as in C printf. Interpreted sequences are:\n\
\n\
\\\" double quote\n\
\\NNN character with octal value NNN (1 to 3 digits)\n\
\\\\ backslash\n\
"), stdout);
fputs (_("\
\\\\ backslash\n\
\\a alert (BEL)\n\
\\b backspace\n\
\\c produce no further output\n\
\\e escape\n\
\\f form feed\n\
"), stdout);
fputs (_("\
\\n new line\n\
\\r carriage return\n\
\\t horizontal tab\n\
\\v vertical tab\n\
"), stdout);
fputs (_("\
\\NNN byte with octal value NNN (1 to 3 digits)\n\
\\xHH byte with hexadecimal value HH (1 to 2 digits)\n\
\\uHHHH Unicode (ISO/IEC 10646) character with hex value HHHH (4 digits)\n\
\\UHHHHHHHH Unicode character with hex value HHHHHHHH (8 digits)\n\
@@ -200,6 +200,9 @@ print_esc_char (char c)
case 'c': /* Cancel the rest of the output. */
exit (EXIT_SUCCESS);
break;
case 'e': /* Escape. */
putchar ('\x1B');
break;
case 'f': /* Form feed. */
putchar ('\f');
break;
@@ -256,7 +259,7 @@ print_esc (const char *escstart, bool octal_0)
esc_value = esc_value * 8 + octtobin (*p);
putchar (esc_value);
}
else if (*p && strchr ("\"\\abcfnrtv", *p))
else if (*p && strchr ("\"\\abcefnrtv", *p))
print_esc_char (*p++);
else if (*p == 'u' || *p == 'U')
{

View File

@@ -19,7 +19,6 @@
#include <config.h>
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
#include "system.h"
@@ -29,6 +28,7 @@
#include "quote.h"
#include "quotearg.h"
#include "regex.h"
#include "stdio--.h"
#include "xstrtol.h"
/* The official name of this program (e.g., no `g' prefix). */

View File

@@ -437,6 +437,18 @@ excise (FTS *fts, FTSENT *ent, struct rm_options const *x, bool is_dir)
return RM_OK;
}
/* The unlinkat from kernels like linux-2.6.32 reports EROFS even for
nonexistent files. When the file is indeed missing, map that to ENOENT,
so that rm -f ignores it, as required. Even without -f, this is useful
because it makes rm print the more precise diagnostic. */
if (errno == EROFS)
{
struct stat st;
if ( ! (lstatat (fts->fts_cwd_fd, ent->fts_accpath, &st)
&& errno == ENOENT))
errno = EROFS;
}
if (ignorable_missing (x, errno))
return RM_OK;
@@ -552,12 +564,7 @@ rm_fts (FTS *fts, FTSENT *ent, struct rm_options const *x)
}
case FTS_DC: /* directory that causes cycles */
error (0, 0, _("\
WARNING: Circular directory structure.\n\
This almost certainly means that you have a corrupted file system.\n\
NOTIFY YOUR SYSTEM MANAGER.\n\
The following directory is part of the cycle:\n %s\n"),
quote (ent->fts_path));
emit_cycle_warning (ent->fts_path);
fts_skip_tree (fts, ent);
return RM_ERROR;

View File

@@ -182,7 +182,7 @@ main (int argc, char **argv)
if (optind >= argc)
{
error (0, 0, _("you must specify -c, -t, -u, -l, -r, or context"));
usage (1);
usage (EXIT_FAILURE);
}
context = argv[optind++];
}
@@ -190,7 +190,7 @@ main (int argc, char **argv)
if (optind >= argc)
{
error (0, 0, _("no command specified"));
usage (1);
usage (EXIT_FAILURE);
}
if (is_selinux_enabled () != 1)

View File

@@ -110,7 +110,7 @@ main (int argc, char **argv)
error (EXIT_FAILURE, 0, _("invalid group %s"),
quote (gr));
if (n_gids == n_gids_allocated)
gids = x2nrealloc (gids, &n_gids_allocated, sizeof *gids);
gids = X2NREALLOC (gids, &n_gids_allocated);
gids[n_gids++] = tmp_ul;
if (*ptr == '\0')
@@ -181,7 +181,7 @@ main (int argc, char **argv)
{
int n = mgetgroups (pwd->pw_name, pwd->pw_gid, &gids);
if (n <= 0)
error (1, errno, _("failed to get groups for user %s"),
error (EXIT_FAILURE, errno, _("failed to get groups for user %s"),
quote (pwd->pw_name));
n_gids = n;
}

View File

@@ -19,7 +19,6 @@
#include <config.h>
#include <stdio.h>
#include <sys/types.h>
#include "system.h"
@@ -29,6 +28,7 @@
#include "quotearg.h"
#include "randint.h"
#include "randperm.h"
#include "stdio--.h"
#include "xstrtol.h"
/* The official name of this program (e.g., no `g' prefix). */

View File

@@ -219,25 +219,39 @@ human_fstype (STRUCT_STATVFS const *statfsbuf)
return "adfs";
case S_MAGIC_AFFS: /* 0xADFF */
return "affs";
case S_MAGIC_AUTOFS: /* 0x187 */
case S_MAGIC_AFS: /* 0x5346414F */
return "afs";
case S_MAGIC_ANON_INODE_FS: /* 0x09041934 */
return "anon-inode FS";
case S_MAGIC_AUTOFS: /* 0x0187 */
return "autofs";
case S_MAGIC_BEFS: /* 0x42465331 */
return "befs";
case S_MAGIC_BFS: /* 0x1BADFACE */
return "bfs";
case S_MAGIC_BINFMT_MISC: /* 0x42494e4d */
case S_MAGIC_BINFMT_MISC: /* 0x42494E4D */
return "binfmt_misc";
case S_MAGIC_BTRFS: /* 0x9123683E */
return "btrfs";
case S_MAGIC_CGROUP: /* 0x0027E0EB */
return "cgroupfs";
case S_MAGIC_CIFS: /* 0xFF534D42 */
return "cifs";
case S_MAGIC_CODA: /* 0x73757245 */
return "coda";
case S_MAGIC_COH: /* 0x012FF7B7 */
return "coh";
case S_MAGIC_CRAMFS: /* 0x28CD3D45 */
return "cramfs";
case S_MAGIC_CRAMFS_WEND: /* 0x453DCD28 */
return "cramfs-wend";
case S_MAGIC_DEBUGFS: /* 0x64626720 */
return "debugfs";
case S_MAGIC_DEVFS: /* 0x1373 */
return "devfs";
case S_MAGIC_DEVPTS: /* 0x1CD1 */
return "devpts";
case S_MAGIC_EFS: /* 0x414A53 */
case S_MAGIC_EFS: /* 0x00414A53 */
return "efs";
case S_MAGIC_EXT: /* 0x137D */
return "ext";
@@ -249,20 +263,26 @@ human_fstype (STRUCT_STATVFS const *statfsbuf)
return "fat";
case S_MAGIC_FUSECTL: /* 0x65735543 */
return "fusectl";
case S_MAGIC_FUTEXFS: /* 0x0BAD1DEA */
return "futexfs";
case S_MAGIC_HFS: /* 0x4244 */
return "hfs";
case S_MAGIC_HPFS: /* 0xF995E849 */
return "hpfs";
case S_MAGIC_HUGETLBFS: /* 0x958458f6 */
case S_MAGIC_HUGETLBFS: /* 0x958458F6 */
return "hugetlbfs";
case S_MAGIC_INOTIFYFS: /* 0x2BAD1DEA */
return "inotifyfs";
case S_MAGIC_ISOFS: /* 0x9660 */
return "isofs";
case S_MAGIC_ISOFS_R_WIN: /* 0x4004 */
return "isofs";
case S_MAGIC_ISOFS_WIN: /* 0x4000 */
return "isofs";
case S_MAGIC_JFFS2: /* 0x72B6 */
return "jffs2";
case S_MAGIC_JFFS: /* 0x07C0 */
return "jffs";
case S_MAGIC_JFFS2: /* 0x72B6 */
return "jffs2";
case S_MAGIC_JFS: /* 0x3153464A */
return "jfs";
case S_MAGIC_LUSTRE: /* 0x0BD00BD0 */
@@ -275,6 +295,8 @@ human_fstype (STRUCT_STATVFS const *statfsbuf)
return "minix v2";
case S_MAGIC_MINIX_V2_30: /* 0x2478 */
return "minix v2 (30 char.)";
case S_MAGIC_MINIX_V3: /* 0x4D5A */
return "minux3";
case S_MAGIC_MSDOS: /* 0x4D44 */
return "msdos";
case S_MAGIC_NCP: /* 0x564C */
@@ -283,9 +305,11 @@ human_fstype (STRUCT_STATVFS const *statfsbuf)
return "nfs";
case S_MAGIC_NFSD: /* 0x6E667364 */
return "nfsd";
case S_MAGIC_NILFS: /* 0x3434 */
return "nilfs";
case S_MAGIC_NTFS: /* 0x5346544E */
return "ntfs";
case S_MAGIC_OPENPROM: /* 0x9fa1 */
case S_MAGIC_OPENPROM: /* 0x9FA1 */
return "openprom";
case S_MAGIC_PROC: /* 0x9FA0 */
return "proc";
@@ -297,6 +321,10 @@ human_fstype (STRUCT_STATVFS const *statfsbuf)
return "reiserfs";
case S_MAGIC_ROMFS: /* 0x7275 */
return "romfs";
case S_MAGIC_SECURITYFS: /* 0x73636673 */
return "securityfs";
case S_MAGIC_SELINUX: /* 0xF97CFF8C */
return "selinux";
case S_MAGIC_SMB: /* 0x517B */
return "smb";
case S_MAGIC_SQUASHFS: /* 0x73717368 */
@@ -307,7 +335,7 @@ human_fstype (STRUCT_STATVFS const *statfsbuf)
return "sysv2";
case S_MAGIC_SYSV4: /* 0x012FF7B5 */
return "sysv4";
case S_MAGIC_TMPFS: /* 0x1021994 */
case S_MAGIC_TMPFS: /* 0x01021994 */
return "tmpfs";
case S_MAGIC_UDF: /* 0x15013346 */
return "udf";
@@ -319,6 +347,8 @@ human_fstype (STRUCT_STATVFS const *statfsbuf)
return "usbdevfs";
case S_MAGIC_VXFS: /* 0xA501FCF5 */
return "vxfs";
case S_MAGIC_XENFS: /* 0xABBA1974 */
return "xenfs";
case S_MAGIC_XENIX: /* 0x012FF7B4 */
return "xenix";
case S_MAGIC_XFS: /* 0x58465342 */
@@ -693,6 +723,9 @@ print_esc_char (char c)
case 'b': /* Backspace. */
c ='\b';
break;
case 'e': /* Escape. */
c ='\x1B';
break;
case 'f': /* Form feed. */
c ='\f';
break;
@@ -872,7 +905,12 @@ do_stat (char const *filename, bool terse, char const *format)
return false;
}
}
else if ((follow_links ? stat : lstat) (filename, &statbuf) != 0)
/* We can't use the shorter
(follow_links?stat:lstat) (filename, &statbug)
since stat might be a function-like macro. */
else if ((follow_links
? stat (filename, &statbuf)
: lstat (filename, &statbuf)) != 0)
{
error (0, errno, _("cannot stat %s"), quote (filename));
return false;

View File

@@ -24,8 +24,10 @@
#include "system.h"
#include "error.h"
#include "filenamecat.h"
#include "posixver.h"
#include "quote.h"
#include "xreadlink.h"
#include "xstrtol.h"
#include "c-ctype.h"
@@ -35,13 +37,8 @@
#define AUTHORS proper_name_utf8 ("Padraig Brady", "P\303\241draig Brady")
/* Internal error */
enum { EXIT_CANCELED = 125 };
static char *program_path;
extern char **environ;
static struct
{
size_t size;
@@ -145,34 +142,26 @@ set_program_path (const char *arg)
}
else
{
char *path;
char tmppath[PATH_MAX + 1];
ssize_t len = readlink ("/proc/self/exe", tmppath, sizeof (tmppath) - 1);
if (len > 0)
{
tmppath[len] = '\0';
program_path = dir_name (tmppath);
}
char *path = xreadlink ("/proc/self/exe");
if (path)
program_path = dir_name (path);
else if ((path = getenv ("PATH")))
{
char *dir;
path = xstrdup (path);
for (dir = strtok (path, ":"); dir != NULL; dir = strtok (NULL, ":"))
{
int req = snprintf (tmppath, sizeof (tmppath), "%s/%s", dir, arg);
if (req >= sizeof (tmppath))
char *candidate = file_name_concat (dir, arg, NULL);
if (access (candidate, X_OK) == 0)
{
error (0, 0, _("path truncated when looking for %s"),
quote (arg));
}
else if (access (tmppath, X_OK) == 0)
{
program_path = dir_name (tmppath);
program_path = dir_name (candidate);
free (candidate);
break;
}
free (candidate);
}
free (path);
}
free (path);
}
}

View File

@@ -113,8 +113,6 @@
char *crypt (char const *key, char const *salt);
extern char **environ;
static void run_shell (char const *, char const *, char **, size_t)
ATTRIBUTE_NORETURN;
@@ -286,13 +284,13 @@ change_identity (const struct passwd *pw)
#ifdef HAVE_INITGROUPS
errno = 0;
if (initgroups (pw->pw_name, pw->pw_gid) == -1)
error (EXIT_FAILURE, errno, _("cannot set groups"));
error (EXIT_CANCELED, errno, _("cannot set groups"));
endgrent ();
#endif
if (setgid (pw->pw_gid))
error (EXIT_FAILURE, errno, _("cannot set group id"));
error (EXIT_CANCELED, errno, _("cannot set group id"));
if (setuid (pw->pw_uid))
error (EXIT_FAILURE, errno, _("cannot set user id"));
error (EXIT_CANCELED, errno, _("cannot set user id"));
}
/* Run SHELL, or DEFAULT_SHELL if SHELL is empty.
@@ -406,7 +404,7 @@ main (int argc, char **argv)
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
initialize_exit_failure (EXIT_FAILURE);
initialize_exit_failure (EXIT_CANCELED);
atexit (close_stdout);
fast_startup = false;
@@ -443,7 +441,7 @@ main (int argc, char **argv)
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
default:
usage (EXIT_FAILURE);
usage (EXIT_CANCELED);
}
}
@@ -458,7 +456,7 @@ main (int argc, char **argv)
pw = getpwnam (new_user);
if (! (pw && pw->pw_name && pw->pw_name[0] && pw->pw_dir && pw->pw_dir[0]
&& pw->pw_passwd))
error (EXIT_FAILURE, 0, _("user %s does not exist"), new_user);
error (EXIT_CANCELED, 0, _("user %s does not exist"), new_user);
/* Make a copy of the password information and point pw at the local
copy instead. Otherwise, some systems (e.g. GNU/Linux) would clobber
@@ -481,7 +479,7 @@ main (int argc, char **argv)
#ifdef SYSLOG_FAILURE
log_su (pw, false);
#endif
error (EXIT_FAILURE, 0, _("incorrect password"));
error (EXIT_CANCELED, 0, _("incorrect password"));
}
#ifdef SYSLOG_SUCCESS
else
@@ -508,5 +506,13 @@ main (int argc, char **argv)
if (simulate_login && chdir (pw->pw_dir) != 0)
error (0, errno, _("warning: cannot change directory to %s"), pw->pw_dir);
/* error() flushes stderr, but does not check for write failure.
Normally, we would catch this via our atexit() hook of
close_stdout, but execv() gets in the way. If stderr
encountered a write failure, there is no need to try calling
error() again. */
if (ferror (stderr))
exit (EXIT_CANCELED);
run_shell (shell, command, argv + optind, MAX (0, argc - optind));
}

View File

@@ -233,6 +233,10 @@ main (int argc, char **argv)
atexit (close_stdout);
/* Line buffer stdout to ensure lines are written atomically and immediately
so that processes running in parallel do not intersperse their output. */
setvbuf (stdout, NULL, _IOLBF, 0);
have_read_stdin = false;
while ((optc = getopt_long (argc, argv, "rs", longopts, NULL)) != -1)

View File

@@ -44,16 +44,8 @@ you must include <sys/types.h> before including this file
#include "configmake.h"
#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# if HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
#endif
#include <sys/time.h>
#include <time.h>
/* Since major is a function on SVR4, we can't use `ifndef major'. */
#if MAJOR_IN_MKDEV
@@ -86,16 +78,8 @@ you must include <sys/types.h> before including this file
#include <errno.h>
/* Some systems don't define the following symbols. */
#ifndef EDQUOT
# define EDQUOT (-1)
#endif
#ifndef EISDIR
# define EISDIR (-1)
#endif
#ifndef ENOSYS
# define ENOSYS (-1)
#endif
/* Some systems don't define this; POSIX mentions it but says it is
obsolete, so gnulib does not provide it either. */
#ifndef ENODATA
# define ENODATA (-1)
#endif
@@ -107,8 +91,10 @@ you must include <sys/types.h> before including this file
/* Exit statuses for programs like 'env' that exec other programs. */
enum
{
EXIT_CANNOT_INVOKE = 126,
EXIT_ENOENT = 127
EXIT_TIMEDOUT = 124, /* Time expired before child completed. */
EXIT_CANCELED = 125, /* Internal error prior to exec attempt. */
EXIT_CANNOT_INVOKE = 126, /* Program located, but not usable. */
EXIT_ENOENT = 127 /* Could not find program to exec. */
};
#include "exitfail.h"
@@ -123,13 +109,6 @@ initialize_exit_failure (int status)
#include <fcntl.h>
#ifndef F_OK
# define F_OK 0
# define X_OK 1
# define W_OK 2
# define R_OK 4
#endif
#include <dirent.h>
#ifndef _D_EXACT_NAMLEN
# define _D_EXACT_NAMLEN(dp) strlen ((dp)->d_name)
@@ -233,10 +212,6 @@ enum
#include <ctype.h>
#if ! (defined isblank || HAVE_DECL_ISBLANK)
# define isblank(c) ((c) == ' ' || (c) == '\t')
#endif
/* ISDIGIT differs from isdigit, as follows:
- Its arg may be any int or unsigned int; it need not be an unsigned char
or EOF.
@@ -279,30 +254,6 @@ select_plural (uintmax_t n)
#define STREQ(a, b) (strcmp (a, b) == 0)
#if !HAVE_DECL_FREE
void free ();
#endif
#if !HAVE_DECL_MALLOC
char *malloc ();
#endif
#if !HAVE_DECL_MEMCHR
char *memchr ();
#endif
#if !HAVE_DECL_REALLOC
char *realloc ();
#endif
#if !HAVE_DECL_GETENV
char *getenv ();
#endif
#if !HAVE_DECL_LSEEK
off_t lseek ();
#endif
#if !HAVE_DECL_GETLOGIN
char *getlogin ();
#endif
@@ -547,10 +498,6 @@ enum
while (0)
#endif
#ifndef EOVERFLOW
# define EOVERFLOW EINVAL
#endif
#if ! HAVE_SYNC
# define sync() /* empty */
#endif
@@ -725,6 +672,18 @@ io_blksize (struct stat sb)
void usage (int status) ATTRIBUTE_NORETURN;
#define emit_cycle_warning(file_name) \
do \
{ \
error (0, 0, _("\
WARNING: Circular directory structure.\n\
This almost certainly means that you have a corrupted file system.\n\
NOTIFY YOUR SYSTEM MANAGER.\n\
The following directory is part of the cycle:\n %s\n"), \
quote (file_name)); \
} \
while (0)
#ifndef ARRAY_CARDINALITY
# define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))
#endif

View File

@@ -260,8 +260,8 @@ With no FILE, or when FILE is -, read standard input.\n\
Mandatory arguments to long options are mandatory for short options too.\n\
"), stdout);
fputs (_("\
-c, --bytes=K output the last K bytes; alternatively, use +K to\n\
output bytes starting with the Kth of each file\n\
-c, --bytes=K output the last K bytes; alternatively, use -c +K\n\
to output bytes starting with the Kth of each file\n\
"), stdout);
fputs (_("\
-f, --follow[={name|descriptor}]\n\
@@ -272,7 +272,7 @@ Mandatory arguments to long options are mandatory for short options too.\n\
"), stdout);
printf (_("\
-n, --lines=K output the last K lines, instead of the last %d;\n\
or use +K to output lines starting with the Kth\n\
or use -n +K to output lines starting with the Kth\n\
--max-unchanged-stats=N\n\
with --follow=name, reopen a FILE which has not\n\
changed size after N (default %d) iterations\n\
@@ -1168,6 +1168,47 @@ wd_comparator (const void *e1, const void *e2)
return spec1->wd == spec2->wd;
}
/* Helper function used by `tail_forever_inotify'. */
static void
check_fspec (struct File_spec *fspec, int wd, int *prev_wd)
{
struct stat stats;
char const *name = pretty_name (fspec);
if (fstat (fspec->fd, &stats) != 0)
{
close_fd (fspec->fd, name);
fspec->fd = -1;
fspec->errnum = errno;
return;
}
if (S_ISREG (fspec->mode) && stats.st_size < fspec->size)
{
error (0, 0, _("%s: file truncated"), name);
*prev_wd = wd;
xlseek (fspec->fd, stats.st_size, SEEK_SET, name);
fspec->size = stats.st_size;
}
else if (S_ISREG (fspec->mode) && stats.st_size == fspec->size
&& timespec_cmp (fspec->mtime, get_stat_mtime (&stats)) == 0)
return;
if (wd != *prev_wd)
{
if (print_headers)
write_header (name);
*prev_wd = wd;
}
uintmax_t bytes_read = dump_remainder (name, fspec->fd, COPY_TO_EOF);
fspec->size += bytes_read;
if (fflush (stdout) != 0)
error (EXIT_FAILURE, errno, _("write error"));
}
/* Tail N_FILES files forever, or until killed.
Check modifications using the inotify events system. */
@@ -1249,6 +1290,14 @@ tail_forever_inotify (int wd, struct File_spec *f, size_t n_files,
prev_wd = f[n_files - 1].wd;
/* Check files again. New data can be available since last time we checked
and before they are watched by inotify. */
for (i = 0; i < n_files; i++)
{
if (!f[i].ignore)
check_fspec (&f[i], f[i].wd, &prev_wd);
}
evlen += sizeof (struct inotify_event) + 1;
evbuf = xmalloc (evlen);
@@ -1257,11 +1306,7 @@ tail_forever_inotify (int wd, struct File_spec *f, size_t n_files,
This loop sleeps on the `safe_read' call until a new event is notified. */
while (1)
{
char const *name;
struct File_spec *fspec;
uintmax_t bytes_read;
struct stat stats;
struct inotify_event *ev;
/* When watching a PID, ensure that a read from WD will not block
@@ -1359,7 +1404,13 @@ tail_forever_inotify (int wd, struct File_spec *f, size_t n_files,
if (ev->mask & (IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF))
{
if (ev->mask & (IN_DELETE_SELF | IN_MOVE_SELF))
/* For IN_DELETE_SELF, we always want to remove the watch.
However, for IN_MOVE_SELF (the file we're watching has
been clobbered via a rename), when tailing by NAME, we
must continue to watch the file. It's only when following
by file descriptor that we must remove the watch. */
if ((ev->mask & IN_DELETE_SELF)
|| ((ev->mask & IN_MOVE_SELF) && follow_mode == Follow_descriptor))
{
inotify_rm_watch (wd, f[i].wd);
hash_delete (wd_table, &(f[i]));
@@ -1369,37 +1420,7 @@ tail_forever_inotify (int wd, struct File_spec *f, size_t n_files,
continue;
}
name = pretty_name (fspec);
if (fstat (fspec->fd, &stats) != 0)
{
close_fd (fspec->fd, name);
fspec->fd = -1;
fspec->errnum = errno;
continue;
}
if (S_ISREG (fspec->mode) && stats.st_size < fspec->size)
{
error (0, 0, _("%s: file truncated"), name);
prev_wd = ev->wd;
xlseek (fspec->fd, stats.st_size, SEEK_SET, name);
fspec->size = stats.st_size;
}
if (ev->wd != prev_wd)
{
if (print_headers)
write_header (name);
prev_wd = ev->wd;
}
bytes_read = dump_remainder (name, fspec->fd, COPY_TO_EOF);
fspec->size += bytes_read;
if (fflush (stdout) != 0)
error (EXIT_FAILURE, errno, _("write error"));
check_fspec (fspec, ev->wd, &prev_wd);
}
}
#endif

View File

@@ -73,12 +73,6 @@
#define AUTHORS proper_name_utf8 ("Padraig Brady", "P\303\241draig Brady")
/* Note ETIMEDOUT is 110 on GNU/Linux systems but this is non standard */
#define EXIT_TIMEDOUT 124
/* Internal failure. */
#define EXIT_CANCELED 125
static int timed_out;
static int term_signal = SIGTERM; /* same default as kill command. */
static int monitored_pid;
@@ -202,7 +196,7 @@ apply_time_suffix (unsigned long *x, char suffix_char)
}
static void
install_signal_handlers (void)
install_signal_handlers (int sigterm)
{
struct sigaction sa;
sigemptyset(&sa.sa_mask); /* Allow concurrent calls to handler */
@@ -212,8 +206,9 @@ install_signal_handlers (void)
sigaction (SIGALRM, &sa, NULL); /* our timeout. */
sigaction (SIGINT, &sa, NULL); /* Ctrl-C at terminal for example. */
sigaction (SIGQUIT, &sa, NULL); /* Ctrl-\ at terminal for example. */
sigaction (SIGTERM, &sa, NULL); /* if we're killed, stop monitored proc. */
sigaction (SIGHUP, &sa, NULL); /* terminal closed for example. */
sigaction (SIGTERM, &sa, NULL); /* if we're killed, stop monitored proc. */
sigaction (sigterm, &sa, NULL); /* user specified termination signal. */
}
int
@@ -277,7 +272,7 @@ main (int argc, char **argv)
/* Setup handlers before fork() so that we
handle any signals caused by child, without races. */
install_signal_handlers ();
install_signal_handlers (term_signal);
signal (SIGTTIN, SIG_IGN); /* don't sTop if background child needs tty. */
signal (SIGTTOU, SIG_IGN); /* don't sTop if background child needs tty. */

View File

@@ -22,6 +22,7 @@
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
#include <assert.h>
#include "system.h"
#include "argmatch.h"
@@ -57,6 +58,9 @@ static bool no_create;
/* (-r) If true, use times from a reference file. */
static bool use_ref;
/* (-h) If true, change the times of an existing symlink, if possible. */
static bool no_dereference;
/* If true, the only thing we have to do is change both the
modification and access time to the current time, so we don't
have to own the file, just be able to read and write it.
@@ -84,6 +88,7 @@ static struct option const longopts[] =
{"date", required_argument, NULL, 'd'},
{"file", required_argument, NULL, 'r'}, /* FIXME: remove --file in 2010 */
{"reference", required_argument, NULL, 'r'},
{"no-dereference", no_argument, NULL, 'h'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
{NULL, 0, NULL, 0}
@@ -119,15 +124,13 @@ static bool
touch (const char *file)
{
bool ok;
struct stat sbuf;
int fd = -1;
int open_errno = 0;
struct timespec timespec[2];
struct timespec const *t;
struct timespec const *t = newtime;
if (STREQ (file, "-"))
fd = STDOUT_FILENO;
else if (! no_create)
else if (! (no_create || no_dereference))
{
/* Try to open FILE, creating it if necessary. */
fd = fd_reopen (STDIN_FILENO, file,
@@ -144,24 +147,13 @@ touch (const char *file)
if (change_times != (CH_ATIME | CH_MTIME))
{
/* We're setting only one of the time values. stat the target to get
the other one. If we have the file descriptor already, use fstat.
Otherwise, either we're in no-create mode (and hence didn't call open)
or FILE is inaccessible or a directory, so we have to use stat. */
if (fd != -1 ? fstat (fd, &sbuf) : stat (file, &sbuf))
/* We're setting only one of the time values. */
if (change_times == CH_MTIME)
newtime[0].tv_nsec = UTIME_OMIT;
else
{
if (open_errno)
error (0, open_errno, _("creating %s"), quote (file));
else
{
if (no_create && (errno == ENOENT || errno == EBADF))
return true;
error (0, errno, _("failed to get attributes of %s"),
quote (file));
}
if (fd == STDIN_FILENO)
close (fd);
return false;
assert (change_times == CH_ATIME);
newtime[1].tv_nsec = UTIME_OMIT;
}
}
@@ -171,18 +163,9 @@ touch (const char *file)
write access to the file, but don't own it. */
t = NULL;
}
else
{
timespec[0] = (change_times & CH_ATIME
? newtime[0]
: get_stat_atime (&sbuf));
timespec[1] = (change_times & CH_MTIME
? newtime[1]
: get_stat_mtime (&sbuf));
t = timespec;
}
ok = (gl_futimens (fd, (fd == STDOUT_FILENO ? NULL : file), t) == 0);
ok = ((no_dereference && fd == -1) ? lutimens (file, t)
: gl_futimens (fd, (fd == STDOUT_FILENO ? NULL : file), t)) == 0;
if (fd == STDIN_FILENO)
{
@@ -195,8 +178,7 @@ touch (const char *file)
else if (fd == STDOUT_FILENO)
{
/* Do not diagnose "touch -c - >&-". */
if (!ok && errno == EBADF && no_create
&& change_times == (CH_ATIME | CH_MTIME))
if (!ok && errno == EBADF && no_create)
return true;
}
@@ -234,7 +216,8 @@ usage (int status)
fputs (_("\
Update the access and modification times of each FILE to the current time.\n\
\n\
A FILE argument that does not exist is created empty.\n\
A FILE argument that does not exist is created empty, unless -c or -h\n\
is supplied.\n\
\n\
A FILE argument string of - is handled specially and causes touch to\n\
change the times of the file associated with standard output.\n\
@@ -248,6 +231,11 @@ Mandatory arguments to long options are mandatory for short options too.\n\
-c, --no-create do not create any files\n\
-d, --date=STRING parse STRING and use it instead of current time\n\
-f (ignored)\n\
"), stdout);
fputs (_("\
-h, --no-dereference affect each symbolic link instead of any referenced\n\
file (useful only on systems that can change the\n\
timestamps of a symlink)\n\
-m change only the modification time\n\
"), stdout);
fputs (_("\
@@ -288,7 +276,7 @@ main (int argc, char **argv)
change_times = 0;
no_create = use_ref = false;
while ((c = getopt_long (argc, argv, "acd:fmr:t:", longopts, &long_idx)) != -1)
while ((c = getopt_long (argc, argv, "acd:fhmr:t:", longopts, &long_idx)) != -1)
{
switch (c)
{
@@ -307,6 +295,10 @@ main (int argc, char **argv)
case 'f':
break;
case 'h':
no_dereference = true;
break;
case 'm':
change_times |= CH_MTIME;
break;
@@ -356,7 +348,10 @@ main (int argc, char **argv)
if (use_ref)
{
struct stat ref_stats;
if (stat (ref_file, &ref_stats))
/* Don't use (no_dereference?lstat:stat) (args), since stat
might be an object-like macro. */
if (no_dereference ? lstat (ref_file, &ref_stats)
: stat (ref_file, &ref_stats))
error (EXIT_FAILURE, errno,
_("failed to get attributes of %s"), quote (ref_file));
newtime[0] = get_stat_atime (&ref_stats);
@@ -429,10 +424,7 @@ main (int argc, char **argv)
if (change_times == (CH_ATIME | CH_MTIME))
amtime_now = true;
else
{
gettime (&newtime[0]);
newtime[1] = newtime[0];
}
newtime[1].tv_nsec = newtime[0].tv_nsec = UTIME_NOW;
}
if (optind == argc)

View File

@@ -54,18 +54,18 @@ Usage: %s [ignored command line arguments]\n\
int
main (int argc, char **argv)
{
initialize_main (&argc, &argv);
set_program_name (argv[0]);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
atexit (close_stdout);
/* Recognize --help or --version only if it's the only command-line
argument. */
if (argc == 2)
{
initialize_main (&argc, &argv);
set_program_name (argv[0]);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
atexit (close_stdout);
if (STREQ (argv[1], "--help"))
usage (EXIT_STATUS);

View File

@@ -22,7 +22,6 @@
#include <config.h>
#include <stdio.h>
#include <assert.h>
#include <getopt.h>
#include <sys/types.h>
@@ -32,6 +31,7 @@
#include "error.h"
#include "quote.h"
#include "readtokens.h"
#include "stdio--.h"
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME "tsort"

View File

@@ -18,7 +18,6 @@
#include <config.h>
#include <stdio.h>
#include <getopt.h>
#include <sys/types.h>
@@ -29,6 +28,7 @@
#include "hard-locale.h"
#include "posixver.h"
#include "quote.h"
#include "stdio--.h"
#include "xmemcoll.h"
#include "xstrtol.h"
#include "memcasecmp.h"

View File

@@ -24,12 +24,12 @@ root_tests = \
cp/preserve-gid \
cp/special-bits \
cp/cp-mv-enotsup-xattr \
chroot/credentials \
dd/skip-seek-past-dev \
install/install-C-root \
ls/capability \
ls/nameless-uid \
misc/chcon \
misc/chroot-credentials \
misc/selinux \
misc/truncate-owned-by-other \
mkdir/writable-under-readonly \
@@ -37,6 +37,7 @@ root_tests = \
rm/fail-2eperm \
rm/no-give-up \
rm/one-file-system \
rm/read-only \
tail-2/append-only \
touch/now-owned-by-other
@@ -74,10 +75,12 @@ EXTRA_DIST += $(TESTS)
TESTS = \
misc/help-version \
tail-2/inotify-race \
misc/invalid-opt \
rm/ext3-perf \
rm/cycle \
cp/link-heap \
tail-2/inotify-rotate \
chmod/no-x \
chgrp/basic \
rm/dangling-symlink \
@@ -125,6 +128,7 @@ TESTS = \
chgrp/no-x \
chgrp/posix-H \
chgrp/recurse \
misc/env \
misc/ptx \
misc/test \
misc/seq \
@@ -157,12 +161,14 @@ TESTS = \
misc/base64 \
misc/basename \
misc/close-stdout \
misc/chroot-fail \
misc/comm \
misc/csplit \
misc/date-sec \
misc/dircolors \
misc/df \
misc/dirname \
misc/env-null \
misc/expand \
misc/expr \
misc/factor \
@@ -178,15 +184,20 @@ TESTS = \
misc/id-groups \
misc/md5sum \
misc/md5sum-newline \
misc/md5sum-parallel \
misc/mknod \
misc/nice \
misc/nice-fail \
misc/nl \
misc/nohup \
misc/nproc-avail \
misc/nproc-positive \
misc/od-N \
misc/od-multiple-t \
misc/od-x8 \
misc/paste \
misc/pathchk1 \
misc/printenv \
misc/printf \
misc/printf-cov \
misc/printf-hex \
@@ -218,10 +229,12 @@ TESTS = \
misc/stat-fmt \
misc/stat-hyphen \
misc/stat-printf \
misc/stat-slash \
misc/stdbuf \
misc/stty \
misc/stty-invalid \
misc/stty-row-col \
misc/su-fail \
misc/sum \
misc/sum-sysv \
misc/tac \
@@ -444,11 +457,13 @@ TESTS = \
touch/fail-diag \
touch/fifo \
touch/no-create-missing \
touch/no-dereference \
touch/no-rights \
touch/not-owner \
touch/obsolescent \
touch/read-only \
touch/relative \
touch/trailing-slash \
$(root_tests)
pr_data = \

View File

@@ -24,7 +24,6 @@ fi
. $srcdir/test-lib.sh
require_membership_in_two_groups_
fail=0
set _ $groups; shift
g1=$1

View File

@@ -29,7 +29,6 @@ g2=$2
mkdir d && touch f && ln -s ../f d/s || framework_failure
fail=0
g_init=`stat --printf=%g f`
chgrp -R $g2 d || fail=1

View File

@@ -38,7 +38,6 @@ test "$g" = $g2 ||
skip_test_ "your system doesn't support changing the owner or group" \
"of a symbolic link."
fail=0
chgrp $g1 f
set _ `ls -ln f`; g=$5; test "$g" = $g1 || fail=1

View File

@@ -33,7 +33,6 @@ g2=$2
mkdir -p d/no-x/y || framework_failure
chmod u=rw d/no-x || framework_failure
fail=0
# This must exit nonzero.
chgrp -R $g2 d >/dev/null 2>out && fail=1

View File

@@ -34,7 +34,6 @@ ln -s 1 1s || framework_failure
ln -s ../3 2/2s || framework_failure
chgrp -R $g1 1 2 3 || framework_failure
fail=0
chgrp --preserve-root -H -R $g2 1s 2 || fail=1

View File

@@ -28,7 +28,6 @@ set _ $groups; shift
g1=$1
g2=$2
fail=0
# chgrp -R should not traverse a symlink to a directory.
mkdir d e

View File

@@ -30,7 +30,6 @@ chmod 444 $file || framework_failure
skip_if_setgid_
fail=0
chmod u=rwx $file || fail=1
chmod -c g=rwx $file > out || fail=1

View File

@@ -26,7 +26,6 @@ fi
file=f
touch $file || framework_failure
fail=0
umask 005
for mode in =x =xX =Xx =x,=X =X,=x; do
chmod a=r,$mode $file || fail=1

Some files were not shown because too many files have changed in this diff Show More