Commit Graph

1165 Commits

Author SHA1 Message Date
Jilles Tjoelker
70d41b5846 wordexp(): Remove wrong IFS usage.
Words in shell script are separated by spaces or tabs independent of the
value of IFS. The value of IFS is only relevant for the result of
substitutions. Therefore, there should be a space between 'wordexp' and the
words to be expanded, not an IFS character.

Paranoia might dictate that the shell ignore IFS from the environment (even
though our sh currently uses it), so do not depend on it in the new test
case.
2013-04-01 20:50:07 +00:00
Pawel Jakub Dawidek
ff96467412 Update regression tests after adding chflagsat(2).
Sponsored by:	The FreeBSD Foundation
2013-03-21 23:07:04 +00:00
Pawel Jakub Dawidek
b4b2596b97 - Make 'flags' argument to chflags(2), fchflags(2) and lchflags(2) of type
u_long. Before this change it was of type int for syscalls, but prototypes
  in sys/stat.h and documentation for chflags(2) and fchflags(2) (but not
  for lchflags(2)) stated that it was u_long. Now some related functions
  use u_long type for flags (strtofflags(3), fflagstostr(3)).
- Make path argument of type 'const char *' for consistency.

Discussed on:	arch
Sponsored by:	The FreeBSD Foundation
2013-03-21 22:44:33 +00:00
Pawel Jakub Dawidek
b48fdae147 Update the tests now that absence of the O_APPEND flag requires CAP_SEEK
capability. Add some more tests.

Sponsored by:	The FreeBSD Foundation
2013-03-16 23:13:49 +00:00
Pawel Jakub Dawidek
ac978022d3 The mode argument for open(2)/openat(2) only makes sense if the O_CREAT flag
was given.

Sponsored by:	The FreeBSD Foundation
2013-03-16 23:10:40 +00:00
Jilles Tjoelker
d70ad6f2d0 sh: Recognize "--" and explicitly reject options in wait builtin.
If syntactically invalid job identifiers are to be taken as jobs that exited
with status 127, this should not apply to options, so that we can add
options later if need be.
2013-03-15 20:29:31 +00:00
Pawel Jakub Dawidek
374b056ce8 Make file name generation to work with both new and old versions of OpenSSL.
Sponsored by:	The FreeBSD Foundation
2013-03-15 00:10:38 +00:00
Jilles Tjoelker
3fe1119f98 sh: When executing a trap, keep exit status along with evalskip.
This ensures 'return' in a trap returns the correct status to the caller.

If evalskip is not set or if it is overridden by a previous evalskip, keep
the old behaviour of restoring the exit status from before the trap.
2013-03-03 17:33:59 +00:00
Pawel Jakub Dawidek
2328a74aa8 If all ioctls are allowed, cap_ioctls_get(2) will return CAP_IOCTLS_ALL.
Update regression tests.
2013-03-02 23:40:42 +00:00
Pawel Jakub Dawidek
7099ae5f3d Add support for bindat(2) and connectat(2).
Sponsored by:	The FreeBSD Foundation
2013-03-02 21:16:40 +00:00
Pawel Jakub Dawidek
de50394176 Add regression tests for the new Capsicum system calls.
Sponsored by:	The FreeBSD Foundation
2013-03-02 01:00:26 +00:00
Pawel Jakub Dawidek
f29088987a Update existing regression tests after Capsicum overhaul. 2013-03-02 00:56:53 +00:00
John Baldwin
9240031ac6 Add an implementation of open_memstream() and open_wmemstream(). These
routines provide write-only stdio FILE objects that store their data in a
dynamically allocated buffer.  They are a string builder interface somewhat
akin to a completely dynamic sbuf.

Reviewed by:	bde, jilles (earlier versions)
MFC after:	1 month
2013-02-27 19:50:46 +00:00
Peter Jeremy
293beebc46 Enhance test(1) by adding provision to compare any combination of the
access, birth, change and modify times of two files, instead of only
being able to compare modify times.  The builtin test in sh(1) will
automagically acquire the same expansion.

Approved by:	grog
MFC after:	2 weeks
2013-02-25 19:05:40 +00:00
Jilles Tjoelker
25e0f0f577 sh: If a SIGINT or SIGQUIT interrupts "wait", return status 128+sig. 2013-02-23 22:50:57 +00:00
Jilles Tjoelker
57f00aa510 sh: Test that the exit status is 1 if read encounters EOF. 2013-02-23 15:15:41 +00:00
Sergey Kandaurov
b57181586c Major update for unix_cmsg from Andrey Simonenko.
Quoting the submitter:
- Added tests for SCM_BINTIME, LOCAL_PEERCRED, cmsghdr.cmsg_len
- Code that checks correctness of groups was corrected (getgroups(2) change)
- unix_cmsg.c was completely redesigned and simplified
- Use less timeout value in unix_cmsg.c for faster work
- Added support for not sending data in a message, not sending data and
  data array associated with a cmsghdr structure in a message
- Existent tests were improved
- unix_cmsg.t was redesigned and simplified

Correctness of unix_cmsg verified on 7.1-STABLE, 9.1-STABLE and 10-CURRENT.

PR:		bin/131567
Submitted by:	Andrey Simonenko <simon@comsys.ntu-kpi.kiev.ua>
MFC after:	2 weeks
2013-02-11 12:56:23 +00:00
Pietro Cerutti
71796d333c - Fix more style(9)-related issues (copyright header, spaces after function
names, unnecessary casts)
- Change type of boolean variable from char to bool

Suggested by:	jhb, zont, jmallett
Reviewed by:	cognet
Approved by:	cognet
2013-02-01 13:04:06 +00:00
Pietro Cerutti
646b68f04d - Remove underscores from the internal structure name, as it doesn't collide
with the user's namespace.

- Correct size and position variables type from long to size_t.

- Do not set errno to ENOMEM on malloc failure, as malloc already does so.

- Implement the concept of "buffer data length", which mandates what SEEK_END
  refers to and the allowed extent for a read.

- Use NULL as read-callback if the buffer is opened in write-only mode.
  Conversely, use NULL as write-callback when opened in read-only mode.

- Implement the handling of the ``b'' character in the mode argument. A binary
  buffer differs from a text buffer (default mode if ``b'' is omitted) in that
  NULL bytes are never appended to writes and that the "buffer data length"
  equals to the size of the buffer.

- Remove shall from the man page. Use indicative instead. Also, specify that
  the ``b'' flag does not conform with POSIX but is supported by glibc.

- Update the regression test so that the ``b'' functionality and the "buffer
  data length" concepts are tested.

- Minor style(9) corrections.

Suggested by:	jilles
Reviewed by:	cognet
Approved by:	cognet
2013-01-31 16:39:50 +00:00
Pietro Cerutti
96c95412ca Add fmemopen(3), an interface to get a FILE * from a buffer in memory, along
with the respective regression test.
See http://pubs.opengroup.org/onlinepubs/9699919799/functions/fmemopen.html

Reviewed by:	cognet
Approved by:	cognet
2013-01-30 14:59:26 +00:00
Jilles Tjoelker
925420d09c sh: Pass $? to command substitution containing compound/multiple commands.
Example:
  false; echo $(echo $?; :)
2013-01-14 12:20:55 +00:00
Jilles Tjoelker
e1e1f0e44f sh: Add testcase that $? is preserved into a simple command substitution.
The test builtins/trap6.0 already uses this but having it separate eases
diagnosis if this would break.
2013-01-13 22:35:51 +00:00
Jilles Tjoelker
f897e827b9 sh: Add some testcases related to subshells.
These failed in earlier attempts to execute more subshells without forking.
The patches are uncommitted.
2013-01-13 19:39:13 +00:00
Jilles Tjoelker
31d396587e sh: Fix crash when parsing '{ } &'.
MFC after:	1 week
2013-01-13 19:26:33 +00:00
Jilles Tjoelker
2c090c7168 sh: Don't lose $? when backquoted command ends with semicolon or newline.
An empty simple command was added and overwrote the exit status with 0.

This affects `...` but not $(...).

Example:
  v=`false;`; echo $?
2013-01-13 19:19:40 +00:00
Eitan Adler
ad9d6ff06a Add an additional regression tests for other cases to ensure these do not get fixed by accident. 2012-12-18 21:42:45 +00:00
Eitan Adler
2f01c791e9 POSIX requires that non-existent or null arguments be treated as if a
zero argument were supplied.

Add a regression test to catch this case as well.

PR:		bin/174521
Submitted by:	Daniel Shahaf <danielsh@elego.de> (pr)
Submitted by:	Mark Johnston <markjdb@gmail.com> (initial patch)
Reviewed by:	jilles
Approved by:	cperciva (implicit)
MFC after:	3 weeks
2012-12-18 21:02:38 +00:00
Jilles Tjoelker
d6d66cfc00 sh: Detect and flag write errors on stdout in builtins.
If there is a write error on stdout, a message will be printed (to stderr)
and the exit status will be changed to 2 if it would have been 0 or 1.

PR:		bin/158206
2012-12-12 22:01:10 +00:00
Jilles Tjoelker
b731376e8c libc: Add a missing header to a test program.
Usage of dup(), mkstemp() and unlink() needs <unistd.h>.
2012-12-08 19:42:15 +00:00
Ed Maste
c153604de3 Non-void function should return a value.
Found by: clang
2012-11-20 19:23:44 +00:00
Ed Maste
f77a2d2f24 Remove unused variable. 2012-11-20 01:42:18 +00:00
Ed Maste
4039f071d0 Use '%zu' and '%zd' as appropriate for size_t / ssize_t. 2012-11-19 23:07:38 +00:00
Ed Maste
8f37d24bed Zero the whole struct not just the size of a pointer.
Found by: clang
2012-11-19 22:56:51 +00:00
Ed Maste
d701ebcb13 Use '%zd' format specifier for ssize_t
Found by: clang
2012-11-19 22:53:57 +00:00
Ed Maste
03aac27561 Use '%zd' printf format for ssize_t. 2012-11-19 22:46:17 +00:00
Jilles Tjoelker
4eefd6e828 sh: Apply rlimits to parser/alias10.0 so it fails fast.
Requested by:	uqs
2012-11-18 23:15:22 +00:00
Jilles Tjoelker
2b6ceccde5 sh: Add tests for modifying an alias (r242766).
Note: parser/alias10.0 will eat a lot of memory/cpu time when it fails (with
the old sh).
2012-11-08 13:36:19 +00:00
Jilles Tjoelker
530f737839 sh: Test that a redefined alias works. 2012-11-07 23:15:36 +00:00
David E. O'Brien
aa1e1e87d0 Test both active and non-active cases. 2012-10-26 20:14:40 +00:00
David E. O'Brien
93665dfffb Iterate rather than use recursion. We can blow out the kernel stack if there
is a long chain of fork(2)s.
2012-10-26 15:44:29 +00:00
Eitan Adler
db702c59cf remove duplicate semicolons where possible.
Approved by:	cperciva
MFC after:	1 week
2012-10-22 03:00:37 +00:00
Eitan Adler
1f35187f99 Covert regression test to python 3
Approved by:	cperciva
MFC after:	3 days
2012-10-22 02:29:44 +00:00
Kevin Lo
9823d52705 Revert previous commit...
Pointyhat to:	kevlo (myself)
2012-10-10 08:36:38 +00:00
Kevin Lo
a10cee30c9 Prefer NULL over 0 for pointers 2012-10-09 08:27:40 +00:00
Ed Maste
8fa4106e74 Add regression test for kern/172075.
Sponsored by:	ADARA Networks
PR:		kern/172075
2012-09-26 00:25:09 +00:00
Jilles Tjoelker
01f7f6ef18 sh: Add some tests for aliasing a utility to itself. 2012-09-22 12:52:41 +00:00
Jilles Tjoelker
9d8ca3b2ad nftw(): POSIX says directories causing loops should be silently skipped.
Formerly, loops caused nftw() to abort the traversal with ELOOP.
2012-08-09 22:05:40 +00:00
Jilles Tjoelker
fe36e227e8 sh: Add a simple test for the "local" builtin. 2012-07-15 10:22:13 +00:00
Jilles Tjoelker
84fbdd8ca0 sh: Expand assignment-like words specially for export/readonly/local.
Examples:
  export x=~
now expands the tilde
  local y=$1
is now safe, even if $1 contains IFS characters or metacharacters.

For a word to "look like an assignment", it must start with a name followed
by an equals sign, none of which may be quoted.

The special treatment applies when the first word (potentially after
"command") is "export", "readonly" or "local". There may be quoting
characters but no expansions. If "local" is overridden with a function there
is no special treatment ("export" and "readonly" cannot be overridden with a
function).

If things like
  local arr=(1 2 3)
are ever allowed in the future, they cannot call a "local" function. This
would either be a run-time error or it would call the builtin.

This matches Austin Group bug #351, planned for the next issue of POSIX.1.

PR:		bin/166771
2012-07-15 10:19:43 +00:00
Jilles Tjoelker
a017ea22e5 sh: Add tests where "export" does not parse differently.
It is planned to expand variable assignments as assignments (no word
splitting, different tilde expansion) when they follow a "declaration
utility" (export, readonly or local). However, a quoted character cannot be
part of a "name" so things like \v=~ are not assignments, and the existing
behaviour applies.
2012-07-13 22:29:02 +00:00