mirror of
https://git.savannah.gnu.org/git/coreutils.git
synced 2025-09-10 07:59:52 +02:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6c935a0554 | ||
|
|
3b7dc2b522 | ||
|
|
aeaa6bf7ae | ||
|
|
82e344ca09 | ||
|
|
2cd1577554 | ||
|
|
41c9e064a6 | ||
|
|
5f303a1293 | ||
|
|
2df272914b | ||
|
|
278109b9f4 | ||
|
|
0f3f7d495c | ||
|
|
4f87cc0364 | ||
|
|
18c5fbd5dc | ||
|
|
cf963e5a54 |
2
.gitattributes
vendored
2
.gitattributes
vendored
@@ -5,5 +5,3 @@
|
||||
# # Derived from the regexp in emacs' lisp/add-log.el.
|
||||
# [diff "texinfo"]
|
||||
# funcname = "^@node[ \t][ \t]*\\([^,][^,]*\\)"
|
||||
|
||||
gl/lib/*.diff -whitespace
|
||||
|
||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -3,7 +3,6 @@
|
||||
*.o
|
||||
*/.deps
|
||||
*~
|
||||
._bootmp
|
||||
.gdb-history
|
||||
.kludge-stamp
|
||||
.tarball-version
|
||||
@@ -48,13 +47,11 @@ 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
|
||||
@@ -75,5 +72,3 @@ src/version.c
|
||||
src/version.h
|
||||
stamp-h1
|
||||
tests/*/*.log
|
||||
tests/t?
|
||||
tests/test-suite.log
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
\.mk$
|
||||
/Makefile\.am$
|
||||
^tests/test-lib\.sh$
|
||||
@@ -1,3 +0,0 @@
|
||||
configure.ac
|
||||
*.m4
|
||||
ChangeLog*
|
||||
@@ -4,4 +4,3 @@ Makefile\.am$
|
||||
^tests/pr/
|
||||
ChangeLog.*
|
||||
^man/help2man$
|
||||
^gl/lib/.*\.c\.diff$
|
||||
|
||||
@@ -9,4 +9,3 @@ m4/lib-prefix.m4
|
||||
m4/po.m4
|
||||
aclocal.m4
|
||||
src/c99-to-c89.diff
|
||||
^gl/lib/.*\.c\.diff$
|
||||
|
||||
3
AUTHORS
3
AUTHORS
@@ -46,12 +46,11 @@ md5sum: Ulrich Drepper, Scott Miller, David Madore
|
||||
mkdir: David MacKenzie
|
||||
mkfifo: David MacKenzie
|
||||
mknod: David MacKenzie
|
||||
mktemp: Jim Meyering, Eric Blake
|
||||
mktemp: Jim Meyering
|
||||
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
|
||||
|
||||
@@ -47,8 +47,6 @@ 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 \
|
||||
|
||||
81
NEWS
81
NEWS
@@ -1,6 +1,6 @@
|
||||
GNU coreutils NEWS -*- outline -*-
|
||||
|
||||
* Noteworthy changes in release 8.1 (2009-11-18) [stable]
|
||||
* Noteworthy changes in release ?.? (????-??-??) [?]
|
||||
|
||||
** Bug fixes
|
||||
|
||||
@@ -8,94 +8,15 @@ GNU coreutils NEWS -*- outline -*-
|
||||
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]
|
||||
|
||||
|
||||
2
README
2
README
@@ -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
|
||||
nproc od paste pathchk pinky pr printenv printf ptx pwd readlink rm rmdir
|
||||
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
|
||||
|
||||
@@ -35,7 +35,7 @@ which are extracted from other source packages:
|
||||
|
||||
And there you are! Just
|
||||
|
||||
$ ./configure --quiet #[--enable-gcc-warnings] [*]
|
||||
$ ./configure #[--enable-gcc-warnings]
|
||||
$ make
|
||||
$ make check
|
||||
|
||||
@@ -48,12 +48,6 @@ 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.
|
||||
|
||||
@@ -29,10 +29,13 @@ FIXME: enable excluded programs like arch? to get their manual pages?
|
||||
|
||||
* Run "make distcheck"
|
||||
|
||||
* 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.,
|
||||
* Manually set the date, version number, and [stable/alpha/beta] on
|
||||
line 3 of NEWS, then do e.g.,:
|
||||
|
||||
build-aux/do-release-commit-and-tag 8.1 beta
|
||||
v=8.0
|
||||
pkg=$(sed -n 's/^PACKAGE = \(.*\)/\1/p' Makefile)
|
||||
git commit -F <(printf 'version '$v'\n\n* NEWS: Record release date.\n') -a
|
||||
git tag -s -m "$pkg $v" v$v HEAD
|
||||
|
||||
* Run the following to create release tarballs. Your choice selects the
|
||||
corresponding upload-to destination in the emitted gnupload command.
|
||||
@@ -76,7 +79,7 @@ Once all the builds and tests have passed,
|
||||
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)
|
||||
https://savannah.gnu.org/project/admin/editgroupfeatures.php?group=gzip)
|
||||
|
||||
Subject: coreutils-0.0 released [beta]
|
||||
The announcement is here:
|
||||
|
||||
8
THANKS
8
THANKS
@@ -52,7 +52,6 @@ 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
|
||||
@@ -211,7 +210,6 @@ 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
|
||||
@@ -248,7 +246,6 @@ 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
|
||||
@@ -265,7 +262,6 @@ 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
|
||||
@@ -372,7 +368,6 @@ 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
|
||||
@@ -402,7 +397,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
|
||||
@@ -544,7 +539,6 @@ 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
1
TODO
@@ -12,6 +12,7 @@ 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
|
||||
|
||||
|
||||
@@ -71,7 +71,6 @@ 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
|
||||
@@ -417,7 +416,7 @@ case ${GNULIB_SRCDIR--} in
|
||||
git_modules_config submodule.gnulib.url >/dev/null; then
|
||||
git submodule init
|
||||
GNULIB_SRCDIR=`cd $GNULIB_SRCDIR && pwd`
|
||||
git_modules_config --replace-all submodule.gnulib.url $GNULIB_SRCDIR
|
||||
git config --replace-all submodule.gnulib.url $GNULIB_SRCDIR
|
||||
echo "$0: getting gnulib files..."
|
||||
git submodule update || exit $?
|
||||
GNULIB_SRCDIR=gnulib
|
||||
@@ -734,7 +733,7 @@ find "$m4_base" "$source_base" \
|
||||
# Reconfigure, getting other files.
|
||||
|
||||
# Skip autoheader if it's not needed.
|
||||
grep -E '^[ ]*AC_CONFIG_HEADERS?\>' configure.ac >/dev/null ||
|
||||
grep '^[ ]*AC_CONFIG_HEADERS\>' configure.ac >/dev/null ||
|
||||
AUTOHEADER=true
|
||||
|
||||
for command in \
|
||||
|
||||
@@ -71,9 +71,7 @@ gnulib_modules="
|
||||
diacrit
|
||||
dirfd
|
||||
dirname
|
||||
do-release-commit-and-tag
|
||||
dup2
|
||||
environ
|
||||
error
|
||||
euidaccess
|
||||
exclude
|
||||
@@ -92,7 +90,6 @@ gnulib_modules="
|
||||
fopen-safer
|
||||
fprintftime
|
||||
freopen
|
||||
freopen-safer
|
||||
fseeko
|
||||
fsusage
|
||||
fsync
|
||||
@@ -130,7 +127,6 @@ gnulib_modules="
|
||||
inttostr
|
||||
inttypes
|
||||
isapipe
|
||||
isblank
|
||||
lchmod
|
||||
lchown
|
||||
lib-ignore
|
||||
@@ -160,7 +156,6 @@ gnulib_modules="
|
||||
modechange
|
||||
mountlist
|
||||
mpsort
|
||||
nproc
|
||||
obstack
|
||||
pathmax
|
||||
perl
|
||||
@@ -183,8 +178,8 @@ gnulib_modules="
|
||||
readutmp
|
||||
realloc
|
||||
regex
|
||||
remove
|
||||
rename
|
||||
rename-dest-slash
|
||||
rmdir
|
||||
root-dev-ino
|
||||
rpmatch
|
||||
@@ -220,7 +215,6 @@ gnulib_modules="
|
||||
unistd-safer
|
||||
unlink-busy
|
||||
unlocked-io
|
||||
unsetenv
|
||||
update-copyright
|
||||
uptime
|
||||
useless-if-before-free
|
||||
|
||||
31
cfg.mk
31
cfg.mk
@@ -191,18 +191,6 @@ 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.
|
||||
@@ -230,23 +218,4 @@ 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
|
||||
|
||||
15
configure.ac
15
configure.ac
@@ -106,7 +106,6 @@ 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])
|
||||
|
||||
@@ -114,16 +113,6 @@ 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
|
||||
@@ -429,10 +418,8 @@ 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.17])
|
||||
AM_GNU_GETTEXT_VERSION([0.15])
|
||||
|
||||
# For a test of uniq: it uses the $LOCALE_FR envvar.
|
||||
gt_LOCALE_FR
|
||||
|
||||
@@ -48,10 +48,8 @@ _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 \
|
||||
@@ -72,18 +70,9 @@ 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; }; \
|
||||
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)builtins?$(W_)' $(srcdir)/*.texi && fail=1; \
|
||||
$(EGREP) -i '$(_W)path(name)?s?$(W_)' $(srcdir)/*.texi \
|
||||
| $(EGREP) -v \
|
||||
'PATH=|path search|search path|@vindex PATH$$|@env[{]PATH[}]' \
|
||||
&& fail=1; \
|
||||
| $(EGREP) -v 'search path|@vindex PATH$$|@env[{]PATH[}]' && fail=1; \
|
||||
exit $$fail
|
||||
|
||||
# Use `time zone', not `timezone'.
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
@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
|
||||
@@ -79,12 +80,10 @@
|
||||
* 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.
|
||||
@@ -194,7 +193,7 @@ Free Documentation License''.
|
||||
* Printing text:: echo printf yes
|
||||
* Conditions:: false true test expr
|
||||
* Redirection:: tee
|
||||
* File name manipulation:: dirname basename pathchk mktemp
|
||||
* File name manipulation:: dirname basename pathchk
|
||||
* Working context:: pwd stty printenv tty
|
||||
* User information:: id logname whoami groups users who
|
||||
* System context:: date arch uname hostname hostid uptime
|
||||
@@ -379,7 +378,6 @@ 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
|
||||
|
||||
@@ -411,7 +409,6 @@ 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
|
||||
@@ -577,18 +574,6 @@ 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
|
||||
@@ -9870,9 +9855,7 @@ touch [@var{option}]@dots{} @var{file}@dots{}
|
||||
@end example
|
||||
|
||||
@cindex empty files, creating
|
||||
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.
|
||||
Any @var{file} argument that does not exist is created empty.
|
||||
|
||||
A @var{file} argument string of @samp{-} is handled specially and
|
||||
causes @command{touch} to change the times of the file associated with
|
||||
@@ -9886,8 +9869,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 standard third one as well: the inode change time. This is often
|
||||
referred to as a file's @code{ctime}.
|
||||
a 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
|
||||
@@ -9899,9 +9882,6 @@ 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}
|
||||
@@ -9930,7 +9910,7 @@ Change the access time only.
|
||||
@itemx --no-create
|
||||
@opindex -c
|
||||
@opindex --no-create
|
||||
Do not warn about or create files that do not exist.
|
||||
Do not create files that do not exist.
|
||||
|
||||
@item -d
|
||||
@itemx --date=@var{time}
|
||||
@@ -9951,24 +9931,6 @@ 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
|
||||
@@ -9988,8 +9950,6 @@ 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,
|
||||
@@ -10391,7 +10351,15 @@ 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}.
|
||||
|
||||
@optNull{du}
|
||||
@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.
|
||||
|
||||
@optSi
|
||||
|
||||
@@ -10803,8 +10771,6 @@ alert (bell)
|
||||
backspace
|
||||
@item \c
|
||||
produce no further output
|
||||
@item \e
|
||||
escape
|
||||
@item \f
|
||||
form feed
|
||||
@item \n
|
||||
@@ -11879,7 +11845,6 @@ 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
|
||||
|
||||
|
||||
@@ -12054,180 +12019,6 @@ 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
|
||||
@@ -12990,13 +12781,8 @@ 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 program accepts the following option. Also see @ref{Common options}.
|
||||
|
||||
@table @samp
|
||||
|
||||
@optNull{printenv}
|
||||
|
||||
@end table
|
||||
The only options are a lone @option{--help} or @option{--version}.
|
||||
@xref{Common options}.
|
||||
|
||||
@cindex exit status of @command{printenv}
|
||||
Exit status:
|
||||
@@ -13410,7 +13196,6 @@ 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.
|
||||
@@ -14070,43 +13855,6 @@ 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
|
||||
|
||||
@@ -14590,7 +14338,7 @@ device files), copy them into place, too.
|
||||
Exit status:
|
||||
|
||||
@display
|
||||
125 if @command{chroot} itself fails
|
||||
1 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
|
||||
@@ -14635,89 +14383,17 @@ 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
|
||||
@@ -14740,7 +14416,7 @@ Exit status:
|
||||
|
||||
@display
|
||||
0 if no @var{command} is specified and the environment is output
|
||||
125 if @command{env} itself fails
|
||||
1 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
|
||||
@@ -14815,7 +14491,7 @@ Exit status:
|
||||
|
||||
@display
|
||||
0 if no @var{command} is specified and the niceness is output
|
||||
125 if @command{nice} itself fails
|
||||
1 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
|
||||
@@ -14933,15 +14609,11 @@ 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 @var{command} cannot be found
|
||||
127 if @command{nohup} itself fails or 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
|
||||
@@ -15146,7 +14818,7 @@ shell is restricted (see @option{-m} just above).
|
||||
Exit status:
|
||||
|
||||
@display
|
||||
125 if @command{su} itself fails
|
||||
1 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
|
||||
|
||||
@@ -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 _UNUSED_PARAMETER_)
|
||||
size_t *width, mbs_align_t align, int flags)
|
||||
{
|
||||
size_t ret = -1;
|
||||
size_t src_size = strlen (src) + 1;
|
||||
|
||||
142
gl/lib/mgetgroups.c
Normal file
142
gl/lib/mgetgroups.c
Normal file
@@ -0,0 +1,142 @@
|
||||
/* 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;
|
||||
}
|
||||
19
gl/lib/mgetgroups.h
Normal file
19
gl/lib/mgetgroups.h
Normal file
@@ -0,0 +1,19 @@
|
||||
/* 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);
|
||||
@@ -1,82 +0,0 @@
|
||||
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;
|
||||
@@ -1,25 +0,0 @@
|
||||
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++)
|
||||
@@ -1,14 +0,0 @@
|
||||
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;
|
||||
@@ -1,45 +0,0 @@
|
||||
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);
|
||||
294
gl/lib/tempname.c
Normal file
294
gl/lib/tempname.c
Normal file
@@ -0,0 +1,294 @@
|
||||
/* 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);
|
||||
}
|
||||
@@ -1,193 +0,0 @@
|
||||
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);
|
||||
}
|
||||
42
gl/lib/tempname.h
Normal file
42
gl/lib/tempname.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/* 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);
|
||||
@@ -1,12 +0,0 @@
|
||||
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 */
|
||||
@@ -21,7 +21,6 @@
|
||||
#include "error.h"
|
||||
#include "exitfail.h"
|
||||
#include "quote.h"
|
||||
#include "stdio--.h"
|
||||
|
||||
#include "gettext.h"
|
||||
#define _(msgid) gettext (msgid)
|
||||
|
||||
11
gl/m4/mgetgroups.m4
Normal file
11
gl/m4/mgetgroups.m4
Normal file
@@ -0,0 +1,11 @@
|
||||
#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])
|
||||
])
|
||||
24
gl/modules/mgetgroups
Normal file
24
gl/modules/mgetgroups
Normal file
@@ -0,0 +1,24 @@
|
||||
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
|
||||
@@ -1,9 +0,0 @@
|
||||
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@
|
||||
@@ -8,7 +8,6 @@ lib/xfreopen.h
|
||||
Depends-on:
|
||||
error
|
||||
exitfail
|
||||
freopen-safer
|
||||
quote
|
||||
|
||||
configure.ac:
|
||||
|
||||
2
gnulib
2
gnulib
Submodule gnulib updated: 0883405cc7...959d9cb463
@@ -1,3 +1 @@
|
||||
include gnulib.mk
|
||||
|
||||
AM_CFLAGS = $(GNULIB_WARN_CFLAGS) # $(WERROR_CFLAGS)
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
include gnulib.mk
|
||||
|
||||
AM_CFLAGS += $(GNULIB_WARN_CFLAGS) $(WERROR_CFLAGS)
|
||||
AM_CFLAGS += $(WARN_CFLAGS) # $(WERROR_CFLAGS)
|
||||
|
||||
libcoreutils_a_SOURCES += \
|
||||
buffer-lcm.c buffer-lcm.h \
|
||||
|
||||
@@ -130,6 +130,6 @@ main (int argc, char **argv)
|
||||
|
||||
ok = euidaccess_stat (&st, mode);
|
||||
printf ("%s: %s\n", file, ok ? "y" : "n");
|
||||
return 0;
|
||||
exit (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
19
lib/xfts.c
19
lib/xfts.c
@@ -61,22 +61,3 @@ 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));
|
||||
}
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
#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);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#serial 26
|
||||
#serial 25
|
||||
# Check declarations for this package.
|
||||
|
||||
dnl Copyright (C) 1997-2001, 2003-2006, 2008-2009 Free Software
|
||||
@@ -35,6 +35,8 @@ AC_DEFUN([gl_CHECK_DECLS],
|
||||
getpwuid,
|
||||
ttyname], , , $headers)
|
||||
|
||||
AC_CHECK_DECLS([isblank], [], [], [#include <ctype.h>])
|
||||
|
||||
AC_CHECK_DECLS_ONCE([geteuid])
|
||||
AC_CHECK_DECLS_ONCE([getlogin])
|
||||
AC_CHECK_DECLS_ONCE([getuid])
|
||||
|
||||
@@ -30,9 +30,7 @@ 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
|
||||
])
|
||||
|
||||
@@ -94,7 +94,6 @@ AC_DEFUN([coreutils_MACROS],
|
||||
|
||||
# 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])
|
||||
@@ -116,8 +115,7 @@ 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.])
|
||||
AC_MSG_WARN([AC_PACKAGE_NAME will be built without capability support.])
|
||||
AC_MSG_WARN([libcap library was not found or not usable, support for libcap will not be built])
|
||||
fi
|
||||
fi
|
||||
else
|
||||
|
||||
@@ -51,7 +51,6 @@ $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" ||
|
||||
|
||||
@@ -22,12 +22,9 @@ 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
1
man/.gitignore
vendored
@@ -48,7 +48,6 @@ mv.1
|
||||
nice.1
|
||||
nl.1
|
||||
nohup.1
|
||||
nproc.1
|
||||
od.1
|
||||
paste.1
|
||||
pathchk.1
|
||||
|
||||
@@ -80,7 +80,6 @@ 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
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
[NAME]
|
||||
nproc \- print the number of processing units available
|
||||
[DESCRIPTION]
|
||||
.\" Add any additional description here
|
||||
@@ -89,7 +89,6 @@ 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
1
src/.gitignore
vendored
@@ -56,7 +56,6 @@ mv
|
||||
nice
|
||||
nl
|
||||
nohup
|
||||
nproc
|
||||
od
|
||||
paste
|
||||
pathchk
|
||||
|
||||
@@ -86,7 +86,6 @@ EXTRA_PROGRAMS = \
|
||||
mktemp \
|
||||
mv \
|
||||
nl \
|
||||
nproc \
|
||||
nohup \
|
||||
od \
|
||||
paste \
|
||||
@@ -190,7 +189,6 @@ chown_LDADD = $(LDADD)
|
||||
chroot_LDADD = $(LDADD)
|
||||
cksum_LDADD = $(LDADD)
|
||||
comm_LDADD = $(LDADD)
|
||||
nproc_LDADD = $(LDADD)
|
||||
cp_LDADD = $(LDADD)
|
||||
csplit_LDADD = $(LDADD)
|
||||
cut_LDADD = $(LDADD)
|
||||
@@ -482,7 +480,6 @@ 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)
|
||||
@@ -541,7 +538,6 @@ 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
|
||||
@@ -551,34 +547,24 @@ 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) \
|
||||
-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/CIFS_MAGIC_NUMBER/CIFS/;' \
|
||||
-e 's/(_SUPER)?_MAGIC//;' \
|
||||
-e 's/\s+0x(\S+)/" 0x" . uc $$1/e;' \
|
||||
-e 's/^\s+//;' \
|
||||
-e 's/^_(XIAFS)/$$1/;' \
|
||||
-e 's/^USBDEVICE/USBDEVFS/;' \
|
||||
-e 's/NTFS_SB/NTFS/;' \
|
||||
-e 's/^/# define S_MAGIC_/;' \
|
||||
-e 's,\s*/\* .*? \*/,,;' \
|
||||
| grep -Ev 'S_MAGIC_EXT[34]|STACK_END' \
|
||||
| LC_ALL=C sort \
|
||||
> $@-t && mv $@-t $@
|
||||
@@ -587,7 +573,20 @@ 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) \
|
||||
-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/(_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/^#define\s+//;' \
|
||||
-e 's/^USBDEVICE/USBDEVFS/;' \
|
||||
-e 's/^/# define S_MAGIC_/;' \
|
||||
-e 's,\s*/\* .*? \*/,,;' \
|
||||
| grep -Ev 'S_MAGIC_EXT[34]|STACK_END' \
|
||||
| LC_ALL=C sort \
|
||||
> $@-t && mv $@-t $@
|
||||
|
||||
231
src/README-rm-timing-2
Normal file
231
src/README-rm-timing-2
Normal file
@@ -0,0 +1,231 @@
|
||||
#!/bin/bash
|
||||
# Demonstrate >5X speed-up in using fts-based rm on ext4
|
||||
# Demonstrate 1.5X speed-up in using fts-based rm on reiserfs
|
||||
|
||||
set -x
|
||||
|
||||
a=$(printf %031d 0)
|
||||
b=$(printf %031d 1)
|
||||
(mkdir $a \
|
||||
&& cd $a \
|
||||
&& seq --format=%031g 10000 |xargs touch \
|
||||
&& seq --format=d%030g 10000 |xargs mkdir ) || framework_failure
|
||||
cp -al $a $b || framework_failure
|
||||
mkdir e || framework_failure
|
||||
mv $a $b e || framework_failure
|
||||
|
||||
cp -a e 1
|
||||
cp -a e 2
|
||||
|
||||
sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'
|
||||
env time /p/bin/rm -rf 1
|
||||
env time /cu/src/rm -rf 2
|
||||
|
||||
cp -a e 1
|
||||
cp -a e 2
|
||||
|
||||
|
||||
sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'
|
||||
env time cu/src/rm -rf 2
|
||||
env time /p/bin/rm -rf 1
|
||||
|
||||
########################################################################
|
||||
# on ext4
|
||||
# + env time /p/bin/rm -rf 1
|
||||
# 0.19user 12.09system 0:14.42elapsed 85%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 0inputs+0outputs (0major+212minor)pagefaults 0swaps
|
||||
# + env time /cu/src/rm -rf 2
|
||||
# 0.13user 0.93system 0:01.08elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 0inputs+0outputs (0major+1235minor)pagefaults 0swaps
|
||||
# + cp -a e 1
|
||||
# + cp -a e 2
|
||||
# + env time /cu/src/rm -rf 2
|
||||
# 0.12user 0.94system 0:01.07elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 0inputs+0outputs (0major+1236minor)pagefaults 0swaps
|
||||
# + env time /p/bin/rm -rf 1
|
||||
# 0.19user 12.08system 0:12.33elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 0inputs+0outputs (0major+212minor)pagefaults 0swaps
|
||||
|
||||
# on reiserfs:
|
||||
# + env time /p/bin/rm -rf 1
|
||||
# 0.30user 4.16system 0:04.49elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 0inputs+0outputs (0major+168minor)pagefaults 0swaps
|
||||
# + env time /cu/src/rm -rf 2
|
||||
# 0.21user 2.47system 0:02.88elapsed 93%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 0inputs+80outputs (0major+1199minor)pagefaults 0swaps
|
||||
# + cp -a e 1
|
||||
# + cp -a e 2
|
||||
# + env time /cu/src/rm -rf 2
|
||||
# 0.19user 2.56system 0:02.76elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 0inputs+0outputs (0major+1200minor)pagefaults 0swaps
|
||||
# + env time /p/bin/rm -rf 1
|
||||
# 0.29user 4.17system 0:04.55elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 0inputs+0outputs (0major+168minor)pagefaults 0swaps
|
||||
|
||||
########################################################################
|
||||
# on xfs, F11, slow-disk laptop: (shows slight improvement)
|
||||
# iou$ bash /cu/src/README-rm-timing-2 :
|
||||
# ++ printf %031d 0
|
||||
# + a=0000000000000000000000000000000
|
||||
# ++ printf %031d 1
|
||||
# + b=0000000000000000000000000000001
|
||||
# + mkdir 0000000000000000000000000000000
|
||||
# + cd 0000000000000000000000000000000
|
||||
# + xargs touch
|
||||
# + seq --format=%031g 10000
|
||||
# + seq --format=d%030g 10000
|
||||
# + xargs mkdir
|
||||
# + cp -al 0000000000000000000000000000000 0000000000000000000000000000001
|
||||
# + mkdir e
|
||||
# + mv 0000000000000000000000000000000 0000000000000000000000000000001 e
|
||||
# + cp -a e 1
|
||||
# + cp -a e 2
|
||||
# + sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'
|
||||
# + env time /p/bin/rm -rf 1
|
||||
# 1.06user 12.10system 1:41.96elapsed 12%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 16368inputs+0outputs (1major+175minor)pagefaults 0swaps
|
||||
# + env time /cu/src/rm -rf 2
|
||||
# 0.57user 5.47system 1:32.69elapsed 6%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 20112inputs+0outputs (1major+1214minor)pagefaults 0swaps
|
||||
# + cp -a e 1
|
||||
# + cp -a e 2
|
||||
# + sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'
|
||||
# + env time /cu/src/rm -rf 2
|
||||
# 0.54user 5.34system 1:28.43elapsed 6%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 19032inputs+0outputs (1major+1198minor)pagefaults 0swaps
|
||||
# + env time /p/bin/rm -rf 1
|
||||
# 0.99user 12.36system 1:37.36elapsed 13%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 20256inputs+0outputs (1major+174minor)pagefaults 0swaps
|
||||
|
||||
########################################################################
|
||||
# on btrfs, F11, slow-disk laptop: (shows 7-8X speed-up)
|
||||
# iou$ env time bash /cu/src/README-rm-timing-2 :
|
||||
# ++ printf %031d 0
|
||||
# + a=0000000000000000000000000000000
|
||||
# ++ printf %031d 1
|
||||
# + b=0000000000000000000000000000001
|
||||
# + mkdir 0000000000000000000000000000000
|
||||
# + cd 0000000000000000000000000000000
|
||||
# + seq --format=%031g 10000
|
||||
# + xargs touch
|
||||
# + seq --format=d%030g 10000
|
||||
# + xargs mkdir
|
||||
# + cp -al 0000000000000000000000000000000 0000000000000000000000000000001
|
||||
# + mkdir e
|
||||
# + mv 0000000000000000000000000000000 0000000000000000000000000000001 e
|
||||
# + cp -a e 1
|
||||
# + cp -a e 2
|
||||
# + sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'
|
||||
# + env time /p/bin/rm -rf 1
|
||||
# 0.51user 59.42system 1:09.73elapsed 85%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 43536inputs+82536outputs (1major+425minor)pagefaults 0swaps
|
||||
# + env time /cu/src/rm -rf 2
|
||||
# 0.26user 8.01system 0:08.50elapsed 97%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 808inputs+54984outputs (1major+1199minor)pagefaults 0swaps
|
||||
# + cp -a e 1
|
||||
# + cp -a e 2
|
||||
# + sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'
|
||||
# 0.26user 8.31system 0:09.17elapsed 93%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 976inputs+47744outputs (1major+1197minor)pagefaults 0swaps
|
||||
# + env time /p/bin/rm -rf 1
|
||||
# 0.48user 57.83system 1:04.81elapsed 89%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 27408inputs+75632outputs (1major+423minor)pagefaults 0swaps
|
||||
# ---
|
||||
# 5.60user 214.36system 4:14.11elapsed 86%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 131544inputs+551320outputs (83major+15945minor)pagefaults 0swaps
|
||||
|
||||
########################################################################
|
||||
# on reiserfs, F11, slow-disk laptop: (shows ~4X speed-up)
|
||||
# but notice total test time: just 51s, compared with 4:11 for btrfs above.
|
||||
# iou$ env time bash /cu/src/README-rm-timing-2 :
|
||||
# ++ printf %031d 0
|
||||
# + a=0000000000000000000000000000000
|
||||
# ++ printf %031d 1
|
||||
# + b=0000000000000000000000000000001
|
||||
# + mkdir 0000000000000000000000000000000
|
||||
# + cd 0000000000000000000000000000000
|
||||
# + seq --format=%031g 10000
|
||||
# + xargs touch
|
||||
# + seq --format=d%030g 10000
|
||||
# + xargs mkdir
|
||||
# + cp -al 0000000000000000000000000000000 0000000000000000000000000000001
|
||||
# + mkdir e
|
||||
# + mv 0000000000000000000000000000000 0000000000000000000000000000001 e
|
||||
# + cp -a e 1
|
||||
# + cp -a e 2
|
||||
# + sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'
|
||||
# + env time /p/bin/rm -rf 1
|
||||
# 0.48user 9.79system 0:10.33elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 256inputs+0outputs (1major+191minor)pagefaults 0swaps
|
||||
# + env time /cu/src/rm -rf 2
|
||||
# 0.25user 2.15system 0:02.50elapsed 96%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 808inputs+0outputs (1major+1198minor)pagefaults 0swaps
|
||||
# + cp -a e 1
|
||||
# + cp -a e 2
|
||||
# + sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'
|
||||
# + env time /cu/src/rm -rf 2
|
||||
# 0.26user 2.10system 0:02.46elapsed 95%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 808inputs+0outputs (1major+1198minor)pagefaults 0swaps
|
||||
# + env time /p/bin/rm -rf 1
|
||||
# 0.44user 9.89system 0:10.41elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 264inputs+0outputs (1major+176minor)pagefaults 0swaps
|
||||
# ---
|
||||
# 4.48user 42.92system 0:51.14elapsed 92%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 21680inputs+54232outputs (86major+16962minor)pagefaults 0swaps
|
||||
|
||||
########################################################################
|
||||
# on ext2, F11, slow-disk laptop: (shows ~4X speed-up)
|
||||
# iou$ env time bash /cu/src/README-rm-timing-2 :
|
||||
# ++ printf %031d 0
|
||||
# + a=0000000000000000000000000000000
|
||||
# ++ printf %031d 1
|
||||
# + b=0000000000000000000000000000001
|
||||
# + mkdir 0000000000000000000000000000000
|
||||
# + cd 0000000000000000000000000000000
|
||||
# + seq --format=%031g 10000
|
||||
# + xargs touch
|
||||
# + seq --format=d%030g 10000
|
||||
# + xargs mkdir
|
||||
# + cp -al 0000000000000000000000000000000 0000000000000000000000000000001
|
||||
# + mkdir e
|
||||
# + mv 0000000000000000000000000000000 0000000000000000000000000000001 e
|
||||
# + cp -a e 1
|
||||
# + cp -a e 2
|
||||
# + sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'
|
||||
# + env time /p/bin/rm -rf 1
|
||||
# 1.02user 15.25system 0:30.76elapsed 52%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 178888inputs+19144outputs (1major+423minor)pagefaults 0swaps
|
||||
# + env time /cu/src/rm -rf 2
|
||||
# 0.40user 2.30system 0:05.99elapsed 45%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 83088inputs+18480outputs (1major+1199minor)pagefaults 0swaps
|
||||
# + cp -a e 1
|
||||
# + cp -a e 2
|
||||
# + sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'
|
||||
# + env time /cu/src/rm -rf 2
|
||||
# 0.38user 2.83system 0:08.18elapsed 39%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 85848inputs+16024outputs (1major+1199minor)pagefaults 0swaps
|
||||
# + env time /p/bin/rm -rf 1
|
||||
# 0.84user 15.24system 0:25.28elapsed 63%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 178656inputs+18728outputs (1major+423minor)pagefaults 0swaps
|
||||
# ---
|
||||
# 6.73user 263.32system 5:27.69elapsed 82%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 780296inputs+891712outputs (86major+17155minor)pagefaults 0swaps
|
||||
|
||||
########################################################################
|
||||
# on tmpfs, F11, slow-disk laptop: (shows ~4X speed-up)
|
||||
# + sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'
|
||||
# + env time /p/bin/rm -rf 1
|
||||
# 0.37user 2.47system 0:03.10elapsed 91%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 256inputs+0outputs (1major+175minor)pagefaults 0swaps
|
||||
# + env time /cu/src/rm -rf 2
|
||||
# 0.23user 0.41system 0:00.76elapsed 85%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 520inputs+0outputs (1major+2092minor)pagefaults 0swaps
|
||||
# + cp -a e 1
|
||||
# + cp -a e 2
|
||||
# + sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'
|
||||
# + env time /cu/src/rm -rf 2
|
||||
# 0.24user 0.41system 0:00.73elapsed 89%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 800inputs+0outputs (1major+2090minor)pagefaults 0swaps
|
||||
# + env time /p/bin/rm -rf 1
|
||||
# 0.36user 2.47system 0:02.86elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
# 256inputs+0outputs (1major+175minor)pagefaults 0swaps
|
||||
297
src/README-rm-timing-compare
Normal file
297
src/README-rm-timing-compare
Normal file
@@ -0,0 +1,297 @@
|
||||
==================================================
|
||||
[SSD: it's a toss-up, when removing a million-file (1000 per dir) tree
|
||||
on (sdd-ocz-summit-120G, F11, x86_64, lots of RAM)
|
||||
$ z-mktree --root=z --depth=2 --b=1000;env time /p/bin/rm -rf z
|
||||
0.50user 13.99system 0:17.83elapsed 81%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
0inputs+0outputs (0major+10834minor)pagefaults 0swaps
|
||||
$ z-mktree --root=z --depth=2 --b=1000;env time src/rm -rf z
|
||||
0.52user 13.88system 0:17.41elapsed 82%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
0inputs+8outputs (0major+10835minor)pagefaults 0swaps
|
||||
|
||||
==================================================
|
||||
on (tmpfs, F11, x86_64, lots of RAM)
|
||||
/t, with very deep, narrow tree, new rm is >20% faster:
|
||||
$ z-mkdir 1000000
|
||||
$ env time /p/bin/rm -rf $TMPDIR/z
|
||||
6.25user 12.88system 0:19.22elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
0inputs+0outputs (0major+70976minor)pagefaults 0swaps
|
||||
$ z-mkdir 1000000
|
||||
env time /bin/rm -rf $TMPDIR/z
|
||||
$ env time /bin/rm -rf $TMPDIR/z
|
||||
11.06user 14.32system 0:25.43elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
56inputs+0outputs (1major+79999minor)pagefaults 0swaps
|
||||
|
||||
*** slow*DOWN* of ~4% on a 1-1Kdir-1M-file (1k-files-per-dir) hierarchy
|
||||
again, this is on tmpfs:
|
||||
$ z-mktree --root=/t/z --depth=2 --b=1000;strace -c /p/bin/rm -rf /t/z
|
||||
vv$ z-mktree --root=/t/z --depth=2 --b=1000;env time /cu/src/rm -rf /t/z
|
||||
0.29user 2.75system 0:03.06elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
0inputs+0outputs (0major+10834minor)pagefaults 0swaps
|
||||
$ z-mktree --root=/t/z --depth=2 --b=1000;env time /p/p/coreutils-7.5/bin/rm -rf /t/z
|
||||
0.14user 2.76system 0:02.92elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
0inputs+0outputs (0major+184minor)pagefaults 0swaps
|
||||
|
||||
|
||||
==================================================
|
||||
|
||||
[old rm]
|
||||
iou$ z-mktree --root=/t/z --depth=2 --b=1000;strace -c /p/bin/rm -rf /t/z
|
||||
% time seconds usecs/call calls errors syscall
|
||||
------ ----------- ----------- --------- --------- ----------------
|
||||
90.66 0.086370 0 1001002 1 unlinkat
|
||||
8.72 0.008310 1 10002 getdents64
|
||||
0.22 0.000214 0 2001 openat
|
||||
0.20 0.000188 0 2021 close
|
||||
0.09 0.000089 0 6019 fstat64
|
||||
0.08 0.000073 0 6003 fcntl64
|
||||
0.03 0.000028 1 29 12 open
|
||||
0.00 0.000000 0 4 read
|
||||
0.00 0.000000 0 1 execve
|
||||
0.00 0.000000 0 1000 lseek
|
||||
0.00 0.000000 0 3 3 access
|
||||
0.00 0.000000 0 3 brk
|
||||
0.00 0.000000 0 1 ioctl
|
||||
0.00 0.000000 0 2 munmap
|
||||
0.00 0.000000 0 4 mprotect
|
||||
0.00 0.000000 0 19 mmap2
|
||||
0.00 0.000000 0 1 lstat64
|
||||
0.00 0.000000 0 1 set_thread_area
|
||||
0.00 0.000000 0 1 fstatat64
|
||||
------ ----------- ----------- --------- --------- ----------------
|
||||
100.00 0.095272 1028117 16 total
|
||||
|
||||
|
||||
[new, fts-based rm]
|
||||
iou$ z-mktree --root=/t/z --depth=2 --b=1000;strace -c ./rm -rf /t/z
|
||||
% time seconds usecs/call calls errors syscall
|
||||
------ ----------- ----------- --------- --------- ----------------
|
||||
95.88 0.122730 0 1001001 unlinkat
|
||||
3.95 0.005058 1 7007 getdents64
|
||||
0.10 0.000126 0 2022 close
|
||||
0.05 0.000064 0 1001 openat
|
||||
0.02 0.000020 0 1017 fstat64
|
||||
0.00 0.000000 0 4 read
|
||||
0.00 0.000000 0 29 12 open
|
||||
0.00 0.000000 0 1 execve
|
||||
0.00 0.000000 0 3 3 access
|
||||
0.00 0.000000 0 510 brk
|
||||
0.00 0.000000 0 1 ioctl
|
||||
0.00 0.000000 0 2 munmap
|
||||
0.00 0.000000 0 4 mprotect
|
||||
0.00 0.000000 0 19 mmap2
|
||||
0.00 0.000000 0 1 lstat64
|
||||
0.00 0.000000 0 3003 fcntl64
|
||||
0.00 0.000000 0 1 set_thread_area
|
||||
0.00 0.000000 0 1001 fstatat64
|
||||
------ ----------- ----------- --------- --------- ----------------
|
||||
100.00 0.127998 1016627 15 total
|
||||
iou$ export LC_ALL=C cu:198-rm-fts
|
||||
iou$ z-mktree --root=/t/z --depth=2 --b=1000;strace -c ./rm -rf /t/z
|
||||
% time seconds usecs/call calls errors syscall
|
||||
------ ----------- ----------- --------- --------- ----------------
|
||||
93.49 0.110607 0 1001001 unlinkat
|
||||
6.32 0.007475 1 7007 getdents64
|
||||
0.10 0.000124 0 1001 fstatat64
|
||||
0.06 0.000068 0 479 brk
|
||||
0.02 0.000018 0 2008 close
|
||||
0.01 0.000015 0 3003 fcntl64
|
||||
0.00 0.000000 0 2 read
|
||||
0.00 0.000000 0 3 open
|
||||
0.00 0.000000 0 1 execve
|
||||
0.00 0.000000 0 3 3 access
|
||||
0.00 0.000000 0 1 ioctl
|
||||
0.00 0.000000 0 1 munmap
|
||||
0.00 0.000000 0 4 mprotect
|
||||
0.00 0.000000 0 6 mmap2
|
||||
0.00 0.000000 0 1 lstat64
|
||||
0.00 0.000000 0 1003 fstat64
|
||||
0.00 0.000000 0 1 set_thread_area
|
||||
0.00 0.000000 0 1001 openat
|
||||
------ ----------- ----------- --------- --------- ----------------
|
||||
100.00 0.118307 1016526 3 total
|
||||
|
||||
iou$ z-mktree --root=/t/z --depth=2 --b=1000;strace -c /p/bin/rm -rf /t/z
|
||||
% time seconds usecs/call calls errors syscall
|
||||
------ ----------- ----------- --------- --------- ----------------
|
||||
92.87 0.107659 0 1001002 1 unlinkat
|
||||
6.59 0.007641 1 10002 getdents64
|
||||
0.22 0.000252 0 2001 openat
|
||||
0.15 0.000179 0 6005 fstat64
|
||||
0.10 0.000113 0 6003 fcntl64
|
||||
0.05 0.000054 0 1000 lseek
|
||||
0.02 0.000027 0 2007 close
|
||||
0.00 0.000000 0 2 read
|
||||
0.00 0.000000 0 3 open
|
||||
0.00 0.000000 0 1 execve
|
||||
0.00 0.000000 0 3 3 access
|
||||
0.00 0.000000 0 3 brk
|
||||
0.00 0.000000 0 1 ioctl
|
||||
0.00 0.000000 0 1 munmap
|
||||
0.00 0.000000 0 4 mprotect
|
||||
0.00 0.000000 0 6 mmap2
|
||||
0.00 0.000000 0 1 lstat64
|
||||
0.00 0.000000 0 1 set_thread_area
|
||||
0.00 0.000000 0 1 fstatat64
|
||||
------ ----------- ----------- --------- --------- ----------------
|
||||
100.00 0.115925 1028047 4 total
|
||||
|
||||
**********************************************************************
|
||||
iou$ z-mktree --root=/t/z --depth=2 --b=1000;env time /p/bin/rm -rf /t/z
|
||||
0.16user 3.35system 0:03.68elapsed 95%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
0inputs+0outputs (0major+166minor)pagefaults 0swaps
|
||||
iou$ z-mktree --root=/t/z --depth=2 --b=1000;env time /p/bin/rm -rf /t/z
|
||||
0.16user 3.12system 0:03.34elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
0inputs+0outputs (0major+166minor)pagefaults 0swaps
|
||||
iou$ z-mktree --root=/t/z --depth=2 --b=1000;env time /p/bin/rm -rf /t/z
|
||||
0.14user 3.12system 0:03.26elapsed 100%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
0inputs+0outputs (0major+167minor)pagefaults 0swaps
|
||||
iou$ z-mktree --root=/t/z --depth=2 --b=1000;env time /p/bin/rm -rf /t/z
|
||||
0.12user 2.98system 0:03.17elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
0inputs+0outputs (0major+167minor)pagefaults 0swaps
|
||||
|
||||
|
||||
iou$ z-mktree --root=/t/z --depth=2 --b=1000;env time ./rm -rf /t/z
|
||||
0.68user 3.08system 0:03.76elapsed 100%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
0inputs+0outputs (0major+1566minor)pagefaults 0swaps
|
||||
iou$ z-mktree --root=/t/z --depth=2 --b=1000;env time ./rm -rf /t/z
|
||||
0.64user 3.12system 0:03.79elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
0inputs+0outputs (0major+1565minor)pagefaults 0swaps
|
||||
iou$ z-mktree --root=/t/z --depth=2 --b=1000;env time ./rm -rf /t/z
|
||||
0.60user 3.09system 0:03.78elapsed 97%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
0inputs+0outputs (0major+1566minor)pagefaults 0swaps
|
||||
|
||||
************************************************************************
|
||||
************************************************************************
|
||||
|
||||
The above are relatively normal hierarchies.
|
||||
Here is one that is extreme (/t is a tmpfs file system):
|
||||
[shows that fts-based rm takes 20-25% more time than the old one]
|
||||
|
||||
iou$ mkdir .j && (cd .j && seq 1000000|xargs touch)
|
||||
|
||||
iou$ env time ./rm -rf /t/.j cu:198-rm-fts
|
||||
0.10user 0.41system 0:00.59elapsed 87%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
256inputs+0outputs (1major+4459minor)pagefaults 0swaps
|
||||
iou$ env time ./rm -rf /t/.j cu:198-rm-fts
|
||||
0.82user 3.48system 0:04.35elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
256inputs+0outputs (1major+43130minor)pagefaults 0swaps
|
||||
iou$ env time /p/bin/rm -rf /t/.j cu:198-rm-fts
|
||||
0.14user 3.02system 0:03.25elapsed 97%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
256inputs+0outputs (1major+164minor)pagefaults 0swaps
|
||||
iou$ env time strace -c /p/bin/rm -rf /t/.j cu:198-rm-fts
|
||||
% time seconds usecs/call calls errors syscall
|
||||
------ ----------- ----------- --------- --------- ----------------
|
||||
95.49 0.122568 0 1000002 1 unlinkat
|
||||
4.51 0.005785 1 7797 getdents64
|
||||
0.00 0.000000 0 2 read
|
||||
0.00 0.000000 0 3 open
|
||||
0.00 0.000000 0 7 close
|
||||
0.00 0.000000 0 1 execve
|
||||
0.00 0.000000 0 1 lseek
|
||||
0.00 0.000000 0 3 3 access
|
||||
0.00 0.000000 0 3 brk
|
||||
0.00 0.000000 0 1 ioctl
|
||||
0.00 0.000000 0 1 munmap
|
||||
0.00 0.000000 0 4 mprotect
|
||||
0.00 0.000000 0 6 mmap2
|
||||
0.00 0.000000 0 1 lstat64
|
||||
0.00 0.000000 0 5 fstat64
|
||||
0.00 0.000000 0 3 fcntl64
|
||||
0.00 0.000000 0 1 set_thread_area
|
||||
0.00 0.000000 0 1 fstatfs64
|
||||
0.00 0.000000 0 1 openat
|
||||
0.00 0.000000 0 1 fstatat64
|
||||
------ ----------- ----------- --------- --------- ----------------
|
||||
100.00 0.128353 1007844 4 total
|
||||
2.96user 21.57system 0:24.80elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
8inputs+0outputs (0major+406minor)pagefaults 0swaps
|
||||
iou$ env time strace -c ./rm -rf /t/.j cu:198-rm-fts
|
||||
% time seconds usecs/call calls errors syscall
|
||||
------ ----------- ----------- --------- --------- ----------------
|
||||
83.46 0.160976 0 1000001 unlinkat
|
||||
14.54 0.028036 21 1306 brk
|
||||
2.01 0.003873 0 7795 getdents64
|
||||
0.00 0.000000 0 2 read
|
||||
0.00 0.000000 0 3 open
|
||||
0.00 0.000000 0 8 close
|
||||
0.00 0.000000 0 1 execve
|
||||
0.00 0.000000 0 3 3 access
|
||||
0.00 0.000000 0 1 ioctl
|
||||
0.00 0.000000 0 1 munmap
|
||||
0.00 0.000000 0 4 mprotect
|
||||
0.00 0.000000 0 6 mmap2
|
||||
0.00 0.000000 0 1 lstat64
|
||||
0.00 0.000000 0 3 fstat64
|
||||
0.00 0.000000 0 3 fcntl64
|
||||
0.00 0.000000 0 1 set_thread_area
|
||||
0.00 0.000000 0 1 fstatfs64
|
||||
0.00 0.000000 0 1 openat
|
||||
0.00 0.000000 0 1 fstatat64
|
||||
------ ----------- ----------- --------- --------- ----------------
|
||||
100.00 0.192885 1009142 3 total
|
||||
3.86user 22.06system 0:26.30elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
0inputs+0outputs (0major+43371minor)pagefaults 0swaps
|
||||
|
||||
======================================================
|
||||
# On a faster system, the new fts-based rm still takes a 20% perf. hit,
|
||||
# probably due to malloc (ab)use, just like above. Yep, sure looks like it.
|
||||
# in /tmpfs, /t
|
||||
mkdir .j && (cd .j && seq 1000000|xargs touch)
|
||||
vv$ env time /p/p/coreutils-7.5/bin/rm -rf .j
|
||||
0.14user 2.81system 0:02.98elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
264inputs+0outputs (1major+174minor)pagefaults 0swaps
|
||||
vv$ cd /t; env time /cu/src/rm -rf .j
|
||||
0.38user 3.17system 0:03.57elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
|
||||
0inputs+0outputs (0major+70489minor)pagefaults 0swaps
|
||||
|
||||
vv$ strace -c /p/p/coreutils-7.5/bin/rm -rf .j
|
||||
% time seconds usecs/call calls errors syscall
|
||||
------ ----------- ----------- --------- --------- ----------------
|
||||
66.41 0.081223 0 1000002 1 unlinkat
|
||||
33.43 0.040887 42 978 getdents
|
||||
0.16 0.000199 199 1 execve
|
||||
0.00 0.000000 0 1 read
|
||||
0.00 0.000000 0 3 open
|
||||
0.00 0.000000 0 7 close
|
||||
0.00 0.000000 0 6 fstat
|
||||
0.00 0.000000 0 1 lstat
|
||||
0.00 0.000000 0 1 lseek
|
||||
0.00 0.000000 0 9 mmap
|
||||
0.00 0.000000 0 3 mprotect
|
||||
0.00 0.000000 0 1 munmap
|
||||
0.00 0.000000 0 3 brk
|
||||
0.00 0.000000 0 1 ioctl
|
||||
0.00 0.000000 0 1 1 access
|
||||
0.00 0.000000 0 3 fcntl
|
||||
0.00 0.000000 0 1 fstatfs
|
||||
0.00 0.000000 0 1 arch_prctl
|
||||
0.00 0.000000 0 1 openat
|
||||
0.00 0.000000 0 1 newfstatat
|
||||
------ ----------- ----------- --------- --------- ----------------
|
||||
100.00 0.122309 1001025 2 total
|
||||
|
||||
|
||||
vv$ cd /t; strace -c /cu/src/rm -rf .j
|
||||
% time seconds usecs/call calls errors syscall
|
||||
------ ----------- ----------- --------- --------- ----------------
|
||||
51.26 0.087638 0 1000001 unlinkat
|
||||
26.49 0.045291 46 976 getdents
|
||||
22.24 0.038024 18 2134 brk
|
||||
0.00 0.000000 0 1 read
|
||||
0.00 0.000000 0 3 open
|
||||
0.00 0.000000 0 8 close
|
||||
0.00 0.000000 0 4 fstat
|
||||
0.00 0.000000 0 1 lstat
|
||||
0.00 0.000000 0 9 mmap
|
||||
0.00 0.000000 0 3 mprotect
|
||||
0.00 0.000000 0 1 munmap
|
||||
0.00 0.000000 0 1 ioctl
|
||||
0.00 0.000000 0 1 1 access
|
||||
0.00 0.000000 0 1 execve
|
||||
0.00 0.000000 0 3 fcntl
|
||||
0.00 0.000000 0 1 fstatfs
|
||||
0.00 0.000000 0 1 arch_prctl
|
||||
0.00 0.000000 0 1 openat
|
||||
0.00 0.000000 0 1 newfstatat
|
||||
------ ----------- ----------- --------- --------- ----------------
|
||||
100.00 0.170953 1003151 1 total
|
||||
10
src/chcon.c
10
src/chcon.c
@@ -267,14 +267,6 @@ 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;
|
||||
}
|
||||
@@ -554,7 +546,7 @@ main (int argc, char **argv)
|
||||
if (reference_file && component_specified)
|
||||
{
|
||||
error (0, 0, _("conflicting security context specifiers given"));
|
||||
usage (EXIT_FAILURE);
|
||||
usage (1);
|
||||
}
|
||||
|
||||
if (recurse && preserve_root)
|
||||
|
||||
@@ -228,15 +228,6 @@ 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;
|
||||
|
||||
@@ -316,14 +316,6 @@ 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;
|
||||
}
|
||||
|
||||
14
src/chroot.c
14
src/chroot.c
@@ -160,7 +160,7 @@ main (int argc, char **argv)
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
|
||||
initialize_exit_failure (EXIT_CANCELED);
|
||||
initialize_exit_failure (EXIT_FAILURE);
|
||||
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_CANCELED);
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (argc <= optind)
|
||||
{
|
||||
error (0, 0, _("missing operand"));
|
||||
usage (EXIT_CANCELED);
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (chroot (argv[optind]) != 0)
|
||||
error (EXIT_CANCELED, errno, _("cannot change root directory to %s"),
|
||||
error (EXIT_FAILURE, errno, _("cannot change root directory to %s"),
|
||||
argv[optind]);
|
||||
|
||||
if (chdir ("/"))
|
||||
error (EXIT_CANCELED, errno, _("cannot chdir to root directory"));
|
||||
error (EXIT_FAILURE, 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_CANCELED, errno, "%s", err);
|
||||
error (EXIT_FAILURE, errno, "%s", err);
|
||||
|
||||
free (user);
|
||||
free (group);
|
||||
@@ -254,7 +254,7 @@ main (int argc, char **argv)
|
||||
}
|
||||
|
||||
if (fail)
|
||||
exit (EXIT_CANCELED);
|
||||
exit (EXIT_FAILURE);
|
||||
|
||||
/* Execute the given command. */
|
||||
execvp (argv[0], argv);
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <getopt.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "system.h"
|
||||
#include "dircolors.h"
|
||||
@@ -26,7 +27,6 @@
|
||||
#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). */
|
||||
|
||||
17
src/du.c
17
src/du.c
@@ -24,6 +24,7 @@
|
||||
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>
|
||||
@@ -39,7 +40,6 @@
|
||||
#include "quotearg.h"
|
||||
#include "same.h"
|
||||
#include "stat-time.h"
|
||||
#include "stdio--.h"
|
||||
#include "xfts.h"
|
||||
#include "xstrtol.h"
|
||||
|
||||
@@ -67,6 +67,7 @@ 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;
|
||||
@@ -193,6 +194,7 @@ enum
|
||||
FILES0_FROM_OPTION,
|
||||
HUMAN_SI_OPTION,
|
||||
MAX_DEPTH_OPTION,
|
||||
MEGABYTES_LONG_OPTION,
|
||||
TIME_OPTION,
|
||||
TIME_STYLE_OPTION
|
||||
};
|
||||
@@ -493,15 +495,6 @@ 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;
|
||||
@@ -762,6 +755,10 @@ 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;
|
||||
|
||||
25
src/echo.c
25
src/echo.c
@@ -63,22 +63,18 @@ 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 (_("\
|
||||
\\\\ 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\
|
||||
\\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\
|
||||
"), stdout);
|
||||
printf (USAGE_BUILTIN_WARNING, PROGRAM_NAME);
|
||||
emit_ancillary_info ();
|
||||
@@ -207,7 +203,6 @@ 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
100
src/env.c
@@ -16,6 +16,66 @@
|
||||
|
||||
/* 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>
|
||||
@@ -23,7 +83,6 @@
|
||||
|
||||
#include "system.h"
|
||||
#include "error.h"
|
||||
#include "quote.h"
|
||||
|
||||
/* The official name of this program (e.g., no `g' prefix). */
|
||||
#define PROGRAM_NAME "env"
|
||||
@@ -32,10 +91,11 @@
|
||||
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},
|
||||
@@ -56,9 +116,8 @@ 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\
|
||||
-0, --null end each output line with 0 byte rather than newline\n\
|
||||
-u, --unset=NAME remove variable from the environment\n\
|
||||
-i, --ignore-environment start with an empty environment\n\
|
||||
-u, --unset=NAME remove variable from the environment\n\
|
||||
"), stdout);
|
||||
fputs (HELP_OPTION_DESCRIPTION, stdout);
|
||||
fputs (VERSION_OPTION_DESCRIPTION, stdout);
|
||||
@@ -76,7 +135,6 @@ 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]);
|
||||
@@ -84,10 +142,10 @@ main (int argc, char **argv)
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
|
||||
initialize_exit_failure (EXIT_CANCELED);
|
||||
initialize_exit_failure (EXIT_FAILURE);
|
||||
atexit (close_stdout);
|
||||
|
||||
while ((optc = getopt_long (argc, argv, "+iu:0", longopts, NULL)) != -1)
|
||||
while ((optc = getopt_long (argc, argv, "+iu:", longopts, NULL)) != -1)
|
||||
{
|
||||
switch (optc)
|
||||
{
|
||||
@@ -96,13 +154,10 @@ 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_CANCELED);
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,36 +171,25 @@ main (int argc, char **argv)
|
||||
}
|
||||
|
||||
optind = 0; /* Force GNU getopt to re-initialize. */
|
||||
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));
|
||||
while ((optc = getopt_long (argc, argv, "+iu:", longopts, NULL)) != -1)
|
||||
if (optc == 'u')
|
||||
putenv (optarg); /* Requires GNU putenv. */
|
||||
|
||||
if (optind < argc && STREQ (argv[optind], "-"))
|
||||
++optind;
|
||||
|
||||
while (optind < argc && strchr (argv[optind], '='))
|
||||
if (putenv (argv[optind++]))
|
||||
{
|
||||
char *name = argv[optind - 1];
|
||||
*(strchr (name, '=')) = '\0';
|
||||
error (EXIT_CANCELED, errno, _("cannot set %s"), quote (name));
|
||||
}
|
||||
putenv (argv[optind++]);
|
||||
|
||||
/* If no program is specified, print the environment and exit. */
|
||||
if (argc <= optind)
|
||||
{
|
||||
char *const *e = environ;
|
||||
while (*e)
|
||||
printf ("%s%c", *e++, opt_nul_terminate_output ? '\0' : '\n');
|
||||
puts (*e++);
|
||||
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]);
|
||||
|
||||
{
|
||||
|
||||
@@ -54,13 +54,14 @@ print_group_list (const char *username,
|
||||
ok = false;
|
||||
}
|
||||
|
||||
#if HAVE_GETGROUPS
|
||||
{
|
||||
gid_t *groups;
|
||||
GETGROUPS_T *groups;
|
||||
int i;
|
||||
|
||||
int n_groups = mgetgroups (username, (pwd ? pwd->pw_gid : (gid_t) -1),
|
||||
&groups);
|
||||
if (n_groups < 0 && errno != ENOSYS)
|
||||
if (n_groups < 0)
|
||||
{
|
||||
if (username)
|
||||
{
|
||||
@@ -83,6 +84,7 @@ print_group_list (const char *username,
|
||||
}
|
||||
free (groups);
|
||||
}
|
||||
#endif /* HAVE_GETGROUPS */
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
6
src/id.c
6
src/id.c
@@ -292,13 +292,14 @@ print_full_info (const char *username)
|
||||
printf ("(%s)", grp->gr_name);
|
||||
}
|
||||
|
||||
#if HAVE_GETGROUPS
|
||||
{
|
||||
gid_t *groups;
|
||||
GETGROUPS_T *groups;
|
||||
int i;
|
||||
|
||||
int n_groups = mgetgroups (username, (pwd ? pwd->pw_gid : (gid_t) -1),
|
||||
&groups);
|
||||
if (n_groups < 0 && errno != ENOSYS)
|
||||
if (n_groups < 0)
|
||||
{
|
||||
if (username)
|
||||
{
|
||||
@@ -326,6 +327,7 @@ 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. */
|
||||
|
||||
2
src/ln.c
2
src/ln.c
@@ -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))
|
||||
|
||||
148
src/ls.c
148
src/ls.c
@@ -214,9 +214,6 @@ 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
|
||||
@@ -244,8 +241,9 @@ 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 struct fileinfo *f,
|
||||
bool symlink_target);
|
||||
static bool print_color_indicator (const char *name, mode_t mode, int linkok,
|
||||
bool stat_ok, enum filetype type,
|
||||
nlink_t nlink);
|
||||
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);
|
||||
@@ -266,9 +264,11 @@ 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 struct fileinfo *f,
|
||||
bool symlink_target,
|
||||
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,
|
||||
size_t start_col);
|
||||
static void prep_non_filename_text (void);
|
||||
static bool print_type_indicator (bool stat_ok, mode_t mode,
|
||||
@@ -2637,37 +2637,6 @@ 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. */
|
||||
@@ -2749,16 +2718,11 @@ 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 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. */
|
||||
highlighting files with the executable
|
||||
bit set even when options like -F are
|
||||
not specified. */
|
||||
|| (print_with_color
|
||||
&& (is_colored (C_EXEC)
|
||||
|| is_colored (C_SETUID)
|
||||
|| is_colored (C_SETGID)
|
||||
|| is_colored (C_CAP)))
|
||||
&& is_colored (C_EXEC))
|
||||
)))))
|
||||
|
||||
{
|
||||
@@ -2829,11 +2793,6 @@ 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;
|
||||
@@ -3802,14 +3761,18 @@ print_long_format (const struct fileinfo *f)
|
||||
}
|
||||
|
||||
DIRED_FPUTS (buf, stdout, p - buf);
|
||||
size_t w = print_name_with_quoting (f, false, &dired_obstack, 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);
|
||||
|
||||
if (f->filetype == symbolic_link)
|
||||
{
|
||||
if (f->linkname)
|
||||
{
|
||||
DIRED_FPUTS_LITERAL (" -> ", stdout);
|
||||
print_name_with_quoting (f, true, NULL, (p - buf) + w + 4);
|
||||
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);
|
||||
if (indicator_style != none)
|
||||
print_type_indicator (true, f->linkmode, unknown);
|
||||
}
|
||||
@@ -3985,20 +3948,19 @@ quote_name (FILE *out, const char *name, struct quoting_options const *options,
|
||||
}
|
||||
|
||||
static size_t
|
||||
print_name_with_quoting (const struct fileinfo *f,
|
||||
bool symlink_target,
|
||||
struct obstack *stack,
|
||||
print_name_with_quoting (const char *p, mode_t mode, int linkok,
|
||||
bool stat_ok, enum filetype type,
|
||||
struct obstack *stack, nlink_t nlink,
|
||||
size_t start_col)
|
||||
{
|
||||
const char* name = symlink_target ? f->linkname : f->name;
|
||||
|
||||
bool used_color_this_time
|
||||
= (print_with_color && print_color_indicator (f, symlink_target));
|
||||
= (print_with_color
|
||||
&& print_color_indicator (p, mode, linkok, stat_ok, type, nlink));
|
||||
|
||||
if (stack)
|
||||
PUSH_CURRENT_DIRED_POS (stack);
|
||||
|
||||
size_t width = quote_name (stdout, name, filename_quoting_options, NULL);
|
||||
size_t width = quote_name (stdout, p, filename_quoting_options, NULL);
|
||||
dired_pos += width;
|
||||
|
||||
if (stack)
|
||||
@@ -4050,7 +4012,9 @@ 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, false, NULL, start_col);
|
||||
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);
|
||||
|
||||
if (indicator_style != none)
|
||||
width += print_type_indicator (f->stat_ok, f->stat.st_mode, f->filetype);
|
||||
@@ -4101,38 +4065,55 @@ 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 struct fileinfo *f, bool symlink_target)
|
||||
print_color_indicator (const char *name, mode_t mode, int linkok,
|
||||
bool stat_ok, enum filetype filetype,
|
||||
nlink_t nlink)
|
||||
{
|
||||
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 (!f->stat_ok)
|
||||
else if (! stat_ok)
|
||||
{
|
||||
static enum indicator_no filetype_indicator[] = FILETYPE_INDICATORS;
|
||||
type = filetype_indicator[f->filetype];
|
||||
type = filetype_indicator[filetype];
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -4144,11 +4125,12 @@ print_color_indicator (const struct fileinfo *f, bool symlink_target)
|
||||
type = C_SETUID;
|
||||
else if ((mode & S_ISGID) != 0 && is_colored (C_SETGID))
|
||||
type = C_SETGID;
|
||||
else if (is_colored (C_CAP) && f->has_capability)
|
||||
/* has_capability() called second for performance. */
|
||||
else if (is_colored (C_CAP) && has_capability (name))
|
||||
type = C_CAP;
|
||||
else if ((mode & S_IXUGO) != 0 && is_colored (C_EXEC))
|
||||
type = C_EXEC;
|
||||
else if ((1 < f->stat.st_nlink) && is_colored (C_MULTIHARDLINK))
|
||||
else if ((1 < nlink) && is_colored (C_MULTIHARDLINK))
|
||||
type = C_MULTIHARDLINK;
|
||||
}
|
||||
else if (S_ISDIR (mode))
|
||||
|
||||
@@ -513,6 +513,7 @@ digest_check (const char *checkfile_name)
|
||||
if (!status_only)
|
||||
{
|
||||
printf (_("%s: FAILED open or read\n"), filename);
|
||||
fflush (stdout);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -538,6 +539,7 @@ digest_check (const char *checkfile_name)
|
||||
printf ("%s: %s\n", filename, _("FAILED"));
|
||||
else if (!quiet)
|
||||
printf ("%s: %s\n", filename, _("OK"));
|
||||
fflush (stdout);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -617,10 +619,6 @@ 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)
|
||||
{
|
||||
|
||||
146
src/mktemp.c
146
src/mktemp.c
@@ -14,27 +14,24 @@
|
||||
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 and Eric Blake. */
|
||||
/* Written by Jim Meyering. */
|
||||
|
||||
#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"), \
|
||||
proper_name ("Eric Blake")
|
||||
#define AUTHORS proper_name ("Jim Meyering")
|
||||
|
||||
static const char *default_template = "tmp.XXXXXXXXXX";
|
||||
|
||||
@@ -42,8 +39,7 @@ static const char *default_template = "tmp.XXXXXXXXXX";
|
||||
non-character as a pseudo short option, starting with CHAR_MAX + 1. */
|
||||
enum
|
||||
{
|
||||
SUFFIX_OPTION = CHAR_MAX + 1,
|
||||
TMPDIR_OPTION
|
||||
TMPDIR_OPTION = CHAR_MAX + 1
|
||||
};
|
||||
|
||||
static struct option const longopts[] =
|
||||
@@ -51,7 +47,6 @@ 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},
|
||||
@@ -69,32 +64,33 @@ usage (int status)
|
||||
printf (_("Usage: %s [OPTION]... [TEMPLATE]\n"), program_name);
|
||||
fputs (_("\
|
||||
Create a temporary file or directory, safely, and print its name.\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\
|
||||
If TEMPLATE is not specified, use tmp.XXXXXXXXXX.\n\
|
||||
"), stdout);
|
||||
fputs ("\n", stdout);
|
||||
fputs (_("\
|
||||
-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\
|
||||
-d, --directory create a directory, not a file\n\
|
||||
"), stdout);
|
||||
fputs (_("\
|
||||
--suffix=SUFF append SUFF to TEMPLATE. SUFF must not contain slash.\n\
|
||||
This option is implied if TEMPLATE does not end in X.\n\
|
||||
-q, --quiet suppress diagnostics about file/dir-creation failure\n\
|
||||
"), stdout);
|
||||
fputs (_("\
|
||||
--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\
|
||||
-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\
|
||||
"), stdout);
|
||||
fputs ("\n", stdout);
|
||||
fputs (_("\
|
||||
-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\
|
||||
-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\
|
||||
"), stdout);
|
||||
fputs ("\n", stdout);
|
||||
fputs (HELP_OPTION_DESCRIPTION, stdout);
|
||||
@@ -106,8 +102,9 @@ If TEMPLATE is not specified, use tmp.XXXXXXXXXX, and --tmpdir is implied.\n\
|
||||
}
|
||||
|
||||
static size_t
|
||||
count_consecutive_X_s (const char *s, size_t len)
|
||||
count_trailing_X_s (const char *s)
|
||||
{
|
||||
size_t len = strlen (s);
|
||||
size_t n = 0;
|
||||
for ( ; len && s[len-1] == 'X'; len--)
|
||||
++n;
|
||||
@@ -115,33 +112,15 @@ count_consecutive_X_s (const char *s, size_t len)
|
||||
}
|
||||
|
||||
static int
|
||||
mkstemp_len (char *tmpl, size_t suff_len, size_t x_len, bool dry_run)
|
||||
mkstemp_len (char *tmpl, size_t suff_len, bool dry_run)
|
||||
{
|
||||
return gen_tempname_len (tmpl, suff_len, 0, dry_run ? GT_NOCREATE : GT_FILE,
|
||||
x_len);
|
||||
return gen_tempname_len (tmpl, 0, dry_run ? GT_NOCREATE : GT_FILE, suff_len);
|
||||
}
|
||||
|
||||
static int
|
||||
mkdtemp_len (char *tmpl, size_t suff_len, size_t x_len, bool dry_run)
|
||||
mkdtemp_len (char *tmpl, size_t suff_len, bool dry_run)
|
||||
{
|
||||
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);
|
||||
return gen_tempname_len (tmpl, 0, dry_run ? GT_NOCREATE : GT_DIR, suff_len);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -153,14 +132,12 @@ 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);
|
||||
@@ -169,7 +146,7 @@ main (int argc, char **argv)
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
|
||||
atexit (maybe_close_stdout);
|
||||
atexit (close_stdout);
|
||||
|
||||
while ((c = getopt_long (argc, argv, "dp:qtuV", longopts, NULL)) != -1)
|
||||
{
|
||||
@@ -198,13 +175,9 @@ main (int argc, char **argv)
|
||||
dest_dir_arg = optarg;
|
||||
break;
|
||||
|
||||
case SUFFIX_OPTION:
|
||||
suffix = optarg;
|
||||
break;
|
||||
|
||||
case_GETOPT_HELP_CHAR;
|
||||
|
||||
case 'V': /* Undocumented alias. FIXME: remove in 2011. */
|
||||
case 'V':
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
default:
|
||||
usage (EXIT_FAILURE);
|
||||
@@ -237,41 +210,7 @@ main (int argc, char **argv)
|
||||
template = argv[optind];
|
||||
}
|
||||
|
||||
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);
|
||||
x_count = count_trailing_X_s (template);
|
||||
if (x_count < 3)
|
||||
error (EXIT_FAILURE, 0, _("too few X's in template %s"), quote (template));
|
||||
|
||||
@@ -305,10 +244,11 @@ main (int argc, char **argv)
|
||||
quote (template));
|
||||
}
|
||||
|
||||
dest_name = file_name_concat (dest_dir, template, NULL);
|
||||
free (template);
|
||||
template = dest_name;
|
||||
/* Note that suffix is now invalid. */
|
||||
template = file_name_concat (dest_dir, template, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
template = xstrdup (template);
|
||||
}
|
||||
|
||||
/* Make a copy to be used in case of diagnostic, since failing
|
||||
@@ -317,7 +257,7 @@ main (int argc, char **argv)
|
||||
|
||||
if (create_directory)
|
||||
{
|
||||
int err = mkdtemp_len (dest_name, suffix_len, x_count, dry_run);
|
||||
int err = mkdtemp_len (dest_name, x_count, dry_run);
|
||||
if (err != 0)
|
||||
{
|
||||
error (0, errno, _("failed to create directory via template %s"),
|
||||
@@ -327,7 +267,7 @@ main (int argc, char **argv)
|
||||
}
|
||||
else
|
||||
{
|
||||
int fd = mkstemp_len (dest_name, suffix_len, x_count, dry_run);
|
||||
int fd = mkstemp_len (dest_name, x_count, dry_run);
|
||||
if (fd < 0 || (!dry_run && close (fd) != 0))
|
||||
{
|
||||
error (0, errno, _("failed to create file via template %s"),
|
||||
@@ -337,17 +277,7 @@ main (int argc, char **argv)
|
||||
}
|
||||
|
||||
if (status == EXIT_SUCCESS)
|
||||
{
|
||||
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"));
|
||||
}
|
||||
}
|
||||
puts (dest_name);
|
||||
|
||||
#ifdef lint
|
||||
free (dest_name);
|
||||
|
||||
30
src/nice.c
30
src/nice.c
@@ -86,12 +86,6 @@ 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)
|
||||
{
|
||||
@@ -107,7 +101,7 @@ main (int argc, char **argv)
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
|
||||
initialize_exit_failure (EXIT_CANCELED);
|
||||
initialize_exit_failure (EXIT_FAILURE);
|
||||
atexit (close_stdout);
|
||||
|
||||
parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version,
|
||||
@@ -138,7 +132,7 @@ main (int argc, char **argv)
|
||||
i += optind - 1;
|
||||
|
||||
if (optc == '?')
|
||||
usage (EXIT_CANCELED);
|
||||
usage (EXIT_FAILURE);
|
||||
else if (optc == 'n')
|
||||
adjustment_given = optarg;
|
||||
else /* optc == -1 */
|
||||
@@ -154,7 +148,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_CANCELED, 0, _("invalid adjustment %s"),
|
||||
error (EXIT_FAILURE, 0, _("invalid adjustment %s"),
|
||||
quote (adjustment_given));
|
||||
adjustment = MAX (MIN_ADJUSTMENT, MIN (tmp, MAX_ADJUSTMENT));
|
||||
}
|
||||
@@ -164,13 +158,13 @@ main (int argc, char **argv)
|
||||
if (adjustment_given)
|
||||
{
|
||||
error (0, 0, _("a command must be given with an adjustment"));
|
||||
usage (EXIT_CANCELED);
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
/* No command given; print the niceness. */
|
||||
errno = 0;
|
||||
current_niceness = GET_NICENESS ();
|
||||
if (current_niceness == -1 && errno != 0)
|
||||
error (EXIT_CANCELED, errno, _("cannot get niceness"));
|
||||
error (EXIT_FAILURE, errno, _("cannot get niceness"));
|
||||
printf ("%d\n", current_niceness);
|
||||
exit (EXIT_SUCCESS);
|
||||
}
|
||||
@@ -181,21 +175,11 @@ main (int argc, char **argv)
|
||||
#else
|
||||
current_niceness = GET_NICENESS ();
|
||||
if (current_niceness == -1 && errno != 0)
|
||||
error (EXIT_CANCELED, errno, _("cannot get niceness"));
|
||||
error (EXIT_FAILURE, errno, _("cannot get niceness"));
|
||||
ok = (setpriority (PRIO_PROCESS, 0, current_niceness + adjustment) == 0);
|
||||
#endif
|
||||
if (!ok)
|
||||
{
|
||||
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);
|
||||
}
|
||||
error (errno == EPERM ? 0 : EXIT_FAILURE, errno, _("cannot set niceness"));
|
||||
|
||||
execvp (argv[i], &argv[i]);
|
||||
|
||||
|
||||
31
src/nohup.c
31
src/nohup.c
@@ -40,7 +40,7 @@
|
||||
enum
|
||||
{
|
||||
/* `nohup' itself failed. */
|
||||
POSIX_NOHUP_FAILURE = 127
|
||||
NOHUP_FAILURE = 127
|
||||
};
|
||||
|
||||
void
|
||||
@@ -85,7 +85,6 @@ 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]);
|
||||
@@ -93,24 +92,18 @@ main (int argc, char **argv)
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
|
||||
/* 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);
|
||||
initialize_exit_failure (NOHUP_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 (exit_internal_failure);
|
||||
usage (NOHUP_FAILURE);
|
||||
|
||||
if (argc <= optind)
|
||||
{
|
||||
error (0, 0, _("missing operand"));
|
||||
usage (exit_internal_failure);
|
||||
usage (NOHUP_FAILURE);
|
||||
}
|
||||
|
||||
ignoring_input = isatty (STDIN_FILENO);
|
||||
@@ -161,7 +154,7 @@ main (int argc, char **argv)
|
||||
if (in_home)
|
||||
error (0, saved_errno2, _("failed to open %s"),
|
||||
quote (in_home));
|
||||
exit (exit_internal_failure);
|
||||
exit (NOHUP_FAILURE);
|
||||
}
|
||||
file = in_home;
|
||||
}
|
||||
@@ -186,7 +179,7 @@ main (int argc, char **argv)
|
||||
|
||||
if (0 <= saved_stderr_fd
|
||||
&& set_cloexec_flag (saved_stderr_fd, true) != 0)
|
||||
error (exit_internal_failure, errno,
|
||||
error (NOHUP_FAILURE, errno,
|
||||
_("failed to set the copy of stderr to close on exec"));
|
||||
|
||||
if (!redirecting_stdout)
|
||||
@@ -196,22 +189,12 @@ main (int argc, char **argv)
|
||||
: N_("redirecting stderr to stdout")));
|
||||
|
||||
if (dup2 (out_fd, STDERR_FILENO) < 0)
|
||||
error (exit_internal_failure, errno,
|
||||
_("failed to redirect standard error"));
|
||||
error (NOHUP_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
127
src/nproc.c
@@ -1,127 +0,0 @@
|
||||
/* 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);
|
||||
}
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <getopt.h>
|
||||
|
||||
#include "system.h"
|
||||
#include "long-options.h"
|
||||
|
||||
/* Exit status for syntax errors, etc. */
|
||||
enum { PRINTENV_FAILURE = 2 };
|
||||
@@ -44,13 +45,7 @@ enum { PRINTENV_FAILURE = 2 };
|
||||
proper_name ("David MacKenzie"), \
|
||||
proper_name ("Richard Mlynarik")
|
||||
|
||||
static struct option const longopts[] =
|
||||
{
|
||||
{"null", no_argument, NULL, '0'},
|
||||
{GETOPT_HELP_OPTION_DECL},
|
||||
{GETOPT_VERSION_OPTION_DECL},
|
||||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
extern char **environ;
|
||||
|
||||
void
|
||||
usage (int status)
|
||||
@@ -61,15 +56,13 @@ usage (int status)
|
||||
else
|
||||
{
|
||||
printf (_("\
|
||||
Usage: %s [OPTION]... [VARIABLE]...\n\
|
||||
Usage: %s [VARIABLE]...\n\
|
||||
or: %s OPTION\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);
|
||||
fputs (_("\
|
||||
-0, --null end each output line with 0 byte rather than newline\n\
|
||||
"), stdout);
|
||||
program_name, program_name);
|
||||
fputs (HELP_OPTION_DESCRIPTION, stdout);
|
||||
fputs (VERSION_OPTION_DESCRIPTION, stdout);
|
||||
printf (USAGE_BUILTIN_WARNING, PROGRAM_NAME);
|
||||
@@ -85,8 +78,6 @@ 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]);
|
||||
@@ -97,24 +88,15 @@ main (int argc, char **argv)
|
||||
initialize_exit_failure (PRINTENV_FAILURE);
|
||||
atexit (close_stdout);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
|
||||
if (optind >= argc)
|
||||
{
|
||||
for (env = environ; *env != NULL; ++env)
|
||||
printf ("%s%c", *env, opt_nul_terminate_output ? '\0' : '\n');
|
||||
puts (*env);
|
||||
ok = true;
|
||||
}
|
||||
else
|
||||
@@ -125,10 +107,6 @@ 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;
|
||||
@@ -137,8 +115,7 @@ main (int argc, char **argv)
|
||||
{
|
||||
if (*ep == '=' && *ap == '\0')
|
||||
{
|
||||
printf ("%s%c", ep + 1,
|
||||
opt_nul_terminate_output ? '\0' : '\n');
|
||||
puts (ep + 1);
|
||||
matched = true;
|
||||
break;
|
||||
}
|
||||
|
||||
13
src/printf.c
13
src/printf.c
@@ -25,7 +25,6 @@
|
||||
\a = alert (bell)
|
||||
\b = backspace
|
||||
\c = produce no further output
|
||||
\e = escape
|
||||
\f = form feed
|
||||
\n = new line
|
||||
\r = carriage return
|
||||
@@ -102,21 +101,22 @@ 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,9 +200,6 @@ 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;
|
||||
@@ -259,7 +256,7 @@ print_esc (const char *escstart, bool octal_0)
|
||||
esc_value = esc_value * 8 + octtobin (*p);
|
||||
putchar (esc_value);
|
||||
}
|
||||
else if (*p && strchr ("\"\\abcefnrtv", *p))
|
||||
else if (*p && strchr ("\"\\abcfnrtv", *p))
|
||||
print_esc_char (*p++);
|
||||
else if (*p == 'u' || *p == 'U')
|
||||
{
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <getopt.h>
|
||||
#include <sys/types.h>
|
||||
#include "system.h"
|
||||
@@ -28,7 +29,6 @@
|
||||
#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). */
|
||||
|
||||
19
src/remove.c
19
src/remove.c
@@ -437,18 +437,6 @@ 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;
|
||||
|
||||
@@ -564,7 +552,12 @@ rm_fts (FTS *fts, FTSENT *ent, struct rm_options const *x)
|
||||
}
|
||||
|
||||
case FTS_DC: /* directory that causes cycles */
|
||||
emit_cycle_warning (ent->fts_path);
|
||||
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));
|
||||
fts_skip_tree (fts, ent);
|
||||
return RM_ERROR;
|
||||
|
||||
|
||||
@@ -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 (EXIT_FAILURE);
|
||||
usage (1);
|
||||
}
|
||||
context = argv[optind++];
|
||||
}
|
||||
@@ -190,7 +190,7 @@ main (int argc, char **argv)
|
||||
if (optind >= argc)
|
||||
{
|
||||
error (0, 0, _("no command specified"));
|
||||
usage (EXIT_FAILURE);
|
||||
usage (1);
|
||||
}
|
||||
|
||||
if (is_selinux_enabled () != 1)
|
||||
|
||||
@@ -181,7 +181,7 @@ main (int argc, char **argv)
|
||||
{
|
||||
int n = mgetgroups (pwd->pw_name, pwd->pw_gid, &gids);
|
||||
if (n <= 0)
|
||||
error (EXIT_FAILURE, errno, _("failed to get groups for user %s"),
|
||||
error (1, errno, _("failed to get groups for user %s"),
|
||||
quote (pwd->pw_name));
|
||||
n_gids = n;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include "system.h"
|
||||
|
||||
@@ -28,7 +29,6 @@
|
||||
#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). */
|
||||
|
||||
@@ -723,9 +723,6 @@ print_esc_char (char c)
|
||||
case 'b': /* Backspace. */
|
||||
c ='\b';
|
||||
break;
|
||||
case 'e': /* Escape. */
|
||||
c ='\x1B';
|
||||
break;
|
||||
case 'f': /* Form feed. */
|
||||
c ='\f';
|
||||
break;
|
||||
@@ -906,7 +903,7 @@ do_stat (char const *filename, bool terse, char const *format)
|
||||
}
|
||||
}
|
||||
/* We can't use the shorter
|
||||
(follow_links?stat:lstat) (filename, &statbug)
|
||||
(follow_links ? stat : lstat) (filename, &statbug)
|
||||
since stat might be a function-like macro. */
|
||||
else if ((follow_links
|
||||
? stat (filename, &statbuf)
|
||||
|
||||
@@ -39,6 +39,8 @@
|
||||
|
||||
static char *program_path;
|
||||
|
||||
extern char **environ;
|
||||
|
||||
static struct
|
||||
{
|
||||
size_t size;
|
||||
|
||||
24
src/su.c
24
src/su.c
@@ -113,6 +113,8 @@
|
||||
|
||||
char *crypt (char const *key, char const *salt);
|
||||
|
||||
extern char **environ;
|
||||
|
||||
static void run_shell (char const *, char const *, char **, size_t)
|
||||
ATTRIBUTE_NORETURN;
|
||||
|
||||
@@ -284,13 +286,13 @@ change_identity (const struct passwd *pw)
|
||||
#ifdef HAVE_INITGROUPS
|
||||
errno = 0;
|
||||
if (initgroups (pw->pw_name, pw->pw_gid) == -1)
|
||||
error (EXIT_CANCELED, errno, _("cannot set groups"));
|
||||
error (EXIT_FAILURE, errno, _("cannot set groups"));
|
||||
endgrent ();
|
||||
#endif
|
||||
if (setgid (pw->pw_gid))
|
||||
error (EXIT_CANCELED, errno, _("cannot set group id"));
|
||||
error (EXIT_FAILURE, errno, _("cannot set group id"));
|
||||
if (setuid (pw->pw_uid))
|
||||
error (EXIT_CANCELED, errno, _("cannot set user id"));
|
||||
error (EXIT_FAILURE, errno, _("cannot set user id"));
|
||||
}
|
||||
|
||||
/* Run SHELL, or DEFAULT_SHELL if SHELL is empty.
|
||||
@@ -404,7 +406,7 @@ main (int argc, char **argv)
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
|
||||
initialize_exit_failure (EXIT_CANCELED);
|
||||
initialize_exit_failure (EXIT_FAILURE);
|
||||
atexit (close_stdout);
|
||||
|
||||
fast_startup = false;
|
||||
@@ -441,7 +443,7 @@ main (int argc, char **argv)
|
||||
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||
|
||||
default:
|
||||
usage (EXIT_CANCELED);
|
||||
usage (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -456,7 +458,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_CANCELED, 0, _("user %s does not exist"), new_user);
|
||||
error (EXIT_FAILURE, 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
|
||||
@@ -479,7 +481,7 @@ main (int argc, char **argv)
|
||||
#ifdef SYSLOG_FAILURE
|
||||
log_su (pw, false);
|
||||
#endif
|
||||
error (EXIT_CANCELED, 0, _("incorrect password"));
|
||||
error (EXIT_FAILURE, 0, _("incorrect password"));
|
||||
}
|
||||
#ifdef SYSLOG_SUCCESS
|
||||
else
|
||||
@@ -506,13 +508,5 @@ 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));
|
||||
}
|
||||
|
||||
@@ -233,10 +233,6 @@ 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)
|
||||
|
||||
16
src/system.h
16
src/system.h
@@ -212,6 +212,10 @@ 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.
|
||||
@@ -672,18 +676,6 @@ 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
|
||||
|
||||
99
src/tail.c
99
src/tail.c
@@ -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 -c +K\n\
|
||||
to output bytes starting with the Kth of each file\n\
|
||||
-c, --bytes=K output the last K bytes; alternatively, use +K to\n\
|
||||
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 -n +K to output lines starting with the Kth\n\
|
||||
or use +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,47 +1168,6 @@ 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. */
|
||||
|
||||
@@ -1290,14 +1249,6 @@ 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);
|
||||
|
||||
@@ -1306,7 +1257,11 @@ 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
|
||||
@@ -1404,13 +1359,7 @@ tail_forever_inotify (int wd, struct File_spec *f, size_t n_files,
|
||||
|
||||
if (ev->mask & (IN_ATTRIB | 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))
|
||||
if (ev->mask & (IN_DELETE_SELF | IN_MOVE_SELF))
|
||||
{
|
||||
inotify_rm_watch (wd, f[i].wd);
|
||||
hash_delete (wd_table, &(f[i]));
|
||||
@@ -1420,7 +1369,37 @@ tail_forever_inotify (int wd, struct File_spec *f, size_t n_files,
|
||||
|
||||
continue;
|
||||
}
|
||||
check_fspec (fspec, ev->wd, &prev_wd);
|
||||
|
||||
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"));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -196,7 +196,7 @@ apply_time_suffix (unsigned long *x, char suffix_char)
|
||||
}
|
||||
|
||||
static void
|
||||
install_signal_handlers (int sigterm)
|
||||
install_signal_handlers (void)
|
||||
{
|
||||
struct sigaction sa;
|
||||
sigemptyset(&sa.sa_mask); /* Allow concurrent calls to handler */
|
||||
@@ -206,9 +206,8 @@ install_signal_handlers (int sigterm)
|
||||
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 (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. */
|
||||
sigaction (SIGHUP, &sa, NULL); /* terminal closed for example. */
|
||||
}
|
||||
|
||||
int
|
||||
@@ -272,7 +271,7 @@ main (int argc, char **argv)
|
||||
|
||||
/* Setup handlers before fork() so that we
|
||||
handle any signals caused by child, without races. */
|
||||
install_signal_handlers (term_signal);
|
||||
install_signal_handlers ();
|
||||
signal (SIGTTIN, SIG_IGN); /* don't sTop if background child needs tty. */
|
||||
signal (SIGTTOU, SIG_IGN); /* don't sTop if background child needs tty. */
|
||||
|
||||
|
||||
28
src/touch.c
28
src/touch.c
@@ -58,9 +58,6 @@ 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.
|
||||
@@ -88,7 +85,6 @@ 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}
|
||||
@@ -130,7 +126,7 @@ touch (const char *file)
|
||||
|
||||
if (STREQ (file, "-"))
|
||||
fd = STDOUT_FILENO;
|
||||
else if (! (no_create || no_dereference))
|
||||
else if (! no_create)
|
||||
{
|
||||
/* Try to open FILE, creating it if necessary. */
|
||||
fd = fd_reopen (STDIN_FILENO, file,
|
||||
@@ -164,8 +160,7 @@ touch (const char *file)
|
||||
t = NULL;
|
||||
}
|
||||
|
||||
ok = ((no_dereference && fd == -1) ? lutimens (file, t)
|
||||
: gl_futimens (fd, (fd == STDOUT_FILENO ? NULL : file), t)) == 0;
|
||||
ok = (gl_futimens (fd, (fd == STDOUT_FILENO ? NULL : file), t) == 0);
|
||||
|
||||
if (fd == STDIN_FILENO)
|
||||
{
|
||||
@@ -216,8 +211,7 @@ 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, unless -c or -h\n\
|
||||
is supplied.\n\
|
||||
A FILE argument that does not exist is created empty.\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\
|
||||
@@ -231,11 +225,6 @@ 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 (_("\
|
||||
@@ -276,7 +265,7 @@ main (int argc, char **argv)
|
||||
change_times = 0;
|
||||
no_create = use_ref = false;
|
||||
|
||||
while ((c = getopt_long (argc, argv, "acd:fhmr:t:", longopts, &long_idx)) != -1)
|
||||
while ((c = getopt_long (argc, argv, "acd:fmr:t:", longopts, &long_idx)) != -1)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
@@ -295,10 +284,6 @@ main (int argc, char **argv)
|
||||
case 'f':
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
no_dereference = true;
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
change_times |= CH_MTIME;
|
||||
break;
|
||||
@@ -348,10 +333,7 @@ main (int argc, char **argv)
|
||||
if (use_ref)
|
||||
{
|
||||
struct stat 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))
|
||||
if (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);
|
||||
|
||||
16
src/true.c
16
src/true.c
@@ -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);
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <getopt.h>
|
||||
#include <sys/types.h>
|
||||
@@ -31,7 +32,6 @@
|
||||
#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"
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <getopt.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
@@ -28,7 +29,6 @@
|
||||
#include "hard-locale.h"
|
||||
#include "posixver.h"
|
||||
#include "quote.h"
|
||||
#include "stdio--.h"
|
||||
#include "xmemcoll.h"
|
||||
#include "xstrtol.h"
|
||||
#include "memcasecmp.h"
|
||||
|
||||
@@ -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,7 +37,6 @@ 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
|
||||
|
||||
@@ -75,12 +74,10 @@ 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 \
|
||||
@@ -128,7 +125,6 @@ TESTS = \
|
||||
chgrp/no-x \
|
||||
chgrp/posix-H \
|
||||
chgrp/recurse \
|
||||
misc/env \
|
||||
misc/ptx \
|
||||
misc/test \
|
||||
misc/seq \
|
||||
@@ -161,14 +157,12 @@ 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 \
|
||||
@@ -184,20 +178,15 @@ 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 \
|
||||
@@ -234,7 +223,6 @@ TESTS = \
|
||||
misc/stty \
|
||||
misc/stty-invalid \
|
||||
misc/stty-row-col \
|
||||
misc/su-fail \
|
||||
misc/sum \
|
||||
misc/sum-sysv \
|
||||
misc/tac \
|
||||
@@ -457,13 +445,11 @@ 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 = \
|
||||
|
||||
@@ -24,6 +24,7 @@ fi
|
||||
. $srcdir/test-lib.sh
|
||||
require_membership_in_two_groups_
|
||||
|
||||
fail=0
|
||||
|
||||
set _ $groups; shift
|
||||
g1=$1
|
||||
|
||||
@@ -29,6 +29,7 @@ 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
|
||||
|
||||
@@ -38,6 +38,7 @@ 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
|
||||
|
||||
@@ -33,6 +33,7 @@ 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
|
||||
|
||||
@@ -34,6 +34,7 @@ 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
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ set _ $groups; shift
|
||||
g1=$1
|
||||
g2=$2
|
||||
|
||||
fail=0
|
||||
|
||||
# chgrp -R should not traverse a symlink to a directory.
|
||||
mkdir d e
|
||||
|
||||
@@ -30,6 +30,7 @@ chmod 444 $file || framework_failure
|
||||
|
||||
skip_if_setgid_
|
||||
|
||||
fail=0
|
||||
|
||||
chmod u=rwx $file || fail=1
|
||||
chmod -c g=rwx $file > out || fail=1
|
||||
|
||||
@@ -26,6 +26,7 @@ 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
|
||||
|
||||
@@ -27,6 +27,7 @@ fi
|
||||
|
||||
touch f || framework_failure
|
||||
|
||||
fail=0
|
||||
|
||||
expected_u=-rwx------
|
||||
expected_g=----rwx---
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user