svn commit: r320532 - in stable/10/usr.bin/compress: . tests

2017-07-01 Thread Jilles Tjoelker
Author: jilles
Date: Sat Jul  1 13:03:02 2017
New Revision: 320532
URL: https://svnweb.freebsd.org/changeset/base/320532

Log:
  MFC r318592: compress: Allow uncompress -c with multiple pathnames,
  as required by POSIX.
  
  Per POSIX, allow passing multiple pathnames to uncompress -c, concatenating
  the uncompressed data.
  
  Passing multiple pathnames to compress -c remains disallowed, since the
  result cannot be decompressed.
  
  PR:   219387

Modified:
  stable/10/usr.bin/compress/compress.c
  stable/10/usr.bin/compress/tests/compress_test.sh
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/usr.bin/compress/compress.c
==
--- stable/10/usr.bin/compress/compress.c   Sat Jul  1 12:57:00 2017
(r320531)
+++ stable/10/usr.bin/compress/compress.c   Sat Jul  1 13:03:02 2017
(r320532)
@@ -128,7 +128,7 @@ main(int argc, char *argv[])
exit (eval);
}
 
-   if (cat == 1 && argc > 1)
+   if (cat == 1 && style == COMPRESS && argc > 1)
errx(1, "the -c option permits only a single file argument");
 
for (; *argv; ++argv)

Modified: stable/10/usr.bin/compress/tests/compress_test.sh
==
--- stable/10/usr.bin/compress/tests/compress_test.sh   Sat Jul  1 12:57:00 
2017(r320531)
+++ stable/10/usr.bin/compress/tests/compress_test.sh   Sat Jul  1 13:03:02 
2017(r320532)
@@ -161,6 +161,27 @@ compress_uncompress_file_2_body()
atf_check cmp file2 expectfile2
 }
 
+atf_test_case compress_uncompress_file_minusc_1
+compress_uncompress_file_minusc_1_head()
+{
+   atf_set "descr" \
+   "Test compressing and uncompressing some data, passing two 
filenames to uncompress -c"
+}
+compress_uncompress_file_minusc_1_body()
+{
+   printf '%01000d\n' 7 8 >expectfile1
+   printf '%01000d\n' 8 7 >expectfile2
+   cp expectfile1 file1
+   cp expectfile2 file2
+   atf_check compress file1 file2
+   atf_check -s exit:1 cmp -s file1.Z expectfile1
+   atf_check -s exit:1 cmp -s file2.Z expectfile2
+   atf_check -s exit:1 cmp -s file1.Z file2.Z
+   atf_check -x 'uncompress -c file1.Z file2.Z >all'
+   atf_check -x 'cat expectfile1 expectfile2 >expectall'
+   atf_check cmp all expectall
+}
+
 atf_init_test_cases()
 {
atf_add_test_case uncompress_file_1
@@ -171,4 +192,5 @@ atf_init_test_cases()
atf_add_test_case compress_uncompress_minusc_1
atf_add_test_case compress_uncompress_file_1
atf_add_test_case compress_uncompress_file_2
+   atf_add_test_case compress_uncompress_file_minusc_1
 }
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r320531 - in stable/10/bin/sh: . tests/builtins

2017-07-01 Thread Jilles Tjoelker
Author: jilles
Date: Sat Jul  1 12:57:00 2017
New Revision: 320531
URL: https://svnweb.freebsd.org/changeset/base/320531

Log:
  MFC r317912: sh: Fix INTOFF leak after a builtin with different locale
  settings.
  
  After executing a builtin with different locale settings such as
LC_ALL=C true
  SIGINT handling was left disabled indefinitely.

Added:
  stable/10/bin/sh/tests/builtins/locale2.0
 - copied unchanged from r317912, head/bin/sh/tests/builtins/locale2.0
Modified:
  stable/10/bin/sh/tests/builtins/Makefile
  stable/10/bin/sh/var.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/bin/sh/tests/builtins/Makefile
==
--- stable/10/bin/sh/tests/builtins/MakefileSat Jul  1 10:04:42 2017
(r320530)
+++ stable/10/bin/sh/tests/builtins/MakefileSat Jul  1 12:57:00 2017
(r320531)
@@ -100,6 +100,7 @@ FILES+= local4.0
 .if ${MK_NLS} != "no"
 FILES+=locale1.0
 .endif
+FILES+=locale2.0
 FILES+=printf1.0
 FILES+=printf2.0
 FILES+=printf3.0

Copied: stable/10/bin/sh/tests/builtins/locale2.0 (from r317912, 
head/bin/sh/tests/builtins/locale2.0)
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/10/bin/sh/tests/builtins/locale2.0   Sat Jul  1 12:57:00 2017
(r320531, copy of r317912, head/bin/sh/tests/builtins/locale2.0)
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+$SH -c 'LC_ALL=C true; kill -INT $$; echo continued'
+r=$?
+[ "$r" -gt 128 ] && [ "$(kill -l "$r")" = INT ]

Modified: stable/10/bin/sh/var.c
==
--- stable/10/bin/sh/var.c  Sat Jul  1 10:04:42 2017(r320530)
+++ stable/10/bin/sh/var.c  Sat Jul  1 12:57:00 2017(r320531)
@@ -506,7 +506,7 @@ bltinunsetlocale(void)
if (localevar(lp->text)) {
setlocale(LC_ALL, "");
updatecharset();
-   return;
+   break;
}
}
INTON;
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r320518 - in stable/10: etc/mtree usr.bin/compress usr.bin/compress/tests

2017-06-30 Thread Jilles Tjoelker
Author: jilles
Date: Fri Jun 30 22:16:28 2017
New Revision: 320518
URL: https://svnweb.freebsd.org/changeset/base/320518

Log:
  MFC r318591: compress: Add basic tests.

Added:
  stable/10/usr.bin/compress/tests/
 - copied from r318591, head/usr.bin/compress/tests/
Modified:
  stable/10/etc/mtree/BSD.tests.dist
  stable/10/usr.bin/compress/Makefile
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/etc/mtree/BSD.tests.dist
==
--- stable/10/etc/mtree/BSD.tests.dist  Fri Jun 30 22:14:22 2017
(r320517)
+++ stable/10/etc/mtree/BSD.tests.dist  Fri Jun 30 22:16:28 2017
(r320518)
@@ -576,6 +576,8 @@
 ..
 cmp
 ..
+compress
+..
 cpio
 ..
 col

Modified: stable/10/usr.bin/compress/Makefile
==
--- stable/10/usr.bin/compress/Makefile Fri Jun 30 22:14:22 2017
(r320517)
+++ stable/10/usr.bin/compress/Makefile Fri Jun 30 22:16:28 2017
(r320518)
@@ -1,6 +1,8 @@
 #  @(#)Makefile8.2 (Berkeley) 4/17/94
 # $FreeBSD$
 
+.include 
+
 PROG=  compress
 SRCS=  compress.c zopen.c
 LINKS= ${BINDIR}/compress ${BINDIR}/uncompress
@@ -8,5 +10,9 @@ MLINKS=compress.1 uncompress.1
 
 # XXX zopen is not part of libc
 # MAN=zopen.3
+
+.if ${MK_TESTS} != "no"
+SUBDIR+=   tests
+.endif
 
 .include 
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r320510 - in stable/10/bin/sh: . tests/expansion

2017-06-30 Thread Jilles Tjoelker
Author: jilles
Date: Fri Jun 30 21:32:48 2017
New Revision: 320510
URL: https://svnweb.freebsd.org/changeset/base/320510

Log:
  MFC r315005: sh: Fix executing wrong command with ${x#$(y)}$(z).
  
  The parsed internal representation of words consists of a byte string with a
  list of nodes (commands in command substitution). Each unescaped CTLBACKQ or
  CTLBACKQ | CTLQUOTE byte corresponds to an entry in the list.
  
  If param in ${param#%##%%word} is not set, the word is not expanded (in a
  deviation of POSIX shared with other ash variants and ksh93). Erroneously,
  the pointer in the list of commands (argbackq) was not advanced. This caused
  the wrong command to be executed later if the outer word contained another
  command substitution.
  
  Example:
echo "${unsetvar#$(echo a)}$(echo b)"
  wrote "a" but should write "b".

Added:
  stable/10/bin/sh/tests/expansion/cmdsubst23.0
 - copied unchanged from r315005, head/bin/sh/tests/expansion/cmdsubst23.0
Modified:
  stable/10/bin/sh/expand.c
  stable/10/bin/sh/tests/expansion/Makefile
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/bin/sh/expand.c
==
--- stable/10/bin/sh/expand.c   Fri Jun 30 20:27:51 2017(r320509)
+++ stable/10/bin/sh/expand.c   Fri Jun 30 21:32:48 2017(r320510)
@@ -740,8 +740,10 @@ again: /* jump here after setting a variable with ${va
case VSTRIMLEFTMAX:
case VSTRIMRIGHT:
case VSTRIMRIGHTMAX:
-   if (!set)
+   if (!set) {
+   set = 1;
break;
+   }
/*
 * Terminate the string and start recording the pattern
 * right after it

Modified: stable/10/bin/sh/tests/expansion/Makefile
==
--- stable/10/bin/sh/tests/expansion/Makefile   Fri Jun 30 20:27:51 2017
(r320509)
+++ stable/10/bin/sh/tests/expansion/Makefile   Fri Jun 30 21:32:48 2017
(r320510)
@@ -43,6 +43,7 @@ FILES+=   cmdsubst19.0
 FILES+=cmdsubst20.0
 FILES+=cmdsubst21.0
 FILES+=cmdsubst22.0
+FILES+=cmdsubst23.0
 FILES+=export1.0
 FILES+=export2.0
 FILES+=export3.0

Copied: stable/10/bin/sh/tests/expansion/cmdsubst23.0 (from r315005, 
head/bin/sh/tests/expansion/cmdsubst23.0)
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/10/bin/sh/tests/expansion/cmdsubst23.0   Fri Jun 30 21:32:48 
2017(r320510, copy of r315005, head/bin/sh/tests/expansion/cmdsubst23.0)
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+unset n
+x=abcd
+[ "X${n#$(echo a)}X${x#$(echo ab)}X$(echo abc)X" = XXcdXabcX ]
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r316942 - in stable/10/bin/sh: . tests/expansion

2017-04-14 Thread Jilles Tjoelker
Author: jilles
Date: Fri Apr 14 21:42:27 2017
New Revision: 316942
URL: https://svnweb.freebsd.org/changeset/base/316942

Log:
  MFC r314686: sh: Fix crash if a -T trap is taken during command substitution.
  
  Code like  t=$(stat -f %m "$file")  segfaulted if -T was active and a trap
  was taken while the shell was waiting for the child process to finish.
  
  What happened was that the dotrap() call in waitforjob() was hit. This
  re-entered command execution (including expand.c) at a point not expected by
  expbackq(), and global state (unallocated stack string and argbackq) was
  corrupted.
  
  To fix this, change expbackq() to prepare for command execution to be
  re-entered.
  
  In stable/10, there is more global state that needs to be restored than in
  stable/11 and head.
  
  Reported by:  bdrewery

Added:
  stable/10/bin/sh/tests/expansion/cmdsubst21.0
 - copied unchanged from r314686, head/bin/sh/tests/expansion/cmdsubst21.0
  stable/10/bin/sh/tests/expansion/cmdsubst22.0
 - copied unchanged from r314686, head/bin/sh/tests/expansion/cmdsubst22.0
Modified:
  stable/10/bin/sh/expand.c
  stable/10/bin/sh/tests/expansion/Makefile
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/bin/sh/expand.c
==
--- stable/10/bin/sh/expand.c   Fri Apr 14 20:15:34 2017(r316941)
+++ stable/10/bin/sh/expand.c   Fri Apr 14 21:42:27 2017(r316942)
@@ -439,9 +439,6 @@ expbackq(union node *cmd, int quoted, in
p = grabstackstr(dest);
evalbackcmd(cmd, );
ungrabstackstr(p, dest);
-   ifsfirst = saveifs;
-   ifslastp = savelastp;
-   argbackq = saveargbackq;
 
p = in.buf;
lastc = '\0';
@@ -479,14 +476,20 @@ expbackq(union node *cmd, int quoted, in
close(in.fd);
if (in.buf)
ckfree(in.buf);
-   if (in.jp)
+   if (in.jp) {
+   p = grabstackstr(dest);
exitstatus = waitforjob(in.jp, (int *)NULL);
-   if (quoted == 0)
-   recordregion(startloc, dest - stackblock(), 0);
+   ungrabstackstr(p, dest);
+   }
TRACE(("expbackq: size=%td: \"%.*s\"\n",
((dest - stackblock()) - startloc),
(int)((dest - stackblock()) - startloc),
stackblock() + startloc));
+   ifsfirst = saveifs;
+   ifslastp = savelastp;
+   if (quoted == 0)
+   recordregion(startloc, dest - stackblock(), 0);
+   argbackq = saveargbackq;
expdest = dest;
INTON;
 }

Modified: stable/10/bin/sh/tests/expansion/Makefile
==
--- stable/10/bin/sh/tests/expansion/Makefile   Fri Apr 14 20:15:34 2017
(r316941)
+++ stable/10/bin/sh/tests/expansion/Makefile   Fri Apr 14 21:42:27 2017
(r316942)
@@ -41,6 +41,8 @@ FILES+=   cmdsubst17.0
 FILES+=cmdsubst18.0
 FILES+=cmdsubst19.0
 FILES+=cmdsubst20.0
+FILES+=cmdsubst21.0
+FILES+=cmdsubst22.0
 FILES+=export1.0
 FILES+=export2.0
 FILES+=export3.0

Copied: stable/10/bin/sh/tests/expansion/cmdsubst21.0 (from r314686, 
head/bin/sh/tests/expansion/cmdsubst21.0)
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/10/bin/sh/tests/expansion/cmdsubst21.0   Fri Apr 14 21:42:27 
2017(r316942, copy of r314686, head/bin/sh/tests/expansion/cmdsubst21.0)
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+set -T
+trapped=''
+trap "trapped=x$trapped" TERM
+[ "x$($SH -c "kill $$")y" = xy ] && [ "$trapped" = x ]

Copied: stable/10/bin/sh/tests/expansion/cmdsubst22.0 (from r314686, 
head/bin/sh/tests/expansion/cmdsubst22.0)
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/10/bin/sh/tests/expansion/cmdsubst22.0   Fri Apr 14 21:42:27 
2017(r316942, copy of r314686, head/bin/sh/tests/expansion/cmdsubst22.0)
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+set -T
+trapped=''
+trap "trapped=x$trapped" TERM
+[ "x$(:; kill $$)y" = xy ] && [ "$trapped" = x ]
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r315179 - stable/10/bin/sh/tests/expansion

2017-03-12 Thread Jilles Tjoelker
Author: jilles
Date: Sun Mar 12 19:49:08 2017
New Revision: 315179
URL: https://svnweb.freebsd.org/changeset/base/315179

Log:
  MFC r314637: sh: Add some already working tests that exercise new code paths

Added:
  stable/10/bin/sh/tests/expansion/cmdsubst18.0
 - copied unchanged from r314637, head/bin/sh/tests/expansion/cmdsubst18.0
  stable/10/bin/sh/tests/expansion/cmdsubst19.0
 - copied unchanged from r314637, head/bin/sh/tests/expansion/cmdsubst19.0
  stable/10/bin/sh/tests/expansion/cmdsubst20.0
 - copied unchanged from r314637, head/bin/sh/tests/expansion/cmdsubst20.0
Modified:
  stable/10/bin/sh/tests/expansion/Makefile
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/bin/sh/tests/expansion/Makefile
==
--- stable/10/bin/sh/tests/expansion/Makefile   Sun Mar 12 19:28:44 2017
(r315178)
+++ stable/10/bin/sh/tests/expansion/Makefile   Sun Mar 12 19:49:08 2017
(r315179)
@@ -38,6 +38,9 @@ FILES+=   cmdsubst14.0
 FILES+=cmdsubst15.0
 FILES+=cmdsubst16.0
 FILES+=cmdsubst17.0
+FILES+=cmdsubst18.0
+FILES+=cmdsubst19.0
+FILES+=cmdsubst20.0
 FILES+=export1.0
 FILES+=export2.0
 FILES+=export3.0

Copied: stable/10/bin/sh/tests/expansion/cmdsubst18.0 (from r314637, 
head/bin/sh/tests/expansion/cmdsubst18.0)
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/10/bin/sh/tests/expansion/cmdsubst18.0   Sun Mar 12 19:49:08 
2017(r315179, copy of r314637, head/bin/sh/tests/expansion/cmdsubst18.0)
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+x=X
+unset n
+r=${x+$(echo a)}${x-$(echo b)}${n+$(echo c)}${n-$(echo d)}$(echo e)
+[ "$r" = aXde ]

Copied: stable/10/bin/sh/tests/expansion/cmdsubst19.0 (from r314637, 
head/bin/sh/tests/expansion/cmdsubst19.0)
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/10/bin/sh/tests/expansion/cmdsubst19.0   Sun Mar 12 19:49:08 
2017(r315179, copy of r314637, head/bin/sh/tests/expansion/cmdsubst19.0)
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+b=200 c=30 d=5 x=4
+r=$(echo a)$(($(echo b) + ${x+$(echo c)} + ${x-$(echo d)}))$(echo e)
+[ "$r" = a234e ]

Copied: stable/10/bin/sh/tests/expansion/cmdsubst20.0 (from r314637, 
head/bin/sh/tests/expansion/cmdsubst20.0)
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/10/bin/sh/tests/expansion/cmdsubst20.0   Sun Mar 12 19:49:08 
2017(r315179, copy of r314637, head/bin/sh/tests/expansion/cmdsubst20.0)
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+set -T
+trapped=''
+trap "trapped=x$trapped" USR1
+[ "x$(kill -USR1 $$)y" = xy ] && [ "$trapped" = x ]
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r313685 - in stable/10: lib/libc/sys share/man/man4

2017-02-12 Thread Jilles Tjoelker
Author: jilles
Date: Sun Feb 12 18:52:01 2017
New Revision: 313685
URL: https://svnweb.freebsd.org/changeset/base/313685

Log:
  MFC r313174: Clean up documentation of AF_UNIX control messages.
  
  Document AF_UNIX control messages in unix(4) only, not split between unix(4)
  and recv(2).
  
  Also, warn about LOCAL_CREDS effective uid/gid fields, since the write could
  be from a setuid or setgid program (with the explicit SCM_CREDS and
  LOCAL_PEERCRED, the credentials are read at such a time that it can be
  assumed that the process intends for them to be used in this context).

Modified:
  stable/10/lib/libc/sys/recv.2
  stable/10/share/man/man4/unix.4
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/sys/recv.2
==
--- stable/10/lib/libc/sys/recv.2   Sun Feb 12 15:22:50 2017
(r313684)
+++ stable/10/lib/libc/sys/recv.2   Sun Feb 12 18:52:01 2017
(r313685)
@@ -28,7 +28,7 @@
 .\" @(#)recv.2 8.3 (Berkeley) 2/21/94
 .\" $FreeBSD$
 .\"
-.Dd March 19, 2013
+.Dd February 3, 2017
 .Dt RECV 2
 .Os
 .Sh NAME
@@ -218,57 +218,10 @@ with no data buffer provided immediately
 .Fn accept
 system call.
 .Pp
-Open file descriptors are now passed as ancillary data for
+With
 .Dv AF_UNIX
-domain sockets, with
-.Fa cmsg_level
-set to
-.Dv SOL_SOCKET
-and
-.Fa cmsg_type
-set to
-.Dv SCM_RIGHTS .
-The close-on-exec flag on received descriptors is set according to the
-.Dv MSG_CMSG_CLOEXEC
-flag passed to
-.Fn recvmsg .
-.Pp
-Process credentials can also be passed as ancillary data for
-.Dv AF_UNIX
-domain sockets using a
-.Fa cmsg_type
-of
-.Dv SCM_CREDS .
-In this case,
-.Fa cmsg_data
-should be a structure of type
-.Fa cmsgcred ,
-which is defined in
-.In sys/socket.h
-as follows:
-.Bd -literal
-struct cmsgcred {
-   pid_t   cmcred_pid; /* PID of sending process */
-   uid_t   cmcred_uid; /* real UID of sending process */
-   uid_t   cmcred_euid;/* effective UID of sending process */
-   gid_t   cmcred_gid; /* real GID of sending process */
-   short   cmcred_ngroups; /* number or groups */
-   gid_t   cmcred_groups[CMGROUP_MAX]; /* groups */
-};
-.Ed
-.Pp
-If a sender supplies ancillary data with enough space for the above struct
-tagged as
-.Dv SCM_CREDS
-control message type to the
-.Fn sendmsg
-system call, then kernel will fill in the credential information of the
-sending process and deliver it to the receiver.
-Since receiver usually has no control over a sender, this method of retrieving
-credential information isn't reliable.
-For reliable retrieval of remote side credentials it is advised to use the
-.Dv LOCAL_CREDS
-socket option on the receiving socket.
+domain sockets, ancillary data can be used to pass file descriptors and
+process credentials.
 See
 .Xr unix 4
 for details.

Modified: stable/10/share/man/man4/unix.4
==
--- stable/10/share/man/man4/unix.4 Sun Feb 12 15:22:50 2017
(r313684)
+++ stable/10/share/man/man4/unix.4 Sun Feb 12 18:52:01 2017
(r313685)
@@ -32,7 +32,7 @@
 .\" @(#)unix.4 8.1 (Berkeley) 6/9/93
 .\" $FreeBSD$
 .\"
-.Dd March 19, 2013
+.Dd February 3, 2017
 .Dt UNIX 4
 .Os
 .Sh NAME
@@ -123,12 +123,12 @@ of a
 or
 .Xr sendto 2
 must be writable.
-.Sh PASSING FILE DESCRIPTORS
+.Sh CONTROL MESSAGES
 The
 .Ux Ns -domain
 sockets support the communication of
 .Ux
-file descriptors through the use of the
+file descriptors and process credentials through the use of the
 .Va msg_control
 field in the
 .Fa msg
@@ -136,13 +136,12 @@ argument to
 .Xr sendmsg 2
 and
 .Xr recvmsg 2 .
-.Pp
-Any valid descriptor may be sent in a message.
-The file descriptor(s) to be passed are described using a
+The items to be passed are described using a
 .Vt "struct cmsghdr"
 that is defined in the include file
 .In sys/socket.h .
-The type of the message is
+.Pp
+To send file descriptors, the type of the message is
 .Dv SCM_RIGHTS ,
 and the data portion of the messages is an array of integers
 representing the file descriptors to be passed.
@@ -165,6 +164,39 @@ call.
 Descriptors that are awaiting delivery, or that are
 purposely not received, are automatically closed by the system
 when the destination socket is closed.
+.Pp
+Credentials of the sending process can be transmitted explicitly using a
+control message of type
+.Dv SCM_CREDS
+with a data portion of type
+.Vt "struct cmsgcred" ,
+defined in
+.In sys/socket.h
+as follows:
+.Bd -literal
+struct cmsgcred {
+  pid_tcmcred_pid; /* PID of sending process */
+  uid_tcmcred_uid; /* real UID of sending process */
+  uid_tcmcred_euid;/* effective UID of sending process */
+  gid_tcmcred_gid; /* real GID of sending process */
+  shortcmcred_ngroups;  

svn commit: r313303 - in stable/10: sys/kern tests/sys/kern

2017-02-05 Thread Jilles Tjoelker
Author: jilles
Date: Sun Feb  5 21:31:40 2017
New Revision: 313303
URL: https://svnweb.freebsd.org/changeset/base/313303

Log:
  MFC r310096: reaper: Make REAPER_KILL_SUBTREE actually work.

Modified:
  stable/10/sys/kern/kern_procctl.c
  stable/10/tests/sys/kern/reaper.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/kern/kern_procctl.c
==
--- stable/10/sys/kern/kern_procctl.c   Sun Feb  5 20:55:01 2017
(r313302)
+++ stable/10/sys/kern/kern_procctl.c   Sun Feb  5 21:31:40 2017
(r313303)
@@ -243,7 +243,7 @@ reap_kill(struct thread *td, struct proc
return (ECAPMODE);
if (rk->rk_sig <= 0 || rk->rk_sig > _SIG_MAXSIG)
return (EINVAL);
-   if ((rk->rk_flags & ~REAPER_KILL_CHILDREN) != 0)
+   if ((rk->rk_flags & ~(REAPER_KILL_CHILDREN | REAPER_KILL_SUBTREE)) != 0)
return (EINVAL);
PROC_UNLOCK(p);
reap = (p->p_treeflag & P_TREE_REAPER) == 0 ? p->p_reaper : p;

Modified: stable/10/tests/sys/kern/reaper.c
==
--- stable/10/tests/sys/kern/reaper.c   Sun Feb  5 20:55:01 2017
(r313302)
+++ stable/10/tests/sys/kern/reaper.c   Sun Feb  5 21:31:40 2017
(r313303)
@@ -639,6 +639,107 @@ ATF_TC_BODY(reaper_kill_normal, tc)
ATF_REQUIRE_EQ(0, r);
 }
 
+ATF_TC_WITHOUT_HEAD(reaper_kill_subtree);
+ATF_TC_BODY(reaper_kill_subtree, tc)
+{
+   struct procctl_reaper_kill params;
+   ssize_t sr;
+   pid_t parent, child1, child2, grandchild1, grandchild2, pid;
+   int r, status;
+   int pip[2];
+
+   parent = getpid();
+   r = procctl(P_PID, parent, PROC_REAP_ACQUIRE, NULL);
+   ATF_REQUIRE_EQ(0, r);
+
+   r = pipe(pip);
+   ATF_REQUIRE_EQ(0, r);
+   child1 = fork();
+   ATF_REQUIRE(child1 != -1);
+   if (child1 == 0) {
+   if (close(pip[0]) != 0)
+   _exit(100);
+   grandchild1 = fork();
+   if (grandchild1 == -1)
+   _exit(101);
+   if (grandchild1 == 0) {
+   if (write(pip[1], &(uint8_t){ 0 }, 1) != 1)
+   _exit(102);
+   for (;;)
+   pause();
+   }
+   for (;;)
+   pause();
+   }
+   child2 = fork();
+   ATF_REQUIRE(child2 != -1);
+   if (child2 == 0) {
+   if (close(pip[0]) != 0)
+   _exit(100);
+   grandchild2 = fork();
+   if (grandchild2 == -1)
+   _exit(101);
+   if (grandchild2 == 0) {
+   if (write(pip[1], &(uint8_t){ 0 }, 1) != 1)
+   _exit(102);
+   for (;;)
+   pause();
+   }
+   for (;;)
+   pause();
+   }
+   r = close(pip[1]);
+   ATF_REQUIRE_EQ(0, r);
+
+   sr = read(pip[0], &(uint8_t){ 0 }, 1);
+   ATF_REQUIRE_EQ(1, sr);
+   sr = read(pip[0], &(uint8_t){ 0 }, 1);
+   ATF_REQUIRE_EQ(1, sr);
+
+   params.rk_sig = SIGUSR1;
+   params.rk_flags = REAPER_KILL_SUBTREE;
+   params.rk_subtree = child1;
+   params.rk_killed = 77;
+   r = procctl(P_PID, parent, PROC_REAP_KILL, );
+   ATF_REQUIRE_EQ(0, r);
+   ATF_REQUIRE_EQ(2, params.rk_killed);
+   ATF_CHECK_EQ(-1, params.rk_fpid);
+
+   pid = waitpid(child1, , 0);
+   ATF_REQUIRE_EQ(child1, pid);
+   ATF_CHECK(WIFSIGNALED(status) && WTERMSIG(status) == SIGUSR1);
+
+   pid = waitpid(-1, , 0);
+   ATF_REQUIRE(pid > 0);
+   ATF_CHECK(pid != parent);
+   ATF_CHECK(pid != child1);
+   ATF_CHECK(pid != child2);
+   ATF_CHECK(WIFSIGNALED(status) && WTERMSIG(status) == SIGUSR1);
+
+   params.rk_sig = SIGUSR2;
+   params.rk_flags = REAPER_KILL_SUBTREE;
+   params.rk_subtree = child2;
+   params.rk_killed = 77;
+   r = procctl(P_PID, parent, PROC_REAP_KILL, );
+   ATF_REQUIRE_EQ(0, r);
+   ATF_REQUIRE_EQ(2, params.rk_killed);
+   ATF_CHECK_EQ(-1, params.rk_fpid);
+
+   pid = waitpid(child2, , 0);
+   ATF_REQUIRE_EQ(child2, pid);
+   ATF_CHECK(WIFSIGNALED(status) && WTERMSIG(status) == SIGUSR2);
+
+   pid = waitpid(-1, , 0);
+   ATF_REQUIRE(pid > 0);
+   ATF_CHECK(pid != parent);
+   ATF_CHECK(pid != child1);
+   ATF_CHECK(pid != child2);
+   ATF_CHECK(WIFSIGNALED(status) && WTERMSIG(status) == SIGUSR2);
+
+   r = close(pip[0]);
+   ATF_REQUIRE_EQ(0, r);
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 
@@ -652,5 +753,6 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, reaper_kill_sigzero);
ATF_TP_ADD_TC(tp, reaper_kill_empty);
ATF_TP_ADD_TC(tp, reaper_kill_normal);
+   ATF_TP_ADD_TC(tp, reaper_kill_subtree);

svn commit: r313288 - stable/10/share/skel

2017-02-05 Thread Jilles Tjoelker
Author: jilles
Date: Sun Feb  5 15:46:05 2017
New Revision: 313288
URL: https://svnweb.freebsd.org/changeset/base/313288

Log:
  MFC r312721: skel: Remove reference to deleted part in previous commit
  to this file.

Modified:
  stable/10/share/skel/dot.shrc
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/share/skel/dot.shrc
==
--- stable/10/share/skel/dot.shrc   Sun Feb  5 15:45:31 2017
(r313287)
+++ stable/10/share/skel/dot.shrc   Sun Feb  5 15:46:05 2017
(r313288)
@@ -13,8 +13,8 @@
 #
 # umask022
 
-# Uncomment this and comment the above to enable the builtin vi(1) command
-# line editor in sh(1), e.g. ESC to go into visual mode.
+# Uncomment this to enable the builtin vi(1) command line editor in sh(1),
+# e.g. ESC to go into visual mode.
 # set -o vi
 
 
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r312654 - stable/10/share/skel

2017-01-22 Thread Jilles Tjoelker
Author: jilles
Date: Sun Jan 22 21:34:26 2017
New Revision: 312654
URL: https://svnweb.freebsd.org/changeset/base/312654

Log:
  MFC r312230: skel: Do not set -o emacs in .shrc.
  
  sh has defaulted to 'set -o emacs' since FreeBSD 9.0. Therefore, do not set
  this again in .shrc, since that only serves to prevent invocations like
  'sh -o vi' and 'sh +o emacs' to have the intended effect.
  
  PR:   215958
  Submitted by: Andras Farkas

Modified:
  stable/10/share/skel/dot.shrc
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/share/skel/dot.shrc
==
--- stable/10/share/skel/dot.shrc   Sun Jan 22 21:31:32 2017
(r312653)
+++ stable/10/share/skel/dot.shrc   Sun Jan 22 21:34:26 2017
(r312654)
@@ -13,10 +13,6 @@
 #
 # umask022
 
-# Enable the builtin emacs(1) command line editor in sh(1),
-# e.g. C-a -> beginning-of-line.
-set -o emacs
-
 # Uncomment this and comment the above to enable the builtin vi(1) command
 # line editor in sh(1), e.g. ESC to go into visual mode.
 # set -o vi
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r310610 - stable/10/tests/sys/kern

2016-12-26 Thread Jilles Tjoelker
Author: jilles
Date: Mon Dec 26 17:26:25 2016
New Revision: 310610
URL: https://svnweb.freebsd.org/changeset/base/310610

Log:
  MFC r309957: Add tests for reaper receiving SIGCHLD (r309886).
  
  PR:   213928

Modified:
  stable/10/tests/sys/kern/reaper.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/tests/sys/kern/reaper.c
==
--- stable/10/tests/sys/kern/reaper.c   Mon Dec 26 17:23:09 2016
(r310609)
+++ stable/10/tests/sys/kern/reaper.c   Mon Dec 26 17:26:25 2016
(r310610)
@@ -35,6 +35,11 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 
+static void
+dummy_sighandler(int sig __unused, siginfo_t *info __unused, void *ctx 
__unused)
+{
+}
+
 ATF_TC_WITHOUT_HEAD(reaper_wait_child_first);
 ATF_TC_BODY(reaper_wait_child_first, tc)
 {
@@ -129,6 +134,161 @@ ATF_TC_BODY(reaper_wait_grandchild_first
ATF_CHECK_EQ(2, r);
 }
 
+ATF_TC(reaper_sigchld_child_first);
+ATF_TC_HEAD(reaper_sigchld_child_first, tc)
+{
+   atf_tc_set_md_var(tc, "timeout", "2");
+}
+ATF_TC_BODY(reaper_sigchld_child_first, tc)
+{
+   struct sigaction act;
+   sigset_t mask;
+   siginfo_t info;
+   pid_t parent, child, grandchild, pid;
+   int r;
+   int pip[2];
+
+   /* Be paranoid. */
+   pid = waitpid(-1, NULL, WNOHANG);
+   ATF_REQUIRE(pid == -1 && errno == ECHILD);
+
+   act.sa_sigaction = dummy_sighandler;
+   act.sa_flags = SA_SIGINFO | SA_RESTART;
+   r = sigemptyset(_mask);
+   ATF_REQUIRE_EQ(0, r);
+   r = sigaction(SIGCHLD, , NULL);
+   ATF_REQUIRE_EQ(0, r);
+
+   r = sigemptyset();
+   ATF_REQUIRE_EQ(0, r);
+   r = sigaddset(, SIGCHLD);
+   ATF_REQUIRE_EQ(0, r);
+   r = sigprocmask(SIG_BLOCK, , NULL);
+   ATF_REQUIRE_EQ(0, r);
+
+   parent = getpid();
+   r = procctl(P_PID, parent, PROC_REAP_ACQUIRE, NULL);
+   ATF_REQUIRE_EQ(0, r);
+
+   r = pipe(pip);
+   ATF_REQUIRE_EQ(0, r);
+
+   child = fork();
+   ATF_REQUIRE(child != -1);
+   if (child == 0) {
+   if (close(pip[1]) != 0)
+   _exit(100);
+   grandchild = fork();
+   if (grandchild == -1)
+   _exit(101);
+   else if (grandchild == 0) {
+   if (read(pip[0], &(uint8_t){ 0 }, 1) != 0)
+   _exit(102);
+   if (getppid() != parent)
+   _exit(103);
+   _exit(2);
+   } else
+   _exit(3);
+   }
+
+   r = sigwaitinfo(, );
+   ATF_REQUIRE_EQ(SIGCHLD, r);
+   ATF_CHECK_EQ(SIGCHLD, info.si_signo);
+   ATF_CHECK_EQ(CLD_EXITED, info.si_code);
+   ATF_CHECK_EQ(3, info.si_status);
+   ATF_CHECK_EQ(child, info.si_pid);
+
+   pid = waitpid(child, NULL, 0);
+   ATF_REQUIRE_EQ(child, pid);
+
+   r = close(pip[1]);
+   ATF_REQUIRE_EQ(0, r);
+
+   r = sigwaitinfo(, );
+   ATF_REQUIRE_EQ(SIGCHLD, r);
+   ATF_CHECK_EQ(SIGCHLD, info.si_signo);
+   ATF_CHECK_EQ(CLD_EXITED, info.si_code);
+   ATF_CHECK_EQ(2, info.si_status);
+   grandchild = info.si_pid;
+   ATF_REQUIRE(grandchild > 0);
+   ATF_REQUIRE(grandchild != parent);
+   ATF_REQUIRE(grandchild != child);
+
+   pid = waitpid(-1, NULL, 0);
+   ATF_REQUIRE_EQ(grandchild, pid);
+
+   r = close(pip[0]);
+   ATF_REQUIRE_EQ(0, r);
+}
+
+ATF_TC(reaper_sigchld_grandchild_first);
+ATF_TC_HEAD(reaper_sigchld_grandchild_first, tc)
+{
+   atf_tc_set_md_var(tc, "timeout", "2");
+}
+ATF_TC_BODY(reaper_sigchld_grandchild_first, tc)
+{
+   struct sigaction act;
+   sigset_t mask;
+   siginfo_t info;
+   pid_t parent, child, grandchild, pid;
+   int r;
+
+   /* Be paranoid. */
+   pid = waitpid(-1, NULL, WNOHANG);
+   ATF_REQUIRE(pid == -1 && errno == ECHILD);
+
+   act.sa_sigaction = dummy_sighandler;
+   act.sa_flags = SA_SIGINFO | SA_RESTART;
+   r = sigemptyset(_mask);
+   ATF_REQUIRE_EQ(0, r);
+   r = sigaction(SIGCHLD, , NULL);
+   ATF_REQUIRE_EQ(0, r);
+
+   r = sigemptyset();
+   ATF_REQUIRE_EQ(0, r);
+   r = sigaddset(, SIGCHLD);
+   ATF_REQUIRE_EQ(0, r);
+   r = sigprocmask(SIG_BLOCK, , NULL);
+   ATF_REQUIRE_EQ(0, r);
+
+   parent = getpid();
+   r = procctl(P_PID, parent, PROC_REAP_ACQUIRE, NULL);
+   ATF_REQUIRE_EQ(0, r);
+
+   child = fork();
+   ATF_REQUIRE(child != -1);
+   if (child == 0) {
+   grandchild = fork();
+   if (grandchild == -1)
+   _exit(101);
+   else if (grandchild == 0)
+   _exit(2);
+   else {
+   if (waitid(P_PID, grandchild, NULL,
+   WNOWAIT | WEXITED) != 0)
+   _exit(102);
+

svn commit: r310558 - stable/10/tests/sys/kern

2016-12-25 Thread Jilles Tjoelker
Author: jilles
Date: Sun Dec 25 22:32:16 2016
New Revision: 310558
URL: https://svnweb.freebsd.org/changeset/base/310558

Log:
  MFC r309836: Add some tests for reaper functionality (in procctl()).

Added:
  stable/10/tests/sys/kern/reaper.c
 - copied unchanged from r309836, head/tests/sys/kern/reaper.c
Modified:
  stable/10/tests/sys/kern/Makefile
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/tests/sys/kern/Makefile
==
--- stable/10/tests/sys/kern/Makefile   Sun Dec 25 21:41:40 2016
(r310557)
+++ stable/10/tests/sys/kern/Makefile   Sun Dec 25 22:32:16 2016
(r310558)
@@ -8,6 +8,7 @@ TESTSDIR=   ${TESTSBASE}/sys/kern
 
 ATF_TESTS_C+=  kern_descrip_test
 ATF_TESTS_C+=  ptrace_test
+ATF_TESTS_C+=  reaper
 ATF_TESTS_C+=  unix_seqpacket_test
 ATF_TESTS_C+=  unix_passfd_test
 TEST_METADATA.unix_seqpacket_test+=timeout="15"

Copied: stable/10/tests/sys/kern/reaper.c (from r309836, 
head/tests/sys/kern/reaper.c)
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/10/tests/sys/kern/reaper.c   Sun Dec 25 22:32:16 2016
(r310558, copy of r309836, head/tests/sys/kern/reaper.c)
@@ -0,0 +1,494 @@
+/*-
+ * Copyright (c) 2016 Jilles Tjoelker
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include 
+__FBSDID("$FreeBSD$");
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+ATF_TC_WITHOUT_HEAD(reaper_wait_child_first);
+ATF_TC_BODY(reaper_wait_child_first, tc)
+{
+   pid_t parent, child, grandchild, pid;
+   int status, r;
+   int pip[2];
+
+   /* Be paranoid. */
+   pid = waitpid(-1, NULL, WNOHANG);
+   ATF_REQUIRE(pid == -1 && errno == ECHILD);
+
+   parent = getpid();
+   r = procctl(P_PID, parent, PROC_REAP_ACQUIRE, NULL);
+   ATF_REQUIRE_EQ(0, r);
+
+   r = pipe(pip);
+   ATF_REQUIRE_EQ(0, r);
+
+   child = fork();
+   ATF_REQUIRE(child != -1);
+   if (child == 0) {
+   if (close(pip[1]) != 0)
+   _exit(100);
+   grandchild = fork();
+   if (grandchild == -1)
+   _exit(101);
+   else if (grandchild == 0) {
+   if (read(pip[0], &(uint8_t){ 0 }, 1) != 0)
+   _exit(102);
+   if (getppid() != parent)
+   _exit(103);
+   _exit(2);
+   } else
+   _exit(3);
+   }
+
+   pid = waitpid(child, , 0);
+   ATF_REQUIRE_EQ(child, pid);
+   r = WIFEXITED(status) ? WEXITSTATUS(status) : -1;
+   ATF_CHECK_EQ(3, r);
+
+   r = close(pip[1]);
+   ATF_REQUIRE_EQ(0, r);
+
+   pid = waitpid(-1, , 0);
+   ATF_REQUIRE(pid > 0 && pid != child);
+   r = WIFEXITED(status) ? WEXITSTATUS(status) : -1;
+   ATF_CHECK_EQ(2, r);
+
+   r = close(pip[0]);
+   ATF_REQUIRE_EQ(0, r);
+}
+
+ATF_TC_WITHOUT_HEAD(reaper_wait_grandchild_first);
+ATF_TC_BODY(reaper_wait_grandchild_first, tc)
+{
+   pid_t parent, child, grandchild, pid;
+   int status, r;
+
+   /* Be paranoid. */
+   pid = waitpid(-1, NULL, WNOHANG);
+   ATF_REQUIRE(pid == -1 && errno == ECHILD);
+
+   parent = getpid();
+   r = procctl(P_PID, parent, PROC_REAP_ACQUIRE, NULL);
+   ATF_REQUIRE_EQ(0, r);
+
+   child = fork();
+   ATF_REQUIRE(child != -1);
+   if (child == 0) {
+   grandchild = fork();
+   if (

svn commit: r309536 - stable/10/lib/libc/sys

2016-12-04 Thread Jilles Tjoelker
Author: jilles
Date: Sun Dec  4 16:00:25 2016
New Revision: 309536
URL: https://svnweb.freebsd.org/changeset/base/309536

Log:
  MFC r309026: open(2): Clarify non-POSIX error when opening a symlink with
  O_NOFOLLOW.
  
  We return [EMLINK] instead of [ELOOP] when trying to open a symlink with
  O_NOFOLLOW, so that the original case of [ELOOP] can be distinguished. Code
  like cmp -h and xz takes advantage of this.
  
  PR:   214633

Modified:
  stable/10/lib/libc/sys/open.2
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/sys/open.2
==
--- stable/10/lib/libc/sys/open.2   Sun Dec  4 15:59:04 2016
(r309535)
+++ stable/10/lib/libc/sys/open.2   Sun Dec  4 16:00:25 2016
(r309536)
@@ -28,7 +28,7 @@
 .\" @(#)open.2 8.2 (Berkeley) 11/16/93
 .\" $FreeBSD$
 .\"
-.Dd April 2, 2015
+.Dd November 22, 2016
 .Dt OPEN 2
 .Os
 .Sh NAME
@@ -471,6 +471,22 @@ The
 .Fn openat
 function was introduced in
 .Fx 8.0 .
+.Sh STANDARDS
+These functions are specified by
+.St -p1003.1-2008 .
+.Fx
+sets
+.Va errno
+to
+.Er EMLINK instead of
+.Er ELOOP
+as specified by
+.Tn POSIX
+when
+.Dv O_NOFOLLOW
+is set in flags and the final component of pathname is a symbolic link
+to distinguish it from the case of too many symbolic link traversals
+in one of its non-final components.
 .Sh BUGS
 The Open Group Extended API Set 2 specification requires that the test
 for whether
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r308886 - in stable/10: etc/rc.d sbin/swapon

2016-11-20 Thread Jilles Tjoelker
Author: jilles
Date: Sun Nov 20 13:44:27 2016
New Revision: 308886
URL: https://svnweb.freebsd.org/changeset/base/308886

Log:
  MFC r307755: swapoff: Remove only late devices with -aL.
  
  Currently, '/etc/rc.d/swaplate stop' removes all swap devices. This can be
  very slow and may not even be possible if there is a lot of swap space in
  use. However, removing swap devices is only needed for late swap devices
  that may depend on daemons that subsequent shutdown steps stop. Normal swap
  devices such as hard disk partitions will remain available throughout the
  shutdown process and need not be removed.
  
  In swapoff, interpret -aL to remove late swap devices only, and use this in
  etc/rc.d/swaplate. The meaning of -aL in swapon remains unchanged (add all
  swap devices, both normal and late).
  
  PR:   187081

Modified:
  stable/10/etc/rc.d/swaplate
  stable/10/sbin/swapon/swapon.8
  stable/10/sbin/swapon/swapon.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/etc/rc.d/swaplate
==
--- stable/10/etc/rc.d/swaplate Sun Nov 20 13:04:02 2016(r308885)
+++ stable/10/etc/rc.d/swaplate Sun Nov 20 13:44:27 2016(r308886)
@@ -11,7 +11,7 @@
 
 name="swaplate"
 start_cmd='/sbin/swapon -aLq'
-stop_cmd='/sbin/swapoff -aq'
+stop_cmd='/sbin/swapoff -aLq'
 
 load_rc_config swap
 run_rc_command "$1"

Modified: stable/10/sbin/swapon/swapon.8
==
--- stable/10/sbin/swapon/swapon.8  Sun Nov 20 13:04:02 2016
(r308885)
+++ stable/10/sbin/swapon/swapon.8  Sun Nov 20 13:44:27 2016
(r308886)
@@ -28,7 +28,7 @@
 .\" @(#)swapon.8   8.1 (Berkeley) 6/5/93
 .\" $FreeBSD$
 .\"
-.Dd October 2, 2016
+.Dd October 21, 2016
 .Dt SWAPON 8
 .Os
 .Sh NAME
@@ -98,6 +98,12 @@ will be removed, unless their
 .Dq noauto
 option is also set.
 If the
+.Fl L
+option is specified,
+only swap devices with the
+.Dq late
+option will be removed.
+If the
 .Fl q
 option is used,
 informational messages will not be

Modified: stable/10/sbin/swapon/swapon.c
==
--- stable/10/sbin/swapon/swapon.c  Sun Nov 20 13:04:02 2016
(r308885)
+++ stable/10/sbin/swapon/swapon.c  Sun Nov 20 13:44:27 2016
(r308886)
@@ -176,6 +176,10 @@ main(int argc, char **argv)
strstr(fsp->fs_mntops, "late") &&
late == 0)
continue;
+   if (which_prog == SWAPOFF &&
+   strstr(fsp->fs_mntops, "late") == NULL &&
+   late != 0)
+   continue;
swfile = swap_on_off(fsp->fs_spec, 1,
fsp->fs_mntops);
if (swfile == NULL) {
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r308866 - stable/10/sbin/swapon

2016-11-19 Thread Jilles Tjoelker
Author: jilles
Date: Sat Nov 19 20:03:59 2016
New Revision: 308866
URL: https://svnweb.freebsd.org/changeset/base/308866

Log:
  MFC r306585: swapon(8): Update to reality: swapoff ignores -L and the late
  option in fstab.

Modified:
  stable/10/sbin/swapon/swapon.8
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sbin/swapon/swapon.8
==
--- stable/10/sbin/swapon/swapon.8  Sat Nov 19 20:02:49 2016
(r308865)
+++ stable/10/sbin/swapon/swapon.8  Sat Nov 19 20:03:59 2016
(r308866)
@@ -28,7 +28,7 @@
 .\" @(#)swapon.8   8.1 (Berkeley) 6/5/93
 .\" $FreeBSD$
 .\"
-.Dd November 22, 2013
+.Dd October 2, 2016
 .Dt SWAPON 8
 .Os
 .Sh NAME
@@ -96,16 +96,8 @@ option is used, all swap devices in
 .Pa /etc/fstab
 will be removed, unless their
 .Dq noauto
-or
-.Dq late
 option is also set.
 If the
-.Fl L
-option is specified,
-swap devices with the
-.Dq late
-option will be removed as well as ones with no option.
-If the
 .Fl q
 option is used,
 informational messages will not be
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r307155 - stable/10/lib/libc/sys

2016-10-12 Thread Jilles Tjoelker
Author: jilles
Date: Wed Oct 12 20:19:33 2016
New Revision: 307155
URL: https://svnweb.freebsd.org/changeset/base/307155

Log:
  MFC r305628: intro(2),_exit(2): Update for reaper
  (procctl(PROC_REAP_ACQUIRE)).

Modified:
  stable/10/lib/libc/sys/_exit.2
  stable/10/lib/libc/sys/intro.2
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/sys/_exit.2
==
--- stable/10/lib/libc/sys/_exit.2  Wed Oct 12 19:53:10 2016
(r307154)
+++ stable/10/lib/libc/sys/_exit.2  Wed Oct 12 20:19:33 2016
(r307155)
@@ -28,7 +28,7 @@
 .\" @(#)_exit.28.1 (Berkeley) 6/4/93
 .\" $FreeBSD$
 .\"
-.Dd June 4, 1993
+.Dd September 8, 2016
 .Dt EXIT 2
 .Os
 .Sh NAME
@@ -64,9 +64,11 @@ is set as defined by
 .Xr wait 2 .
 .It
 The parent process-ID of all of the calling process's existing child
-processes are set to 1; the initialization process
+processes are set to the process-ID of the calling process's reaper;
+the reaper (normally the initialization process)
 inherits each of these processes
 (see
+.Xr procctl 2 ,
 .Xr init 8
 and the
 .Sx DEFINITIONS

Modified: stable/10/lib/libc/sys/intro.2
==
--- stable/10/lib/libc/sys/intro.2  Wed Oct 12 19:53:10 2016
(r307154)
+++ stable/10/lib/libc/sys/intro.2  Wed Oct 12 20:19:33 2016
(r307155)
@@ -28,7 +28,7 @@
 .\" @(#)intro.28.5 (Berkeley) 2/27/95
 .\" $FreeBSD$
 .\"
-.Dd May 4, 2013
+.Dd September 8, 2016
 .Dt INTRO 2
 .Os
 .Sh NAME
@@ -486,7 +486,10 @@ A new process is created by a currently 
 .Xr fork 2 ) .
 The parent process ID of a process is initially the process ID of its creator.
 If the creating process exits,
-the parent process ID of each child is set to the ID of a system process,
+the parent process ID of each child is set to the ID of the calling process's
+reaper (see
+.Xr procctl 2 ) ,
+normally
 .Xr init 8 .
 .It Process Group
 Each active process is a member of a process group that is identified by
@@ -535,7 +538,7 @@ when none of its members has a parent pr
 as the group,
 but is in a different process group.
 Note that when a process exits, the parent process for its children
-is changed to be
+is normally changed to be
 .Xr init 8 ,
 which is in a separate session.
 Not all members of an orphaned process group are necessarily orphaned
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r307065 - in stable/10: sys/kern tests/sys/kern

2016-10-11 Thread Jilles Tjoelker
Author: jilles
Date: Tue Oct 11 18:51:03 2016
New Revision: 307065
URL: https://svnweb.freebsd.org/changeset/base/307065

Log:
  wait: Do not copyout uninitialized status/rusage/wrusage.
  
  If wait4() or wait6() return 0 because of WNOHANG, the status, rusage and
  wrusage information should not be returned.
  
  PR:   212048
  Reported by:  Casey Lucas

Added:
  stable/10/tests/sys/kern/waitpid_nohang.c
 - copied unchanged from r305676, head/tests/sys/kern/waitpid_nohang.c
Modified:
  stable/10/sys/kern/kern_exit.c
  stable/10/tests/sys/kern/Makefile
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/kern/kern_exit.c
==
--- stable/10/sys/kern/kern_exit.c  Tue Oct 11 18:09:37 2016
(r307064)
+++ stable/10/sys/kern/kern_exit.c  Tue Oct 11 18:51:03 2016
(r307065)
@@ -785,9 +785,9 @@ sys_wait4(struct thread *td, struct wait
else
rup = NULL;
error = kern_wait(td, uap->pid, , uap->options, rup);
-   if (uap->status != NULL && error == 0)
+   if (uap->status != NULL && error == 0 && td->td_retval[0] != 0)
error = copyout(, uap->status, sizeof(status));
-   if (uap->rusage != NULL && error == 0)
+   if (uap->rusage != NULL && error == 0 && td->td_retval[0] != 0)
error = copyout(, uap->rusage, sizeof(struct rusage));
return (error);
 }
@@ -821,9 +821,9 @@ sys_wait6(struct thread *td, struct wait
 */
error = kern_wait6(td, idtype, id, , uap->options, wrup, sip);
 
-   if (uap->status != NULL && error == 0)
+   if (uap->status != NULL && error == 0 && td->td_retval[0] != 0)
error = copyout(, uap->status, sizeof(status));
-   if (uap->wrusage != NULL && error == 0)
+   if (uap->wrusage != NULL && error == 0 && td->td_retval[0] != 0)
error = copyout(, uap->wrusage, sizeof(wru));
if (uap->info != NULL && error == 0)
error = copyout(, uap->info, sizeof(si));

Modified: stable/10/tests/sys/kern/Makefile
==
--- stable/10/tests/sys/kern/Makefile   Tue Oct 11 18:09:37 2016
(r307064)
+++ stable/10/tests/sys/kern/Makefile   Tue Oct 11 18:51:03 2016
(r307065)
@@ -11,6 +11,7 @@ ATF_TESTS_C+= ptrace_test
 ATF_TESTS_C+=  unix_seqpacket_test
 ATF_TESTS_C+=  unix_passfd_test
 TEST_METADATA.unix_seqpacket_test+=timeout="15"
+ATF_TESTS_C+=  waitpid_nohang
 
 LDADD.ptrace_test+=-lpthread
 LDADD.unix_seqpacket_test+=-lpthread

Copied: stable/10/tests/sys/kern/waitpid_nohang.c (from r305676, 
head/tests/sys/kern/waitpid_nohang.c)
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/10/tests/sys/kern/waitpid_nohang.c   Tue Oct 11 18:51:03 2016
(r307065, copy of r305676, head/tests/sys/kern/waitpid_nohang.c)
@@ -0,0 +1,70 @@
+/*-
+ * Copyright (c) 2016 Jilles Tjoelker
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include 
+__FBSDID("$FreeBSD$");
+
+#include 
+
+#include 
+#include 
+#include 
+
+ATF_TC_WITHOUT_HEAD(waitpid_nohang);
+ATF_TC_BODY(waitpid_nohang, tc)
+{
+   pid_t child, pid;
+   int status, r;
+
+   child = fork();
+   ATF_REQUIRE(child != -1);
+   if (child == 0) {
+   sleep(10);
+ 

svn commit: r305569 - stable/10/lib/libc/gen

2016-09-07 Thread Jilles Tjoelker
Author: jilles
Date: Wed Sep  7 21:09:44 2016
New Revision: 305569
URL: https://svnweb.freebsd.org/changeset/base/305569

Log:
  MFC r305154: directory(3): Deprecate readdir_r(). Clarify dirent buffers.
  
  In existing implementations including FreeBSD, there is no reason to use
  readdir_r() in the common case where potentially multiple threads each list
  their own directory. Code using readdir() is simpler.
  
  What's more, although readdir_r() can safely be used on FreeBSD because
  NAME_MAX is forced to 255, it cannot be used safely on systems where
  {NAME_MAX} is not fixed. As a concrete example, FAT/NTFS filenames can be up
  to 255 UTF-16 code units long, which can be up to 765 UTF-8 bytes.
  
  Deprecating readdir_r() in POSIX has been proposed in
  http://www.austingroupbugs.net/view.php?id=696
  and glibc wants to deprecate it as well.

Modified:
  stable/10/lib/libc/gen/directory.3
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/gen/directory.3
==
--- stable/10/lib/libc/gen/directory.3  Wed Sep  7 21:04:39 2016
(r305568)
+++ stable/10/lib/libc/gen/directory.3  Wed Sep  7 21:09:44 2016
(r305569)
@@ -28,7 +28,7 @@
 .\" @(#)directory.38.1 (Berkeley) 6/4/93
 .\" $FreeBSD$
 .\"
-.Dd May 6, 2015
+.Dd August 31, 2016
 .Dt DIRECTORY 3
 .Os
 .Sh NAME
@@ -69,6 +69,15 @@
 .Ft int
 .Fn dirfd "DIR *dirp"
 .Sh DESCRIPTION
+.Bf -symbolic
+The
+.Fn readdir_r
+interface is deprecated
+because it cannot be used correctly unless
+.Brq Va NAME_MAX
+is a fixed value.
+.Ef
+.Pp
 The
 .Fn opendir
 function
@@ -123,7 +132,13 @@ The
 .Fn readdir
 function
 returns a pointer to the next directory entry.
-It returns
+The directory entry remains valid until the next call to
+.Fn readdir
+or
+.Fn closedir
+on the same
+.Em directory stream .
+The function returns
 .Dv NULL
 upon reaching the end of the directory or on error.
 In the event of an error,
@@ -140,6 +155,13 @@ provides the same functionality as
 but the caller must provide a directory
 .Fa entry
 buffer to store the results in.
+The buffer must be large enough for a
+.Vt struct dirent
+with a
+.Va d_name
+array with
+.Brq Va NAME_MAX
++ 1 elements.
 If the read succeeds,
 .Fa result
 is pointed at the
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r305568 - stable/10/lib/libc/gen

2016-09-07 Thread Jilles Tjoelker
Author: jilles
Date: Wed Sep  7 21:04:39 2016
New Revision: 305568
URL: https://svnweb.freebsd.org/changeset/base/305568

Log:
  MFC r305090: getvfsbyname(3): Remove [EFAULT] error.
  
  Since r101651 in 2002, getvfsbyname() has written *vfc using userland
  memcpy(), so the [EFAULT] error no longer occurs.

Modified:
  stable/10/lib/libc/gen/getvfsbyname.3
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/gen/getvfsbyname.3
==
--- stable/10/lib/libc/gen/getvfsbyname.3   Wed Sep  7 21:03:11 2016
(r305567)
+++ stable/10/lib/libc/gen/getvfsbyname.3   Wed Sep  7 21:04:39 2016
(r305568)
@@ -28,7 +28,7 @@
 .\" @(#)kvm_getvfsbyname.3 8.3 (Berkeley) 5/4/95
 .\" $FreeBSD$
 .\"
-.Dd April 5, 2007
+.Dd August 30, 2016
 .Dt GETVFSBYNAME 3
 .Os
 .Sh NAME
@@ -97,11 +97,6 @@ sysctl is set to
 .Sh ERRORS
 The following errors may be reported:
 .Bl -tag -width Er
-.It Bq Er EFAULT
-The
-.Fa vfc
-argument
-points to an invalid address.
 .It Bq Er ENOENT
 The
 .Fa name
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r302323 - stable/10/sys/kern

2016-07-03 Thread Jilles Tjoelker
Author: jilles
Date: Sun Jul  3 11:45:54 2016
New Revision: 302323
URL: https://svnweb.freebsd.org/changeset/base/302323

Log:
  MFC r302151: posixshm: Fix lock leak when mac_posixshm_check_read rejects
  read.
  
  While reading the code, I noticed that shm_read() returns without unlocking
  foffset and rangelock if mac_posixshm_check_read() rejects the read.

Modified:
  stable/10/sys/kern/uipc_shm.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/kern/uipc_shm.c
==
--- stable/10/sys/kern/uipc_shm.c   Sun Jul  3 01:56:48 2016
(r302322)
+++ stable/10/sys/kern/uipc_shm.c   Sun Jul  3 11:45:54 2016
(r302323)
@@ -293,14 +293,14 @@ shm_read(struct file *fp, struct uio *ui
int error;
 
shmfd = fp->f_data;
-   foffset_lock_uio(fp, uio, flags);
-   rl_cookie = rangelock_rlock(>shm_rl, uio->uio_offset,
-   uio->uio_offset + uio->uio_resid, >shm_mtx);
 #ifdef MAC
error = mac_posixshm_check_read(active_cred, fp->f_cred, shmfd);
if (error)
return (error);
 #endif
+   foffset_lock_uio(fp, uio, flags);
+   rl_cookie = rangelock_rlock(>shm_rl, uio->uio_offset,
+   uio->uio_offset + uio->uio_resid, >shm_mtx);
error = uiomove_object(shmfd->shm_object, shmfd->shm_size, uio);
rangelock_unlock(>shm_rl, rl_cookie, >shm_mtx);
foffset_unlock_uio(fp, uio, flags);
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r302011 - stable/10/share/man/man3

2016-06-18 Thread Jilles Tjoelker
Author: jilles
Date: Sat Jun 18 13:44:10 2016
New Revision: 302011
URL: https://svnweb.freebsd.org/changeset/base/302011

Log:
  MFC r301076: Fix typo ESRC -> ESRCH in pthread man pages.

Modified:
  stable/10/share/man/man3/pthread_attr_get_np.3
  stable/10/share/man/man3/pthread_resume_np.3
  stable/10/share/man/man3/pthread_suspend_np.3
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/share/man/man3/pthread_attr_get_np.3
==
--- stable/10/share/man/man3/pthread_attr_get_np.3  Sat Jun 18 13:42:33 
2016(r302010)
+++ stable/10/share/man/man3/pthread_attr_get_np.3  Sat Jun 18 13:44:10 
2016(r302011)
@@ -93,7 +93,7 @@ function will fail if:
 .Bl -tag -width Er
 .It Bq Er EINVAL
 Invalid value for one of given parameters.
-.It Bq Er ESRC
+.It Bq Er ESRCH
 No thread could be found corresponding to that specified by the given
 thread ID.
 .El

Modified: stable/10/share/man/man3/pthread_resume_np.3
==
--- stable/10/share/man/man3/pthread_resume_np.3Sat Jun 18 13:42:33 
2016(r302010)
+++ stable/10/share/man/man3/pthread_resume_np.3Sat Jun 18 13:44:10 
2016(r302011)
@@ -57,7 +57,7 @@ function will fail if:
 The value specified by the
 .Fa tid
 argument is invalid.
-.It Bq Er ESRC
+.It Bq Er ESRCH
 No thread could be found corresponding to the thread ID specified by the
 .Fa tid
 argument.

Modified: stable/10/share/man/man3/pthread_suspend_np.3
==
--- stable/10/share/man/man3/pthread_suspend_np.3   Sat Jun 18 13:42:33 
2016(r302010)
+++ stable/10/share/man/man3/pthread_suspend_np.3   Sat Jun 18 13:44:10 
2016(r302011)
@@ -63,7 +63,7 @@ An attempt was made to suspend the curre
 The value specified by the
 .Fa tid
 argument is invalid.
-.It Bq Er ESRC
+.It Bq Er ESRCH
 No thread could be found corresponding to the thread ID specified by the
 .Fa tid
 argument.
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r302010 - in stable/10: lib/libthr share/man/man3

2016-06-18 Thread Jilles Tjoelker
Author: jilles
Date: Sat Jun 18 13:42:33 2016
New Revision: 302010
URL: https://svnweb.freebsd.org/changeset/base/302010

Log:
  MFC r300970: Remove non-history libkse references and fix typo
  "PTHREAD_PROCESSES_PRIVATE".

Modified:
  stable/10/lib/libthr/libthr.3
  stable/10/share/man/man3/pthread_barrier_destroy.3
  stable/10/share/man/man3/pthread_barrierattr.3
  stable/10/share/man/man3/pthread_condattr.3
  stable/10/share/man/man3/pthread_spin_init.3
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libthr/libthr.3
==
--- stable/10/lib/libthr/libthr.3   Sat Jun 18 13:41:00 2016
(r302009)
+++ stable/10/lib/libthr/libthr.3   Sat Jun 18 13:42:33 2016
(r302010)
@@ -47,9 +47,7 @@ library provides a 1:1 implementation of
 library interfaces for application threading.
 It
 has been optimized for use by applications expecting system scope thread
-semantics, and can provide significant performance improvements
-compared to
-.Lb libkse .
+semantics.
 .Pp
 The library is tightly integrated with the run-time link editor
 .Xr ld-elf.so.1 1

Modified: stable/10/share/man/man3/pthread_barrier_destroy.3
==
--- stable/10/share/man/man3/pthread_barrier_destroy.3  Sat Jun 18 13:41:00 
2016(r302009)
+++ stable/10/share/man/man3/pthread_barrier_destroy.3  Sat Jun 18 13:42:33 
2016(r302010)
@@ -75,9 +75,7 @@ argument to
 .Fn pthread_barrier_init .
 Once the threads have been released the barrier will be reset.
 .Sh IMPLEMENTATION NOTES
-In both
-.Lb libkse
-and
+In
 .Lb libthr
 the
 .Dv PTHREAD_BARRIER_SERIAL_THREAD

Modified: stable/10/share/man/man3/pthread_barrierattr.3
==
--- stable/10/share/man/man3/pthread_barrierattr.3  Sat Jun 18 13:41:00 
2016(r302009)
+++ stable/10/share/man/man3/pthread_barrierattr.3  Sat Jun 18 13:42:33 
2016(r302010)
@@ -137,11 +137,9 @@ barriers
 does not fully conform to
 .St -p1003.2
 because the process-shared attribute is ignored in
-.Lb libthr ,
-and in
-.Lb libkse ;
+.Lb libthr ;
 if any value other than
-.Dv PTHREAD_PROCESSES_PRIVATE
+.Dv PTHREAD_PROCESS_PRIVATE
 is specified in a call to
 .Fn pthread_barrierattr_setpshared ,
 it will return

Modified: stable/10/share/man/man3/pthread_condattr.3
==
--- stable/10/share/man/man3/pthread_condattr.3 Sat Jun 18 13:41:00 2016
(r302009)
+++ stable/10/share/man/man3/pthread_condattr.3 Sat Jun 18 13:42:33 2016
(r302010)
@@ -167,7 +167,7 @@ does not fully conform to
 .St -p1003.2
 because the process-shared attribute is ignored;
 if any value other than
-.Dv PTHREAD_PROCESSES_PRIVATE
+.Dv PTHREAD_PROCESS_PRIVATE
 is specified in a call to
 .Fn pthread_condattr_setpshared ,
 it will return

Modified: stable/10/share/man/man3/pthread_spin_init.3
==
--- stable/10/share/man/man3/pthread_spin_init.3Sat Jun 18 13:41:00 
2016(r302009)
+++ stable/10/share/man/man3/pthread_spin_init.3Sat Jun 18 13:42:33 
2016(r302010)
@@ -129,10 +129,8 @@ does not fully conform to
 because the
 .Fa pshared
 argument is ignored in
-.Lb libthr ,
-and in
-.Lb libkse
+.Lb libthr ;
 if any value other than
-.Dv PTHREAD_PROCESSES_PRIVATE
+.Dv PTHREAD_PROCESS_PRIVATE
 is specified, it returns
 .Er EINVAL .
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r302009 - stable/10

2016-06-18 Thread Jilles Tjoelker
Author: jilles
Date: Sat Jun 18 13:41:00 2016
New Revision: 302009
URL: https://svnweb.freebsd.org/changeset/base/302009

Log:
  Add mergeinfo missed in r300954.

Modified:
Directory Properties:
  stable/10/   (props changed)
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r300954 - stable/10/lib/libc/sys

2016-05-29 Thread Jilles Tjoelker
Author: jilles
Date: Sun May 29 12:16:58 2016
New Revision: 300954
URL: https://svnweb.freebsd.org/changeset/base/300954

Log:
  MFC r300420: vfork(2): Mention some risks of calling vfork() from
  application code.

Modified:
  stable/10/lib/libc/sys/vfork.2

Modified: stable/10/lib/libc/sys/vfork.2
==
--- stable/10/lib/libc/sys/vfork.2  Sun May 29 11:54:09 2016
(r300953)
+++ stable/10/lib/libc/sys/vfork.2  Sun May 29 12:16:58 2016
(r300954)
@@ -28,7 +28,7 @@
 .\" @(#)vfork.28.1 (Berkeley) 6/4/93
 .\" $FreeBSD$
 .\"
-.Dd April 6, 2015
+.Dd May 22, 2016
 .Dt VFORK 2
 .Os
 .Sh NAME
@@ -41,11 +41,20 @@
 .Ft pid_t
 .Fn vfork void
 .Sh DESCRIPTION
+.Bf -symbolic
+Since this function is hard to use correctly from application software,
+it is recommended to use
+.Xr posix_spawn 3
+or
+.Xr fork 2
+instead.
+.Ef
+.Pp
 The
 .Fn vfork
 system call
 can be used to create new processes without fully copying the address
-space of the old process, which is horrendously inefficient in a paged
+space of the old process, which is inefficient in a paged
 environment.
 It is useful when the purpose of
 .Xr fork 2
@@ -56,13 +65,15 @@ The
 system call
 differs from
 .Xr fork 2
-in that the child borrows the parent's memory and thread of
-control until a call to
+in that the child borrows the parent process's address space and the
+calling thread's stack
+until a call to
 .Xr execve 2
 or an exit (either by a call to
 .Xr _exit 2
 or abnormally).
-The parent process is suspended while the child is using its resources.
+The calling thread is suspended while the child is using its resources.
+Other threads continue to run.
 .Pp
 The
 .Fn vfork
@@ -70,17 +81,21 @@ system call
 returns 0 in the child's context and (later) the pid of the child in
 the parent's context.
 .Pp
-The
-.Fn vfork
-system call
-can normally be used just like
-.Xr fork 2 .
-It does not work, however, to return while running in the child's context
+Many problems can occur when replacing
+.Xr fork 2
+with
+.Fn vfork .
+For example, it does not work to return while running in the child's context
 from the procedure that called
 .Fn vfork
 since the eventual return from
 .Fn vfork
 would then return to a no longer existent stack frame.
+Also, changing process state which is partially implemented in user space
+such as signal handlers with
+.Xr libthr 3
+will corrupt the parent's state.
+.Pp
 Be careful, also, to call
 .Xr _exit 2
 rather than
@@ -106,7 +121,8 @@ Same as for
 .Xr rfork 2 ,
 .Xr sigaction 2 ,
 .Xr wait 2 ,
-.Xr exit 3
+.Xr exit 3 ,
+.Xr posix_spawn 3
 .Sh HISTORY
 The
 .Fn vfork
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r297783 - stable/10/usr.bin/touch

2016-04-10 Thread Jilles Tjoelker
Author: jilles
Date: Sun Apr 10 15:24:07 2016
New Revision: 297783
URL: https://svnweb.freebsd.org/changeset/base/297783

Log:
  MFC r278817: touch: Fix some subtle bugs related to NULL times fallback:
  
  * Do not subvert vfs.timestamp_precision by reading the time and passing
that to utimensat(). Instead, pass UTIME_NOW. A fallback to a NULL times
pointer is no longer used.
  
  * Do not ignore -a/-m if the user has write access but does not own the
file. Leave timestamps unchanged using UTIME_OMIT and do not fall back to
a NULL times pointer (which would set both timestamps) if that fails.

Modified:
  stable/10/usr.bin/touch/touch.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/usr.bin/touch/touch.c
==
--- stable/10/usr.bin/touch/touch.c Sun Apr 10 15:02:29 2016
(r297782)
+++ stable/10/usr.bin/touch/touch.c Sun Apr 10 15:24:07 2016
(r297783)
@@ -76,8 +76,8 @@ main(int argc, char *argv[])
myname = basename(argv[0]);
Aflag = aflag = cflag = mflag = timeset = 0;
atflag = 0;
-   if (clock_gettime(CLOCK_REALTIME, [0]) == -1)
-   err(1, "clock_gettime(CLOCK_REALTIME)");
+   ts[0].tv_sec = ts[1].tv_sec = 0;
+   ts[0].tv_nsec = ts[1].tv_nsec = UTIME_NOW;
 
while ((ch = getopt(argc, argv, "A:acd:fhmr:t:")) != -1)
switch(ch) {
@@ -152,6 +152,11 @@ main(int argc, char *argv[])
ts[1] = ts[0];
}
 
+   if (!aflag)
+   ts[0].tv_nsec = UTIME_OMIT;
+   if (!mflag)
+   ts[1].tv_nsec = UTIME_OMIT;
+
if (*argv == NULL)
usage(myname);
 
@@ -183,11 +188,6 @@ main(int argc, char *argv[])
continue;
}
 
-   if (!aflag)
-   ts[0] = sb.st_atim;
-   if (!mflag)
-   ts[1] = sb.st_mtim;
-
/*
 * We're adjusting the times based on the file times, not a
 * specified time (that gets handled above).
@@ -203,26 +203,9 @@ main(int argc, char *argv[])
}
}
 
-   /* Try utimensat(2). */
if (!utimensat(AT_FDCWD, *argv, ts, atflag))
continue;
 
-   /* If the user specified a time, nothing else we can do. */
-   if (timeset || Aflag) {
-   rval = 1;
-   warn("%s", *argv);
-   continue;
-   }
-
-   /*
-* System V and POSIX 1003.1 require that a NULL argument
-* set the access/modification times to the current time.
-* The permission checks are different, too, in that the
-* ability to write the file is sufficient.  Take a shot.
-*/
-if (!utimensat(AT_FDCWD, *argv, NULL, atflag))
-   continue;
-
rval = 1;
warn("%s", *argv);
}
@@ -238,8 +221,8 @@ stime_arg1(const char *arg, struct times
struct tm *t;
int yearset;
char *p;
-   /* Start with the current time. */
-   now = tvp[0].tv_sec;
+
+   now = time(NULL);
if ((t = localtime()) == NULL)
err(1, "localtime");
/* [[CC]YY]MMDDhhmm[.SS] */
@@ -300,8 +283,8 @@ stime_arg2(const char *arg, int year, st
 {
time_t now;
struct tm *t;
-   /* Start with the current time. */
-   now = tvp[0].tv_sec;
+
+   now = time(NULL);
if ((t = localtime()) == NULL)
err(1, "localtime");
 
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r297782 - in stable/10: bin/cp bin/mv usr.bin/touch

2016-04-10 Thread Jilles Tjoelker
Author: jilles
Date: Sun Apr 10 15:02:29 2016
New Revision: 297782
URL: https://svnweb.freebsd.org/changeset/base/297782

Log:
  MFC r277645: cp,mv,touch: Set timestamps with nanosecond precision.
  
  This uses utimensat().

Modified:
  stable/10/bin/cp/utils.c
  stable/10/bin/mv/mv.c
  stable/10/usr.bin/touch/touch.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/bin/cp/utils.c
==
--- stable/10/bin/cp/utils.cSun Apr 10 07:11:29 2016(r297781)
+++ stable/10/bin/cp/utils.cSun Apr 10 15:02:29 2016(r297782)
@@ -344,7 +344,7 @@ copy_special(struct stat *from_stat, int
 int
 setfile(struct stat *fs, int fd)
 {
-   static struct timeval tv[2];
+   static struct timespec tspec[2];
struct stat ts;
int rval, gotstat, islink, fdval;
 
@@ -354,10 +354,11 @@ setfile(struct stat *fs, int fd)
fs->st_mode &= S_ISUID | S_ISGID | S_ISVTX |
S_IRWXU | S_IRWXG | S_IRWXO;
 
-   TIMESPEC_TO_TIMEVAL([0], >st_atim);
-   TIMESPEC_TO_TIMEVAL([1], >st_mtim);
-   if (islink ? lutimes(to.p_path, tv) : utimes(to.p_path, tv)) {
-   warn("%sutimes: %s", islink ? "l" : "", to.p_path);
+   tspec[0] = fs->st_atim;
+   tspec[1] = fs->st_mtim;
+   if (utimensat(AT_FDCWD, to.p_path, tspec,
+   islink ? AT_SYMLINK_NOFOLLOW : 0)) {
+   warn("utimensat: %s", to.p_path);
rval = 1;
}
if (fdval ? fstat(fd, ) :

Modified: stable/10/bin/mv/mv.c
==
--- stable/10/bin/mv/mv.c   Sun Apr 10 07:11:29 2016(r297781)
+++ stable/10/bin/mv/mv.c   Sun Apr 10 15:02:29 2016(r297782)
@@ -273,7 +273,7 @@ do_move(const char *from, const char *to
 static int
 fastcopy(const char *from, const char *to, struct stat *sbp)
 {
-   struct timeval tval[2];
+   struct timespec ts[2];
static u_int blen = MAXPHYS;
static char *bp = NULL;
mode_t oldmode;
@@ -341,10 +341,9 @@ err:   if (unlink(to))
if (errno != EOPNOTSUPP || sbp->st_flags != 0)
warn("%s: set flags (was: 0%07o)", to, sbp->st_flags);
 
-   tval[0].tv_sec = sbp->st_atime;
-   tval[1].tv_sec = sbp->st_mtime;
-   tval[0].tv_usec = tval[1].tv_usec = 0;
-   if (utimes(to, tval))
+   ts[0] = sbp->st_atim;
+   ts[1] = sbp->st_mtim;
+   if (utimensat(AT_FDCWD, to, ts, 0))
warn("%s: set times", to);
 
if (close(to_fd)) {

Modified: stable/10/usr.bin/touch/touch.c
==
--- stable/10/usr.bin/touch/touch.c Sun Apr 10 07:11:29 2016
(r297781)
+++ stable/10/usr.bin/touch/touch.c Sun Apr 10 15:02:29 2016
(r297782)
@@ -56,10 +56,10 @@ static const char sccsid[] = "@(#)touch.
 #include 
 #include 
 
-static voidstime_arg1(const char *, struct timeval *);
-static voidstime_arg2(const char *, int, struct timeval *);
-static voidstime_darg(const char *, struct timeval *);
-static voidstime_file(const char *, struct timeval *);
+static voidstime_arg1(const char *, struct timespec *);
+static voidstime_arg2(const char *, int, struct timespec *);
+static voidstime_darg(const char *, struct timespec *);
+static voidstime_file(const char *, struct timespec *);
 static int timeoffset(const char *);
 static voidusage(const char *);
 
@@ -67,19 +67,17 @@ int
 main(int argc, char *argv[])
 {
struct stat sb;
-   struct timeval tv[2];
-   int (*stat_f)(const char *, struct stat *);
-   int (*utimes_f)(const char *, const struct timeval *);
+   struct timespec ts[2];
+   int atflag;
int Aflag, aflag, cflag, mflag, ch, fd, len, rval, timeset;
char *p;
char *myname;
 
myname = basename(argv[0]);
Aflag = aflag = cflag = mflag = timeset = 0;
-   stat_f = stat;
-   utimes_f = utimes;
-   if (gettimeofday([0], NULL) == -1)
-   err(1, "gettimeofday");
+   atflag = 0;
+   if (clock_gettime(CLOCK_REALTIME, [0]) == -1)
+   err(1, "clock_gettime(CLOCK_REALTIME)");
 
while ((ch = getopt(argc, argv, "A:acd:fhmr:t:")) != -1)
switch(ch) {
@@ -94,26 +92,25 @@ main(int argc, char *argv[])
break;
case 'd':
timeset = 1;
-   stime_darg(optarg, tv);
+   stime_darg(optarg, ts);
break;
case 'f':
/* No-op for compatibility. */
break;
case 'h':
cflag = 1;
-   stat_f = lstat;
-   utimes_f = lutimes;
+   atflag = AT_SYMLINK_NOFOLLOW;

svn commit: r297766 - stable/10/bin/test

2016-04-09 Thread Jilles Tjoelker
Author: jilles
Date: Sat Apr  9 21:49:57 2016
New Revision: 297766
URL: https://svnweb.freebsd.org/changeset/base/297766

Log:
  MFC r258799: test: Simplify the code by unifying op_num and op_type.
  
  The global variable t_wp_op is no longer needed.

Modified:
  stable/10/bin/test/test.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/bin/test/test.c
==
--- stable/10/bin/test/test.c   Sat Apr  9 21:04:51 2016(r297765)
+++ stable/10/bin/test/test.c   Sat Apr  9 21:49:57 2016(r297766)
@@ -67,9 +67,18 @@ error(const char *msg, ...)
operand ::= 
 */
 
+enum token_types {
+   UNOP = 0x100,
+   BINOP = 0x200,
+   BUNOP = 0x300,
+   BBINOP = 0x400,
+   PAREN = 0x500
+};
+
 enum token {
EOI,
-   FILRD,
+   OPERAND,
+   FILRD = UNOP + 1,
FILWR,
FILEX,
FILEXIST,
@@ -85,13 +94,13 @@ enum token {
FILSUID,
FILSGID,
FILSTCK,
-   FILNT,
-   FILOT,
-   FILEQ,
-   FILUID,
-   FILGID,
STREZ,
STRNZ,
+   FILUID,
+   FILGID,
+   FILNT = BINOP + 1,
+   FILOT,
+   FILEQ,
STREQ,
STRNE,
STRLT,
@@ -102,70 +111,62 @@ enum token {
INTGT,
INTLE,
INTLT,
-   UNOT,
-   BAND,
+   UNOT = BUNOP + 1,
+   BAND = BBINOP + 1,
BOR,
-   LPAREN,
-   RPAREN,
-   OPERAND
+   LPAREN = PAREN + 1,
+   RPAREN
 };
 
-enum token_types {
-   UNOP,
-   BINOP,
-   BUNOP,
-   BBINOP,
-   PAREN
-};
+#define TOKEN_TYPE(token) ((token) & 0xff00)
 
 static struct t_op {
char op_text[4];
-   short op_num, op_type;
+   short op_num;
 } const ops [] = {
-   {"-r",  FILRD,  UNOP},
-   {"-w",  FILWR,  UNOP},
-   {"-x",  FILEX,  UNOP},
-   {"-e",  FILEXIST,UNOP},
-   {"-f",  FILREG, UNOP},
-   {"-d",  FILDIR, UNOP},
-   {"-c",  FILCDEV,UNOP},
-   {"-b",  FILBDEV,UNOP},
-   {"-p",  FILFIFO,UNOP},
-   {"-u",  FILSUID,UNOP},
-   {"-g",  FILSGID,UNOP},
-   {"-k",  FILSTCK,UNOP},
-   {"-s",  FILGZ,  UNOP},
-   {"-t",  FILTT,  UNOP},
-   {"-z",  STREZ,  UNOP},
-   {"-n",  STRNZ,  UNOP},
-   {"-h",  FILSYM, UNOP},  /* for backwards compat */
-   {"-O",  FILUID, UNOP},
-   {"-G",  FILGID, UNOP},
-   {"-L",  FILSYM, UNOP},
-   {"-S",  FILSOCK,UNOP},
-   {"=",   STREQ,  BINOP},
-   {"==",  STREQ,  BINOP},
-   {"!=",  STRNE,  BINOP},
-   {"<",   STRLT,  BINOP},
-   {">",   STRGT,  BINOP},
-   {"-eq", INTEQ,  BINOP},
-   {"-ne", INTNE,  BINOP},
-   {"-ge", INTGE,  BINOP},
-   {"-gt", INTGT,  BINOP},
-   {"-le", INTLE,  BINOP},
-   {"-lt", INTLT,  BINOP},
-   {"-nt", FILNT,  BINOP},
-   {"-ot", FILOT,  BINOP},
-   {"-ef", FILEQ,  BINOP},
-   {"!",   UNOT,   BUNOP},
-   {"-a",  BAND,   BBINOP},
-   {"-o",  BOR,BBINOP},
-   {"(",   LPAREN, PAREN},
-   {")",   RPAREN, PAREN},
-   {"",0,  0}
+   {"-r",  FILRD},
+   {"-w",  FILWR},
+   {"-x",  FILEX},
+   {"-e",  FILEXIST},
+   {"-f",  FILREG},
+   {"-d",  FILDIR},
+   {"-c",  FILCDEV},
+   {"-b",  FILBDEV},
+   {"-p",  FILFIFO},
+   {"-u",  FILSUID},
+   {"-g",  FILSGID},
+   {"-k",  FILSTCK},
+   {"-s",  FILGZ},
+   {"-t",  FILTT},
+   {"-z",  STREZ},
+   {"-n",  STRNZ},
+   {"-h",  FILSYM},/* for backwards compat */
+   {"-O",  FILUID},
+   {"-G",  FILGID},
+   {"-L",  FILSYM},
+   {"-S",  FILSOCK},
+   {"=",   STREQ},
+   {"==",  STREQ},
+   {"!=",  STRNE},
+   {"<",   STRLT},
+   {">",   STRGT},
+   {"-eq", INTEQ},
+   {"-ne", INTNE},
+   {"-ge", INTGE},
+   {"-gt", INTGT},
+   {"-le", INTLE},
+   {"-lt", INTLT},
+   {"-nt", FILNT},
+   {"-ot", FILOT},
+   {"-ef", FILEQ},
+   {"!",   UNOT},
+   {"-a",  BAND},
+   {"-o",  BOR},
+   {"(",   LPAREN},
+   {")",   RPAREN},
+   {"",0}
 };
 
-static struct t_op const *t_wp_op;
 static int nargc;
 static char **t_wp;
 static int parenlevel;
@@ -295,10 +296,10 @@ primary(enum token n)
parenlevel--;
return res;
}
-   if (t_wp_op && t_wp_op->op_type == UNOP) {
+   if (TOKEN_TYPE(n) == UNOP) {
/* unary expression */
if (--nargc == 0)
-   syntax(t_wp_op->op_text, "argument expected");
+   syntax(NULL, "argument expected"); /* impossible */
switch (n) {
case STREZ:
return strlen(*++t_wp) == 0;
@@ -311,10 +312,8 @@ primary(enum token n)
}
}
 
-   if (t_lex(nargc > 0 ? t_wp[1] : NULL), t_wp_op && t_wp_op->op_type ==
-   BINOP) {
+  

svn commit: r297765 - stable/10/sys/kern

2016-04-09 Thread Jilles Tjoelker
Author: jilles
Date: Sat Apr  9 21:04:51 2016
New Revision: 297765
URL: https://svnweb.freebsd.org/changeset/base/297765

Log:
  MFC r281086: utimensat: Correct Capsicum required capability rights.

Modified:
  stable/10/sys/kern/vfs_syscalls.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/kern/vfs_syscalls.c
==
--- stable/10/sys/kern/vfs_syscalls.c   Sat Apr  9 20:36:07 2016
(r297764)
+++ stable/10/sys/kern/vfs_syscalls.c   Sat Apr  9 21:04:51 2016
(r297765)
@@ -3405,6 +3405,7 @@ kern_utimensat(struct thread *td, int fd
 {
struct nameidata nd;
struct timespec ts[2];
+   cap_rights_t rights;
int error, flags;
 
if (flag & ~AT_SYMLINK_NOFOLLOW)
@@ -3412,8 +3413,9 @@ kern_utimensat(struct thread *td, int fd
 
if ((error = getutimens(tptr, tptrseg, ts, )) != 0)
return (error);
-   NDINIT_AT(, LOOKUP, ((flag & AT_SYMLINK_NOFOLLOW) ? NOFOLLOW :
-   FOLLOW) | AUDITVNODE1, pathseg, path, fd, td);
+   NDINIT_ATRIGHTS(, LOOKUP, ((flag & AT_SYMLINK_NOFOLLOW) ? NOFOLLOW :
+   FOLLOW) | AUDITVNODE1, pathseg, path, fd,
+   cap_rights_init(, CAP_FUTIMES), td);
if ((error = namei()) != 0)
return (error);
/*
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r297759 - stable/10/lib/libc/sys

2016-04-09 Thread Jilles Tjoelker
Author: jilles
Date: Sat Apr  9 19:29:39 2016
New Revision: 297759
URL: https://svnweb.freebsd.org/changeset/base/297759

Log:
  MFC r287753: setuid(2): Suggest O_CLOEXEC instead of fcntl(F_SETFD).

Modified:
  stable/10/lib/libc/sys/setuid.2
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/sys/setuid.2
==
--- stable/10/lib/libc/sys/setuid.2 Sat Apr  9 19:09:06 2016
(r297758)
+++ stable/10/lib/libc/sys/setuid.2 Sat Apr  9 19:29:39 2016
(r297759)
@@ -28,7 +28,7 @@
 .\" @(#)setuid.2   8.1 (Berkeley) 6/4/93
 .\" $FreeBSD$
 .\"
-.Dd June 4, 1993
+.Dd September 13, 2015
 .Dt SETUID 2
 .Os
 .Sh NAME
@@ -178,15 +178,10 @@ pseudocode(void)
int fd;
/* ... */
 
-   fd = open("/path/to/sensitive/data", O_RDWR);
+   fd = open("/path/to/sensitive/data", O_RDWR | O_CLOEXEC);
if (fd == -1)
err(1, "open");
 
-   /*
-* Set close-on-exec flag; see fcntl(2) for more information.
-*/
-   if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
-   err(1, "fcntl(F_SETFD)");
/* ... */
execve(path, argv, environ);
 }
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r297719 - stable/10/lib/libc/sys

2016-04-08 Thread Jilles Tjoelker
Author: jilles
Date: Fri Apr  8 15:43:49 2016
New Revision: 297719
URL: https://svnweb.freebsd.org/changeset/base/297719

Log:
  MFC r295384: semget(2): Add missing [EINVAL] conditions.
  
  PR:   206927

Modified:
  stable/10/lib/libc/sys/semget.2
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/sys/semget.2
==
--- stable/10/lib/libc/sys/semget.2 Fri Apr  8 15:28:12 2016
(r297718)
+++ stable/10/lib/libc/sys/semget.2 Fri Apr  8 15:43:49 2016
(r297719)
@@ -25,7 +25,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd September 12, 1995
+.Dd February 7, 2016
 .Dt SEMGET 2
 .Os
 .Sh NAME
@@ -132,6 +132,17 @@ already exists.
 .It Bq Er EINVAL
 The number of semaphores requested exceeds the system imposed maximum
 per set.
+.It Bq Er EINVAL
+A semaphore set corresponding to
+.Fa key
+already exists and contains fewer semaphores than
+.Fa nsems .
+.It Bq Er EINVAL
+A semaphore set corresponding to
+.Fa key
+does not exist and
+.Fa nsems
+is 0 or negative.
 .It Bq Er ENOSPC
 Insufficiently many semaphores are available.
 .It Bq Er ENOSPC
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r294963 - in stable/10: lib/libc/gen tools/regression/posixsem2

2016-01-27 Thread Jilles Tjoelker
Author: jilles
Date: Wed Jan 27 22:56:04 2016
New Revision: 294963
URL: https://svnweb.freebsd.org/changeset/base/294963

Log:
  MFC r294565: sem: Don't free nameinfo that is still in list when open()
  fails.
  
  This bug could be reproduced easily by calling sem_open() with O_CREAT |
  O_EXCL on a semaphore that is already open in the process. The struct
  sem_nameinfo would be freed while still in sem_list and later calls to
  sem_open() or sem_close() could access freed memory.
  
  PR:   206396

Modified:
  stable/10/lib/libc/gen/sem_new.c
  stable/10/tools/regression/posixsem2/semtest.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/gen/sem_new.c
==
--- stable/10/lib/libc/gen/sem_new.cWed Jan 27 22:52:20 2016
(r294962)
+++ stable/10/lib/libc/gen/sem_new.cWed Jan 27 22:56:04 2016
(r294963)
@@ -176,8 +176,10 @@ _sem_open(const char *name, int flags, .
if (ni->name != NULL && strcmp(name, ni->name) == 0) {
fd = _open(path, flags | O_RDWR | O_CLOEXEC |
O_EXLOCK, mode);
-   if (fd == -1 || _fstat(fd, ) == -1)
+   if (fd == -1 || _fstat(fd, ) == -1) {
+   ni = NULL;
goto error;
+   }
if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT |
O_EXCL) || ni->dev != sb.st_dev ||
ni->ino != sb.st_ino) {

Modified: stable/10/tools/regression/posixsem2/semtest.c
==
--- stable/10/tools/regression/posixsem2/semtest.c  Wed Jan 27 22:52:20 
2016(r294962)
+++ stable/10/tools/regression/posixsem2/semtest.c  Wed Jan 27 22:56:04 
2016(r294963)
@@ -7,6 +7,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -14,6 +15,7 @@
 
 int test_unnamed(void);
 int test_named(void);
+int test_named2(void);
 
 int
 test_unnamed(void)
@@ -94,9 +96,42 @@ test_named(void)
 }
 
 int
+test_named2(void)
+{
+   sem_t *s, *s2, *s3;
+
+   printf("testing named process-shared semaphore, O_EXCL cases\n");
+   sem_unlink(SEM_NAME);
+   s = sem_open(SEM_NAME, O_CREAT | O_EXCL, 0777, 0);
+   if (s == SEM_FAILED)
+   err(1, "sem_open failed");
+   s2 = sem_open(SEM_NAME, O_CREAT | O_EXCL, 0777, 0);
+   if (s2 != SEM_FAILED)
+   errx(2, "second sem_open call wrongly succeeded");
+   if (errno != EEXIST)
+   err(3, "second sem_open call failed with wrong errno");
+
+   s3 = sem_open(SEM_NAME, 0);
+   if (s3 == SEM_FAILED)
+   err(4, "third sem_open call failed");
+   if (s != s3)
+   errx(5,
+"two sem_open calls for same semaphore do not return same address");
+   if (sem_close(s3))
+   err(6, "sem_close failed");
+
+   if (sem_close(s))
+   err(7, "sem_close failed");
+   
+   printf("OK.\n");
+   return (0);
+}
+
+int
 main(void)
 {
test_unnamed();
test_named();
+   test_named2();
return (0);
 }
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r294532 - stable/10/lib/libc/sys

2016-01-21 Thread Jilles Tjoelker
Author: jilles
Date: Thu Jan 21 21:16:57 2016
New Revision: 294532
URL: https://svnweb.freebsd.org/changeset/base/294532

Log:
  MFC r294234: utimensat(2): Correct description of [EINVAL] error.

Modified:
  stable/10/lib/libc/sys/utimensat.2
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/sys/utimensat.2
==
--- stable/10/lib/libc/sys/utimensat.2  Thu Jan 21 20:52:20 2016
(r294531)
+++ stable/10/lib/libc/sys/utimensat.2  Thu Jan 21 21:16:57 2016
(r294532)
@@ -31,7 +31,7 @@
 .\" @(#)utimes.2   8.1 (Berkeley) 6/4/93
 .\" $FreeBSD$
 .\"
-.Dd January 12, 2016
+.Dd January 17, 2016
 .Dt UTIMENSAT 2
 .Os
 .Sh NAME
@@ -183,10 +183,13 @@ argument
 points outside the process's allocated address space.
 .It Bq Er EINVAL
 The
-.Va tv_usec
+.Va tv_nsec
 component of at least one of the values specified by the
 .Fa times
-argument has a value less than 0 or greater than 99.
+argument has a value less than 0 or greater than 9 and is not equal to
+.Dv UTIME_NOW
+or
+.Dv UTIME_OMIT .
 .It Bq Er EIO
 An I/O error occurred while reading or writing the affected inode.
 .It Bq Er EPERM
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r294099 - stable/10/lib/libc/sys

2016-01-15 Thread Jilles Tjoelker
Author: jilles
Date: Fri Jan 15 20:55:44 2016
New Revision: 294099
URL: https://svnweb.freebsd.org/changeset/base/294099

Log:
  MFC r293783: futimens/utimensat: Use the new system calls.
  
  Update the __FreeBSD_version check in lib/libc/sys/futimens.c and
  lib/libc/sys/utimensat.c. Before this, fallback code using
  futimes/futimesat/lutimes was used except when running on a sufficiently
  recent 11-current kernel.
  
  Also, update the history section in the man page.

Modified:
  stable/10/lib/libc/sys/futimens.c
  stable/10/lib/libc/sys/utimensat.2
  stable/10/lib/libc/sys/utimensat.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/sys/futimens.c
==
--- stable/10/lib/libc/sys/futimens.c   Fri Jan 15 18:53:06 2016
(r294098)
+++ stable/10/lib/libc/sys/futimens.c   Fri Jan 15 20:55:44 2016
(r294099)
@@ -42,8 +42,11 @@ futimens(int fd, const struct timespec t
 {
struct timeval now, tv[2], *tvp;
struct stat sb;
+   int osreldate;
 
-   if (__getosreldate() >= 1100056)
+   osreldate = __getosreldate();
+   if (osreldate >= 1100056 ||
+   (osreldate >= 1002506 && osreldate < 110))
return (__sys_futimens(fd, times));
 
if (times == NULL || (times[0].tv_nsec == UTIME_NOW &&

Modified: stable/10/lib/libc/sys/utimensat.2
==
--- stable/10/lib/libc/sys/utimensat.2  Fri Jan 15 18:53:06 2016
(r294098)
+++ stable/10/lib/libc/sys/utimensat.2  Fri Jan 15 20:55:44 2016
(r294099)
@@ -31,7 +31,7 @@
 .\" @(#)utimes.2   8.1 (Berkeley) 6/4/93
 .\" $FreeBSD$
 .\"
-.Dd January 23, 2015
+.Dd January 12, 2016
 .Dt UTIMENSAT 2
 .Os
 .Sh NAME
@@ -289,4 +289,4 @@ The
 and
 .Fn utimensat
 system calls appeared in
-.Fx 11.0 .
+.Fx 10.3 .

Modified: stable/10/lib/libc/sys/utimensat.c
==
--- stable/10/lib/libc/sys/utimensat.c  Fri Jan 15 18:53:06 2016
(r294098)
+++ stable/10/lib/libc/sys/utimensat.c  Fri Jan 15 20:55:44 2016
(r294099)
@@ -42,8 +42,11 @@ utimensat(int fd, const char *path, cons
 {
struct timeval now, tv[2], *tvp;
struct stat sb;
+   int osreldate;
 
-   if (__getosreldate() >= 1100056)
+   osreldate = __getosreldate();
+   if (osreldate >= 1100056 ||
+   (osreldate >= 1002506 && osreldate < 110))
return (__sys_utimensat(fd, path, times, flag));
 
if ((flag & ~AT_SYMLINK_NOFOLLOW) != 0) {
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r292841 - stable/10/etc/defaults

2015-12-28 Thread Jilles Tjoelker
Author: jilles
Date: Mon Dec 28 21:35:06 2015
New Revision: 292841
URL: https://svnweb.freebsd.org/changeset/base/292841

Log:
  MFC r290515: periodic: Fix backwards compatibility for
  daily_status_security_* vars.
  
  Most daily_status_security_* variables in periodic.conf were changed to
  security_status_* in SVN r254974. The compatibility code for the old names
  did not work.
  
  PR:   204331
  Submitted by: martin at lispworks.com

Modified:
  stable/10/etc/defaults/periodic.conf
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/etc/defaults/periodic.conf
==
--- stable/10/etc/defaults/periodic.confMon Dec 28 20:24:08 2015
(r292840)
+++ stable/10/etc/defaults/periodic.confMon Dec 28 21:35:06 2015
(r292841)
@@ -319,8 +319,8 @@ if [ -z "${source_periodic_confs_defined
"use \$$var instead." >&2
case "$value" in
[Yy][Ee][Ss])
-   $var=YES
-   $periodvar=daily
+   eval $var=YES
+   eval $periodvar=daily
;;
*)
eval $var=\"$value\"
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r292786 - stable/10/bin/sh

2015-12-27 Thread Jilles Tjoelker
Author: jilles
Date: Sun Dec 27 17:53:39 2015
New Revision: 292786
URL: https://svnweb.freebsd.org/changeset/base/292786

Log:
  MFC r292517: sh/mknodes: Close files and check for errors when writing.
  
  This is a build tool only and does not affect run time.
  
  PR:   204951

Modified:
  stable/10/bin/sh/mknodes.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/bin/sh/mknodes.c
==
--- stable/10/bin/sh/mknodes.c  Sun Dec 27 17:51:10 2015(r292785)
+++ stable/10/bin/sh/mknodes.c  Sun Dec 27 17:53:39 2015(r292786)
@@ -89,7 +89,6 @@ static struct str *nodestr[MAXTYPES]; /*
 static int nstr;   /* number of structures */
 static struct str str[MAXTYPES];   /* the structures */
 static struct str *curstr; /* current structure */
-static FILE *infp;
 static char line[1024];
 static int linno;
 static char *linep;
@@ -102,7 +101,7 @@ static void outfunc(FILE *, int);
 static void indent(int, FILE *);
 static int nextfield(char *);
 static void skipbl(void);
-static int readline(void);
+static int readline(FILE *);
 static void error(const char *, ...) __printf0like(1, 2) __dead2;
 static char *savestr(const char *);
 
@@ -110,17 +109,19 @@ static char *savestr(const char *);
 int
 main(int argc, char *argv[])
 {
+   FILE *infp;
+
if (argc != 3)
error("usage: mknodes file");
-   infp = stdin;
if ((infp = fopen(argv[1], "r")) == NULL)
error("Can't open %s: %s", argv[1], strerror(errno));
-   while (readline()) {
+   while (readline(infp)) {
if (line[0] == ' ' || line[0] == '\t')
parsefield();
else if (line[0] != '\0')
parsenode();
}
+   fclose(infp);
output(argv[2]);
exit(0);
 }
@@ -253,6 +254,10 @@ output(char *file)
fputs("union node *getfuncnode(struct funcdef *);\n", hfile);
fputs("void reffunc(struct funcdef *);\n", hfile);
fputs("void unreffunc(struct funcdef *);\n", hfile);
+   if (ferror(hfile))
+   error("Can't write to nodes.h");
+   if (fclose(hfile))
+   error("Can't close nodes.h");
 
fputs(writer, cfile);
while (fgets(line, sizeof line, patfile) != NULL) {
@@ -266,6 +271,11 @@ output(char *file)
else
fputs(line, cfile);
}
+   fclose(patfile);
+   if (ferror(cfile))
+   error("Can't write to nodes.c");
+   if (fclose(cfile))
+   error("Can't close nodes.c");
 }
 
 
@@ -401,7 +411,7 @@ skipbl(void)
 
 
 static int
-readline(void)
+readline(FILE *infp)
 {
char *p;
 
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r292776 - stable/10/lib/libc/sys

2015-12-27 Thread Jilles Tjoelker
Author: jilles
Date: Sun Dec 27 15:30:13 2015
New Revision: 292776
URL: https://svnweb.freebsd.org/changeset/base/292776

Log:
  MFC r292513: clock_gettime(2),gettimeofday(2): Remove [EFAULT] error.
  
  Depending on system configuration and parameters, clock_gettime() and
  gettimeofday() may not be system calls. If so, passing an invalid pointer
  will cause a signal and not an [EFAULT] error.
  
  From a standards perspective, this is OK since passing an invalid pointer is
  undefined behaviour.

Modified:
  stable/10/lib/libc/sys/clock_gettime.2
  stable/10/lib/libc/sys/gettimeofday.2
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/sys/clock_gettime.2
==
--- stable/10/lib/libc/sys/clock_gettime.2  Sun Dec 27 15:18:01 2015
(r292775)
+++ stable/10/lib/libc/sys/clock_gettime.2  Sun Dec 27 15:30:13 2015
(r292776)
@@ -29,7 +29,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd December 29, 2009
+.Dd December 20, 2015
 .Dt CLOCK_GETTIME 2
 .Os
 .Sh NAME
@@ -136,10 +136,6 @@ The
 .Fa clock_id
 argument
 was not a valid value.
-.It Bq Er EFAULT
-The
-.Fa *tp
-argument address referenced invalid memory.
 .It Bq Er EPERM
 A user other than the super-user attempted to set the time.
 .El

Modified: stable/10/lib/libc/sys/gettimeofday.2
==
--- stable/10/lib/libc/sys/gettimeofday.2   Sun Dec 27 15:18:01 2015
(r292775)
+++ stable/10/lib/libc/sys/gettimeofday.2   Sun Dec 27 15:30:13 2015
(r292776)
@@ -28,7 +28,7 @@
 .\" @(#)gettimeofday.2 8.2 (Berkeley) 5/26/95
 .\" $FreeBSD$
 .\"
-.Dd May 26, 1995
+.Dd December 20, 2015
 .Dt GETTIMEOFDAY 2
 .Os
 .Sh NAME
@@ -110,8 +110,6 @@ system call even when the system is secu
 The following error codes may be set in
 .Va errno :
 .Bl -tag -width Er
-.It Bq Er EFAULT
-An argument address referenced invalid memory.
 .It Bq Er EPERM
 A user other than the super-user attempted to set the time.
 .El
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r292450 - stable/10/etc

2015-12-18 Thread Jilles Tjoelker
Author: jilles
Date: Fri Dec 18 19:58:34 2015
New Revision: 292450
URL: https://svnweb.freebsd.org/changeset/base/292450

Log:
  MFC r291770: rc.subr: Check for running daemons before a custom start_cmd
  is executed.
  
  Currently rc scripts implementing their own start_cmd do not enjoy the
  benefits of rc.subr's own check for rc_pid.
  
  This leads to around a third of ports with such a start_cmd not to check for
  the process at all and two thirds of ports to re-implement this check
  (sometimes wrongly).
  
  This patch moves the check for rc_pid to before ${rc_arg}_cmd is executed.
  
  Submitted by: Dirk Engling
  Reviewed by:  feld
  Relnotes: yes

Modified:
  stable/10/etc/rc.subr
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/etc/rc.subr
==
--- stable/10/etc/rc.subr   Fri Dec 18 19:29:58 2015(r292449)
+++ stable/10/etc/rc.subr   Fri Dec 18 19:58:34 2015(r292450)
@@ -974,6 +974,14 @@ run_rc_command()
fi
fi
 
+   if [ $rc_arg = "start" -a -z "$rc_fast" -a -n "$rc_pid" ]; then
+   if [ -z "$rc_quiet" ]; then
+   echo 1>&2 "${name} already running? " \
+   "(pid=$rc_pid)."
+   fi
+   return 1
+   fi
+
# if there's a custom ${XXX_cmd},
# run that instead of the default
#
@@ -1002,14 +1010,6 @@ run_rc_command()
;;
 
start)
-   if [ -z "$rc_fast" -a -n "$rc_pid" ]; then
-   if [ -z "$rc_quiet" ]; then
-   echo 1>&2 "${name} already running? " \
-   "(pid=$rc_pid)."
-   fi
-   return 1
-   fi
-
if [ ! -x "${_chroot}${_chroot:+/}${command}" ]; then
warn "run_rc_command: cannot run $command"
return 1
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r290062 - stable/10/etc

2015-10-27 Thread Jilles Tjoelker
Author: jilles
Date: Tue Oct 27 20:58:14 2015
New Revision: 290062
URL: https://svnweb.freebsd.org/changeset/base/290062

Log:
  MFC r286163: rc.subr: Allow rc.conf.d with multi-directory local_startup.
  
  I also changed ${...%*/rc.d} to ${...%/rc.d} since the shortest match always
  has an empty string for the asterisk.
  
  PR:   201641
  Submitted by: Jamie Landeg-Jones (original version)

Modified:
  stable/10/etc/rc.subr
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/etc/rc.subr
==
--- stable/10/etc/rc.subr   Tue Oct 27 20:56:57 2015(r290061)
+++ stable/10/etc/rc.subr   Tue Oct 27 20:58:14 2015(r290062)
@@ -1335,7 +1335,8 @@ load_rc_config()
# If a service name was specified, attempt to load
# service-specific configuration
if [ -n "$_name" ] ; then
-   for _d in /etc ${local_startup%*/rc.d}; do
+   for _d in /etc ${local_startup}; do
+   _d=${_d%/rc.d}
if [ -f ${_d}/rc.conf.d/"$_name" ]; then
debug "Sourcing ${_d}/rc.conf.d/$_name"
. ${_d}/rc.conf.d/"$_name"
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r289938 - in stable/10: bin/sh lib/libc/gen

2015-10-25 Thread Jilles Tjoelker
Author: jilles
Date: Sun Oct 25 17:17:50 2015
New Revision: 289938
URL: https://svnweb.freebsd.org/changeset/base/289938

Log:
  MFC r288430: wordexp: Rewrite to make WRDE_NOCMD reliable.
  
  Shell syntax is too complicated to detect command substitution and unquoted
  operators reliably without implementing much of sh's parser. Therefore, have
  sh do this detection.
  
  While changing sh's support anyway, also read input from a pipe instead of
  arguments to avoid {ARG_MAX} limits and improve privacy, and output count
  and length using 16 instead of 8 digits.
  
  The basic concept is:
  execl("/bin/sh", "sh", "-c", "freebsd_wordexp ${1:+\"$1\"} -f "$2",
  "", flags & WRDE_NOCMD ? "-p" : "", );
  
  The WRDE_BADCHAR error is still implemented in libc. POSIX requires us to
  fail strings containing unquoted braces with code WRDE_BADCHAR. Since this
  is normally not a syntax error in sh, there is still a need for checking
  code in libc, we_check().
  
  The new we_check() is an optimistic check that all the characters
 | & ; < > ( ) { }
  are quoted. To avoid duplicating too much sh logic, such characters are
  permitted when quoting characters are seen, even if the quoting characters
  may themselves be quoted. This code reports all WRDE_BADCHAR errors; bad
  characters that get past it and are a syntax error in sh return WRDE_SYNTAX.
  
  Although many implementations of WRDE_NOCMD erroneously allow some command
  substitutions (and ours even documented this), there appears to be code that
  relies on its security (codesearch.debian.net shows quite a few uses).
  Passing untrusted data to wordexp() still exposes a denial of service
  possibility and a fairly large attack surface.
  
  This is also a MFC of r286830 to reduce conflicts. I changed the code
  somewhat to avoid changes from r286941; in particular, WRDE_BADVAL can still
  only be returned if WRDE_UNDEF was passed.
  
  Relnotes: yes
  Security: fixes command execution with wordexp(untrusted, WRDE_NOCMD)

Modified:
  stable/10/bin/sh/builtins.def
  stable/10/bin/sh/expand.c
  stable/10/bin/sh/parser.c
  stable/10/bin/sh/parser.h
  stable/10/lib/libc/gen/wordexp.3
  stable/10/lib/libc/gen/wordexp.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/bin/sh/builtins.def
==
--- stable/10/bin/sh/builtins.def   Sun Oct 25 16:04:31 2015
(r289937)
+++ stable/10/bin/sh/builtins.def   Sun Oct 25 17:17:50 2015
(r289938)
@@ -65,6 +65,7 @@ exportcmd -s export -s readonly
 #exprcmd   expr
 falsecmd   false
 fgcmd -j   fg
+freebsd_wordexpcmd freebsd_wordexp
 getoptscmd getopts
 hashcmdhash
 histcmd -h fc

Modified: stable/10/bin/sh/expand.c
==
--- stable/10/bin/sh/expand.c   Sun Oct 25 16:04:31 2015(r289937)
+++ stable/10/bin/sh/expand.c   Sun Oct 25 17:17:50 2015(r289938)
@@ -1660,3 +1660,57 @@ wordexpcmd(int argc, char **argv)
outbin(argv[i], strlen(argv[i]) + 1, out1);
 return (0);
 }
+
+/*
+ * Do most of the work for wordexp(3), new version.
+ */
+
+int
+freebsd_wordexpcmd(int argc __unused, char **argv __unused)
+{
+   struct arglist arglist;
+   union node *args, *n;
+   struct strlist *sp;
+   size_t count, len;
+   int ch;
+   int protected = 0;
+   int fd = -1;
+
+   while ((ch = nextopt("f:p")) != '\0') {
+   switch (ch) {
+   case 'f':
+   fd = number(shoptarg);
+   break;
+   case 'p':
+   protected = 1;
+   break;
+   }
+   }
+   if (*argptr != NULL)
+   error("wrong number of arguments");
+   if (fd < 0)
+   error("missing fd");
+   INTOFF;
+   setinputfd(fd, 1);
+   INTON;
+   args = parsewordexp();
+   popfile(); /* will also close fd */
+   if (protected)
+   for (n = args; n != NULL; n = n->narg.next) {
+   if (n->narg.backquote != NULL) {
+   outcslow('C', out1);
+   error("command substitution disabled");
+   }
+   }
+   outcslow(' ', out1);
+   arglist.lastp = 
+   for (n = args; n != NULL; n = n->narg.next)
+   expandarg(n, , EXP_FULL | EXP_TILDE);
+   *arglist.lastp = NULL;
+   for (sp = arglist.list, count = len = 0; sp; sp = sp->next)
+   count++, len += strlen(sp->text);
+   out1fmt("%016zx %016zx", count, len);
+   for (sp = arglist.list; sp; sp = sp->next)
+   outbin(sp->text, strlen(sp->text) + 1, out1);
+   return (0);
+}

Modified: stable/10/bin/sh/parser.c

svn commit: r287751 - stable/10/bin/sh

2015-09-13 Thread Jilles Tjoelker
Author: jilles
Date: Sun Sep 13 13:52:54 2015
New Revision: 287751
URL: https://svnweb.freebsd.org/changeset/base/287751

Log:
  MFC r278826,279330: sh: Various cleanups to expand.c:
  
  * Remove some gotos.
  * Remove unused parameter.
  * Remove duplicate code.
  
  This MFC is to avoid conflicts in the MFC of r287148.

Modified:
  stable/10/bin/sh/expand.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/bin/sh/expand.c
==
--- stable/10/bin/sh/expand.c   Sun Sep 13 13:43:08 2015(r287750)
+++ stable/10/bin/sh/expand.c   Sun Sep 13 13:52:54 2015(r287751)
@@ -105,11 +105,12 @@ static void expbackq(union node *, int, 
 static int subevalvar(char *, char *, int, int, int, int, int);
 static char *evalvar(char *, int);
 static int varisset(const char *, int);
+static void strtodest(const char *, int, int, int);
 static void varvalue(const char *, int, int, int);
 static void recordregion(int, int, int);
 static void removerecordregions(int);
 static void ifsbreakup(char *, struct arglist *);
-static void expandmeta(struct strlist *, int);
+static void expandmeta(struct strlist *);
 static void expmeta(char *, char *);
 static void addfname(char *);
 static struct strlist *expsort(struct strlist *);
@@ -175,7 +176,7 @@ expandarg(union node *arg, struct arglis
ifsbreakup(p, );
*exparg.lastp = NULL;
exparg.lastp = 
-   expandmeta(exparg.list, flag);
+   expandmeta(exparg.list);
} else {
sp = (struct strlist *)stalloc(sizeof (struct strlist));
sp->text = p;
@@ -298,9 +299,9 @@ exptilde(char *p, int flag)
char c, *startp = p;
struct passwd *pw;
char *home;
-   int quotes = flag & (EXP_FULL | EXP_CASE);
 
-   while ((c = *p) != '\0') {
+   for (;;) {
+   c = *p;
switch(c) {
case CTLESC: /* This means CTL* are always considered quoted. */
case CTLVAR:
@@ -311,31 +312,27 @@ exptilde(char *p, int flag)
case CTLQUOTEMARK:
return (startp);
case ':':
-   if (flag & EXP_VARTILDE)
-   goto done;
-   break;
+   if ((flag & EXP_VARTILDE) == 0)
+   break;
+   /* FALLTHROUGH */
+   case '\0':
case '/':
case CTLENDVAR:
-   goto done;
+   *p = '\0';
+   if (*(startp+1) == '\0') {
+   home = lookupvar("HOME");
+   } else {
+   pw = getpwnam(startp+1);
+   home = pw != NULL ? pw->pw_dir : NULL;
+   }
+   *p = c;
+   if (home == NULL || *home == '\0')
+   return (startp);
+   strtodest(home, flag, VSNORMAL, 1);
+   return (p);
}
p++;
}
-done:
-   *p = '\0';
-   if (*(startp+1) == '\0') {
-   home = lookupvar("HOME");
-   } else {
-   pw = getpwnam(startp+1);
-   home = pw != NULL ? pw->pw_dir : NULL;
-   }
-   *p = c;
-   if (home == NULL || *home == '\0')
-   return (startp);
-   if (quotes)
-   STPUTS_QUOTES(home, DQSYNTAX, expdest);
-   else
-   STPUTS(home, expdest);
-   return (p);
 }
 
 
@@ -496,6 +493,17 @@ expbackq(union node *cmd, int quoted, in
 
 
 
+static void
+recordleft(const char *str, const char *loc, char *startp)
+{
+   int amount;
+
+   amount = ((str - 1) - (loc - startp)) - expdest;
+   STADJUST(amount, expdest);
+   while (loc != str - 1)
+   *startp++ = *loc++;
+}
+
 static int
 subevalvar(char *p, char *str, int strloc, int subtype, int startloc,
   int varflags, int quotes)
@@ -540,7 +548,8 @@ subevalvar(char *p, char *str, int strlo
*loc = '\0';
if (patmatch(str, startp, quotes)) {
*loc = c;
-   goto recordleft;
+   recordleft(str, loc, startp);
+   return 1;
}
*loc = c;
if (quotes && *loc == CTLESC)
@@ -554,7 +563,8 @@ subevalvar(char *p, char *str, int strlo
*loc = '\0';
if (patmatch(str, startp, quotes)) {
*loc = c;
-   goto recordleft;
+   recordleft(str, loc, startp);
+   return 1;

svn commit: r287752 - in stable/10/bin/sh: . tests/builtins

2015-09-13 Thread Jilles Tjoelker
Author: jilles
Date: Sun Sep 13 13:58:46 2015
New Revision: 287752
URL: https://svnweb.freebsd.org/changeset/base/287752

Log:
  MFC r287148: sh: Fix out of bounds read when there is no ] after a [:class:].
  
  The initial check for a matching ] was incorrect if a ] may be consumed by a
  [:class:]. The subsequent loop assumed that there must be a ].
  
  Remove the initial check and make the loop cope with a missing ].
  
  Found with afl-fuzz.

Added:
  stable/10/bin/sh/tests/builtins/case20.0
 - copied unchanged from r287148, head/bin/sh/tests/builtins/case20.0
Modified:
  stable/10/bin/sh/expand.c
  stable/10/bin/sh/tests/builtins/Makefile
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/bin/sh/expand.c
==
--- stable/10/bin/sh/expand.c   Sun Sep 13 13:52:54 2015(r287751)
+++ stable/10/bin/sh/expand.c   Sun Sep 13 13:58:46 2015(r287752)
@@ -1468,21 +1468,11 @@ patmatch(const char *pattern, const char
bt_q = q;
break;
case '[': {
-   const char *endp;
+   const char *savep, *saveq;
int invert, found;
wchar_t chr;
 
-   endp = p;
-   if (*endp == '!' || *endp == '^')
-   endp++;
-   do {
-   while (*endp == CTLQUOTEMARK)
-   endp++;
-   if (*endp == 0)
-   goto dft;   /* no matching 
] */
-   if (*endp == CTLESC)
-   endp++;
-   } while (*++endp != ']');
+   savep = p, saveq = q;
invert = 0;
if (*p == '!' || *p == '^') {
invert++;
@@ -1501,6 +1491,11 @@ patmatch(const char *pattern, const char
chr = (unsigned char)*q++;
c = *p++;
do {
+   if (c == '\0') {
+   p = savep, q = saveq;
+   c = '[';
+   goto dft;
+   }
if (c == CTLQUOTEMARK)
continue;
if (c == '[' && *p == ':') {

Modified: stable/10/bin/sh/tests/builtins/Makefile
==
--- stable/10/bin/sh/tests/builtins/MakefileSun Sep 13 13:52:54 2015
(r287751)
+++ stable/10/bin/sh/tests/builtins/MakefileSun Sep 13 13:58:46 2015
(r287752)
@@ -34,6 +34,7 @@ FILES+=   case16.0
 FILES+=case17.0
 FILES+=case18.0
 FILES+=case19.0
+FILES+=case20.0
 FILES+=cd1.0
 FILES+=cd2.0
 FILES+=cd3.0

Copied: stable/10/bin/sh/tests/builtins/case20.0 (from r287148, 
head/bin/sh/tests/builtins/case20.0)
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/10/bin/sh/tests/builtins/case20.0Sun Sep 13 13:58:46 2015
(r287752, copy of r287148, head/bin/sh/tests/builtins/case20.0)
@@ -0,0 +1,9 @@
+# $FreeBSD$
+
+# Shells do not agree about what this pattern should match, but it is
+# certain that it must not crash and the missing close bracket must not
+# be simply ignored.
+
+case B in
+[[:alpha:]) echo bad ;;
+esac
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r287750 - stable/10/bin/sh

2015-09-13 Thread Jilles Tjoelker
Author: jilles
Date: Sun Sep 13 13:43:08 2015
New Revision: 287750
URL: https://svnweb.freebsd.org/changeset/base/287750

Log:
  MFC r272575: sh: Eliminate some gotos.
  
  This MFC is to avoid conflicts in the MFC of r287148.

Modified:
  stable/10/bin/sh/eval.c
  stable/10/bin/sh/expand.c
  stable/10/bin/sh/jobs.c
  stable/10/bin/sh/redir.c
  stable/10/bin/sh/trap.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/bin/sh/eval.c
==
--- stable/10/bin/sh/eval.c Sun Sep 13 13:31:51 2015(r287749)
+++ stable/10/bin/sh/eval.c Sun Sep 13 13:43:08 2015(r287750)
@@ -316,9 +316,10 @@ evalloop(union node *n, int flags)
loopnest++;
status = 0;
for (;;) {
-   evaltree(n->nbinary.ch1, EV_TESTED);
+   if (!evalskip)
+   evaltree(n->nbinary.ch1, EV_TESTED);
if (evalskip) {
-skipping:if (evalskip == SKIPCONT && --skipcount <= 0) {
+   if (evalskip == SKIPCONT && --skipcount <= 0) {
evalskip = 0;
continue;
}
@@ -337,8 +338,6 @@ skipping: if (evalskip == SKIPCONT && 
}
evaltree(n->nbinary.ch2, flags);
status = exitstatus;
-   if (evalskip)
-   goto skipping;
}
loopnest--;
exitstatus = status;
@@ -648,15 +647,15 @@ evalbackcmd(union node *n, struct backcm
struct jmploc *savehandler;
struct localvar *savelocalvars;
 
-   setstackmark();
result->fd = -1;
result->buf = NULL;
result->nleft = 0;
result->jp = NULL;
if (n == NULL) {
exitstatus = 0;
-   goto out;
+   return;
}
+   setstackmark();
exitstatus = oexitstatus;
if (is_valid_fast_cmdsubst(n)) {
savelocalvars = localvars;
@@ -698,7 +697,6 @@ evalbackcmd(union node *n, struct backcm
result->fd = pip[0];
result->jp = jp;
}
-out:
popstackmark();
TRACE(("evalbackcmd done: fd=%d buf=%p nleft=%d jp=%p\n",
result->fd, result->buf, result->nleft, result->jp));

Modified: stable/10/bin/sh/expand.c
==
--- stable/10/bin/sh/expand.c   Sun Sep 13 13:31:51 2015(r287749)
+++ stable/10/bin/sh/expand.c   Sun Sep 13 13:43:08 2015(r287750)
@@ -323,24 +323,19 @@ exptilde(char *p, int flag)
 done:
*p = '\0';
if (*(startp+1) == '\0') {
-   if ((home = lookupvar("HOME")) == NULL)
-   goto lose;
+   home = lookupvar("HOME");
} else {
-   if ((pw = getpwnam(startp+1)) == NULL)
-   goto lose;
-   home = pw->pw_dir;
+   pw = getpwnam(startp+1);
+   home = pw != NULL ? pw->pw_dir : NULL;
}
-   if (*home == '\0')
-   goto lose;
*p = c;
+   if (home == NULL || *home == '\0')
+   return (startp);
if (quotes)
STPUTS_QUOTES(home, DQSYNTAX, expdest);
else
STPUTS(home, expdest);
return (p);
-lose:
-   *p = c;
-   return (startp);
 }
 
 

Modified: stable/10/bin/sh/jobs.c
==
--- stable/10/bin/sh/jobs.c Sun Sep 13 13:31:51 2015(r287749)
+++ stable/10/bin/sh/jobs.c Sun Sep 13 13:43:08 2015(r287750)
@@ -347,13 +347,13 @@ showjob(struct job *jp, int mode)
strcat(statestr, " (core dumped)");
}
 
-   for (ps = jp->ps ; ; ps++) {/* for each process */
+   for (ps = jp->ps ; procno > 0 ; ps++, procno--) { /* for each process */
if (mode == SHOWJOBS_PIDS || mode == SHOWJOBS_PGIDS) {
out1fmt("%d\n", (int)ps->pid);
-   goto skip;
+   continue;
}
if (mode != SHOWJOBS_VERBOSE && ps != jp->ps)
-   goto skip;
+   continue;
if (jobno == curr && ps == jp->ps)
c = '+';
else if (jobno == prev && ps == jp->ps)
@@ -384,8 +384,6 @@ showjob(struct job *jp, int mode)
out1c('\n');
} else
printjobcmd(jp);
-skip:  if (--procno <= 0)
-   break;
}
 }
 

Modified: stable/10/bin/sh/redir.c
==
--- stable/10/bin/sh/redir.cSun Sep 13 13:31:51 2015(r287749)
+++ stable/10/bin/sh/redir.cSun Sep 13 13:43:08 2015(r287750)
@@ -173,21 

svn commit: r287755 - in stable/10/bin/sh/tests: expansion parameters parser

2015-09-13 Thread Jilles Tjoelker
Author: jilles
Date: Sun Sep 13 14:24:12 2015
New Revision: 287755
URL: https://svnweb.freebsd.org/changeset/base/287755

Log:
  MFC r268436,273243,278806,280920,286971: sh: Add various tests.
  
  These new tests from head pass with unmodified stable/10 sh.

Added:
  stable/10/bin/sh/tests/expansion/ifs5.0
 - copied unchanged from r278806, head/bin/sh/tests/expansion/ifs5.0
  stable/10/bin/sh/tests/expansion/ifs6.0
 - copied unchanged from r280920, head/bin/sh/tests/expansion/ifs6.0
  stable/10/bin/sh/tests/expansion/ifs7.0
 - copied unchanged from r280920, head/bin/sh/tests/expansion/ifs7.0
  stable/10/bin/sh/tests/expansion/pathname5.0
 - copied unchanged from r278806, head/bin/sh/tests/expansion/pathname5.0
  stable/10/bin/sh/tests/parameters/positional3.0
 - copied unchanged from r268436, head/bin/sh/tests/parameters/positional3.0
  stable/10/bin/sh/tests/parser/dollar-quote12.0
 - copied unchanged from r286971, head/bin/sh/tests/parser/dollar-quote12.0
  stable/10/bin/sh/tests/parser/line-cont1.0
 - copied unchanged from r273243, head/bin/sh/tests/parser/line-cont1.0
  stable/10/bin/sh/tests/parser/line-cont2.0
 - copied unchanged from r273243, head/bin/sh/tests/parser/line-cont2.0
  stable/10/bin/sh/tests/parser/line-cont3.0
 - copied unchanged from r273243, head/bin/sh/tests/parser/line-cont3.0
Modified:
  stable/10/bin/sh/tests/expansion/Makefile
  stable/10/bin/sh/tests/parameters/Makefile
  stable/10/bin/sh/tests/parser/Makefile
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/bin/sh/tests/expansion/Makefile
==
--- stable/10/bin/sh/tests/expansion/Makefile   Sun Sep 13 14:04:42 2015
(r287754)
+++ stable/10/bin/sh/tests/expansion/Makefile   Sun Sep 13 14:24:12 2015
(r287755)
@@ -45,6 +45,9 @@ FILES+=   ifs1.0
 FILES+=ifs2.0
 FILES+=ifs3.0
 FILES+=ifs4.0
+FILES+=ifs5.0
+FILES+=ifs6.0
+FILES+=ifs7.0
 FILES+=length1.0
 FILES+=length2.0
 FILES+=length3.0
@@ -59,6 +62,7 @@ FILES+=   pathname1.0
 FILES+=pathname2.0
 FILES+=pathname3.0
 FILES+=pathname4.0
+FILES+=pathname5.0
 FILES+=plus-minus1.0
 FILES+=plus-minus2.0
 FILES+=plus-minus3.0

Copied: stable/10/bin/sh/tests/expansion/ifs5.0 (from r278806, 
head/bin/sh/tests/expansion/ifs5.0)
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/10/bin/sh/tests/expansion/ifs5.0 Sun Sep 13 14:24:12 2015
(r287755, copy of r278806, head/bin/sh/tests/expansion/ifs5.0)
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+set -- $(echo a b c d)
+[ "$#" = 4 ]

Copied: stable/10/bin/sh/tests/expansion/ifs6.0 (from r280920, 
head/bin/sh/tests/expansion/ifs6.0)
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/10/bin/sh/tests/expansion/ifs6.0 Sun Sep 13 14:24:12 2015
(r287755, copy of r280920, head/bin/sh/tests/expansion/ifs6.0)
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+IFS=': '
+x=': :'
+set -- $x
+[ "$#|$1|$2|$3" = "2|||" ]

Copied: stable/10/bin/sh/tests/expansion/ifs7.0 (from r280920, 
head/bin/sh/tests/expansion/ifs7.0)
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/10/bin/sh/tests/expansion/ifs7.0 Sun Sep 13 14:24:12 2015
(r287755, copy of r280920, head/bin/sh/tests/expansion/ifs7.0)
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+IFS=2
+set -- $((123))
+[ "$#|$1|$2|$3" = "2|1|3|" ]

Copied: stable/10/bin/sh/tests/expansion/pathname5.0 (from r278806, 
head/bin/sh/tests/expansion/pathname5.0)
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/10/bin/sh/tests/expansion/pathname5.0Sun Sep 13 14:24:12 
2015(r287755, copy of r278806, head/bin/sh/tests/expansion/pathname5.0)
@@ -0,0 +1,3 @@
+# $FreeBSD$
+
+[ `echo '/[e]tc'` = /etc ]

Modified: stable/10/bin/sh/tests/parameters/Makefile
==
--- stable/10/bin/sh/tests/parameters/Makefile  Sun Sep 13 14:04:42 2015
(r287754)
+++ stable/10/bin/sh/tests/parameters/Makefile  Sun Sep 13 14:24:12 2015
(r287755)
@@ -13,6 +13,7 @@ FILES+=   optind1.0
 FILES+=optind2.0
 FILES+=positional1.0
 FILES+=positional2.0
+FILES+=positional3.0
 FILES+=positional5.0
 FILES+=pwd1.0
 

svn commit: r287749 - in stable/10/bin/sh: . tests/errors

2015-09-13 Thread Jilles Tjoelker
Author: jilles
Date: Sun Sep 13 13:31:51 2015
New Revision: 287749
URL: https://svnweb.freebsd.org/changeset/base/287749

Log:
  MFC r287081: sh: Don't create bad parse result when postponing a bad
  substitution error.
  
  An invalid substitution like ${var@} does not cause a parse error but is
  stored in the intermediate representation, to be written as part of the
  error message. If there is a CTL* byte in the stored part, this confuses
  some code such as the code to skip an unused alternative such as in
  ${var-alternative}.
  
  To keep things simple, do not store CTL* bytes.
  
  Found with afl-fuzz.

Added:
  stable/10/bin/sh/tests/errors/bad-parm-exp7.0
 - copied unchanged from r287081, head/bin/sh/tests/errors/bad-parm-exp7.0
  stable/10/bin/sh/tests/errors/bad-parm-exp8.0
 - copied unchanged from r287081, head/bin/sh/tests/errors/bad-parm-exp8.0
Modified:
  stable/10/bin/sh/parser.c
  stable/10/bin/sh/tests/errors/Makefile
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/bin/sh/parser.c
==
--- stable/10/bin/sh/parser.c   Sun Sep 13 13:00:20 2015(r287748)
+++ stable/10/bin/sh/parser.c   Sun Sep 13 13:31:51 2015(r287749)
@@ -1671,7 +1671,7 @@ varname:
pungetc();
else if (c == '\n' || c == PEOF)
synerror("Unexpected end of line in 
substitution");
-   else
+   else if (BASESYNTAX[c] != CCTL)
USTPUTC(c, out);
}
if (subtype == 0) {
@@ -1687,7 +1687,8 @@ varname:
synerror("Unexpected end of 
line in substitution");
if (flags == VSNUL)
STPUTC(':', out);
-   STPUTC(c, out);
+   if (BASESYNTAX[c] != CCTL)
+   STPUTC(c, out);
subtype = VSERROR;
} else
subtype = p - types + VSNORMAL;

Modified: stable/10/bin/sh/tests/errors/Makefile
==
--- stable/10/bin/sh/tests/errors/Makefile  Sun Sep 13 13:00:20 2015
(r287748)
+++ stable/10/bin/sh/tests/errors/Makefile  Sun Sep 13 13:31:51 2015
(r287749)
@@ -17,6 +17,8 @@ FILES+=   bad-parm-exp3.2 bad-parm-exp3.2
 FILES+=bad-parm-exp4.2 bad-parm-exp4.2.stderr
 FILES+=bad-parm-exp5.2 bad-parm-exp5.2.stderr
 FILES+=bad-parm-exp6.2 bad-parm-exp6.2.stderr
+FILES+=bad-parm-exp7.0
+FILES+=bad-parm-exp8.0
 FILES+=option-error.0
 FILES+=redirection-error.0
 FILES+=redirection-error2.2

Copied: stable/10/bin/sh/tests/errors/bad-parm-exp7.0 (from r287081, 
head/bin/sh/tests/errors/bad-parm-exp7.0)
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/10/bin/sh/tests/errors/bad-parm-exp7.0   Sun Sep 13 13:31:51 
2015(r287749, copy of r287081, head/bin/sh/tests/errors/bad-parm-exp7.0)
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+v=1
+eval ": $(printf '${v-${\372}}')"

Copied: stable/10/bin/sh/tests/errors/bad-parm-exp8.0 (from r287081, 
head/bin/sh/tests/errors/bad-parm-exp8.0)
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/10/bin/sh/tests/errors/bad-parm-exp8.0   Sun Sep 13 13:31:51 
2015(r287749, copy of r287081, head/bin/sh/tests/errors/bad-parm-exp8.0)
@@ -0,0 +1,4 @@
+# $FreeBSD$
+
+v=1
+eval ": $(printf '${v-${w\372}}')"
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"


svn commit: r287298 - stable/10/lib/libc/gen

2015-08-29 Thread Jilles Tjoelker
Author: jilles
Date: Sat Aug 29 20:41:09 2015
New Revision: 287298
URL: https://svnweb.freebsd.org/changeset/base/287298

Log:
  MFC r279084,280713: setmode(): Use sysctl kern.proc.umask instead of umask()
  if possible.
  
  The kern.proc.umask.pid sysctl allows querying the umask without
  temporarily modifying it.
  
  r280713 is the actual change, while r279084 is a whitespace change.

Modified:
  stable/10/lib/libc/gen/setmode.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/gen/setmode.c
==
--- stable/10/lib/libc/gen/setmode.cSat Aug 29 19:47:20 2015
(r287297)
+++ stable/10/lib/libc/gen/setmode.cSat Aug 29 20:41:09 2015
(r287298)
@@ -39,6 +39,7 @@ __FBSDID($FreeBSD$);
 #include namespace.h
 #include sys/types.h
 #include sys/stat.h
+#include sys/sysctl.h
 
 #include ctype.h
 #include errno.h
@@ -68,6 +69,7 @@ typedef struct bitcmd {
 #defineCMD2_OBITS  0x08
 #defineCMD2_UBITS  0x10
 
+static mode_t   getumask(void);
 static BITCMD  *addcmd(BITCMD *, mode_t, mode_t, mode_t, mode_t);
 static void compress_mode(BITCMD *);
 #ifdef SETMODE_DEBUG
@@ -169,7 +171,6 @@ setmode(const char *p)
int serrno;
char op, *ep;
BITCMD *set, *saveset, *endset;
-   sigset_t sigset, sigoset;
mode_t mask, perm, permXbits, who;
long perml;
int equalopdone;
@@ -182,15 +183,9 @@ setmode(const char *p)
 
/*
 * Get a copy of the mask for the permissions that are mask relative.
-* Flip the bits, we want what's not set.  Since it's possible that
-* the caller is opening files inside a signal handler, protect them
-* as best we can.
+* Flip the bits, we want what's not set.
 */
-   sigfillset(sigset);
-(void)_sigprocmask(SIG_BLOCK, sigset, sigoset);
-   (void)umask(mask = umask(0));
-   mask = ~mask;
-(void)_sigprocmask(SIG_SETMASK, sigoset, NULL);
+   mask = ~getumask();
 
setlen = SET_LEN + 2;
 
@@ -346,6 +341,35 @@ out:
return NULL;
 }
 
+static mode_t
+getumask(void)
+{
+   sigset_t sigset, sigoset;
+   size_t len;
+   mode_t mask;
+   u_short smask;
+
+   /*
+* First try requesting the umask without temporarily modifying it.
+* Note that this does not work if the sysctl
+* security.bsd.unprivileged_proc_debug is set to 0.
+*/
+   len = sizeof(smask);
+   if (sysctl((int[4]){ CTL_KERN, KERN_PROC, KERN_PROC_UMASK, getpid() },
+   4, smask, len, NULL, 0) == 0)
+   return (smask);
+
+   /*
+* Since it's possible that the caller is opening files inside a signal
+* handler, protect them as best we can.
+*/
+   sigfillset(sigset);
+   (void)_sigprocmask(SIG_BLOCK, sigset, sigoset);
+   (void)umask(mask = umask(0));
+   (void)_sigprocmask(SIG_SETMASK, sigoset, NULL);
+   return (mask);
+}
+
 static BITCMD *
 addcmd(BITCMD *set, mode_t op, mode_t who, mode_t oparg, mode_t mask)
 {
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to svn-src-stable-10-unsubscr...@freebsd.org


svn commit: r287027 - stable/10/bin/mv

2015-08-22 Thread Jilles Tjoelker
Author: jilles
Date: Sat Aug 22 21:35:35 2015
New Revision: 287027
URL: https://svnweb.freebsd.org/changeset/base/287027

Log:
  MFC r284916: mv: Improve message when moving two or more files to
  non-directory.
  
  The message text is from cp, which has had a nicer message for this since
  2007 (PR bin/50656).
  
  As with cp, the exit status changes from 64 to 1.
  
  PR:   201083

Modified:
  stable/10/bin/mv/mv.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/bin/mv/mv.c
==
--- stable/10/bin/mv/mv.c   Sat Aug 22 16:59:27 2015(r287026)
+++ stable/10/bin/mv/mv.c   Sat Aug 22 21:35:35 2015(r287027)
@@ -122,7 +122,7 @@ main(int argc, char *argv[])
 */
if (stat(argv[argc - 1], sb) || !S_ISDIR(sb.st_mode)) {
if (argc  2)
-   usage();
+   errx(1, %s is not a directory, argv[argc - 1]);
exit(do_move(argv[0], argv[1]));
}
 
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to svn-src-stable-10-unsubscr...@freebsd.org


svn commit: r286534 - stable/10/lib/libc/gen

2015-08-09 Thread Jilles Tjoelker
Author: jilles
Date: Sun Aug  9 15:53:02 2015
New Revision: 286534
URL: https://svnweb.freebsd.org/changeset/base/286534

Log:
  MFC r284649: fts_children: preserve errno after running close/fchdir
  
  PR:   200942
  Submitted by: Conrad Meyer

Modified:
  stable/10/lib/libc/gen/fts.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/gen/fts.c
==
--- stable/10/lib/libc/gen/fts.cSun Aug  9 15:51:56 2015
(r286533)
+++ stable/10/lib/libc/gen/fts.cSun Aug  9 15:53:02 2015
(r286534)
@@ -515,7 +515,7 @@ FTSENT *
 fts_children(FTS *sp, int instr)
 {
FTSENT *p;
-   int fd;
+   int fd, rc, serrno;
 
if (instr != 0  instr != FTS_NAMEONLY) {
errno = EINVAL;
@@ -571,11 +571,14 @@ fts_children(FTS *sp, int instr)
if ((fd = _open(., O_RDONLY | O_CLOEXEC, 0))  0)
return (NULL);
sp-fts_child = fts_build(sp, instr);
-   if (fchdir(fd)) {
-   (void)_close(fd);
-   return (NULL);
-   }
+   serrno = (sp-fts_child == NULL) ? errno : 0;
+   rc = fchdir(fd);
+   if (rc  0  serrno == 0)
+   serrno = errno;
(void)_close(fd);
+   errno = serrno;
+   if (rc  0)
+   return (NULL);
return (sp-fts_child);
 }
 
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to svn-src-stable-10-unsubscr...@freebsd.org


svn commit: r281743 - stable/10/lib/libc/gen

2015-04-19 Thread Jilles Tjoelker
Author: jilles
Date: Sun Apr 19 13:51:25 2015
New Revision: 281743
URL: https://svnweb.freebsd.org/changeset/base/281743

Log:
  MFC r280919: wordexp: Explicitly pass along IFS.
  
  Per Austin group issue #884, sh should not import IFS from the environment
  but always set it to $' \t\n'. For wordexp(), however, it is documented and
  useful for it to use IFS from the environment.
  
  Since sh currently imports IFS from the environment, this change has no
  functional effect.

Modified:
  stable/10/lib/libc/gen/wordexp.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/gen/wordexp.c
==
--- stable/10/lib/libc/gen/wordexp.cSun Apr 19 13:46:13 2015
(r281742)
+++ stable/10/lib/libc/gen/wordexp.cSun Apr 19 13:51:25 2015
(r281743)
@@ -118,8 +118,10 @@ we_askshell(const char *words, wordexp_t
char *nstrings; /* Temporary for realloc() */
char **nwv; /* Temporary for realloc() */
sigset_t newsigblock, oldsigblock;
+   const char *ifs;
 
serrno = errno;
+   ifs = getenv(IFS);
 
if (pipe2(pdes, O_CLOEXEC)  0)
return (WRDE_NOSPACE);  /* XXX */
@@ -145,7 +147,8 @@ we_askshell(const char *words, wordexp_t
_fcntl(pdes[1], F_SETFD, 0))  0)
_exit(1);
execl(_PATH_BSHELL, sh, flags  WRDE_UNDEF ? -u : +u,
-   -c, eval \$1\;eval \wordexp $2\, ,
+   -c, IFS=$1;eval \$2\;eval \wordexp $3\, ,
+   ifs != NULL ? ifs :  \t\n,
flags  WRDE_SHOWERR ?  : exec 2/dev/null, words,
(char *)NULL);
_exit(1);
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to svn-src-stable-10-unsubscr...@freebsd.org


svn commit: r281742 - stable/10/tools/regression/lib/libc/gen

2015-04-19 Thread Jilles Tjoelker
Author: jilles
Date: Sun Apr 19 13:46:13 2015
New Revision: 281742
URL: https://svnweb.freebsd.org/changeset/base/281742

Log:
  MFC r280830: wordexp(): Add testcase for non-default IFS in environment.
  
  The non-default IFS is expected to be used.

Modified:
  stable/10/tools/regression/lib/libc/gen/test-wordexp.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/tools/regression/lib/libc/gen/test-wordexp.c
==
--- stable/10/tools/regression/lib/libc/gen/test-wordexp.c  Sun Apr 19 
13:28:32 2015(r281741)
+++ stable/10/tools/regression/lib/libc/gen/test-wordexp.c  Sun Apr 19 
13:46:13 2015(r281742)
@@ -240,6 +240,21 @@ main(int argc, char *argv[])
r = unsetenv(IFS);
assert(r == 0);
 
+   /*
+* With IFS set to a non-default value, and using it.
+*/
+   r = setenv(IFS, :, 1);
+   assert(r == 0);
+   r = wordexp(${IFS+hello:world}, we, 0);
+   assert(r == 0);
+   assert(we.we_wordc == 2);
+   assert(strcmp(we.we_wordv[0], hello) == 0);
+   assert(strcmp(we.we_wordv[1], world) == 0);
+   assert(we.we_wordv[2] == NULL);
+   wordfree(we);
+   r = unsetenv(IFS);
+   assert(r == 0);
+
printf(PASS wordexp()\n);
printf(PASS wordfree()\n);
 
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to svn-src-stable-10-unsubscr...@freebsd.org


svn commit: r280002 - stable/10/tools/regression/usr.bin/env

2015-03-14 Thread Jilles Tjoelker
Author: jilles
Date: Sat Mar 14 20:40:04 2015
New Revision: 280002
URL: https://svnweb.freebsd.org/changeset/base/280002

Log:
  MFC r279722: env: Fix testsuite for additional variables set by sh.

Modified:
  stable/10/tools/regression/usr.bin/env/regress-env.rgdata
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/tools/regression/usr.bin/env/regress-env.rgdata
==
--- stable/10/tools/regression/usr.bin/env/regress-env.rgdata   Sat Mar 14 
19:22:15 2015(r280001)
+++ stable/10/tools/regression/usr.bin/env/regress-env.rgdata   Sat Mar 14 
20:40:04 2015(r280002)
@@ -235,9 +235,9 @@ gblenv=OUTSIDEVAR=OutsideValue
script:/bin/echo === set ===
script:# drop some environment variables that 'sh' itself sets, and
script:# then have 'set' print out all remaining environment variables.
-   script:# (can't unset OPTIND, so we use grep to get rid of that)
-   script:unset -v IFS PS1 PS2 PPID
-   script:set | grep -v '^OPTIND=' | sort
+   script:# (can't unset OPTIND/PWD, so we use grep to get rid of those)
+   script:unset -v IFS PS1 PS2 PS4 PPID
+   script:set | grep -Ev '^(OPTIND|PWD)=' | sort
stdout:=== set ===
stdout:PATH=/bin:/usr/bin:/Not
stdout:TESTVAR=SbValue
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to svn-src-stable-10-unsubscr...@freebsd.org


svn commit: r279866 - stable/10/bin/ln

2015-03-10 Thread Jilles Tjoelker
Author: jilles
Date: Tue Mar 10 22:23:56 2015
New Revision: 279866
URL: https://svnweb.freebsd.org/changeset/base/279866

Log:
  MFC r278848: symlink(7): Mention chflagsat() (can take AT_SYMLINK_NOFOLLOW).

Modified:
  stable/10/bin/ln/symlink.7
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/bin/ln/symlink.7
==
--- stable/10/bin/ln/symlink.7  Tue Mar 10 21:17:10 2015(r279865)
+++ stable/10/bin/ln/symlink.7  Tue Mar 10 22:23:56 2015(r279866)
@@ -29,7 +29,7 @@
 .\@(#)symlink.7   8.3 (Berkeley) 3/31/94
 .\ $FreeBSD$
 .\
-.Dd December 29, 2014
+.Dd February 16, 2015
 .Dt SYMLINK 7
 .Os
 .Sh NAME
@@ -146,6 +146,7 @@ The following system calls follow symbol
 unless given the
 .Dv AT_SYMLINK_NOFOLLOW
 flag:
+.Xr chflagsat 2 ,
 .Xr fchmodat 2 ,
 .Xr fchownat 2
 and
___
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to svn-src-stable-10-unsubscr...@freebsd.org