Commit Graph

2307 Commits

Author SHA1 Message Date
Jaakko Heinonen
bb2f41f9a4 MFC r202945:
Fixes for ls(1) long format (-l) output:

- Allow -h option to work if the listing contains at least one device
  file.
- Align major and minor device numbers correctly to the size field.

PR:		bin/125678
2010-02-24 15:27:31 +00:00
Rebecca Cran
b9d3fd67b9 MFC r203688:
Initialize the execfile argument to NULL instead of _PATH_DEVNULL. This allows
the -M option to be used without specifying -N.

PR:	bin/138146
Approved by:	rrs (mentor)
2010-02-18 10:46:25 +00:00
Gavin Atkinson
3d4d4693f0 Merge r202461 from head:
Implement an "-x" option to cp(1), for compatibility with Linux and
  feature parity with du(1) and similar:  When set, cp(1) will not traverse
  mount points.

PR:		bin/88056
Initial patch by: Graham J Lee   leeg teaching.physics.ox.ac.uk
2010-02-16 22:19:55 +00:00
Jaakko Heinonen
8abe3cc36b MFC r202944:
Print full path in the error message. It's possible that fts(3)
provides an empty fts_name and reporting the full path is more
appropriate especially with the -R option.

PR:		bin/107515
Approved by:	trasz (mentor)
2010-01-31 15:07:38 +00:00
Edward Tomasz Napierala
f4d24e0ea3 MFC r201018:
Fix breakage introduced in last commit.
2010-01-30 15:53:32 +00:00
Edward Tomasz Napierala
e8fdbf3d5c MFC r201016:
Improve ACL branding mismatch detection and reporting in some rare cases,
such as "setfacl -m ''".
2010-01-30 15:50:01 +00:00
Edward Tomasz Napierala
d91f45d608 MFC r196936:
Add NFSv4 support to setfacl(1).
2010-01-30 14:58:25 +00:00
Edward Tomasz Napierala
e0649d28d9 MFC r196841:
Add NFSv4 ACL support to mv(1).
2010-01-30 14:56:13 +00:00
Edward Tomasz Napierala
113c95e756 MFC r196827:
Add NFSv4 ACL support to getfacl(1).
2010-01-30 14:51:24 +00:00
Edward Tomasz Napierala
1ed226c0a9 MFC r196754:
Add NFSv4 ACL support to cp(1) and fix a few memory leaks.

Note that this changes error reporting behaviour somewhat - before,
no error was reported if ACL couldn't be copied because the target
filesystem doesn't support ACLs.  Now, it will be reported - of course,
only if there actually is an ACL to copy.

Reviewed by:	rwatson
2010-01-30 14:49:17 +00:00
Edward Tomasz Napierala
3736d570d3 MFC r196753:
- Don't include both <sys/types.h> and <sys/param.h>

- Keep variables sorted

- Fix logic error with -f and -v options - don't print
  the usual -v output if there was an error, whether or not
  we were passed -f

- Don't call free(3) just before exit(2)

- Whitespace fixes

Submitted by:	bde
2010-01-30 14:47:23 +00:00
Edward Tomasz Napierala
af0a0fb12e MFC r196712:
Add NFSv4 ACL support to ls(1).

MFC r196773:

Fix regression introduced in r196712 - the 'name' string needs
to be rewritten for each file we want to check ACL on.  Without
this change, ls(1) would check only the ACL on the first file
to list.
2010-01-30 14:44:32 +00:00
Edward Tomasz Napierala
7ecc6d21d9 MFC r196711:
Make the code more readable and fix chmod(1) on symlinks with
NFSv4 enabled.
2010-01-30 14:40:42 +00:00
Antoine Brodin
e2b36efde5 MFC r201145 to stable/8:
(S)LIST_HEAD_INITIALIZER takes a (S)LIST_HEAD as an argument.
  Fix some wrong usages.
  Note: this does not affect generated binaries as this argument is not used.

  PR:		137213
  Submitted by:	Eygene Ryabinkin (initial version)
2010-01-30 12:11:21 +00:00
Jilles Tjoelker
e859c2af80 MFC r201355: sh(1): document ulimit -w (swapuse rlimit). 2010-01-08 14:33:03 +00:00
Jilles Tjoelker
716779e2ff MFC r201354: sh(1): Correct two places where "$@" lacked necessary quotes. 2010-01-08 14:30:03 +00:00
Xin LI
e8a4477a72 Plug a memory leak.
PR:		bin/141835
Submitted by:	Henning Petersen <henning.petersen t-online.de>
2010-01-04 01:08:27 +00:00
Jilles Tjoelker
7a8c242784 MFC r199458: Add pwait utility, which waits for any process to terminate.
This is similar to the Solaris utility of the same name.

Some use cases:
* rc.subr's wait_for_pids
* interactive use, e.g. to shut down the computer when some task is done
  even if the task is already running
2009-12-23 22:59:03 +00:00
Jilles Tjoelker
088e699c18 MFC r198173: sh: show more info about syntax errors in command substitution:
the line number where the command substitution started.
This applies to both the $() and `` forms but is most useful for ``
because the other line number is relative to the enclosed text there.
(For older versions, -v can be used as a workaround.)
2009-12-20 20:51:20 +00:00
Jilles Tjoelker
7635c69726 MFC r198963: sh: Fix memory leak when using a variable in arithmetic
like $((x)).
2009-12-06 22:01:45 +00:00
Alexander Leidinger
c8cfdb0768 MFC r199351:
Fix small resource leak (memory).

  Reviewed by:        gad
2009-11-24 10:46:17 +00:00
Jilles Tjoelker
defb74dce5 MFC r197371: Mention that NUL characters are not allowed in sh(1) input.
I do not consider this a bug because POSIX permits it and argument strings
and environment variables cannot contain '\0' anyway.

PR:		bin/25542
2009-10-29 21:13:57 +00:00
Hajimu UMEMOTO
b40a504727 MFC r198189: Check error of dlfunc(3).
Approved by:	re (kib)
2009-10-20 11:52:39 +00:00
Jilles Tjoelker
f6d21b6ed0 MFC r196483,r196634:
sh: Fix crash when undefining or redefining a currently executing function

Add a reference count to function definitions.
Memory may leak if a SIGINT arrives in interactive mode at exactly the wrong
time, this will be fixed later by changing SIGINT handling.

PR:		bin/137640
Approved by:	re (kib)
2009-10-11 16:35:12 +00:00
Brian Somers
aa14b5ab89 Add the -d switch to the usage message.
Submitted by:	Emil Mikulic - emil at dmr dot ath dot cx
Approved by:	re (kib)
MFC after:	1 week
2009-07-23 10:20:12 +00:00
Jilles Tjoelker
80a0e9b5f5 Allow creating hard links to symlinks using ln(1).
This implements the POSIX.1-2008 -L and -P flags.

The default remains to create hard links to the target of symlinks.

Approved by:	re (kib), ed (mentor)
2009-07-19 17:35:23 +00:00
Edward Tomasz Napierala
e50022797f Add manual page links to advertise procstat(1) a little better.
Approved by:	re (kib)
2009-07-09 16:40:00 +00:00
Edward Tomasz Napierala
deda5987bc With NFSv4 ACLs, it is possible that applying a mode to an ACL which
is identical to the mode computed from that ACL will modify the ACL.
For example, mode computed from the following ACL is 0600:

   user:kamila:rwx--------C--:------:allow
        owner@:--x-----------:------:deny
        owner@:rw-p---A-W-Co-:------:allow
        group@:rwxp----------:------:deny
        group@:--------------:------:allow
     everyone@:rwxp---A-W-Co-:------:deny
     everyone@:------a-R-c--s:------:allow

However, applying that mode (chmod 0600) changes the ACL into this:

   user:kamila:rwx-----------:------:deny
   user:kamila:rwx--------C--:------:allow
        owner@:--x-----------:------:deny
        owner@:rw-p---A-W-Co-:------:allow
        group@:rwxp----------:------:deny
        group@:--------------:------:allow
     everyone@:rwxp---A-W-Co-:------:deny
     everyone@:------a-R-c--s:------:allow

In chmod(1) utility, there is an optimisation, which makes it not
call chmod(2) if the mode of the file is the same as the new mode.
Disable that optimisation for files which may have NFSv4 ACLs.

Reviewed by:	rwatson
Approved by:	re (kib)
2009-07-01 15:52:19 +00:00
Jilles Tjoelker
f19a2f6c57 Fix some weirdnesses in the NetBSD IFS code,
in particular "$@"$ifschar if the final positional parameter is empty.
With the NetBSD code, adding the $ifschar removes a parameter.

PR:		standards/79067
Approved by:	ed (mentor) (implicit)
2009-06-25 17:14:06 +00:00
Jilles Tjoelker
18d56246e9 Improve IFS expansion using code from NetBSD.
We now pass the ifs.sh testsuite.

PR:		standards/79067
Approved by:	ed (mentor) (implicit)
Obtained from:	NetBSD
2009-06-25 17:10:51 +00:00
Jilles Tjoelker
30268dfa3f Designate special builtins as such in command -V and type.
Also document various properties of special builtins that we implement.

Approved by:	ed (mentor) (implicit)
2009-06-24 22:04:04 +00:00
Xin LI
431586a895 Staticify internal routines. 2009-06-23 23:30:56 +00:00
Jilles Tjoelker
689f1cbba5 Quote -x tracing output so it is unambiguous.
It is usually but not always suitable for re-input to the shell.

Approved by:	ed (mentor) (implicit)
2009-06-23 22:53:34 +00:00
Jilles Tjoelker
4f6e4215a0 Do not fork for a subshell if it is the last thing this shell is doing
(EV_EXIT). The fork is still done as normal if any traps are active.

In many cases, the fork can be avoided even without this change by using {}
instead of (), but in practice many scripts use (), likely because the
syntax is simpler.

Example:
  sh -c '(/bin/sleep 10)& sleep 1;ps -p $! -o comm='
Now prints "sleep" instead of "sh". $! is more useful this way.
Most shells (dash, bash, pdksh, ksh93, zsh) seem to print "sleep" for this.

Example:
  sh -c '( ( ( (ps jT))))'
Now shows no waiting shell processes instead of four.
Most shells (dash, bash, pdksh, ksh93, zsh) seem to show zero or one.

PR:		bin/74404
Approved by:	ed (mentor) (implicit)
2009-06-23 21:50:06 +00:00
Konstantin Belousov
c9253e931d Usermode portion of the support for swap allocation accounting:
- update for getrlimit(2) manpage;
- support for setting RLIMIT_SWAP in login class;
- addition to the limits(1) and sh and csh limit-setting builtins;
- tuning(7) documentation on the sysctls controlling overcommit.

In collaboration with:	pho
Reviewed by:	alc
Approved by:	re (kensmith)
2009-06-23 20:57:27 +00:00
Jilles Tjoelker
224fbf9fd6 sh: Improve handling of setjmp/longjmp volatile:
- remove ineffective and unnecessary (void) &var; [1]
- remove some unnecessary volatile keywords
- add a necessary volatile keyword
- save the old handler before doing something that could use the saved
  value

Submitted by:	Christoph Mallon [1]
Approved by:	ed (mentor)
2009-06-23 20:45:12 +00:00
Jilles Tjoelker
deb090cba3 Fix race condition in noclobber option.
Formerly, it was possible for the file to be created between the check if it
existed and the open; the contents would then be lost.

Because this must use O_EXCL, noclobber > will not create a file through a
symlink anymore. This agrees with behaviour of other shells.

Approved by:	ed (mentor) (implicit)
2009-06-20 20:44:27 +00:00
Jilles Tjoelker
e68165a6bb Fix some issues with quoted output and shorten it in some cases.
Output quoted suitable for re-input to the shell occurs in
various cases such as 'set', 'trap'.

Bugfix: *, ? and [ must be quoted (except sole [)
Bugfix: ~ and # must be quoted (really only sometimes, but keep it simple)
Bugfix: space, tab and newline must always be quoted
Shortening: other IFS characters do not need quoting
Bugfix: send to correct output file, not hard-coded stdout
Shortening: avoid unnecessary '' with \'

Approved by:	ed (mentor)
2009-06-19 22:09:55 +00:00
Jilles Tjoelker
3055b7c6ff Properly flush input after an error in backquotes in interactive mode.
For parsing an old-style backquote substitution (`...`),
a string "file" is used to store the contents of the
substitution (with the special backslash processing done).
If an error occurs, the shell cleans up all these files
(returning to the top level) and flush the top level
file. Erroneously, it first flushed the current file and
then cleaned up all extra files, so that the top level
file (i.e. the terminal) was not flushed.

Example (in interactive mode):
  echo `for` echo This should not be printed

Also noticeable in (in interactive mode):
  echo `(`
The old version prints an extraneous prompt.

Approved by:	ed (mentor)
2009-06-17 21:58:32 +00:00
Jilles Tjoelker
960da93430 Avoid leaving unnecessary waiting shells in many forms of sh -c COMMAND.
This change only affects strings passed to -c, when the -s
option is not used.

The approach is to check if there may be additional data
in the string after parsing each command. If there is none,
use the EV_EXIT flag so that a fork may be omitted in
specific cases.

If there are empty lines after the command, the check will
not see the end and forks will not be omitted. The same
thing seems to happen in bash.

Example:
  sh -c 'ps lT'
No longer shows a shell process waiting for ps to finish.

PR:		bin/113860
Reviewed by:	stefanf
Approved by:	ed (mentor)
2009-06-13 21:17:45 +00:00
Jilles Tjoelker
6e28dacfda Don't skip forking for an external command if any traps are active.
Example:
  sh -c '(trap "echo trapped" EXIT; sleep 3)'
now correctly prints "trapped".

With this check, it is no longer necessary to check for -T
explicitly in that case.

This is a useful bugfix by itself and also important because I plan to
skip forking more often.

PR:		bin/113860 (part of)
PR:		bin/74404 (part of)
Reviewed by:	stefanf
Approved by:	ed (mentor)
2009-06-13 21:10:41 +00:00
Jilles Tjoelker
a68fbc44ee Mention the range for the exit status for the exit special builtin.
The exit status may exceed 255 in some cases (return); even though it seems
unwise to rely on this, it is also unwise to assume that $? is always
between 0 and 255.

This resolves bin/124748 by documenting that 'exit -1' is not valid.

PR:		bin/124748
Approved by:	ed (mentor)
2009-06-07 15:04:43 +00:00
Simon L. B. Nielsen
b93ce3b716 Make "human-readable" (-H/-h) output also "humanize" inode counts.
Base 10 is always used for the inode counts as I could not think of any
reason base 2 inode counts would be useful.

Minor mdoc markup fix to df(1) while here anyway.

MFC after:	3 weeks
2009-06-07 09:06:21 +00:00
Ralf S. Engelschall
f001f89625 use explicit 'unsigned int' instead of just the implicit-style 'unsigned' to make linting tools (e.g. FlexeLint) happy, too 2009-06-01 11:38:38 +00:00
Ralf S. Engelschall
35f2d3b6b1 align coding style with style(9) to avoid misunderstandings 2009-06-01 11:11:46 +00:00
Ralf S. Engelschall
26286b8acf correctly test for __GNUC__ macro (non-GCC compilers do not have it defined at all) 2009-06-01 11:02:09 +00:00
Ralf S. Engelschall
ac08b88250 be more type correct and align local ckmalloc() with its underlying malloc(3) by using a "size_t" instead of an "int" argument 2009-06-01 10:50:17 +00:00
Jilles Tjoelker
fe40d6d3b1 sh: Make read's timeout (-t) apply to the entire line, not only the first
character.

This avoids using non-standard behaviour of the old (upto FreeBSD 7) TTY
layer: it reprocesses the input queue when switching to canonical mode. The
new TTY layer does not provide this functionality and so read -t worked
very poorly (first character is not echoed, cannot be backspaced but is
still read).

This also agrees with what most other shells with read -t do.

PR:		bin/129566
Reviewed by:	stefanf
Approved by:	ed (mentor)
2009-05-31 19:37:06 +00:00
Stefan Farfeleder
cb806389db Fix the eval command in combination with set -e. Before this change the shell
would always terminate if eval returned with a non-zero exit status regardless
if the status was actually tested.  Unfortunately a new file-scope variable
is needed, the alternative would only be to add a new parameter to all
built-ins.

PR:	134881
2009-05-31 12:36:14 +00:00
Jilles Tjoelker
6911f596a1 rm, find -delete: fix removing symlinks with uchg/uappnd set.
Formerly, this tried to clear the flags on the symlink's target
instead of the symlink itself.

As before, this only happens for root or for the unlink(1) variant of rm.

PR:		bin/111226 (part of)
Submitted by:	Martin Kammerhofer
Approved by:	ed (mentor)
MFC after:	3 weeks
2009-05-30 10:42:19 +00:00