2322 Commits

Author SHA1 Message Date
Jilles Tjoelker
d366e1de7f MFC r207944: sh: Fix pathname expansion with quoted slashes like *\/.
These are git commits 36f0fa8fcbc8c7b2b194addd29100fb40e73e4e9 and
d6d06ff5c2ea0fa44becc5ef4340e5f2f15073e4 in dash.

Because this is the first code I'm importing from dash to expand.c, add the
Herbert Xu copyright notice which is in dash's expand.c.

When pathname expanding *\/, the CTLESC representing the quoted state was
erroneously taken as part of the * pathname component. This CTLESC was then
seen by the pattern matching code as escaping the '\0' terminating the
string.

The code is slightly different because dash converts the CTLESC characters
to backslashes and removes all the other CTL* characters to allow
substituting glob(3).

The effect of the bug was also slightly different from dash (where nothing
matched at all). Because a CTLESC can escape a '\0' in some way, whether
files were included despite the bug depended on memory that should not be
read. In particular, on many machines /*\/ expanded to a strict subset of
what /*/ expanded to.

Example:
  echo /*"/null"

This should print /dev/null, not /*/null.

PR:		bin/146378
Obtained from:	dash
2010-05-16 22:52:51 +00:00
Stefan Farfeleder
7baf1076be Merge r199631: Handle current work directories of arbitrary length. 2010-05-16 10:01:06 +00:00
Konstantin Belousov
b721d61527 MFC r206548:
Update the list of the process flags for P_WKILLED.
2010-05-11 11:22:18 +00:00
Jilles Tjoelker
f4eb99be97 MFC r207189: symlink(7): Add lpathconf(2) and *at system calls. 2010-05-02 13:36:23 +00:00
Jilles Tjoelker
e96d10e414 MFC r207188: symlink(7): The ownership of symlinks is used by the system,
in at least three ways, so do not say it is ignored:
* who may delete/rename a symlink in a sticky directory
* who may do lchflags(2)/lchown(2)/lchmod(2)
* whose inode quota is charged
2010-05-02 12:43:18 +00:00
Jilles Tjoelker
312a3c0cba MFC r207021: ln: Allow a trailing slash when creating a link to a directory.
In the 'ln source... directory' synopsis, the basename of each source
determines the name of the created link. Determine this using basename(3)
instead of strrchr(..., '/') which is incorrect if the pathname ends in a
slash.

PR:		121568
2010-05-01 14:33:26 +00:00
Jilles Tjoelker
1577aa79c0 MFC r206773: ln: Do not delete a file by hardlinking it to itself.
Two pathnames refer to the same directory entry iff the directories match
and the final components' names match.

Example: (assuming file1 is an existing file)
  ln -f file1 file1
This now fails while leaving file1 intact. It used to delete file1 and then
complain it cannot be linked because it is gone.

With -i, this error is detected before the question is asked.
2010-05-01 14:29:33 +00:00
Jilles Tjoelker
1f7026c763 MFC r197848: Clarify quoting of word in ${v=word} in sh(1). 2010-04-23 19:26:03 +00:00
Jilles Tjoelker
f08f4ed374 MFC r203576,r203677: sh: Don't stat() $MAIL/$MAILPATH if not interactive.
These may be NFS mounted, and we should not touch them unless we are going
to do something useful with the information.
2010-04-20 22:52:28 +00:00
Jilles Tjoelker
7e140e7e32 MFC r200943: sh: Remove setting variables from dotcmd/exportcmd.
It is already done by evalcommand(), unless special-ness has been removed,
in which case variable assignments should not persist. (These are currently
always special builtins, but this may change later: command builtin,
command substitution.)

This also fixes a memory leak when calling . with variable assignments.

Example:
  valgrind --leak-check=full sh -c 'x=1 . /dev/null; x=2'
2010-04-20 22:32:34 +00:00
Jilles Tjoelker
631680bf1c MFC r199282: sh: Allow a newline before "in" in a for command,
as required by POSIX.
2010-04-20 22:20:31 +00:00
Konstantin Belousov
5a9ca220b2 MFC r204755:
Update the list of the process flags. Note that the lists of pending
signals for process and its threads are distinct.
2010-03-19 10:25:59 +00:00
Konstantin Belousov
a617939995 MFC r204308:
Do not restrict the allowed signals that can be specified by number
to the list of signals that has symbolic name. It was impossible to
send rt signals with kill(1) due to the check.
2010-03-04 07:08:01 +00:00
Jaakko Heinonen
91288970ce MFC r204276:
Fix expansion of \W in prompt strings when the working directory is "/".
The prompt string was truncated after \W when the working directory was "/".

PR:		bin/89410
2010-03-03 16:06:43 +00:00
Jaakko Heinonen
e0d5ebc30f MFC r203665:
Make sure that FTS_COMFOLLOW is not set when the -P option is in effect.
Otherwise the -i option will show the inode number of the referenced file
for symbolic links given on the command line. Similarly, the file color
was printed according to the link target in colorized output.

PR:		bin/102394
2010-02-28 14:04:20 +00:00
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