svn commit: r365037 - in head/bin/sh: . tests/builtins

2020-09-01 Thread Jilles Tjoelker
Author: jilles
Date: Tue Sep  1 13:19:15 2020
New Revision: 365037
URL: https://svnweb.freebsd.org/changeset/base/365037

Log:
  sh: Write absolute path in command -vV and type
  
  POSIX is pretty clear that command -v, command -V and type shall write
  absolute pathnames. Therefore, we need to prepend the current directory's
  name to relative pathnames.
  
  This can happen either when PATH contains a relative pathname or when the
  operand contains a slash but is not an absolute pathname.

Added:
  head/bin/sh/tests/builtins/command13.0   (contents, props changed)
  head/bin/sh/tests/builtins/command14.0   (contents, props changed)
  head/bin/sh/tests/builtins/type4.0   (contents, props changed)
Modified:
  head/bin/sh/exec.c
  head/bin/sh/tests/builtins/Makefile

Modified: head/bin/sh/exec.c
==
--- head/bin/sh/exec.c  Tue Sep  1 12:21:17 2020(r365036)
+++ head/bin/sh/exec.c  Tue Sep  1 13:19:15 2020(r365037)
@@ -679,6 +679,21 @@ isfunc(const char *name)
 }
 
 
+static void
+print_absolute_path(const char *name)
+{
+   const char *pwd;
+
+   if (*name != '/' && (pwd = lookupvar("PWD")) != NULL && *pwd != '\0') {
+   out1str(pwd);
+   if (strcmp(pwd, "/") != 0)
+   outcslow('/', out1);
+   }
+   out1str(name);
+   outcslow('\n', out1);
+}
+
+
 /*
  * Shared code for the following builtin commands:
  *type, command -v, command -V
@@ -745,20 +760,16 @@ typecmd_impl(int argc, char **argv, int cmd, const cha
name = padvance(, , argv[i]);
stunalloc(name);
} while (--j >= 0);
-   if (cmd == TYPECMD_SMALLV)
-   out1fmt("%s\n", name);
-   else
-   out1fmt("%s is%s %s\n", argv[i],
+   if (cmd != TYPECMD_SMALLV)
+   out1fmt("%s is%s ", argv[i],
(cmdp && cmd == TYPECMD_TYPE) ?
-   " a tracked alias for" : "",
-   name);
+   " a tracked alias for" : "");
+   print_absolute_path(name);
} else {
if (eaccess(argv[i], X_OK) == 0) {
-   if (cmd == TYPECMD_SMALLV)
-   out1fmt("%s\n", argv[i]);
-   else
-   out1fmt("%s is %s\n", argv[i],
-   argv[i]);
+   if (cmd != TYPECMD_SMALLV)
+   out1fmt("%s is ", argv[i]);
+   print_absolute_path(argv[i]);
} else {
if (cmd != TYPECMD_SMALLV)
outfmt(out2, "%s: %s\n",

Modified: head/bin/sh/tests/builtins/Makefile
==
--- head/bin/sh/tests/builtins/Makefile Tue Sep  1 12:21:17 2020
(r365036)
+++ head/bin/sh/tests/builtins/Makefile Tue Sep  1 13:19:15 2020
(r365037)
@@ -69,6 +69,8 @@ ${PACKAGE}FILES+= command9.0
 ${PACKAGE}FILES+=  command10.0
 ${PACKAGE}FILES+=  command11.0
 ${PACKAGE}FILES+=  command12.0
+${PACKAGE}FILES+=  command13.0
+${PACKAGE}FILES+=  command14.0
 ${PACKAGE}FILES+=  dot1.0
 ${PACKAGE}FILES+=  dot2.0
 ${PACKAGE}FILES+=  dot3.0
@@ -170,6 +172,7 @@ ${PACKAGE}FILES+=   trap9.0
 ${PACKAGE}FILES+=  type1.0 type1.0.stderr
 ${PACKAGE}FILES+=  type2.0
 ${PACKAGE}FILES+=  type3.0
+${PACKAGE}FILES+=  type4.0
 ${PACKAGE}FILES+=  unalias.0
 ${PACKAGE}FILES+=  var-assign.0
 ${PACKAGE}FILES+=  var-assign2.0

Added: head/bin/sh/tests/builtins/command13.0
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/bin/sh/tests/builtins/command13.0  Tue Sep  1 13:19:15 2020
(r365037)
@@ -0,0 +1,21 @@
+# $FreeBSD$
+
+failures=0
+
+check() {
+   if [ "$1" != "$2" ] && { [ "$#" -lt 3 ] || [ "$1" != "$3" ]; } then
+   echo "Mismatch found"
+   echo "Expected: $2"
+   if [ "$#" -ge 3 ]; then
+   echo "Alternative expected: $3"
+   fi
+   echo "Actual: $1"
+

svn commit: r364919 - in head/bin/sh: . tests/execution

2020-08-28 Thread Jilles Tjoelker
Author: jilles
Date: Fri Aug 28 15:35:45 2020
New Revision: 364919
URL: https://svnweb.freebsd.org/changeset/base/364919

Log:
  sh: Keep ignored SIGINT/SIGQUIT after set in a background job
  
  If job control is not enabled, a background job (... &) ignores SIGINT and
  SIGQUIT, but this can be reverted using the trap builtin in the same shell
  environment.
  
  Using the set builtin to change options would also revert SIGINT and SIGQUIT
  to their previous dispositions.
  
  This broke due to r317298. Calling setsignal() reverts the effect of
  ignoresig().
  
  Reported by:  bdrewery
  MFC after:1 week

Added:
  head/bin/sh/tests/execution/bg13.0   (contents, props changed)
Modified:
  head/bin/sh/main.c
  head/bin/sh/tests/execution/Makefile
  head/bin/sh/trap.c
  head/bin/sh/trap.h

Modified: head/bin/sh/main.c
==
--- head/bin/sh/main.c  Fri Aug 28 15:09:43 2020(r364918)
+++ head/bin/sh/main.c  Fri Aug 28 15:35:45 2020(r364919)
@@ -134,6 +134,7 @@ main(int argc, char *argv[])
setstackmark();
setstackmark();
procargs(argc, argv);
+   trap_init();
pwd_init(iflag);
INTON;
if (iflag)

Modified: head/bin/sh/tests/execution/Makefile
==
--- head/bin/sh/tests/execution/MakefileFri Aug 28 15:09:43 2020
(r364918)
+++ head/bin/sh/tests/execution/MakefileFri Aug 28 15:35:45 2020
(r364919)
@@ -19,6 +19,7 @@ ${PACKAGE}FILES+= bg9.0
 ${PACKAGE}FILES+=  bg10.0 bg10.0.stdout
 ${PACKAGE}FILES+=  bg11.0
 ${PACKAGE}FILES+=  bg12.0
+${PACKAGE}FILES+=  bg13.0
 ${PACKAGE}FILES+=  env1.0
 ${PACKAGE}FILES+=  fork1.0
 ${PACKAGE}FILES+=  fork2.0

Added: head/bin/sh/tests/execution/bg13.0
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/bin/sh/tests/execution/bg13.0  Fri Aug 28 15:35:45 2020
(r364919)
@@ -0,0 +1,16 @@
+# $FreeBSD$
+
+T=`mktemp -d ${TMPDIR:-/tmp}/sh-test.`
+trap 'rm -rf $T' 0
+cd $T || exit 3
+mkfifo fifo1
+# Use a trap, not the default action, since the shell may catch SIGINT and
+# therefore its processing may be delayed.
+{ set -C; trap 'exit 5' TERM; read dummy fifo1
+kill -INT "$!"
+kill -TERM "$!"
+exec 3>&-
+wait "$!"
+r=$?
+[ "$r" = 5 ]

Modified: head/bin/sh/trap.c
==
--- head/bin/sh/trap.c  Fri Aug 28 15:09:43 2020(r364918)
+++ head/bin/sh/trap.c  Fri Aug 28 15:35:45 2020(r364919)
@@ -474,14 +474,20 @@ dotrap(void)
 }
 
 
+void
+trap_init(void)
+{
+   setsignal(SIGINT);
+   setsignal(SIGQUIT);
+}
+
+
 /*
  * Controls whether the shell is interactive or not based on iflag.
  */
 void
 setinteractive(void)
 {
-   setsignal(SIGINT);
-   setsignal(SIGQUIT);
setsignal(SIGTERM);
 }
 

Modified: head/bin/sh/trap.h
==
--- head/bin/sh/trap.h  Fri Aug 28 15:09:43 2020(r364918)
+++ head/bin/sh/trap.h  Fri Aug 28 15:35:45 2020(r364919)
@@ -45,6 +45,7 @@ void ignoresig(int);
 int issigchldtrapped(void);
 void onsig(int);
 void dotrap(void);
+void trap_init(void);
 void setinteractive(void);
 void exitshell(int) __dead2;
 void exitshell_savedstatus(void) __dead2;
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r363057 - head/bin/sh

2020-07-09 Thread Jilles Tjoelker
Author: jilles
Date: Thu Jul  9 20:53:56 2020
New Revision: 363057
URL: https://svnweb.freebsd.org/changeset/base/363057

Log:
  sh: Do not ignore INTOFF during a trap
  
  INTOFF postpones SIGINT processing and INTON enables it again. This is
  important so an interactive shell can return to the top level prompt when
  Ctrl+C is pressed.
  
  Given that INTON is automatically done when a builtin completes, the part
  where onsig() ignores suppressint when in_dotrap is true is both unnecessary
  and unsafe. If the trap is for some other signal than SIGINT, arbitrary code
  could have been interrupted.
  
  Historically, INTOFF remained in effect for longer.
  
  Reviewed by:  bdrewery
  MFC after:2 weeks
  Differential Revision:https://reviews.freebsd.org/D25270

Modified:
  head/bin/sh/trap.c

Modified: head/bin/sh/trap.c
==
--- head/bin/sh/trap.c  Thu Jul  9 19:11:57 2020(r363056)
+++ head/bin/sh/trap.c  Thu Jul  9 20:53:56 2020(r363057)
@@ -382,12 +382,7 @@ onsig(int signo)
 {
 
if (signo == SIGINT && trap[SIGINT] == NULL) {
-   /*
-* The !in_dotrap here is safe.  The only way we can arrive
-* here with in_dotrap set is that a trap handler set SIGINT to
-* SIG_DFL and killed itself.
-*/
-   if (suppressint && !in_dotrap)
+   if (suppressint)
SET_PENDING_INT;
else
onint();
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r363054 - stable/12/bin/sh/tests

2020-07-09 Thread Jilles Tjoelker
Author: jilles
Date: Thu Jul  9 17:43:25 2020
New Revision: 363054
URL: https://svnweb.freebsd.org/changeset/base/363054

Log:
  MFC r362738: sh/tests: Re-enable bin.sh.execution.functional_test.bg12.0
  
  PR:   247559

Modified:
  stable/12/bin/sh/tests/functional_test.sh
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/bin/sh/tests/functional_test.sh
==
--- stable/12/bin/sh/tests/functional_test.sh   Thu Jul  9 17:42:31 2020
(r363053)
+++ stable/12/bin/sh/tests/functional_test.sh   Thu Jul  9 17:43:25 2020
(r363054)
@@ -27,7 +27,6 @@
 # $FreeBSD$
 
 SRCDIR=$(atf_get_srcdir)
-CATEGORY=$(basename ${SRCDIR})
 
 check()
 {
@@ -61,20 +60,7 @@ add_testcase()
esac
 
atf_test_case ${tc_escaped}
-
-   if [ "$(atf_config_get ci false)" = "true" ]; then
-   case "${CATEGORY}/${tc}" in
-   execution/bg12.0)
-   eval "${tc_escaped}_body() { atf_skip 
'https://bugs.freebsd.org/247559'; }"
-   ;;
-   *)
-   eval "${tc_escaped}_body() { check ${tc}; }"
-   ;;
-   esac
-   else
-   eval "${tc_escaped}_body() { check ${tc}; }"
-   fi
-
+   eval "${tc_escaped}_body() { check ${tc}; }"
atf_add_test_case ${tc_escaped}
 }
 
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r363053 - stable/12/bin/sh/tests/execution

2020-07-09 Thread Jilles Tjoelker
Author: jilles
Date: Thu Jul  9 17:42:31 2020
New Revision: 363053
URL: https://svnweb.freebsd.org/changeset/base/363053

Log:
  MFC r362737: sh/tests: Fix flaky execution/bg12.0
  
  When job control is not enabled, the shell ignores SIGINT while waiting for
  a foreground process unless that process exits on SIGINT. In this case, the
  foreground process is sleep and it does not exit on SIGINT because the
  signal is only sent to the shell. Depending on order of events, this could
  cause the SIGINT to be unexpectedly ignored.
  
  On lightly loaded bare metal, the chance of this happening tends to be less
  than 0.01% but with higher loads and/or virtualization it becomes more
  likely.
  
  Starting the sleep in background and using the wait builtin ensures SIGINT
  will not be ignored.
  
  PR:   247559
  Reported by:  lwhsu

Modified:
  stable/12/bin/sh/tests/execution/bg12.0
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/bin/sh/tests/execution/bg12.0
==
--- stable/12/bin/sh/tests/execution/bg12.0 Thu Jul  9 17:27:14 2020
(r363052)
+++ stable/12/bin/sh/tests/execution/bg12.0 Thu Jul  9 17:42:31 2020
(r363053)
@@ -4,7 +4,7 @@ T=`mktemp -d ${TMPDIR:-/tmp}/sh-test.`
 trap 'rm -rf $T' 0
 cd $T || exit 3
 mkfifo fifo1
-{ trap - INT; : >fifo1; sleep 5; exit 4; } &
+{ trap - INT; : >fifo1; sleep 5 & wait; exit 4; } &
 : https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r362738 - head/bin/sh/tests

2020-06-28 Thread Jilles Tjoelker
Author: jilles
Date: Sun Jun 28 21:33:08 2020
New Revision: 362738
URL: https://svnweb.freebsd.org/changeset/base/362738

Log:
  sh/tests: Re-enable bin.sh.execution.functional_test.bg12.0
  
  This reverts r362646.
  
  PR:   247559
  MFC after:1 week

Modified:
  head/bin/sh/tests/functional_test.sh

Modified: head/bin/sh/tests/functional_test.sh
==
--- head/bin/sh/tests/functional_test.shSun Jun 28 21:15:29 2020
(r362737)
+++ head/bin/sh/tests/functional_test.shSun Jun 28 21:33:08 2020
(r362738)
@@ -27,7 +27,6 @@
 # $FreeBSD$
 
 SRCDIR=$(atf_get_srcdir)
-CATEGORY=$(basename ${SRCDIR})
 
 check()
 {
@@ -61,20 +60,7 @@ add_testcase()
esac
 
atf_test_case ${tc_escaped}
-
-   if [ "$(atf_config_get ci false)" = "true" ]; then
-   case "${CATEGORY}/${tc}" in
-   execution/bg12.0)
-   eval "${tc_escaped}_body() { atf_skip 
'https://bugs.freebsd.org/247559'; }"
-   ;;
-   *)
-   eval "${tc_escaped}_body() { check ${tc}; }"
-   ;;
-   esac
-   else
-   eval "${tc_escaped}_body() { check ${tc}; }"
-   fi
-
+   eval "${tc_escaped}_body() { check ${tc}; }"
atf_add_test_case ${tc_escaped}
 }
 
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r362737 - head/bin/sh/tests/execution

2020-06-28 Thread Jilles Tjoelker
Author: jilles
Date: Sun Jun 28 21:15:29 2020
New Revision: 362737
URL: https://svnweb.freebsd.org/changeset/base/362737

Log:
  sh/tests: Fix flaky execution/bg12.0
  
  When job control is not enabled, the shell ignores SIGINT while waiting for
  a foreground process unless that process exits on SIGINT. In this case, the
  foreground process is sleep and it does not exit on SIGINT because the
  signal is only sent to the shell. Depending on order of events, this could
  cause the SIGINT to be unexpectedly ignored.
  
  On lightly loaded bare metal, the chance of this happening tends to be less
  than 0.01% but with higher loads and/or virtualization it becomes more
  likely.
  
  Starting the sleep in background and using the wait builtin ensures SIGINT
  will not be ignored.
  
  PR:   247559
  Reported by:  lwhsu
  MFC after:1 week

Modified:
  head/bin/sh/tests/execution/bg12.0

Modified: head/bin/sh/tests/execution/bg12.0
==
--- head/bin/sh/tests/execution/bg12.0  Sun Jun 28 21:11:10 2020
(r362736)
+++ head/bin/sh/tests/execution/bg12.0  Sun Jun 28 21:15:29 2020
(r362737)
@@ -4,7 +4,7 @@ T=`mktemp -d ${TMPDIR:-/tmp}/sh-test.`
 trap 'rm -rf $T' 0
 cd $T || exit 3
 mkfifo fifo1
-{ trap - INT; : >fifo1; sleep 5; exit 4; } &
+{ trap - INT; : >fifo1; sleep 5 & wait; exit 4; } &
 : https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r362467 - stable/12/bin/sh/tests/execution

2020-06-21 Thread Jilles Tjoelker
Author: jilles
Date: Sun Jun 21 16:06:01 2020
New Revision: 362467
URL: https://svnweb.freebsd.org/changeset/base/362467

Log:
  MFC r362182: sh/tests: Add tests for SIGINT in non-jobc background commands
  
  If job control is not enabled, background commands shall ignore SIGINT and
  SIGQUIT, and it shall be possible to override that ignore in the same shell.

Added:
  stable/12/bin/sh/tests/execution/bg11.0
 - copied unchanged from r362182, head/bin/sh/tests/execution/bg11.0
  stable/12/bin/sh/tests/execution/bg12.0
 - copied unchanged from r362182, head/bin/sh/tests/execution/bg12.0
Modified:
  stable/12/bin/sh/tests/execution/Makefile
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/bin/sh/tests/execution/Makefile
==
--- stable/12/bin/sh/tests/execution/Makefile   Sun Jun 21 13:34:08 2020
(r362466)
+++ stable/12/bin/sh/tests/execution/Makefile   Sun Jun 21 16:06:01 2020
(r362467)
@@ -17,6 +17,8 @@ ${PACKAGE}FILES+= bg7.0
 ${PACKAGE}FILES+=  bg8.0
 ${PACKAGE}FILES+=  bg9.0
 ${PACKAGE}FILES+=  bg10.0 bg10.0.stdout
+${PACKAGE}FILES+=  bg11.0
+${PACKAGE}FILES+=  bg12.0
 ${PACKAGE}FILES+=  fork1.0
 ${PACKAGE}FILES+=  fork2.0
 ${PACKAGE}FILES+=  fork3.0

Copied: stable/12/bin/sh/tests/execution/bg11.0 (from r362182, 
head/bin/sh/tests/execution/bg11.0)
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/12/bin/sh/tests/execution/bg11.0 Sun Jun 21 16:06:01 2020
(r362467, copy of r362182, head/bin/sh/tests/execution/bg11.0)
@@ -0,0 +1,16 @@
+# $FreeBSD$
+
+T=`mktemp -d ${TMPDIR:-/tmp}/sh-test.`
+trap 'rm -rf $T' 0
+cd $T || exit 3
+mkfifo fifo1
+# Use a trap, not the default action, since the shell may catch SIGINT and
+# therefore its processing may be delayed.
+{ trap 'exit 5' TERM; read dummy fifo1
+kill -INT "$!"
+kill -TERM "$!"
+exec 3>&-
+wait "$!"
+r=$?
+[ "$r" = 5 ]

Copied: stable/12/bin/sh/tests/execution/bg12.0 (from r362182, 
head/bin/sh/tests/execution/bg12.0)
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/12/bin/sh/tests/execution/bg12.0 Sun Jun 21 16:06:01 2020
(r362467, copy of r362182, head/bin/sh/tests/execution/bg12.0)
@@ -0,0 +1,12 @@
+# $FreeBSD$
+
+T=`mktemp -d ${TMPDIR:-/tmp}/sh-test.`
+trap 'rm -rf $T' 0
+cd $T || exit 3
+mkfifo fifo1
+{ trap - INT; : >fifo1; sleep 5; exit 4; } &
+: https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r362182 - head/bin/sh/tests/execution

2020-06-14 Thread Jilles Tjoelker
Author: jilles
Date: Sun Jun 14 19:41:24 2020
New Revision: 362182
URL: https://svnweb.freebsd.org/changeset/base/362182

Log:
  sh/tests: Add tests for SIGINT in non-jobc background commands
  
  If job control is not enabled, background commands shall ignore SIGINT and
  SIGQUIT, and it shall be possible to override that ignore in the same shell.
  
  MFC after:1 week

Added:
  head/bin/sh/tests/execution/bg11.0   (contents, props changed)
  head/bin/sh/tests/execution/bg12.0   (contents, props changed)
Modified:
  head/bin/sh/tests/execution/Makefile

Modified: head/bin/sh/tests/execution/Makefile
==
--- head/bin/sh/tests/execution/MakefileSun Jun 14 18:49:06 2020
(r362181)
+++ head/bin/sh/tests/execution/MakefileSun Jun 14 19:41:24 2020
(r362182)
@@ -17,6 +17,8 @@ ${PACKAGE}FILES+= bg7.0
 ${PACKAGE}FILES+=  bg8.0
 ${PACKAGE}FILES+=  bg9.0
 ${PACKAGE}FILES+=  bg10.0 bg10.0.stdout
+${PACKAGE}FILES+=  bg11.0
+${PACKAGE}FILES+=  bg12.0
 ${PACKAGE}FILES+=  env1.0
 ${PACKAGE}FILES+=  fork1.0
 ${PACKAGE}FILES+=  fork2.0

Added: head/bin/sh/tests/execution/bg11.0
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/bin/sh/tests/execution/bg11.0  Sun Jun 14 19:41:24 2020
(r362182)
@@ -0,0 +1,16 @@
+# $FreeBSD$
+
+T=`mktemp -d ${TMPDIR:-/tmp}/sh-test.`
+trap 'rm -rf $T' 0
+cd $T || exit 3
+mkfifo fifo1
+# Use a trap, not the default action, since the shell may catch SIGINT and
+# therefore its processing may be delayed.
+{ trap 'exit 5' TERM; read dummy fifo1
+kill -INT "$!"
+kill -TERM "$!"
+exec 3>&-
+wait "$!"
+r=$?
+[ "$r" = 5 ]

Added: head/bin/sh/tests/execution/bg12.0
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/bin/sh/tests/execution/bg12.0  Sun Jun 14 19:41:24 2020
(r362182)
@@ -0,0 +1,12 @@
+# $FreeBSD$
+
+T=`mktemp -d ${TMPDIR:-/tmp}/sh-test.`
+trap 'rm -rf $T' 0
+cd $T || exit 3
+mkfifo fifo1
+{ trap - INT; : >fifo1; sleep 5; exit 4; } &
+: https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r361647 - in head/bin/sh: . tests/execution

2020-05-30 Thread Jilles Tjoelker
Author: jilles
Date: Sat May 30 16:00:49 2020
New Revision: 361647
URL: https://svnweb.freebsd.org/changeset/base/361647

Log:
  sh: Allow more scripts without #!
  
  Austin Group bugs #1226 and #1250 changed the requirements for shell scripts
  without #! (POSIX does not specify #!; this is about the shell execution
  when execve(2) returns an [ENOEXEC] error).
  
  POSIX says we shall allow execution if the initial part intended to be
  parsed by the shell consists of characters and does not contain the NUL
  character.  This allows concatenating a shell script (ending with exec or
  exit) and a binary payload.
  
  In order to reject common binary files such as PNG images, check that there
  is a lowercase letter or expansion before the last newline before the NUL
  character, in addition to the check for the newline character suggested by
  POSIX.

Added:
  head/bin/sh/tests/execution/shellproc6.0   (contents, props changed)
Modified:
  head/bin/sh/exec.c
  head/bin/sh/tests/execution/Makefile

Modified: head/bin/sh/exec.c
==
--- head/bin/sh/exec.c  Sat May 30 13:39:56 2020(r361646)
+++ head/bin/sh/exec.c  Sat May 30 16:00:49 2020(r361647)
@@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 #include 
 
 /*
@@ -140,6 +141,37 @@ shellexec(char **argv, char **envp, const char *path, 
 }
 
 
+static bool
+isbinary(const char *data, size_t len)
+{
+   const char *nul, *p;
+   bool hasletter;
+
+   nul = memchr(data, '\0', len);
+   if (nul == NULL)
+   return false;
+   /*
+* POSIX says we shall allow execution if the initial part intended
+* to be parsed by the shell consists of characters and does not
+* contain the NUL character. This allows concatenating a shell
+* script (ending with exec or exit) and a binary payload.
+*
+* In order to reject common binary files such as PNG images, check
+* that there is a lowercase letter or expansion before the last
+* newline before the NUL character, in addition to the check for
+* the newline character suggested by POSIX.
+*/
+   hasletter = false;
+   for (p = data; *p != '\0'; p++) {
+   if ((*p >= 'a' && *p <= 'z') || *p == '$' || *p == '`')
+   hasletter = true;
+   if (hasletter && *p == '\n')
+   return false;
+   }
+   return true;
+}
+
+
 static void
 tryexec(char *cmd, char **argv, char **envp)
 {
@@ -155,7 +187,7 @@ tryexec(char *cmd, char **argv, char **envp)
if (in != -1) {
n = pread(in, buf, sizeof buf, 0);
close(in);
-   if (n > 0 && memchr(buf, '\0', n) != NULL) {
+   if (n > 0 && isbinary(buf, n)) {
errno = ENOEXEC;
return;
}

Modified: head/bin/sh/tests/execution/Makefile
==
--- head/bin/sh/tests/execution/MakefileSat May 30 13:39:56 2020
(r361646)
+++ head/bin/sh/tests/execution/MakefileSat May 30 16:00:49 2020
(r361647)
@@ -59,6 +59,7 @@ ${PACKAGE}FILES+= shellproc2.0
 ${PACKAGE}FILES+=  shellproc3.0
 ${PACKAGE}FILES+=  shellproc4.0
 ${PACKAGE}FILES+=  shellproc5.0
+${PACKAGE}FILES+=  shellproc6.0
 ${PACKAGE}FILES+=  subshell1.0 subshell1.0.stdout
 ${PACKAGE}FILES+=  subshell2.0
 ${PACKAGE}FILES+=  subshell3.0

Added: head/bin/sh/tests/execution/shellproc6.0
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/bin/sh/tests/execution/shellproc6.0Sat May 30 16:00:49 2020
(r361647)
@@ -0,0 +1,8 @@
+# $FreeBSD$
+
+T=`mktemp -d "${TMPDIR:-/tmp}/sh-test."` || exit
+trap 'rm -rf "${T}"' 0
+printf 'printf "this "\necho is a test\nexit\n\0' >"$T/testshellproc"
+chmod 755 "$T/testshellproc"
+PATH=$T:$PATH
+[ "`testshellproc`" = "this is a test" ]
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r361646 - in stable/12/bin/sh: . tests/execution

2020-05-30 Thread Jilles Tjoelker
Author: jilles
Date: Sat May 30 13:39:56 2020
New Revision: 361646
URL: https://svnweb.freebsd.org/changeset/base/361646

Log:
  MFC r361112,r361117: sh: Fix double INTON with vfork
  
  The shell maintains a count of the number of times SIGINT processing has
  been disabled via INTOFF, so SIGINT processing resumes when all disables
  have enabled again (INTON).
  
  If an error occurs in a vfork() child, the processing of the error enables
  SIGINT processing again, and the INTON in vforkexecshell() causes the count
  to become negative.
  
  As a result, a later INTOFF may not actually disable SIGINT processing. This
  might cause memory corruption if a SIGINT arrives at an inopportune time.
  
  Note that various places such as errors in non-special builtins
  unconditionally reset the count to 0, so the problem might still not always
  be visible.
  
  PR:   246497

Added:
 - copied unchanged from r361112, head/bin/sh/tests/execution/unknown2.0
Directory Properties:
  stable/12/bin/sh/tests/execution/unknown2.0   (props changed)
Modified:
  stable/12/bin/sh/jobs.c
  stable/12/bin/sh/tests/execution/Makefile
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/bin/sh/jobs.c
==
--- stable/12/bin/sh/jobs.c Sat May 30 02:56:13 2020(r361645)
+++ stable/12/bin/sh/jobs.c Sat May 30 13:39:56 2020(r361646)
@@ -1007,9 +1007,11 @@ vforkexecshell(struct job *jp, char **argv, char **env
pid_t pid;
struct jmploc jmploc;
struct jmploc *savehandler;
+   int inton;
 
TRACE(("vforkexecshell(%%%td, %s, %p) called\n", jp - jobtab, argv[0],
(void *)pip));
+   inton = is_int_on();
INTOFF;
flushall();
savehandler = handler;
@@ -1044,7 +1046,7 @@ vforkexecshell(struct job *jp, char **argv, char **env
setcurjob(jp);
 #endif
}
-   INTON;
+   SETINTON(inton);
TRACE(("In parent shell:  child = %d\n", (int)pid));
return pid;
 }

Modified: stable/12/bin/sh/tests/execution/Makefile
==
--- stable/12/bin/sh/tests/execution/Makefile   Sat May 30 02:56:13 2020
(r361645)
+++ stable/12/bin/sh/tests/execution/Makefile   Sat May 30 13:39:56 2020
(r361646)
@@ -59,6 +59,7 @@ ${PACKAGE}FILES+= subshell2.0
 ${PACKAGE}FILES+=  subshell3.0
 ${PACKAGE}FILES+=  subshell4.0
 ${PACKAGE}FILES+=  unknown1.0
+${PACKAGE}FILES+=  unknown2.0
 ${PACKAGE}FILES+=  var-assign1.0
 
 .include 

Copied: stable/12/bin/sh/tests/execution/unknown2.0 (from r361112, 
head/bin/sh/tests/execution/unknown2.0)
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/12/bin/sh/tests/execution/unknown2.0 Sat May 30 13:39:56 2020
(r361646, copy of r361112, head/bin/sh/tests/execution/unknown2.0)
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+{
+   : $(/var/empty/nosuchtool) 
+   : $(:)
+} 2>/dev/null
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r361384 - head/bin/sh

2020-05-22 Thread Jilles Tjoelker
Author: jilles
Date: Fri May 22 14:46:23 2020
New Revision: 361384
URL: https://svnweb.freebsd.org/changeset/base/361384

Log:
  sh: Remove a comment that was obsoleted by r358152
  
  Since r358152, the read builtin has used a buffer.
  
  Also, remove a space at the end of the line in a comment.
  
  No functional change is intended.

Modified:
  head/bin/sh/miscbltin.c

Modified: head/bin/sh/miscbltin.c
==
--- head/bin/sh/miscbltin.c Fri May 22 13:27:02 2020(r361383)
+++ head/bin/sh/miscbltin.c Fri May 22 14:46:23 2020(r361384)
@@ -124,7 +124,7 @@ fdctx_destroy(struct fdctx *fdc)
 * Reposition the file offset.  Here is the layout of buf:
 *
 * | off
-* v 
+* v
 * |*|---|
 * buf   ep   buf+buflen
 * |<- residue ->|
@@ -142,8 +142,6 @@ fdctx_destroy(struct fdctx *fdc)
 /*
  * The read builtin.  The -r option causes backslashes to be treated like
  * ordinary characters.
- *
- * This uses unbuffered input, which may be avoidable in some cases.
  *
  * Note that if IFS=' :' then read x y should work so that:
  * 'a b'   x='a', y='b'
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r361117 - head/bin/sh/tests/execution

2020-05-16 Thread Jilles Tjoelker
Author: jilles
Date: Sat May 16 19:38:58 2020
New Revision: 361117
URL: https://svnweb.freebsd.org/changeset/base/361117

Log:
  sh/tests: Fix keywords on newly added test

Modified:
Directory Properties:
  head/bin/sh/tests/execution/unknown2.0   (props changed)
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r361112 - in head/bin/sh: . tests/execution

2020-05-16 Thread Jilles Tjoelker
Author: jilles
Date: Sat May 16 16:29:23 2020
New Revision: 361112
URL: https://svnweb.freebsd.org/changeset/base/361112

Log:
  sh: Fix double INTON with vfork
  
  The shell maintains a count of the number of times SIGINT processing has
  been disabled via INTOFF, so SIGINT processing resumes when all disables
  have enabled again (INTON).
  
  If an error occurs in a vfork() child, the processing of the error enables
  SIGINT processing again, and the INTON in vforkexecshell() causes the count
  to become negative.
  
  As a result, a later INTOFF may not actually disable SIGINT processing. This
  might cause memory corruption if a SIGINT arrives at an inopportune time. As
  of r360452, it causes the shell to abort when it would unsafely allocate or
  free memory in certain ways.
  
  Note that various places such as errors in non-special builtins
  unconditionally reset the count to 0, so the problem might still not always
  be visible.
  
  PR:   246497
  Reported by:  jbeich
  MFC after:2 weeks

Added:
  head/bin/sh/tests/execution/unknown2.0   (contents, props changed)
Modified:
  head/bin/sh/jobs.c
  head/bin/sh/tests/execution/Makefile

Modified: head/bin/sh/jobs.c
==
--- head/bin/sh/jobs.c  Sat May 16 14:33:08 2020(r36)
+++ head/bin/sh/jobs.c  Sat May 16 16:29:23 2020(r361112)
@@ -1008,9 +1008,11 @@ vforkexecshell(struct job *jp, char **argv, char **env
pid_t pid;
struct jmploc jmploc;
struct jmploc *savehandler;
+   int inton;
 
TRACE(("vforkexecshell(%%%td, %s, %p) called\n", jp - jobtab, argv[0],
(void *)pip));
+   inton = is_int_on();
INTOFF;
flushall();
savehandler = handler;
@@ -1045,7 +1047,7 @@ vforkexecshell(struct job *jp, char **argv, char **env
setcurjob(jp);
 #endif
}
-   INTON;
+   SETINTON(inton);
TRACE(("In parent shell:  child = %d\n", (int)pid));
return pid;
 }

Modified: head/bin/sh/tests/execution/Makefile
==
--- head/bin/sh/tests/execution/MakefileSat May 16 14:33:08 2020
(r36)
+++ head/bin/sh/tests/execution/MakefileSat May 16 16:29:23 2020
(r361112)
@@ -64,6 +64,7 @@ ${PACKAGE}FILES+= subshell2.0
 ${PACKAGE}FILES+=  subshell3.0
 ${PACKAGE}FILES+=  subshell4.0
 ${PACKAGE}FILES+=  unknown1.0
+${PACKAGE}FILES+=  unknown2.0
 ${PACKAGE}FILES+=  var-assign1.0
 
 .include 

Added: head/bin/sh/tests/execution/unknown2.0
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/bin/sh/tests/execution/unknown2.0  Sat May 16 16:29:23 2020
(r361112)
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+{
+   : $(/var/empty/nosuchtool) 
+   : $(:)
+} 2>/dev/null
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r360992 - head/bin/sh/tests/parser

2020-05-12 Thread Jilles Tjoelker
Author: jilles
Date: Tue May 12 21:59:21 2020
New Revision: 360992
URL: https://svnweb.freebsd.org/changeset/base/360992

Log:
  sh/tests: Test some obscure cases with aliasing keywords

Added:
  head/bin/sh/tests/parser/alias19.0   (contents, props changed)
  head/bin/sh/tests/parser/alias19.0.stdout   (contents, props changed)
  head/bin/sh/tests/parser/alias20.0   (contents, props changed)
  head/bin/sh/tests/parser/alias20.0.stdout   (contents, props changed)
Modified:
  head/bin/sh/tests/parser/Makefile

Modified: head/bin/sh/tests/parser/Makefile
==
--- head/bin/sh/tests/parser/Makefile   Tue May 12 21:51:56 2020
(r360991)
+++ head/bin/sh/tests/parser/Makefile   Tue May 12 21:59:21 2020
(r360992)
@@ -25,6 +25,8 @@ ${PACKAGE}FILES+= alias15.0 alias15.0.stdout
 ${PACKAGE}FILES+=  alias16.0
 ${PACKAGE}FILES+=  alias17.0
 ${PACKAGE}FILES+=  alias18.0
+${PACKAGE}FILES+=  alias19.0 alias19.0.stdout
+${PACKAGE}FILES+=  alias20.0 alias20.0.stdout
 ${PACKAGE}FILES+=  and-pipe-not.0
 ${PACKAGE}FILES+=  case1.0
 ${PACKAGE}FILES+=  case2.0

Added: head/bin/sh/tests/parser/alias19.0
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/bin/sh/tests/parser/alias19.0  Tue May 12 21:59:21 2020
(r360992)
@@ -0,0 +1,8 @@
+# $FreeBSD$
+
+alias begin={ end=}
+begin
+cat 

svn commit: r360452 - head/bin/sh

2020-04-28 Thread Jilles Tjoelker
Author: jilles
Date: Tue Apr 28 20:34:27 2020
New Revision: 360452
URL: https://svnweb.freebsd.org/changeset/base/360452

Log:
  sh: Assert INTOFF rather than applying it in ck*
  
  As I noted in https://reviews.freebsd.org/D22756, INTOFF should be in effect
  when calling ckmalloc/ckrealloc/ckfree to avoid memory leaks and double
  frees. Therefore, change the functions to check if INTOFF is in effect
  instead of applying it.
  
  Reviewed by:  bdrewery
  Differential Revision:https://reviews.freebsd.org/D24599

Modified:
  head/bin/sh/memalloc.c

Modified: head/bin/sh/memalloc.c
==
--- head/bin/sh/memalloc.c  Tue Apr 28 20:14:38 2020(r360451)
+++ head/bin/sh/memalloc.c  Tue Apr 28 20:34:27 2020(r360452)
@@ -50,6 +50,13 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 
+static void
+badalloc(const char *message)
+{
+   write(2, message, strlen(message));
+   abort();
+}
+
 /*
  * Like malloc, but returns an error when out of space.
  */
@@ -59,9 +66,9 @@ ckmalloc(size_t nbytes)
 {
pointer p;
 
-   INTOFF;
+   if (!is_int_on())
+   badalloc("Unsafe ckmalloc() call\n");
p = malloc(nbytes);
-   INTON;
if (p == NULL)
error("Out of space");
return p;
@@ -75,9 +82,9 @@ ckmalloc(size_t nbytes)
 pointer
 ckrealloc(pointer p, int nbytes)
 {
-   INTOFF;
+   if (!is_int_on())
+   badalloc("Unsafe ckrealloc() call\n");
p = realloc(p, nbytes);
-   INTON;
if (p == NULL)
error("Out of space");
return p;
@@ -86,9 +93,9 @@ ckrealloc(pointer p, int nbytes)
 void
 ckfree(pointer p)
 {
-   INTOFF;
+   if (!is_int_on())
+   badalloc("Unsafe ckfree() call\n");
free(p);
-   INTON;
 }
 
 
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r360210 - head/bin/sh

2020-04-22 Thread Jilles Tjoelker
Author: jilles
Date: Wed Apr 22 21:45:43 2020
New Revision: 360210
URL: https://svnweb.freebsd.org/changeset/base/360210

Log:
  sh: Remove remnants to compile out fc completely
  
  r360139 made compiling with NO_HISTORY work. This #define does not remove
  the fc and bind builtins completely but makes them always write an error
  message.
  
  However, there was also some code in builtins.def and mkbuiltins to remove
  the fc builtin entirely (but not the bind builtin). The additional build
  system complication to make this work seems not worth it, so remove that
  code.

Modified:
  head/bin/sh/builtins.def
  head/bin/sh/mkbuiltins

Modified: head/bin/sh/builtins.def
==
--- head/bin/sh/builtins.defWed Apr 22 21:22:33 2020(r360209)
+++ head/bin/sh/builtins.defWed Apr 22 21:45:43 2020(r360210)
@@ -39,8 +39,6 @@
 # of a C routine.
 # The -j flag specifies that this command is to be excluded from systems
 # without job control.
-# The -h flag specifies that this command is to be excluded from systems
-# based on the NO_HISTORY compile-time symbol.
 # The -n flag specifies that this command can safely be run in the same
 # process when it is the only command in a command substitution.  Some
 # commands have special logic defined in safe_builtin().
@@ -71,7 +69,7 @@ fgcmd -j  fg
 freebsd_wordexpcmd freebsd_wordexp
 getoptscmd getopts
 hashcmdhash
-histcmd -h fc
+histcmdfc
 jobidcmd -njobid
 jobscmd -n jobs
 killcmd -n kill

Modified: head/bin/sh/mkbuiltins
==
--- head/bin/sh/mkbuiltins  Wed Apr 22 21:22:33 2020(r360209)
+++ head/bin/sh/mkbuiltins  Wed Apr 22 21:45:43 2020(r360210)
@@ -35,11 +35,6 @@
 # $FreeBSD$
 
 temp=`mktemp -t ka`
-havehist=1
-if [ "X$1" = "X-h" ]; then
-   havehist=0
-   shift
-fi
 srcdir=$1
 havejobs=0
 if grep '^#define[  ]*JOBS[ ]*1' $srcdir/shell.h > /dev/null
@@ -56,8 +51,8 @@ cat <<\!
 #include "builtins.h"
 
 !
-awk '/^[^#]/ {if(('$havejobs' || $2 != "-j") && ('$havehist' || $2 != "-h")) \
-print $0}' $srcdir/builtins.def | sed 's/-[hj]//' > $temp
+awk '/^[^#]/ {if('$havejobs' || $2 != "-j") \
+print $0}' $srcdir/builtins.def | sed 's/-j//' > $temp
 echo 'int (*const builtinfunc[])(int, char **) = {'
 awk '/^[^#]/ { printf "\t%s,\n", $1}' $temp
 echo '};
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r357138 - head/bin/pwait

2020-01-30 Thread Jilles Tjoelker

On 26-01-2020 11:49, Pawel Jakub Dawidek wrote:

Author: pjd
Date: Sun Jan 26 10:49:24 2020
New Revision: 357138
URL: https://svnweb.freebsd.org/changeset/base/357138

Log:
   - Be consistent with using sysexits(3) codes.
   - Turn fprintf()+exit() into errx().
   
   Sponsored by:	Fudo Security


Modified:
   head/bin/pwait/pwait.c

Modified: head/bin/pwait/pwait.c
==
--- head/bin/pwait/pwait.c  Sun Jan 26 07:24:49 2020(r357137)
+++ head/bin/pwait/pwait.c  Sun Jan 26 10:49:24 2020(r357138)
@@ -53,8 +53,7 @@ static void
  usage(void)
  {
  
-	fprintf(stderr, "usage: pwait [-t timeout] [-v] pid ...\n");

-   exit(EX_USAGE);
+   errx(EX_USAGE, "usage: pwait [-t timeout] [-v] pid ...");


This adds a "pwait: " before the line, which most other programs do not do.

--
Jilles Tjoelker
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r356251 - head/bin/sh

2020-01-01 Thread Jilles Tjoelker
Author: jilles
Date: Wed Jan  1 12:06:37 2020
New Revision: 356251
URL: https://svnweb.freebsd.org/changeset/base/356251

Log:
  sh: Fix rare memory leak with SIGINT
  
  If getcwd() failed earlier on but later succeeded in the pwd builtin,
  there was no INTOFF protection between calling savestr() and storing its
  result.
  
  It is quite rare for getcwd() to fail, and rarer for it to succeed later in
  the same directory.
  
  Found via code inspection for changing ckmalloc() and similar to assert
  INTOFF protection instead of applying it directly (which protects against
  corrupting malloc's internal state but allows memory leaks or double frees).
  
  MFC after:1 week

Modified:
  head/bin/sh/cd.c

Modified: head/bin/sh/cd.c
==
--- head/bin/sh/cd.cWed Jan  1 09:22:06 2020(r356250)
+++ head/bin/sh/cd.cWed Jan  1 12:06:37 2020(r356251)
@@ -376,8 +376,11 @@ getpwd(void)
return curdir;
 
p = getpwd2();
-   if (p != NULL)
+   if (p != NULL) {
+   INTOFF;
curdir = savestr(p);
+   INTON;
+   }
 
return curdir;
 }
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r356208 - head/bin/sh/tests/execution

2019-12-30 Thread Jilles Tjoelker
Author: jilles
Date: Mon Dec 30 21:32:55 2019
New Revision: 356208
URL: https://svnweb.freebsd.org/changeset/base/356208

Log:
  sh: Test that executing various binary files is rejected
  
  If executing a file fails with an [ENOEXEC] error, the shell executes the
  file as a shell script, except that this execution may instead result in an
  error message if the file is binary.
  
  Per a recent Austin Group interpretation, we will need to change this to
  allow a concatenation of a shell script and a binary payload. See
  Austin Group bugs #1226 and #1250.
  
  MFC after:1 week

Added:
  head/bin/sh/tests/execution/shellproc2.0   (contents, props changed)
  head/bin/sh/tests/execution/shellproc3.0   (contents, props changed)
  head/bin/sh/tests/execution/shellproc4.0   (contents, props changed)
  head/bin/sh/tests/execution/shellproc5.0   (contents, props changed)
Modified:
  head/bin/sh/tests/execution/Makefile

Modified: head/bin/sh/tests/execution/Makefile
==
--- head/bin/sh/tests/execution/MakefileMon Dec 30 20:30:31 2019
(r356207)
+++ head/bin/sh/tests/execution/MakefileMon Dec 30 21:32:55 2019
(r356208)
@@ -55,6 +55,10 @@ ${PACKAGE}FILES+=set-x2.0
 ${PACKAGE}FILES+=  set-x3.0
 ${PACKAGE}FILES+=  set-x4.0
 ${PACKAGE}FILES+=  shellproc1.0
+${PACKAGE}FILES+=  shellproc2.0
+${PACKAGE}FILES+=  shellproc3.0
+${PACKAGE}FILES+=  shellproc4.0
+${PACKAGE}FILES+=  shellproc5.0
 ${PACKAGE}FILES+=  subshell1.0 subshell1.0.stdout
 ${PACKAGE}FILES+=  subshell2.0
 ${PACKAGE}FILES+=  subshell3.0

Added: head/bin/sh/tests/execution/shellproc2.0
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/bin/sh/tests/execution/shellproc2.0Mon Dec 30 21:32:55 2019
(r356208)
@@ -0,0 +1,18 @@
+# $FreeBSD$
+# This tests a quality of implementation issue.
+# Shells are not required to reject executing binary files as shell scripts
+# but executing, for example, ELF files for a different architecture as
+# shell scripts may have annoying side effects.
+
+T=`mktemp -d "${TMPDIR:-/tmp}/sh-test."` || exit
+trap 'rm -rf "${T}"' 0
+printf '\0' >"$T/testshellproc"
+chmod 755 "$T/testshellproc"
+if [ ! -s "$T/testshellproc" ]; then
+   printf "printf did not write a NUL character\n" >&2
+   exit 2
+fi
+PATH=$T:$PATH
+errout=`testshellproc 3>&2 2>&1 >&3 3>&-`
+r=$?
+[ "$r" = 126 ] && [ -n "$errout" ]

Added: head/bin/sh/tests/execution/shellproc3.0
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/bin/sh/tests/execution/shellproc3.0Mon Dec 30 21:32:55 2019
(r356208)
@@ -0,0 +1,14 @@
+# $FreeBSD$
+# This tests a quality of implementation issue.
+# Shells are not required to reject executing binary files as shell scripts
+# but executing, for example, ELF files for a different architecture as
+# shell scripts may have annoying side effects.
+
+T=`mktemp -d "${TMPDIR:-/tmp}/sh-test."` || exit
+trap 'rm -rf "${T}"' 0
+printf '\177ELF\001!!\011\0\0\0\0\0\0\0\0' >"$T/testshellproc"
+chmod 755 "$T/testshellproc"
+PATH=$T:$PATH
+errout=`testshellproc 3>&2 2>&1 >&3 3>&-`
+r=$?
+[ "$r" = 126 ] && [ -n "$errout" ]

Added: head/bin/sh/tests/execution/shellproc4.0
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/bin/sh/tests/execution/shellproc4.0Mon Dec 30 21:32:55 2019
(r356208)
@@ -0,0 +1,14 @@
+# $FreeBSD$
+# This tests a quality of implementation issue.
+# Shells are not required to reject executing binary files as shell scripts
+# but executing, for example, ELF files for a different architecture as
+# shell scripts may have annoying side effects.
+
+T=`mktemp -d "${TMPDIR:-/tmp}/sh-test."` || exit
+trap 'rm -rf "${T}"' 0
+printf '\211PNG\015\012\032\012\0\0\0\015IHDR' >"$T/testshellproc"
+chmod 755 "$T/testshellproc"
+PATH=$T:$PATH
+errout=`testshellproc 3>&2 2>&1 >&3 3>&-`
+r=$?
+[ "$r" = 126 ] && [ -n "$errout" ]

Added: head/bin/sh/tests/execution/shellproc5.0
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/bin/sh/tests/execution/shellproc5.0Mon Dec 30 21:32:55 2019
(r356208)
@@ -0,0 +1,14 @@
+# $FreeBSD$
+# This tests a quality of implementation issue.
+# Shells are not required to reject executing binary files as shell scripts
+# but executing, for example, ELF files for a different architecture as
+# shell scripts may have annoying side effects.
+
+T=`mktemp -d "${TMPDIR:-/tmp}/sh-test."` || 

Re: svn commit: r346017 - in head: libexec/rc libexec/rc/rc.d share/man/man5

2019-10-12 Thread Jilles Tjoelker
On Tue, Apr 09, 2019 at 10:24:16PM +0100, Chris Rees wrote:
> On 9 April 2019 22:13:29 BST, Chris Rees  wrote:
> >On 9 April 2019 22:08:35 BST, "Rodney W. Grimes"
> > wrote:
> >>> On 09/04/2019 20:59, Chris Rees wrote:
> >>> > On 9 April 2019 20:55:07 BST, "Rodney W. Grimes"
> >> wrote:
> >>> >>> On 09/04/2019 21:33, Rodney W. Grimes wrote:
> >>> >>>> I think the trigger issue is:
> >>> >>>> grep zfs /etc/rc.d/zvol
> >>> >>>> rcvar="zfs_enable"
> >>> >>>> required_modules="zfs"

> >>> >>>> that module requires may be going south with the
> >>> >>>> new code when the module is built into the kernel.
> >>> >>> Maybe it's because the module's name is zfsctrl (for whatever
> >>reason)
> >>> >> while the
> >>> >>> module file is named zfs.ko.
> >>> >> I suspect that could also lead to issues with the new code.
> >>> >> It seems to be failing to detect that zfs is infact functional in
> >>the
> >>> >> kernel,
> >>> >> and blindly, or not so blindly, trying to load zfs,ko, which when
> >>you
> >>> >> build
> >>> >> it into the kernel you usually do so without any modules built,
> >so
> >>> >> there is
> >>> >> no /boot/kernel/zfs.ko, and even if you did build it any attempt
> >>to
> >>> >> load
> >>> >> it would return an error.
> >>> > Loading with it built in isn't a problem, as I showed earlier.

> >>> > Loading when it doesn't exist *is*.

> >>> > I'm torn.  Either we could revert this, or add a check to the
> >>required_modules function instead, which I think is the better solution.

> >>> Hang on,

> >>> [crees@pegasus]~% sudo kldload -n zfsctrl && echo yes
> >>> yes

> >>I think your testing the return value of sudo here?

> >Sudo returns the child's return value.

> Turns out Oliver had also reported this to current@ with a log

> https://lists.freebsd.org/pipermail/freebsd-current/2019-April/073148.html

> Jilles@, mind if I revert this while I get some testing on this
> scenario done?

> It seems to me that zfs may not be included in the kernel, just
> zfsctrl, or something like that.

It seems like kldload -n does not work as expected for zfs, so reverting
seems the right approach.

-- 
Jilles Tjoelker


___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r353148 - in stable/12: contrib/netbsd-tests/lib/libc/sys tests/sys/posixshm tests/sys/vm

2019-10-06 Thread Jilles Tjoelker
Author: jilles
Date: Sun Oct  6 20:36:25 2019
New Revision: 353148
URL: https://svnweb.freebsd.org/changeset/base/353148

Log:
  MFC r352495,r352869: Adjust tests for page fault changes in r353102
  
  PR:   211924

Added:
  stable/12/tests/sys/vm/page_fault_signal.c
 - copied, changed from r352495, head/tests/sys/vm/page_fault_signal.c
Modified:
  stable/12/contrib/netbsd-tests/lib/libc/sys/t_mmap.c
  stable/12/tests/sys/posixshm/posixshm_test.c
  stable/12/tests/sys/vm/Makefile
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/contrib/netbsd-tests/lib/libc/sys/t_mmap.c
==
--- stable/12/contrib/netbsd-tests/lib/libc/sys/t_mmap.cSun Oct  6 
19:11:01 2019(r353147)
+++ stable/12/contrib/netbsd-tests/lib/libc/sys/t_mmap.cSun Oct  6 
20:36:25 2019(r353148)
@@ -480,10 +480,6 @@ ATF_TC_BODY(mmap_truncate_signal, tc)
int fd, sta;
pid_t pid;
 
-#ifdef __FreeBSD__
-   atf_tc_expect_fail("testcase fails with SIGSEGV on FreeBSD; bug # 
211924");
-#endif
-
fd = open(path, O_RDWR | O_CREAT, 0700);
 
if (fd < 0)

Modified: stable/12/tests/sys/posixshm/posixshm_test.c
==
--- stable/12/tests/sys/posixshm/posixshm_test.cSun Oct  6 19:11:01 
2019(r353147)
+++ stable/12/tests/sys/posixshm/posixshm_test.cSun Oct  6 20:36:25 
2019(r353148)
@@ -445,7 +445,7 @@ ATF_TC_BODY(object_resize, tc)
/*
 * The previous ftruncate(2) shrunk the backing object
 * so that this address is no longer valid, so reading
-* from it should trigger a SIGSEGV.
+* from it should trigger a SIGBUS.
 */
c = page[pagesize];
fprintf(stderr, "child: page 1: '%c'\n", c);
@@ -455,7 +455,7 @@ ATF_TC_BODY(object_resize, tc)
if (wait() < 0)
atf_tc_fail("wait failed; errno=%d", errno);
 
-   if (!WIFSIGNALED(status) || WTERMSIG(status) != SIGSEGV)
+   if (!WIFSIGNALED(status) || WTERMSIG(status) != SIGBUS)
atf_tc_fail("child terminated with status %x", status);
 
/* Grow the object back to 2 pages. */

Modified: stable/12/tests/sys/vm/Makefile
==
--- stable/12/tests/sys/vm/Makefile Sun Oct  6 19:11:01 2019
(r353147)
+++ stable/12/tests/sys/vm/Makefile Sun Oct  6 20:36:25 2019
(r353148)
@@ -5,6 +5,7 @@ PACKAGE=tests
 TESTSDIR=  ${TESTSBASE}/sys/vm
 
 ATF_TESTS_C+=  mlock_test \
-   mmap_test
+   mmap_test \
+   page_fault_signal
 
 .include 

Copied and modified: stable/12/tests/sys/vm/page_fault_signal.c (from r352495, 
head/tests/sys/vm/page_fault_signal.c)
==
--- head/tests/sys/vm/page_fault_signal.c   Wed Sep 18 21:00:32 2019
(r352495, copy source)
+++ stable/12/tests/sys/vm/page_fault_signal.c  Sun Oct  6 20:36:25 2019
(r353148)
@@ -129,7 +129,6 @@ ATF_TC_BODY(page_fault_signal__bus_objerr_1, tc)
int fd;
int sz;
 
-   atf_tc_expect_fail("bug 211924");
sz = getpagesize();
fd = shm_open(SHM_ANON, O_RDWR | O_CREAT, 0600);
ATF_REQUIRE(fd != -1);
@@ -153,7 +152,6 @@ ATF_TC_BODY(page_fault_signal__bus_objerr_2, tc)
int r;
int sz;
 
-   atf_tc_expect_fail("bug 211924");
sz = getpagesize();
fd = shm_open(SHM_ANON, O_RDWR | O_CREAT, 0600);
ATF_REQUIRE(fd != -1);
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r352869 - in head: contrib/netbsd-tests/lib/libc/sys tests/sys/posixshm tests/sys/vm

2019-09-29 Thread Jilles Tjoelker
Author: jilles
Date: Sun Sep 29 15:17:58 2019
New Revision: 352869
URL: https://svnweb.freebsd.org/changeset/base/352869

Log:
  Adjust tests after page fault changes in r352807
  
  Commit r352807 fixed various signal numbers and codes from page faults;
  adjust the tests so they expect the fixes to be present.
  
  PR:   211924

Modified:
  head/contrib/netbsd-tests/lib/libc/sys/t_mmap.c
  head/tests/sys/posixshm/posixshm_test.c
  head/tests/sys/vm/page_fault_signal.c

Modified: head/contrib/netbsd-tests/lib/libc/sys/t_mmap.c
==
--- head/contrib/netbsd-tests/lib/libc/sys/t_mmap.c Sun Sep 29 10:45:13 
2019(r352868)
+++ head/contrib/netbsd-tests/lib/libc/sys/t_mmap.c Sun Sep 29 15:17:58 
2019(r352869)
@@ -480,10 +480,6 @@ ATF_TC_BODY(mmap_truncate_signal, tc)
int fd, sta;
pid_t pid;
 
-#ifdef __FreeBSD__
-   atf_tc_expect_fail("testcase fails with SIGSEGV on FreeBSD; bug # 
211924");
-#endif
-
fd = open(path, O_RDWR | O_CREAT, 0700);
 
if (fd < 0)

Modified: head/tests/sys/posixshm/posixshm_test.c
==
--- head/tests/sys/posixshm/posixshm_test.c Sun Sep 29 10:45:13 2019
(r352868)
+++ head/tests/sys/posixshm/posixshm_test.c Sun Sep 29 15:17:58 2019
(r352869)
@@ -697,7 +697,7 @@ ATF_TC_BODY(object_resize, tc)
/*
 * The previous ftruncate(2) shrunk the backing object
 * so that this address is no longer valid, so reading
-* from it should trigger a SIGSEGV.
+* from it should trigger a SIGBUS.
 */
c = page[pagesize];
fprintf(stderr, "child: page 1: '%c'\n", c);
@@ -707,7 +707,7 @@ ATF_TC_BODY(object_resize, tc)
if (wait() < 0)
atf_tc_fail("wait failed; errno=%d", errno);
 
-   if (!WIFSIGNALED(status) || WTERMSIG(status) != SIGSEGV)
+   if (!WIFSIGNALED(status) || WTERMSIG(status) != SIGBUS)
atf_tc_fail("child terminated with status %x", status);
 
/* Grow the object back to 2 pages. */

Modified: head/tests/sys/vm/page_fault_signal.c
==
--- head/tests/sys/vm/page_fault_signal.c   Sun Sep 29 10:45:13 2019
(r352868)
+++ head/tests/sys/vm/page_fault_signal.c   Sun Sep 29 15:17:58 2019
(r352869)
@@ -129,7 +129,6 @@ ATF_TC_BODY(page_fault_signal__bus_objerr_1, tc)
int fd;
int sz;
 
-   atf_tc_expect_fail("bug 211924");
sz = getpagesize();
fd = shm_open(SHM_ANON, O_RDWR | O_CREAT, 0600);
ATF_REQUIRE(fd != -1);
@@ -153,7 +152,6 @@ ATF_TC_BODY(page_fault_signal__bus_objerr_2, tc)
int r;
int sz;
 
-   atf_tc_expect_fail("bug 211924");
sz = getpagesize();
fd = shm_open(SHM_ANON, O_RDWR | O_CREAT, 0600);
ATF_REQUIRE(fd != -1);
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r352495 - head/tests/sys/vm

2019-09-18 Thread Jilles Tjoelker
Author: jilles
Date: Wed Sep 18 21:00:32 2019
New Revision: 352495
URL: https://svnweb.freebsd.org/changeset/base/352495

Log:
  Add some tests for page fault signals and codes
  
  It is useful to have some tests for page fault signals.
  
  More tests would be useful but creating the conditions (such as various
  kinds of running out of memory and I/O errors) is more complicated.
  
  The tests page_fault_signal__bus_objerr_1 and
  page_fault_signal__bus_objerr_2 depend on https://reviews.freebsd.org/D21566
  before they can pass.
  
  PR:   211924
  Reviewed by:  kib
  Differential Revision:https://reviews.freebsd.org/D21624

Added:
  head/tests/sys/vm/page_fault_signal.c   (contents, props changed)
Modified:
  head/tests/sys/vm/Makefile

Modified: head/tests/sys/vm/Makefile
==
--- head/tests/sys/vm/Makefile  Wed Sep 18 19:53:58 2019(r352494)
+++ head/tests/sys/vm/Makefile  Wed Sep 18 21:00:32 2019(r352495)
@@ -5,6 +5,7 @@ PACKAGE=tests
 TESTSDIR=  ${TESTSBASE}/sys/vm
 
 ATF_TESTS_C+=  mlock_test \
-   mmap_test
+   mmap_test \
+   page_fault_signal
 
 .include 

Added: head/tests/sys/vm/page_fault_signal.c
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/tests/sys/vm/page_fault_signal.c   Wed Sep 18 21:00:32 2019
(r352495)
@@ -0,0 +1,184 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2019 Jilles Tjoelker
+ *
+ * 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.
+ *
+ * $FreeBSD$
+ */
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static sigjmp_buf sig_env;
+static volatile int last_sig, last_code;
+
+static void
+sighandler(int sig, siginfo_t *info, void *context __unused)
+{
+
+   last_sig = sig;
+   last_code = info->si_code;
+   siglongjmp(sig_env, 1);
+}
+
+static void
+setup_signals(void)
+{
+   struct sigaction sa;
+   int r;
+
+   sa.sa_sigaction = sighandler;
+   sa.sa_flags = SA_RESTART | SA_RESETHAND | SA_SIGINFO;
+   r = sigfillset(_mask);
+   ATF_REQUIRE(r != -1);
+   r = sigaction(SIGILL, , NULL);
+   ATF_REQUIRE(r != -1);
+   r = sigaction(SIGBUS, , NULL);
+   ATF_REQUIRE(r != -1);
+   r = sigaction(SIGSEGV, , NULL);
+   ATF_REQUIRE(r != -1);
+}
+
+ATF_TC_WITHOUT_HEAD(page_fault_signal__segv_maperr_1);
+ATF_TC_BODY(page_fault_signal__segv_maperr_1, tc)
+{
+   int *p;
+   int r;
+   int sz;
+
+   sz = getpagesize();
+   p = mmap(NULL, sz, PROT_READ, MAP_ANON, -1, 0);
+   ATF_REQUIRE(p != MAP_FAILED);
+   r = munmap(p, sz);
+   ATF_REQUIRE(r != -1);
+   if (sigsetjmp(sig_env, 1) == 0) {
+   setup_signals();
+   *(volatile int *)p = 1;
+   }
+   ATF_CHECK_EQ(SIGSEGV, last_sig);
+   ATF_CHECK_EQ(SEGV_MAPERR, last_code);
+}
+
+ATF_TC_WITHOUT_HEAD(page_fault_signal__segv_accerr_1);
+ATF_TC_BODY(page_fault_signal__segv_accerr_1, tc)
+{
+   int *p;
+   int sz;
+
+   sz = getpagesize();
+   p = mmap(NULL, sz, PROT_READ, MAP_ANON, -1, 0);
+   ATF_REQUIRE(p != MAP_FAILED);
+   if (sigsetjmp(sig_env, 1) == 0) {
+   setup_signals();
+   *(volatile int *)p = 1;
+   }
+   (void)munmap(p, sz);
+   ATF_CHECK_EQ(SIGSEGV, last_sig);
+   ATF_CHECK_EQ(SEGV_ACCERR, last_code);
+}
+
+ATF_TC_WITHOUT_HEAD(page_fault_signal__segv_accerr_2);
+ATF_TC_BODY(page_fault_signal__segv_accerr_2, tc)
+{
+   int *p;
+   volatile int dummy;
+   int sz;
+
+  

svn commit: r352492 - stable/11/usr.bin/procstat/tests

2019-09-18 Thread Jilles Tjoelker
Author: jilles
Date: Wed Sep 18 19:28:17 2019
New Revision: 352492
URL: https://svnweb.freebsd.org/changeset/base/352492

Log:
  MFC r351819: procstat/tests: Fix flakiness by waiting for program to start
  
  Some of the procstat tests start a program "while1" and examine the process
  using procstat, but did not wait properly for it to start (kill -0 will
  succeed immediately after the child process has been created).
  
  Instead, have "while1" write something when it starts, and use a fifo to
  wait for that.
  
  PR:   233587, 233588

Modified:
  stable/11/usr.bin/procstat/tests/procstat_test.sh
  stable/11/usr.bin/procstat/tests/while1.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.bin/procstat/tests/procstat_test.sh
==
--- stable/11/usr.bin/procstat/tests/procstat_test.sh   Wed Sep 18 19:21:20 
2019(r352491)
+++ stable/11/usr.bin/procstat/tests/procstat_test.sh   Wed Sep 18 19:28:17 
2019(r352492)
@@ -25,7 +25,6 @@
 # $FreeBSD$
 #
 
-MAX_TRIES=20
 PROG_PID=
 PROG_PATH=$(atf_get_srcdir)/while1
 
@@ -37,16 +36,13 @@ start_program()
PROG_COMM=while1
PROG_PATH=$(atf_get_srcdir)/$PROG_COMM
 
-   $PROG_PATH $* &
+   mkfifo wait_for_start || atf_fail "mkfifo"
+   $PROG_PATH $* >wait_for_start &
PROG_PID=$!
-   try=0
-   while [ $try -lt $MAX_TRIES ] && ! kill -0 $PROG_PID; do
-   sleep 0.5
-   : $(( try += 1 ))
-   done
-   if [ $try -ge $MAX_TRIES ]; then
-   atf_fail "Polled for program start $MAX_TRIES tries and failed"
+   if ! read dummy https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r352491 - stable/12/usr.bin/procstat/tests

2019-09-18 Thread Jilles Tjoelker
Author: jilles
Date: Wed Sep 18 19:21:20 2019
New Revision: 352491
URL: https://svnweb.freebsd.org/changeset/base/352491

Log:
  MFC r351819: procstat/tests: Fix flakiness by waiting for program to start
  
  Some of the procstat tests start a program "while1" and examine the process
  using procstat, but did not wait properly for it to start (kill -0 will
  succeed immediately after the child process has been created).
  
  Instead, have "while1" write something when it starts, and use a fifo to
  wait for that.
  
  PR:   233587, 233588

Modified:
  stable/12/usr.bin/procstat/tests/procstat_test.sh
  stable/12/usr.bin/procstat/tests/while1.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/usr.bin/procstat/tests/procstat_test.sh
==
--- stable/12/usr.bin/procstat/tests/procstat_test.sh   Wed Sep 18 17:21:34 
2019(r352490)
+++ stable/12/usr.bin/procstat/tests/procstat_test.sh   Wed Sep 18 19:21:20 
2019(r352491)
@@ -25,7 +25,6 @@
 # $FreeBSD$
 #
 
-MAX_TRIES=20
 PROG_PID=
 PROG_PATH=$(atf_get_srcdir)/while1
 
@@ -37,16 +36,13 @@ start_program()
PROG_COMM=while1
PROG_PATH=$(atf_get_srcdir)/$PROG_COMM
 
-   $PROG_PATH $* &
+   mkfifo wait_for_start || atf_fail "mkfifo"
+   $PROG_PATH $* >wait_for_start &
PROG_PID=$!
-   try=0
-   while [ $try -lt $MAX_TRIES ] && ! kill -0 $PROG_PID; do
-   sleep 0.5
-   : $(( try += 1 ))
-   done
-   if [ $try -ge $MAX_TRIES ]; then
-   atf_fail "Polled for program start $MAX_TRIES tries and failed"
+   if ! read dummy https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r351819 - head/usr.bin/procstat/tests

2019-09-04 Thread Jilles Tjoelker
Author: jilles
Date: Wed Sep  4 16:25:41 2019
New Revision: 351819
URL: https://svnweb.freebsd.org/changeset/base/351819

Log:
  procstat/tests: Fix flakiness by waiting for program to start
  
  Some of the procstat tests start a program "while1" and examine the process
  using procstat, but did not wait properly for it to start (kill -0 will
  succeed immediately after the child process has been created).
  
  Instead, have "while1" write something when it starts, and use a fifo to
  wait for that.
  
  PR:   233587, 233588
  Reviewed by:  ngie
  MFC after:1 week
  Differential Revision:https://reviews.freebsd.org/D21519

Modified:
  head/usr.bin/procstat/tests/procstat_test.sh
  head/usr.bin/procstat/tests/while1.c

Modified: head/usr.bin/procstat/tests/procstat_test.sh
==
--- head/usr.bin/procstat/tests/procstat_test.shWed Sep  4 15:55:44 
2019(r351818)
+++ head/usr.bin/procstat/tests/procstat_test.shWed Sep  4 16:25:41 
2019(r351819)
@@ -25,7 +25,6 @@
 # $FreeBSD$
 #
 
-MAX_TRIES=20
 PROG_PID=
 PROG_PATH=$(atf_get_srcdir)/while1
 
@@ -37,16 +36,13 @@ start_program()
PROG_COMM=while1
PROG_PATH=$(atf_get_srcdir)/$PROG_COMM
 
-   $PROG_PATH $* &
+   mkfifo wait_for_start || atf_fail "mkfifo"
+   $PROG_PATH $* >wait_for_start &
PROG_PID=$!
-   try=0
-   while [ $try -lt $MAX_TRIES ] && ! kill -0 $PROG_PID; do
-   sleep 0.5
-   : $(( try += 1 ))
-   done
-   if [ $try -ge $MAX_TRIES ]; then
-   atf_fail "Polled for program start $MAX_TRIES tries and failed"
+   if ! read dummy https://bugs.freebsd.org/233587;
-
arguments="my arguments"
 
start_program $arguments
@@ -104,8 +98,6 @@ environment_head()
 }
 environment_body()
 {
-   atf_skip "https://bugs.freebsd.org/233588;
-
var="MY_VARIABLE=foo"
eval "export $var"
 

Modified: head/usr.bin/procstat/tests/while1.c
==
--- head/usr.bin/procstat/tests/while1.cWed Sep  4 15:55:44 2019
(r351818)
+++ head/usr.bin/procstat/tests/while1.cWed Sep  4 16:25:41 2019
(r351819)
@@ -33,7 +33,8 @@ int
 main(void)
 {
 
+   if (write(STDOUT_FILENO, "started\n", 8) != 8)
+   abort();
for (;;)
-   usleep(100);
-   exit(1);
+   pause();
 }
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r345617 - stable/11/bin/sh

2019-09-03 Thread Jilles Tjoelker
Author: jilles
Date: Wed Mar 27 22:09:35 2019
New Revision: 345617
URL: https://svnweb.freebsd.org/changeset/base/345617

Log:
  MFC r344306: sh: Send normal output from bind builtin to stdout
  
  PR:   233343

Modified:
  stable/11/bin/sh/histedit.c
  stable/11/bin/sh/output.c
  stable/11/bin/sh/output.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/bin/sh/histedit.c
==
--- stable/11/bin/sh/histedit.c Wed Mar 27 22:05:57 2019(r345616)
+++ stable/11/bin/sh/histedit.c Wed Mar 27 22:09:35 2019(r345617)
@@ -474,10 +474,31 @@ str_to_event(const char *str, int last)
 int
 bindcmd(int argc, char **argv)
 {
+   int ret;
+   FILE *old;
+   FILE *out;
 
if (el == NULL)
error("line editing is disabled");
-   return (el_parse(el, argc, __DECONST(const char **, argv)));
+
+   INTOFF;
+
+   out = out1fp();
+   if (out == NULL)
+   error("Out of space");
+
+   el_get(el, EL_GETFP, 1, );
+   el_set(el, EL_SETFP, 1, out);
+
+   ret = el_parse(el, argc, __DECONST(const char **, argv));
+
+   el_set(el, EL_SETFP, 1, old);
+
+   fclose(out);
+
+   INTON;
+
+   return ret;
 }
 
 #else

Modified: stable/11/bin/sh/output.c
==
--- stable/11/bin/sh/output.c   Wed Mar 27 22:05:57 2019(r345616)
+++ stable/11/bin/sh/output.c   Wed Mar 27 22:09:35 2019(r345617)
@@ -345,6 +345,12 @@ doformat(struct output *dest, const char *f, va_list a
}
 }
 
+FILE *
+out1fp(void)
+{
+   return fwopen(out1, doformat_wr);
+}
+
 /*
  * Version of write which resumes after a signal is caught.
  */

Modified: stable/11/bin/sh/output.h
==
--- stable/11/bin/sh/output.h   Wed Mar 27 22:05:57 2019(r345616)
+++ stable/11/bin/sh/output.h   Wed Mar 27 22:09:35 2019(r345617)
@@ -37,6 +37,7 @@
 
 #include 
 #include 
+#include 
 
 struct output {
char *nextc;
@@ -73,6 +74,7 @@ void out1fmt(const char *, ...) __printflike(1, 2);
 void out2fmt_flush(const char *, ...) __printflike(1, 2);
 void fmtstr(char *, int, const char *, ...) __printflike(3, 4);
 void doformat(struct output *, const char *, va_list) __printflike(2, 0);
+FILE *out1fp(void);
 int xwrite(int, const char *, int);
 
 #define outc(c, file)  (--(file)->nleft < 0? (emptyoutbuf(file), 
*(file)->nextc++ = (c)) : (*(file)->nextc++ = (c)))


___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r345613 - stable/12/bin/sh

2019-09-03 Thread Jilles Tjoelker
Author: jilles
Date: Wed Mar 27 21:53:44 2019
New Revision: 345613
URL: https://svnweb.freebsd.org/changeset/base/345613

Log:
  MFC r344306: sh: Send normal output from bind builtin to stdout
  
  PR:   233343

Modified:
  stable/12/bin/sh/histedit.c
  stable/12/bin/sh/output.c
  stable/12/bin/sh/output.h
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/bin/sh/histedit.c
==
--- stable/12/bin/sh/histedit.c Wed Mar 27 21:50:07 2019(r345612)
+++ stable/12/bin/sh/histedit.c Wed Mar 27 21:53:44 2019(r345613)
@@ -474,10 +474,31 @@ str_to_event(const char *str, int last)
 int
 bindcmd(int argc, char **argv)
 {
+   int ret;
+   FILE *old;
+   FILE *out;
 
if (el == NULL)
error("line editing is disabled");
-   return (el_parse(el, argc, __DECONST(const char **, argv)));
+
+   INTOFF;
+
+   out = out1fp();
+   if (out == NULL)
+   error("Out of space");
+
+   el_get(el, EL_GETFP, 1, );
+   el_set(el, EL_SETFP, 1, out);
+
+   ret = el_parse(el, argc, __DECONST(const char **, argv));
+
+   el_set(el, EL_SETFP, 1, old);
+
+   fclose(out);
+
+   INTON;
+
+   return ret;
 }
 
 #else

Modified: stable/12/bin/sh/output.c
==
--- stable/12/bin/sh/output.c   Wed Mar 27 21:50:07 2019(r345612)
+++ stable/12/bin/sh/output.c   Wed Mar 27 21:53:44 2019(r345613)
@@ -340,6 +340,12 @@ doformat(struct output *dest, const char *f, va_list a
}
 }
 
+FILE *
+out1fp(void)
+{
+   return fwopen(out1, doformat_wr);
+}
+
 /*
  * Version of write which resumes after a signal is caught.
  */

Modified: stable/12/bin/sh/output.h
==
--- stable/12/bin/sh/output.h   Wed Mar 27 21:50:07 2019(r345612)
+++ stable/12/bin/sh/output.h   Wed Mar 27 21:53:44 2019(r345613)
@@ -39,6 +39,7 @@
 
 #include 
 #include 
+#include 
 
 struct output {
char *nextc;
@@ -75,6 +76,7 @@ void out1fmt(const char *, ...) __printflike(1, 2);
 void out2fmt_flush(const char *, ...) __printflike(1, 2);
 void fmtstr(char *, int, const char *, ...) __printflike(3, 4);
 void doformat(struct output *, const char *, va_list) __printflike(2, 0);
+FILE *out1fp(void);
 int xwrite(int, const char *, int);
 
 #define outc(c, file)  ((file)->nextc == (file)->bufend ? (emptyoutbuf(file), 
*(file)->nextc++ = (c)) : (*(file)->nextc++ = (c)))


___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r351643 - in head/cddl/contrib/opensolaris/cmd/dtrace/test/tst/common: dtraceUtil speculation

2019-09-03 Thread Jilles Tjoelker
On Tue, Sep 03, 2019 at 06:42:00PM +0800, Li-Wen Hsu wrote:
> On Mon, Sep 2, 2019 at 11:49 PM Rodney W. Grimes
>  wrote:

> > > > On Aug 31, 2019, at 16:29, Warner Losh  wrote:

> > > >> On Sat, Aug 31, 2019 at 5:29 PM Conrad Meyer  wrote:
> > > >> Thanks Li-Wen!  Might it be less fragile to have the test fixture
> > > >> create a file, if the test(s) will expect one to be present to read?

> > > > Or just use the realpath $0, which you know has to exist :)

> > > I don?t know if this would work, with other some of the dtrace
> > > tests are called. Plus, that relies on a FreeBSD utility which
> > > doesn?t necessarily exist on Linux and I don?t think exists on
> > > IllumOS.

> > > It makes more sense to create a file with mktemp and test for it
> > > in the loop to make the tests portable over to IllumOS, since
> > > that?s where they originally came from and can be contributed back
> > > to.

> > Agreed, especially if these tests are expected to be portable the
> > assumption of existance of /COPYRIGHT is a mistake/bug.

> Thanks for the inputs.  Indeed, depending on any irrelevant files or
> FreeBSD specified tools both do not sound a good solution.  After
> reading these test cases again, I feel that creating a temp file might
> be slightly over engineering because in the end we also need to take
> care of cleaning, in normal and abnormal exiting cases.  In these
> tests, we only need someone calls open(2) and read(2).

> How about changing them to `cat / > /dev/null` ?

Reading a directory as bytes is not portable. For example, FreeBSD
fdescfs and nfs do not allow it, and Linux does not allow it at all.

Apart from the fact that the resulting bytes depend on the filesystem
type, this operation is problematic because it may expose filenames that
were previously deleted.

The files /etc/group and /etc/passwd exist on most operating systems,
but for optimal portability a temporary file seems unavoidable (assuming
that data must come from a regular file).

-- 
Jilles Tjoelker
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r350658 - head/tests/sys/kern

2019-08-06 Thread Jilles Tjoelker
Author: jilles
Date: Tue Aug  6 21:17:22 2019
New Revision: 350658
URL: https://svnweb.freebsd.org/changeset/base/350658

Log:
  Add a test for kill() on a zombie

Added:
  head/tests/sys/kern/kill_zombie.c   (contents, props changed)
Modified:
  head/tests/sys/kern/Makefile

Modified: head/tests/sys/kern/Makefile
==
--- head/tests/sys/kern/MakefileTue Aug  6 20:21:57 2019
(r350657)
+++ head/tests/sys/kern/MakefileTue Aug  6 21:17:22 2019
(r350658)
@@ -8,6 +8,7 @@ TESTSDIR=   ${TESTSBASE}/sys/kern
 #ATF_TESTS_C+= kcov
 ATF_TESTS_C+=  kern_copyin
 ATF_TESTS_C+=  kern_descrip_test
+ATF_TESTS_C+=  kill_zombie
 ATF_TESTS_C+=  ptrace_test
 TEST_METADATA.ptrace_test+=timeout="15"
 ATF_TESTS_C+=  reaper

Added: head/tests/sys/kern/kill_zombie.c
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/tests/sys/kern/kill_zombie.c   Tue Aug  6 21:17:22 2019
(r350658)
@@ -0,0 +1,65 @@
+/*-
+ * Copyright (c) 2018 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(kill_zombie);
+ATF_TC_BODY(kill_zombie, tc)
+{
+   pid_t child, pid;
+   int status, r;
+
+   child = fork();
+   ATF_REQUIRE(child != -1);
+   if (child == 0) {
+   _exit(42);
+   }
+
+   r = waitid(P_PID, child, NULL, WEXITED | WNOWAIT);
+   ATF_REQUIRE(r == 0);
+
+   r = kill(child, SIGTERM);
+   ATF_CHECK(r == 0);
+
+   status = -1;
+   pid = waitpid(child, , 0);
+   ATF_REQUIRE(pid == child);
+   ATF_CHECK(WIFEXITED(status) && WEXITSTATUS(status) == 42);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+   ATF_TP_ADD_TC(tp, kill_zombie);
+   return (atf_no_error());
+}
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r350615 - stable/11/usr.bin/printf

2019-08-05 Thread Jilles Tjoelker
Author: jilles
Date: Mon Aug  5 20:21:35 2019
New Revision: 350615
URL: https://svnweb.freebsd.org/changeset/base/350615

Log:
  MFC r350425: printf(1): Note that \c only works in %b strings
  
  PR:   238313

Modified:
  stable/11/usr.bin/printf/printf.1
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.bin/printf/printf.1
==
--- stable/11/usr.bin/printf/printf.1   Mon Aug  5 20:20:14 2019
(r350614)
+++ stable/11/usr.bin/printf/printf.1   Mon Aug  5 20:21:35 2019
(r350615)
@@ -31,7 +31,7 @@
 .\"@(#)printf.18.1 (Berkeley) 6/6/93
 .\" $FreeBSD$
 .\"
-.Dd April 21, 2014
+.Dd July 29, 2019
 .Dt PRINTF 1
 .Os
 .Sh NAME
@@ -87,8 +87,6 @@ are as follows:
 Write a  character.
 .It Cm \eb
 Write a  character.
-.It Cm \ec
-Ignore remaining characters in this string.
 .It Cm \ef
 Write a  character.
 .It Cm \en
@@ -289,7 +287,12 @@ The permitted escape sequences are slightly different 
 octal escapes are
 .Cm \e0 Ns Ar num
 instead of
-.Cm \e Ns Ar num .
+.Cm \e Ns Ar num
+and that an additional escape sequence
+.Cm \ec
+stops further output from this
+.Nm
+invocation.
 .It Cm n$
 Allows reordering of the output according to
 .Ar argument .
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r350613 - stable/12/usr.bin/printf

2019-08-05 Thread Jilles Tjoelker
Author: jilles
Date: Mon Aug  5 20:19:38 2019
New Revision: 350613
URL: https://svnweb.freebsd.org/changeset/base/350613

Log:
  MFC r350425: printf(1): Note that \c only works in %b strings
  
  PR:   238313

Modified:
  stable/12/usr.bin/printf/printf.1
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/usr.bin/printf/printf.1
==
--- stable/12/usr.bin/printf/printf.1   Mon Aug  5 20:15:46 2019
(r350612)
+++ stable/12/usr.bin/printf/printf.1   Mon Aug  5 20:19:38 2019
(r350613)
@@ -31,7 +31,7 @@
 .\"@(#)printf.18.1 (Berkeley) 6/6/93
 .\" $FreeBSD$
 .\"
-.Dd April 21, 2014
+.Dd July 29, 2019
 .Dt PRINTF 1
 .Os
 .Sh NAME
@@ -87,8 +87,6 @@ are as follows:
 Write a  character.
 .It Cm \eb
 Write a  character.
-.It Cm \ec
-Ignore remaining characters in this string.
 .It Cm \ef
 Write a  character.
 .It Cm \en
@@ -289,7 +287,12 @@ The permitted escape sequences are slightly different 
 octal escapes are
 .Cm \e0 Ns Ar num
 instead of
-.Cm \e Ns Ar num .
+.Cm \e Ns Ar num
+and that an additional escape sequence
+.Cm \ec
+stops further output from this
+.Nm
+invocation.
 .It Cm n$
 Allows reordering of the output according to
 .Ar argument .
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r350425 - head/usr.bin/printf

2019-07-29 Thread Jilles Tjoelker
Author: jilles
Date: Mon Jul 29 20:43:07 2019
New Revision: 350425
URL: https://svnweb.freebsd.org/changeset/base/350425

Log:
  printf(1): Note that \c only works in %b strings
  
  PR:   238313
  Reported by:  Andras Farkas
  MFC after:1 week

Modified:
  head/usr.bin/printf/printf.1

Modified: head/usr.bin/printf/printf.1
==
--- head/usr.bin/printf/printf.1Mon Jul 29 20:41:11 2019
(r350424)
+++ head/usr.bin/printf/printf.1Mon Jul 29 20:43:07 2019
(r350425)
@@ -31,7 +31,7 @@
 .\"@(#)printf.18.1 (Berkeley) 6/6/93
 .\" $FreeBSD$
 .\"
-.Dd April 21, 2014
+.Dd July 29, 2019
 .Dt PRINTF 1
 .Os
 .Sh NAME
@@ -87,8 +87,6 @@ are as follows:
 Write a  character.
 .It Cm \eb
 Write a  character.
-.It Cm \ec
-Ignore remaining characters in this string.
 .It Cm \ef
 Write a  character.
 .It Cm \en
@@ -289,7 +287,12 @@ The permitted escape sequences are slightly different 
 octal escapes are
 .Cm \e0 Ns Ar num
 instead of
-.Cm \e Ns Ar num .
+.Cm \e Ns Ar num
+and that an additional escape sequence
+.Cm \ec
+stops further output from this
+.Nm
+invocation.
 .It Cm n$
 Allows reordering of the output according to
 .Ar argument .
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r349974 - head/libexec/rc/rc.d

2019-07-28 Thread Jilles Tjoelker
On Sat, Jul 13, 2019 at 04:07:38PM +, Ian Lepore wrote:
> Author: ian
> Date: Sat Jul 13 16:07:38 2019
> New Revision: 349974
> URL: https://svnweb.freebsd.org/changeset/base/349974

> Log:
>   Limit access to system accounting files.

>   In 2013 the security chapter of the Handbook was updated in r42501 to
>   suggest limiting access to the system accounting file [*1] by creating the
>   initial file with a mode of 0600. This was in part based on a discussion in
>   the forums [*2]. Unfortunately, this advice is overridden by the fact that a
>   new file is created as part of periodic daily processing, and the file mode
>   is set by the rc.d/accounting script.

>   These changes update the accounting script to create the directory with mode
>   0750 if it doesn't already exist, and to create the daily file with mode
>   0640. This limits write access to root only, read access to root and members
>   of wheel, and eliminates world access completely. For admins who want to
>   prevent even members of wheel from accessing the files, the mode of the
>   /var/account directory can be manually changed to 0700, because the script
>   never creates or changes that directory if it already exists.

I like it. However, the /var/account directory is normally created by
mtree: etc/mtree/BSD.var.dist. Perhaps the permissions should be
adjusted there as well.

-- 
Jilles Tjoelker
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r350116 - head/lib/libc/gen

2019-07-19 Thread Jilles Tjoelker
On Thu, Jul 18, 2019 at 09:41:15PM +, Brooks Davis wrote:
> On Thu, Jul 18, 2019 at 09:33:56PM +, Brooks Davis wrote:
> > Author: brooks
> > Date: Thu Jul 18 21:33:55 2019
> > New Revision: 350116
> > URL: https://svnweb.freebsd.org/changeset/base/350116

> > Log:
> >   Document that setmode(3) is not thread safe.

> >   In some circumstances, setmode(3) may call umask(2) twice to retrieve
> >   the current mode and then restore it.  Between calls, the process will
> >   have a umask of 0.

> This race isn't especially serious, since it only occurs when
> security.bsd.unprivileged_proc_debug=0, but it's probably something to
> fix.  The easiest solution would probably be to implement a getumask()
> syscall.

Or make the KERN_PROC_UMASK sysctl work on the process itself even if
security.bsd.unprivileged_proc_debug=0. This security sysctl is
currently also lowering security.

-- 
Jilles Tjoelker
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r346017 - in head: libexec/rc libexec/rc/rc.d share/man/man5

2019-04-09 Thread Jilles Tjoelker
On Tue, Apr 09, 2019 at 10:24:16PM +0100, Chris Rees wrote:
> On 9 April 2019 22:13:29 BST, Chris Rees  wrote:
> >On 9 April 2019 22:08:35 BST, "Rodney W. Grimes"
> > wrote:
> >>> On 09/04/2019 20:59, Chris Rees wrote:
> >>> > On 9 April 2019 20:55:07 BST, "Rodney W. Grimes"
> >> wrote:
> >>> >>> On 09/04/2019 21:33, Rodney W. Grimes wrote:
> >>> >>>> I think the trigger issue is:
> >>> >>>> grep zfs /etc/rc.d/zvol
> >>> >>>> rcvar="zfs_enable"
> >>> >>>> required_modules="zfs"

> >>> >>>> that module requires may be going south with the
> >>> >>>> new code when the module is built into the kernel.
> >>> >>> Maybe it's because the module's name is zfsctrl (for whatever
> >>reason)
> >>> >> while the
> >>> >>> module file is named zfs.ko.
> >>> >> I suspect that could also lead to issues with the new code.
> >>> >> It seems to be failing to detect that zfs is infact functional in
> >>the
> >>> >> kernel,
> >>> >> and blindly, or not so blindly, trying to load zfs,ko, which when
> >>you
> >>> >> build
> >>> >> it into the kernel you usually do so without any modules built,
> >so
> >>> >> there is
> >>> >> no /boot/kernel/zfs.ko, and even if you did build it any attempt
> >>to
> >>> >> load
> >>> >> it would return an error.
> >>> > Loading with it built in isn't a problem, as I showed earlier.

> >>> > Loading when it doesn't exist *is*.

> >>> > I'm torn.  Either we could revert this, or add a check to the
> >>required_modules function instead, which I think is the better solution.

> >>> Hang on,

> >>> [crees@pegasus]~% sudo kldload -n zfsctrl && echo yes
> >>> yes

> >>I think your testing the return value of sudo here?

> >Sudo returns the child's return value.

> Turns out Oliver had also reported this to current@ with a log

> https://lists.freebsd.org/pipermail/freebsd-current/2019-April/073148.html

> Jilles@, mind if I revert this while I get some testing on this
> scenario done?

> It seems to me that zfs may not be included in the kernel, just
> zfsctrl, or something like that.

It seems like kldload -n does not work as expected for zfs, so reverting
seems the right approach.

-- 
Jilles Tjoelker
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r345617 - stable/11/bin/sh

2019-03-27 Thread Jilles Tjoelker
Author: jilles
Date: Wed Mar 27 22:09:35 2019
New Revision: 345617
URL: https://svnweb.freebsd.org/changeset/base/345617

Log:
  MFC r344306: sh: Send normal output from bind builtin to stdout
  
  PR:   233343

Modified:
  stable/11/bin/sh/histedit.c
  stable/11/bin/sh/output.c
  stable/11/bin/sh/output.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/bin/sh/histedit.c
==
--- stable/11/bin/sh/histedit.c Wed Mar 27 22:05:57 2019(r345616)
+++ stable/11/bin/sh/histedit.c Wed Mar 27 22:09:35 2019(r345617)
@@ -474,10 +474,31 @@ str_to_event(const char *str, int last)
 int
 bindcmd(int argc, char **argv)
 {
+   int ret;
+   FILE *old;
+   FILE *out;
 
if (el == NULL)
error("line editing is disabled");
-   return (el_parse(el, argc, __DECONST(const char **, argv)));
+
+   INTOFF;
+
+   out = out1fp();
+   if (out == NULL)
+   error("Out of space");
+
+   el_get(el, EL_GETFP, 1, );
+   el_set(el, EL_SETFP, 1, out);
+
+   ret = el_parse(el, argc, __DECONST(const char **, argv));
+
+   el_set(el, EL_SETFP, 1, old);
+
+   fclose(out);
+
+   INTON;
+
+   return ret;
 }
 
 #else

Modified: stable/11/bin/sh/output.c
==
--- stable/11/bin/sh/output.c   Wed Mar 27 22:05:57 2019(r345616)
+++ stable/11/bin/sh/output.c   Wed Mar 27 22:09:35 2019(r345617)
@@ -345,6 +345,12 @@ doformat(struct output *dest, const char *f, va_list a
}
 }
 
+FILE *
+out1fp(void)
+{
+   return fwopen(out1, doformat_wr);
+}
+
 /*
  * Version of write which resumes after a signal is caught.
  */

Modified: stable/11/bin/sh/output.h
==
--- stable/11/bin/sh/output.h   Wed Mar 27 22:05:57 2019(r345616)
+++ stable/11/bin/sh/output.h   Wed Mar 27 22:09:35 2019(r345617)
@@ -37,6 +37,7 @@
 
 #include 
 #include 
+#include 
 
 struct output {
char *nextc;
@@ -73,6 +74,7 @@ void out1fmt(const char *, ...) __printflike(1, 2);
 void out2fmt_flush(const char *, ...) __printflike(1, 2);
 void fmtstr(char *, int, const char *, ...) __printflike(3, 4);
 void doformat(struct output *, const char *, va_list) __printflike(2, 0);
+FILE *out1fp(void);
 int xwrite(int, const char *, int);
 
 #define outc(c, file)  (--(file)->nleft < 0? (emptyoutbuf(file), 
*(file)->nextc++ = (c)) : (*(file)->nextc++ = (c)))
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r345613 - stable/12/bin/sh

2019-03-27 Thread Jilles Tjoelker
Author: jilles
Date: Wed Mar 27 21:53:44 2019
New Revision: 345613
URL: https://svnweb.freebsd.org/changeset/base/345613

Log:
  MFC r344306: sh: Send normal output from bind builtin to stdout
  
  PR:   233343

Modified:
  stable/12/bin/sh/histedit.c
  stable/12/bin/sh/output.c
  stable/12/bin/sh/output.h
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/bin/sh/histedit.c
==
--- stable/12/bin/sh/histedit.c Wed Mar 27 21:50:07 2019(r345612)
+++ stable/12/bin/sh/histedit.c Wed Mar 27 21:53:44 2019(r345613)
@@ -474,10 +474,31 @@ str_to_event(const char *str, int last)
 int
 bindcmd(int argc, char **argv)
 {
+   int ret;
+   FILE *old;
+   FILE *out;
 
if (el == NULL)
error("line editing is disabled");
-   return (el_parse(el, argc, __DECONST(const char **, argv)));
+
+   INTOFF;
+
+   out = out1fp();
+   if (out == NULL)
+   error("Out of space");
+
+   el_get(el, EL_GETFP, 1, );
+   el_set(el, EL_SETFP, 1, out);
+
+   ret = el_parse(el, argc, __DECONST(const char **, argv));
+
+   el_set(el, EL_SETFP, 1, old);
+
+   fclose(out);
+
+   INTON;
+
+   return ret;
 }
 
 #else

Modified: stable/12/bin/sh/output.c
==
--- stable/12/bin/sh/output.c   Wed Mar 27 21:50:07 2019(r345612)
+++ stable/12/bin/sh/output.c   Wed Mar 27 21:53:44 2019(r345613)
@@ -340,6 +340,12 @@ doformat(struct output *dest, const char *f, va_list a
}
 }
 
+FILE *
+out1fp(void)
+{
+   return fwopen(out1, doformat_wr);
+}
+
 /*
  * Version of write which resumes after a signal is caught.
  */

Modified: stable/12/bin/sh/output.h
==
--- stable/12/bin/sh/output.h   Wed Mar 27 21:50:07 2019(r345612)
+++ stable/12/bin/sh/output.h   Wed Mar 27 21:53:44 2019(r345613)
@@ -39,6 +39,7 @@
 
 #include 
 #include 
+#include 
 
 struct output {
char *nextc;
@@ -75,6 +76,7 @@ void out1fmt(const char *, ...) __printflike(1, 2);
 void out2fmt_flush(const char *, ...) __printflike(1, 2);
 void fmtstr(char *, int, const char *, ...) __printflike(3, 4);
 void doformat(struct output *, const char *, va_list) __printflike(2, 0);
+FILE *out1fp(void);
 int xwrite(int, const char *, int);
 
 #define outc(c, file)  ((file)->nextc == (file)->bufend ? (emptyoutbuf(file), 
*(file)->nextc++ = (c)) : (*(file)->nextc++ = (c)))
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r345561 - in stable/11/bin/sh: . tests/execution

2019-03-26 Thread Jilles Tjoelker
Author: jilles
Date: Tue Mar 26 22:34:07 2019
New Revision: 345561
URL: https://svnweb.freebsd.org/changeset/base/345561

Log:
  MFC r344502: sh: Add set -o pipefail
  
  The pipefail option allows checking the exit status of all commands in a
  pipeline more easily, at a limited cost of complexity in sh itself. It works
  similarly to the option in bash, ksh93 and mksh.
  
  Like ksh93 and unlike bash and mksh, the state of the option is saved when a
  pipeline is started. Therefore, even in the case of commands like
A | B &
  a later change of the option does not change the exit status, the same way
(A | B) &
  works.
  
  Since SIGPIPE is not handled specially, more work in the script is required
  for a proper exit status for pipelines containing commands such as head that
  may terminate successfully without reading all input. This can be something
  like
  
  (
cmd1
r=$?
if [ "$r" -gt 128 ] && [ "$(kill -l "$r")" = PIPE ]; then
exit 0
else
exit "$r"
fi
  ) | head
  
  PR:   224270
  Relnotes: yes

Added:
  stable/11/bin/sh/tests/execution/pipefail1.0
 - copied unchanged from r344502, head/bin/sh/tests/execution/pipefail1.0
  stable/11/bin/sh/tests/execution/pipefail2.42
 - copied unchanged from r344502, head/bin/sh/tests/execution/pipefail2.42
  stable/11/bin/sh/tests/execution/pipefail3.42
 - copied unchanged from r344502, head/bin/sh/tests/execution/pipefail3.42
  stable/11/bin/sh/tests/execution/pipefail4.42
 - copied unchanged from r344502, head/bin/sh/tests/execution/pipefail4.42
  stable/11/bin/sh/tests/execution/pipefail5.42
 - copied unchanged from r344502, head/bin/sh/tests/execution/pipefail5.42
  stable/11/bin/sh/tests/execution/pipefail6.42
 - copied unchanged from r344502, head/bin/sh/tests/execution/pipefail6.42
  stable/11/bin/sh/tests/execution/pipefail7.0
 - copied unchanged from r344502, head/bin/sh/tests/execution/pipefail7.0
Modified:
  stable/11/bin/sh/jobs.c
  stable/11/bin/sh/options.h
  stable/11/bin/sh/sh.1
  stable/11/bin/sh/tests/execution/Makefile
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/bin/sh/jobs.c
==
--- stable/11/bin/sh/jobs.c Tue Mar 26 22:14:50 2019(r345560)
+++ stable/11/bin/sh/jobs.c Tue Mar 26 22:34:07 2019(r345561)
@@ -104,6 +104,7 @@ struct job {
char changed;   /* true if status has changed */
char foreground;/* true if running in the foreground */
char remembered;/* true if $! referenced */
+   char pipefail;  /* pass any non-zero status */
 #if JOBS
char jobctl;/* job running under job control */
struct job *next;   /* job used after this one */
@@ -143,6 +144,7 @@ static void setcurjob(struct job *);
 static void deljob(struct job *);
 static struct job *getcurjob(struct job *);
 #endif
+static int getjobstatus(const struct job *);
 static void printjobcmd(struct job *);
 static void showjob(struct job *, int);
 
@@ -340,6 +342,20 @@ jobscmd(int argc __unused, char *argv[] __unused)
return (0);
 }
 
+static int getjobstatus(const struct job *jp)
+{
+   int i, status;
+
+   if (!jp->pipefail)
+   return (jp->ps[jp->nprocs - 1].status);
+   for (i = jp->nprocs - 1; i >= 0; i--) {
+   status = jp->ps[i].status;
+   if (status != 0)
+   return (status);
+   }
+   return (0);
+}
+
 static void
 printjobcmd(struct job *jp)
 {
@@ -376,7 +392,7 @@ showjob(struct job *jp, int mode)
}
 #endif
coredump = "";
-   status = jp->ps[jp->nprocs - 1].status;
+   status = getjobstatus(jp);
if (jp->state == 0) {
statestr = "Running";
 #if JOBS
@@ -555,7 +571,7 @@ waitcmdloop(struct job *job)
do {
if (job != NULL) {
if (job->state == JOBDONE) {
-   status = job->ps[job->nprocs - 1].status;
+   status = getjobstatus(job);
if (WIFEXITED(status))
retval = WEXITSTATUS(status);
else
@@ -780,6 +796,7 @@ makejob(union node *node __unused, int nprocs)
jp->nprocs = 0;
jp->foreground = 0;
jp->remembered = 0;
+   jp->pipefail = pipefailflag;
 #if JOBS
jp->jobctl = jobctl;
jp->next = NULL;
@@ -1075,7 +1092,7 @@ waitforjob(struct job *jp, int *origstatus)
if (jp->state == JOBSTOPPED)
setcurjob(jp);
 #endif
-   status = jp->ps[jp->nprocs - 1].status;
+   status = getjobstatus(jp);
if (origstatus != NULL)
*origstatus = status;
/* convert to 8 bits */

Modified: stable/11/bin/sh/options.h

svn commit: r345559 - stable/11/bin/sh

2019-03-26 Thread Jilles Tjoelker
Author: jilles
Date: Tue Mar 26 21:30:26 2019
New Revision: 345559
URL: https://svnweb.freebsd.org/changeset/base/345559

Log:
  MFC r328818: sh: Refactor job status printing, preparing for -o pipefail and
  similar
  
  No functional change is intended.
  
  PR:   224270

Modified:
  stable/11/bin/sh/jobs.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/bin/sh/jobs.c
==
--- stable/11/bin/sh/jobs.c Tue Mar 26 21:20:42 2019(r345558)
+++ stable/11/bin/sh/jobs.c Tue Mar 26 21:30:26 2019(r345559)
@@ -362,7 +362,7 @@ showjob(struct job *jp, int mode)
const char *statestr, *coredump;
struct procstat *ps;
struct job *j;
-   int col, curr, i, jobno, prev, procno;
+   int col, curr, i, jobno, prev, procno, status;
char c;
 
procno = (mode == SHOWJOBS_PGIDS) ? 1 : jp->nprocs;
@@ -376,11 +376,12 @@ showjob(struct job *jp, int mode)
}
 #endif
coredump = "";
-   ps = jp->ps + jp->nprocs - 1;
+   status = jp->ps[jp->nprocs - 1].status;
if (jp->state == 0) {
statestr = "Running";
 #if JOBS
} else if (jp->state == JOBSTOPPED) {
+   ps = jp->ps + jp->nprocs - 1;
while (!WIFSTOPPED(ps->status) && ps > jp->ps)
ps--;
if (WIFSTOPPED(ps->status))
@@ -391,20 +392,20 @@ showjob(struct job *jp, int mode)
if (statestr == NULL)
statestr = "Suspended";
 #endif
-   } else if (WIFEXITED(ps->status)) {
-   if (WEXITSTATUS(ps->status) == 0)
+   } else if (WIFEXITED(status)) {
+   if (WEXITSTATUS(status) == 0)
statestr = "Done";
else {
fmtstr(statebuf, sizeof(statebuf), "Done(%d)",
-   WEXITSTATUS(ps->status));
+   WEXITSTATUS(status));
statestr = statebuf;
}
} else {
-   i = WTERMSIG(ps->status);
+   i = WTERMSIG(status);
statestr = strsignal(i);
if (statestr == NULL)
statestr = "Unknown signal";
-   if (WCOREDUMP(ps->status))
+   if (WCOREDUMP(status))
coredump = " (core dumped)";
}
 
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r345556 - stable/11/bin/sh

2019-03-26 Thread Jilles Tjoelker
Author: jilles
Date: Tue Mar 26 20:47:30 2019
New Revision: 345556
URL: https://svnweb.freebsd.org/changeset/base/345556

Log:
  MFC r327475: sh: Move various structs from jobs.h to jobs.c
  
  These implementation details of jobs.c need not be exposed.
  
  PR:   224270

Modified:
  stable/11/bin/sh/jobs.c
  stable/11/bin/sh/jobs.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/bin/sh/jobs.c
==
--- stable/11/bin/sh/jobs.c Tue Mar 26 20:44:02 2019(r34)
+++ stable/11/bin/sh/jobs.c Tue Mar 26 20:47:30 2019(r345556)
@@ -75,6 +75,42 @@ __FBSDID("$FreeBSD$");
 #include "builtins.h"
 
 
+/*
+ * A job structure contains information about a job.  A job is either a
+ * single process or a set of processes contained in a pipeline.  In the
+ * latter case, pidlist will be non-NULL, and will point to a -1 terminated
+ * array of pids.
+ */
+
+struct procstat {
+   pid_t pid;  /* process id */
+   int status; /* status flags (defined above) */
+   char *cmd;  /* text of command being run */
+};
+
+
+/* states */
+#define JOBSTOPPED 1   /* all procs are stopped */
+#define JOBDONE 2  /* all procs are completed */
+
+
+struct job {
+   struct procstat ps0;/* status of process */
+   struct procstat *ps;/* status or processes when more than one */
+   short nprocs;   /* number of processes */
+   pid_t pgrp; /* process group of this job */
+   char state; /* true if job is finished */
+   char used;  /* true if this entry is in used */
+   char changed;   /* true if status has changed */
+   char foreground;/* true if running in the foreground */
+   char remembered;/* true if $! referenced */
+#if JOBS
+   char jobctl;/* job running under job control */
+   struct job *next;   /* job used after this one */
+#endif
+};
+
+
 static struct job *jobtab; /* array of jobs */
 static int njobs;  /* size of array */
 static pid_t backgndpid = -1;  /* pid of last background process */

Modified: stable/11/bin/sh/jobs.h
==
--- stable/11/bin/sh/jobs.h Tue Mar 26 20:44:02 2019(r34)
+++ stable/11/bin/sh/jobs.h Tue Mar 26 20:47:30 2019(r345556)
@@ -40,40 +40,7 @@
 
 #include /* for sig_atomic_t */
 
-/*
- * A job structure contains information about a job.  A job is either a
- * single process or a set of processes contained in a pipeline.  In the
- * latter case, pidlist will be non-NULL, and will point to a -1 terminated
- * array of pids.
- */
-
-struct procstat {
-   pid_t pid;  /* process id */
-   int status; /* status flags (defined above) */
-   char *cmd;  /* text of command being run */
-};
-
-
-/* states */
-#define JOBSTOPPED 1   /* all procs are stopped */
-#define JOBDONE 2  /* all procs are completed */
-
-
-struct job {
-   struct procstat ps0;/* status of process */
-   struct procstat *ps;/* status or processes when more than one */
-   short nprocs;   /* number of processes */
-   pid_t pgrp; /* process group of this job */
-   char state; /* true if job is finished */
-   char used;  /* true if this entry is in used */
-   char changed;   /* true if status has changed */
-   char foreground;/* true if running in the foreground */
-   char remembered;/* true if $! referenced */
-#if JOBS
-   char jobctl;/* job running under job control */
-   struct job *next;   /* job used after this one */
-#endif
-};
+struct job;
 
 enum {
SHOWJOBS_DEFAULT,   /* job number, status, command */
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r345487 - in stable/12/bin/sh: . tests/execution

2019-03-24 Thread Jilles Tjoelker
Author: jilles
Date: Sun Mar 24 22:10:26 2019
New Revision: 345487
URL: https://svnweb.freebsd.org/changeset/base/345487

Log:
  MFC r344502: sh: Add set -o pipefail
  
  The pipefail option allows checking the exit status of all commands in a
  pipeline more easily, at a limited cost of complexity in sh itself. It works
  similarly to the option in bash, ksh93 and mksh.
  
  Like ksh93 and unlike bash and mksh, the state of the option is saved when a
  pipeline is started. Therefore, even in the case of commands like
A | B &
  a later change of the option does not affect the exit status, the same way
(A | B) &
  works.
  
  Since SIGPIPE is not handled specially, more work in the script is required
  for a proper exit status for pipelines containing commands such as head that
  may terminate successfully without reading all input. This can be something
  like
  
  (
cmd1
r=$?
if [ "$r" -gt 128 ] && [ "$(kill -l "$r")" = PIPE ]; then
exit 0
else
exit "$r"
fi
  ) | head
  
  PR:   244270
  Relnotes: yes

Added:
  stable/12/bin/sh/tests/execution/pipefail1.0
 - copied unchanged from r344502, head/bin/sh/tests/execution/pipefail1.0
  stable/12/bin/sh/tests/execution/pipefail2.42
 - copied unchanged from r344502, head/bin/sh/tests/execution/pipefail2.42
  stable/12/bin/sh/tests/execution/pipefail3.42
 - copied unchanged from r344502, head/bin/sh/tests/execution/pipefail3.42
  stable/12/bin/sh/tests/execution/pipefail4.42
 - copied unchanged from r344502, head/bin/sh/tests/execution/pipefail4.42
  stable/12/bin/sh/tests/execution/pipefail5.42
 - copied unchanged from r344502, head/bin/sh/tests/execution/pipefail5.42
  stable/12/bin/sh/tests/execution/pipefail6.42
 - copied unchanged from r344502, head/bin/sh/tests/execution/pipefail6.42
  stable/12/bin/sh/tests/execution/pipefail7.0
 - copied unchanged from r344502, head/bin/sh/tests/execution/pipefail7.0
Modified:
  stable/12/bin/sh/jobs.c
  stable/12/bin/sh/options.h
  stable/12/bin/sh/sh.1
  stable/12/bin/sh/tests/execution/Makefile
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/bin/sh/jobs.c
==
--- stable/12/bin/sh/jobs.c Sun Mar 24 20:43:21 2019(r345486)
+++ stable/12/bin/sh/jobs.c Sun Mar 24 22:10:26 2019(r345487)
@@ -104,6 +104,7 @@ struct job {
char changed;   /* true if status has changed */
char foreground;/* true if running in the foreground */
char remembered;/* true if $! referenced */
+   char pipefail;  /* pass any non-zero status */
 #if JOBS
char jobctl;/* job running under job control */
struct job *next;   /* job used after this one */
@@ -143,6 +144,7 @@ static void setcurjob(struct job *);
 static void deljob(struct job *);
 static struct job *getcurjob(struct job *);
 #endif
+static int getjobstatus(const struct job *);
 static void printjobcmd(struct job *);
 static void showjob(struct job *, int);
 
@@ -340,6 +342,20 @@ jobscmd(int argc __unused, char *argv[] __unused)
return (0);
 }
 
+static int getjobstatus(const struct job *jp)
+{
+   int i, status;
+
+   if (!jp->pipefail)
+   return (jp->ps[jp->nprocs - 1].status);
+   for (i = jp->nprocs - 1; i >= 0; i--) {
+   status = jp->ps[i].status;
+   if (status != 0)
+   return (status);
+   }
+   return (0);
+}
+
 static void
 printjobcmd(struct job *jp)
 {
@@ -376,7 +392,7 @@ showjob(struct job *jp, int mode)
}
 #endif
coredump = "";
-   status = jp->ps[jp->nprocs - 1].status;
+   status = getjobstatus(jp);
if (jp->state == 0) {
statestr = "Running";
 #if JOBS
@@ -555,7 +571,7 @@ waitcmdloop(struct job *job)
do {
if (job != NULL) {
if (job->state == JOBDONE) {
-   status = job->ps[job->nprocs - 1].status;
+   status = getjobstatus(job);
if (WIFEXITED(status))
retval = WEXITSTATUS(status);
else
@@ -780,6 +796,7 @@ makejob(union node *node __unused, int nprocs)
jp->nprocs = 0;
jp->foreground = 0;
jp->remembered = 0;
+   jp->pipefail = pipefailflag;
 #if JOBS
jp->jobctl = jobctl;
jp->next = NULL;
@@ -1075,7 +1092,7 @@ waitforjob(struct job *jp, int *signaled)
if (jp->state == JOBSTOPPED)
setcurjob(jp);
 #endif
-   status = jp->ps[jp->nprocs - 1].status;
+   status = getjobstatus(jp);
if (signaled != NULL)
*signaled = WIFSIGNALED(status);
/* convert to 8 bits */

Modified: stable/12/bin/sh/options.h

svn commit: r345117 - in stable/12/bin/sh: . tests/expansion

2019-03-13 Thread Jilles Tjoelker
Author: jilles
Date: Wed Mar 13 21:53:10 2019
New Revision: 345117
URL: https://svnweb.freebsd.org/changeset/base/345117

Log:
  MFC r342880,r343981,r344902: sh: Fix $((-9223372036854775808))
  
  Since $((9223372036854775808)) overflows, $((-9223372036854775808)) was not
  parsed correctly (with x=-9223372036854775808, $((x)) already worked, since
  that parses the value with the minus sign in one step). Values further from
  zero are still clamped to 9223372036854775807.
  
  Also, allow the full 64 bits in octal and hexadecimal.

Added:
  stable/12/bin/sh/tests/expansion/arith15.0
 - copied, changed from r342880, head/bin/sh/tests/expansion/arith15.0
  stable/12/bin/sh/tests/expansion/arith16.0
 - copied unchanged from r343981, head/bin/sh/tests/expansion/arith16.0
  stable/12/bin/sh/tests/expansion/arith17.0
 - copied unchanged from r343981, head/bin/sh/tests/expansion/arith17.0
Modified:
  stable/12/bin/sh/arith_yacc.c
  stable/12/bin/sh/arith_yacc.h
  stable/12/bin/sh/arith_yylex.c
  stable/12/bin/sh/shell.h
  stable/12/bin/sh/tests/expansion/Makefile
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/bin/sh/arith_yacc.c
==
--- stable/12/bin/sh/arith_yacc.c   Wed Mar 13 20:29:10 2019
(r345116)
+++ stable/12/bin/sh/arith_yacc.c   Wed Mar 13 21:53:10 2019
(r345117)
@@ -104,7 +104,7 @@ static arith_t arith_lookupvarint(char *varname)
if (str == NULL || *str == '\0')
str = "0";
errno = 0;
-   result = strtoarith_t(str, , 0);
+   result = strtoarith_t(str, );
if (errno != 0 || *p != '\0')
yyerror("variable conversion error");
return result;

Modified: stable/12/bin/sh/arith_yacc.h
==
--- stable/12/bin/sh/arith_yacc.h   Wed Mar 13 20:29:10 2019
(r345116)
+++ stable/12/bin/sh/arith_yacc.h   Wed Mar 13 21:53:10 2019
(r345117)
@@ -90,4 +90,5 @@ union yystype {
 
 extern union yystype yylval;
 
+arith_t strtoarith_t(const char *restrict nptr, char **restrict endptr);
 int yylex(void);

Modified: stable/12/bin/sh/arith_yylex.c
==
--- stable/12/bin/sh/arith_yylex.c  Wed Mar 13 20:29:10 2019
(r345116)
+++ stable/12/bin/sh/arith_yylex.c  Wed Mar 13 21:53:10 2019
(r345117)
@@ -35,6 +35,8 @@
 #include 
 __FBSDID("$FreeBSD$");
 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -50,6 +52,32 @@ __FBSDID("$FreeBSD$");
 #error Arithmetic tokens are out of order.
 #endif
 
+arith_t
+strtoarith_t(const char *restrict nptr, char **restrict endptr)
+{
+   arith_t val;
+
+   while (isspace((unsigned char)*nptr))
+   nptr++;
+   switch (*nptr) {
+   case '-':
+   return strtoimax(nptr, endptr, 0);
+   case '0':
+   return (arith_t)strtoumax(nptr, endptr, 0);
+   default:
+   val = (arith_t)strtoumax(nptr, endptr, 0);
+   if (val >= 0)
+   return val;
+   else if (val == ARITH_MIN) {
+   errno = ERANGE;
+   return ARITH_MIN;
+   } else {
+   errno = ERANGE;
+   return ARITH_MAX;
+   }
+   }
+}
+
 int
 yylex(void)
 {
@@ -78,7 +106,7 @@ yylex(void)
case '7':
case '8':
case '9':
-   yylval.val = strtoarith_t(buf, , 0);
+   yylval.val = strtoarith_t(buf, );
arith_buf = end;
return ARITH_NUM;
case 'A':

Modified: stable/12/bin/sh/shell.h
==
--- stable/12/bin/sh/shell.hWed Mar 13 20:29:10 2019(r345116)
+++ stable/12/bin/sh/shell.hWed Mar 13 21:53:10 2019(r345117)
@@ -59,8 +59,6 @@
  */
 typedef intmax_t arith_t;
 #defineARITH_FORMAT_STR  "%" PRIdMAX
-#defineatoarith_t(arg)  strtoimax(arg, NULL, 0)
-#definestrtoarith_t(nptr, endptr, base)  strtoimax(nptr, endptr, base)
 #defineARITH_MIN INTMAX_MIN
 #defineARITH_MAX INTMAX_MAX
 

Modified: stable/12/bin/sh/tests/expansion/Makefile
==
--- stable/12/bin/sh/tests/expansion/Makefile   Wed Mar 13 20:29:10 2019
(r345116)
+++ stable/12/bin/sh/tests/expansion/Makefile   Wed Mar 13 21:53:10 2019
(r345117)
@@ -21,6 +21,9 @@ ${PACKAGE}FILES+= arith11.0
 ${PACKAGE}FILES+=  arith12.0
 ${PACKAGE}FILES+=  arith13.0
 ${PACKAGE}FILES+=  arith14.0

svn commit: r344902 - head/bin/sh/tests/expansion

2019-03-07 Thread Jilles Tjoelker
Author: jilles
Date: Thu Mar  7 22:51:58 2019
New Revision: 344902
URL: https://svnweb.freebsd.org/changeset/base/344902

Log:
  sh/tests: Improve failure messages of expansion/arith15.0

Modified:
  head/bin/sh/tests/expansion/arith15.0

Modified: head/bin/sh/tests/expansion/arith15.0
==
--- head/bin/sh/tests/expansion/arith15.0   Thu Mar  7 22:34:45 2019
(r344901)
+++ head/bin/sh/tests/expansion/arith15.0   Thu Mar  7 22:51:58 2019
(r344902)
@@ -12,9 +12,9 @@ check() {
 XXX=-9223372036854775808
 check "XXX"-9223372036854775808
 check "XXX - 1"9223372036854775807
-check $(($XXX - 1))9223372036854775807
-check $(($XXX - 2))9223372036854775806
-check $((0x8000 == 0x7fff)) \
+check "$XXX - 1"   9223372036854775807
+check "$XXX - 2"   9223372036854775806
+check "0x8000 == 0x7fff" \
0
 
 exit $((failures != 0))
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r344570 - head/usr.sbin/sysrc

2019-02-26 Thread Jilles Tjoelker
On Tue, Feb 26, 2019 at 04:47:59AM -0800, Rodney W. Grimes wrote:
> [ Charset UTF-8 unsupported, converting... ]
> > Author: 0mp (ports committer)
> > Date: Tue Feb 26 09:28:10 2019
> > New Revision: 344570
> > URL: https://svnweb.freebsd.org/changeset/base/344570

> > Log:
> >   sysrc.8: Pet igor and mandoc

> This only tells the source of why you changed some,
> a good commit log entry tells me that, and what it
> is that you changed.  You normally do not need to
> name the file your changed in a commit log as the
> log is attached to the file, sometimes it does make
> since to mention a file name in a log entry when you
> are describing the changes to just that file in a
> commit that includes many files.

> A better log might of been:
>   Pet igor and mandoc.  Remove unneeded .Li, use .Fx as needed,
>   escape hard stop, and sort cross references.

Naming the affected area, file or directory can be useful to make the
commit message understandable outside of its file's context without
needing to look at the diff or list of changed files. Even better, there
is a convention of making the first line of the commit message a
summary. When following this convention, displaying just the first line
of each commit's message allows a good overview of recent changes in the
whole tree. I'm happy to see that quite a few committers follow this
convention.

An extended description can follow the summary after an empty line, but
I don't think it is necessary for this commit as the information that
would be written there is obvious from the diff.

-- 
Jilles Tjoelker
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r344502 - in head/bin/sh: . tests/execution

2019-02-24 Thread Jilles Tjoelker
Author: jilles
Date: Sun Feb 24 21:05:13 2019
New Revision: 344502
URL: https://svnweb.freebsd.org/changeset/base/344502

Log:
  sh: Add set -o pipefail
  
  The pipefail option allows checking the exit status of all commands in a
  pipeline more easily, at a limited cost of complexity in sh itself. It works
  similarly to the option in bash, ksh93 and mksh.
  
  Like ksh93 and unlike bash and mksh, the state of the option is saved when a
  pipeline is started. Therefore, even in the case of commands like
A | B &
  a later change of the option does not change the exit status, the same way
(A | B) &
  works.
  
  Since SIGPIPE is not handled specially, more work in the script is required
  for a proper exit status for pipelines containing commands such as head that
  may terminate successfully without reading all input. This can be something
  like
  
  (
  cmd1
  r=$?
  if [ "$r" -gt 128 ] && [ "$(kill -l "$r")" = PIPE ]; then
  exit 0
  else
  exit "$r"
  fi
  ) | head
  
  PR:   224270
  Relnotes: yes

Added:
  head/bin/sh/tests/execution/pipefail1.0   (contents, props changed)
  head/bin/sh/tests/execution/pipefail2.42   (contents, props changed)
  head/bin/sh/tests/execution/pipefail3.42   (contents, props changed)
  head/bin/sh/tests/execution/pipefail4.42   (contents, props changed)
  head/bin/sh/tests/execution/pipefail5.42   (contents, props changed)
  head/bin/sh/tests/execution/pipefail6.42   (contents, props changed)
  head/bin/sh/tests/execution/pipefail7.0   (contents, props changed)
Modified:
  head/bin/sh/jobs.c
  head/bin/sh/options.h
  head/bin/sh/sh.1
  head/bin/sh/tests/execution/Makefile

Modified: head/bin/sh/jobs.c
==
--- head/bin/sh/jobs.c  Sun Feb 24 20:55:00 2019(r344501)
+++ head/bin/sh/jobs.c  Sun Feb 24 21:05:13 2019(r344502)
@@ -105,6 +105,7 @@ struct job {
char changed;   /* true if status has changed */
char foreground;/* true if running in the foreground */
char remembered;/* true if $! referenced */
+   char pipefail;  /* pass any non-zero status */
 #if JOBS
char jobctl;/* job running under job control */
struct job *next;   /* job used after this one */
@@ -144,6 +145,7 @@ static void setcurjob(struct job *);
 static void deljob(struct job *);
 static struct job *getcurjob(struct job *);
 #endif
+static int getjobstatus(const struct job *);
 static void printjobcmd(struct job *);
 static void showjob(struct job *, int);
 
@@ -341,6 +343,20 @@ jobscmd(int argc __unused, char *argv[] __unused)
return (0);
 }
 
+static int getjobstatus(const struct job *jp)
+{
+   int i, status;
+
+   if (!jp->pipefail)
+   return (jp->ps[jp->nprocs - 1].status);
+   for (i = jp->nprocs - 1; i >= 0; i--) {
+   status = jp->ps[i].status;
+   if (status != 0)
+   return (status);
+   }
+   return (0);
+}
+
 static void
 printjobcmd(struct job *jp)
 {
@@ -377,7 +393,7 @@ showjob(struct job *jp, int mode)
}
 #endif
coredump = "";
-   status = jp->ps[jp->nprocs - 1].status;
+   status = getjobstatus(jp);
if (jp->state == 0) {
statestr = "Running";
 #if JOBS
@@ -556,7 +572,7 @@ waitcmdloop(struct job *job)
do {
if (job != NULL) {
if (job->state == JOBDONE) {
-   status = job->ps[job->nprocs - 1].status;
+   status = getjobstatus(job);
if (WIFEXITED(status))
retval = WEXITSTATUS(status);
else
@@ -781,6 +797,7 @@ makejob(union node *node __unused, int nprocs)
jp->nprocs = 0;
jp->foreground = 0;
jp->remembered = 0;
+   jp->pipefail = pipefailflag;
 #if JOBS
jp->jobctl = jobctl;
jp->next = NULL;
@@ -1076,7 +1093,7 @@ waitforjob(struct job *jp, int *signaled)
if (jp->state == JOBSTOPPED)
setcurjob(jp);
 #endif
-   status = jp->ps[jp->nprocs - 1].status;
+   status = getjobstatus(jp);
if (signaled != NULL)
*signaled = WIFSIGNALED(status);
/* convert to 8 bits */

Modified: head/bin/sh/options.h
==
--- head/bin/sh/options.h   Sun Feb 24 20:55:00 2019(r344501)
+++ head/bin/sh/options.h   Sun Feb 24 21:05:13 2019(r344502)
@@ -67,9 +67,10 @@ struct shparam {
 #definePflag optval[17]
 #definehflag optval[18]
 #definenologflag optval[19]
+#definepipefailflag optval[20]
 
 #define NSHORTOPTS 19
-#define NOPTS  20
+#define NOPTS  21
 
 extern char 

svn commit: r344306 - head/bin/sh

2019-02-19 Thread Jilles Tjoelker
Author: jilles
Date: Tue Feb 19 21:27:30 2019
New Revision: 344306
URL: https://svnweb.freebsd.org/changeset/base/344306

Log:
  sh: Send normal output from bind builtin to stdout
  
  PR:   233343
  Submitted by: Yuichiro NAITO (original version)

Modified:
  head/bin/sh/histedit.c
  head/bin/sh/output.c
  head/bin/sh/output.h

Modified: head/bin/sh/histedit.c
==
--- head/bin/sh/histedit.c  Tue Feb 19 21:22:22 2019(r344305)
+++ head/bin/sh/histedit.c  Tue Feb 19 21:27:30 2019(r344306)
@@ -472,10 +472,31 @@ str_to_event(const char *str, int last)
 int
 bindcmd(int argc, char **argv)
 {
+   int ret;
+   FILE *old;
+   FILE *out;
 
if (el == NULL)
error("line editing is disabled");
-   return (el_parse(el, argc, __DECONST(const char **, argv)));
+
+   INTOFF;
+
+   out = out1fp();
+   if (out == NULL)
+   error("Out of space");
+
+   el_get(el, EL_GETFP, 1, );
+   el_set(el, EL_SETFP, 1, out);
+
+   ret = el_parse(el, argc, __DECONST(const char **, argv));
+
+   el_set(el, EL_SETFP, 1, old);
+
+   fclose(out);
+
+   INTON;
+
+   return ret;
 }
 
 #else

Modified: head/bin/sh/output.c
==
--- head/bin/sh/output.cTue Feb 19 21:22:22 2019(r344305)
+++ head/bin/sh/output.cTue Feb 19 21:27:30 2019(r344306)
@@ -340,6 +340,12 @@ doformat(struct output *dest, const char *f, va_list a
}
 }
 
+FILE *
+out1fp(void)
+{
+   return fwopen(out1, doformat_wr);
+}
+
 /*
  * Version of write which resumes after a signal is caught.
  */

Modified: head/bin/sh/output.h
==
--- head/bin/sh/output.hTue Feb 19 21:22:22 2019(r344305)
+++ head/bin/sh/output.hTue Feb 19 21:27:30 2019(r344306)
@@ -39,6 +39,7 @@
 
 #include 
 #include 
+#include 
 
 struct output {
char *nextc;
@@ -75,6 +76,7 @@ void out1fmt(const char *, ...) __printflike(1, 2);
 void out2fmt_flush(const char *, ...) __printflike(1, 2);
 void fmtstr(char *, int, const char *, ...) __printflike(3, 4);
 void doformat(struct output *, const char *, va_list) __printflike(2, 0);
+FILE *out1fp(void);
 int xwrite(int, const char *, int);
 
 #define outc(c, file)  ((file)->nextc == (file)->bufend ? (emptyoutbuf(file), 
*(file)->nextc++ = (c)) : (*(file)->nextc++ = (c)))
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r344237 - stable/12/sbin/dhclient

2019-02-17 Thread Jilles Tjoelker
Author: jilles
Date: Sun Feb 17 20:25:07 2019
New Revision: 344237
URL: https://svnweb.freebsd.org/changeset/base/344237

Log:
  MFC r343896,r343922: dhclient: Pass through exit status from script
  
  The wait status is translated into 8 bits the same way as the shell
  calculates $?.

Modified:
  stable/12/sbin/dhclient/dhclient.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sbin/dhclient/dhclient.c
==
--- stable/12/sbin/dhclient/dhclient.c  Sun Feb 17 18:32:19 2019
(r344236)
+++ stable/12/sbin/dhclient/dhclient.c  Sun Feb 17 20:25:07 2019
(r344237)
@@ -2350,7 +2350,8 @@ priv_script_go(void)
if (ip)
script_flush_env(ip->client);
 
-   return (wstatus & 0xff);
+   return (WIFEXITED(wstatus) ?
+   WEXITSTATUS(wstatus) : 128 + WTERMSIG(wstatus));
 }
 
 void
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r343981 - in head/bin/sh: . tests/expansion

2019-02-10 Thread Jilles Tjoelker
Author: jilles
Date: Sun Feb 10 22:23:05 2019
New Revision: 343981
URL: https://svnweb.freebsd.org/changeset/base/343981

Log:
  sh: Restore $((x)) error checking after fix for $((-9223372036854775808))
  
  SVN r342880 was designed to fix $((-9223372036854775808)) and things like
  $((0x8000)) but also broke error detection for values of
  variables without dollar sign ($((x))).
  
  For compatibility, overflow in plain literals continues to be ignored and
  the value is clamped to the boundary (except 9223372036854775808 which is
  changed to -9223372036854775808).
  
  Reviewed by:  se (although he would like error checking to be removed)
  MFC after:2 weeks
  X-MFC-with:   r342880
  Differential Revision:https://reviews.freebsd.org/D18926

Added:
  head/bin/sh/tests/expansion/arith16.0   (contents, props changed)
  head/bin/sh/tests/expansion/arith17.0   (contents, props changed)
Modified:
  head/bin/sh/arith_yacc.c
  head/bin/sh/arith_yacc.h
  head/bin/sh/arith_yylex.c
  head/bin/sh/shell.h
  head/bin/sh/tests/expansion/Makefile

Modified: head/bin/sh/arith_yacc.c
==
--- head/bin/sh/arith_yacc.cSun Feb 10 21:32:39 2019(r343980)
+++ head/bin/sh/arith_yacc.cSun Feb 10 22:23:05 2019(r343981)
@@ -104,7 +104,7 @@ static arith_t arith_lookupvarint(char *varname)
if (str == NULL || *str == '\0')
str = "0";
errno = 0;
-   result = strtoarith_t(str, , 0);
+   result = strtoarith_t(str, );
if (errno != 0 || *p != '\0')
yyerror("variable conversion error");
return result;

Modified: head/bin/sh/arith_yacc.h
==
--- head/bin/sh/arith_yacc.hSun Feb 10 21:32:39 2019(r343980)
+++ head/bin/sh/arith_yacc.hSun Feb 10 22:23:05 2019(r343981)
@@ -90,4 +90,5 @@ union yystype {
 
 extern union yystype yylval;
 
+arith_t strtoarith_t(const char *restrict nptr, char **restrict endptr);
 int yylex(void);

Modified: head/bin/sh/arith_yylex.c
==
--- head/bin/sh/arith_yylex.c   Sun Feb 10 21:32:39 2019(r343980)
+++ head/bin/sh/arith_yylex.c   Sun Feb 10 22:23:05 2019(r343981)
@@ -35,6 +35,8 @@
 #include 
 __FBSDID("$FreeBSD$");
 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -50,6 +52,32 @@ __FBSDID("$FreeBSD$");
 #error Arithmetic tokens are out of order.
 #endif
 
+arith_t
+strtoarith_t(const char *restrict nptr, char **restrict endptr)
+{
+   arith_t val;
+
+   while (isspace((unsigned char)*nptr))
+   nptr++;
+   switch (*nptr) {
+   case '-':
+   return strtoimax(nptr, endptr, 0);
+   case '0':
+   return (arith_t)strtoumax(nptr, endptr, 0);
+   default:
+   val = (arith_t)strtoumax(nptr, endptr, 0);
+   if (val >= 0)
+   return val;
+   else if (val == ARITH_MIN) {
+   errno = ERANGE;
+   return ARITH_MIN;
+   } else {
+   errno = ERANGE;
+   return ARITH_MAX;
+   }
+   }
+}
+
 int
 yylex(void)
 {
@@ -78,7 +106,7 @@ yylex(void)
case '7':
case '8':
case '9':
-   yylval.val = strtoarith_t(buf, , 0);
+   yylval.val = strtoarith_t(buf, );
arith_buf = end;
return ARITH_NUM;
case 'A':

Modified: head/bin/sh/shell.h
==
--- head/bin/sh/shell.h Sun Feb 10 21:32:39 2019(r343980)
+++ head/bin/sh/shell.h Sun Feb 10 22:23:05 2019(r343981)
@@ -59,7 +59,6 @@
  */
 typedef intmax_t arith_t;
 #defineARITH_FORMAT_STR  "%" PRIdMAX
-#definestrtoarith_t(nptr, endptr, base)  (intmax_t)strtoumax(nptr, 
endptr, base)
 #defineARITH_MIN INTMAX_MIN
 #defineARITH_MAX INTMAX_MAX
 

Modified: head/bin/sh/tests/expansion/Makefile
==
--- head/bin/sh/tests/expansion/MakefileSun Feb 10 21:32:39 2019
(r343980)
+++ head/bin/sh/tests/expansion/MakefileSun Feb 10 22:23:05 2019
(r343981)
@@ -22,6 +22,8 @@ ${PACKAGE}FILES+= arith12.0
 ${PACKAGE}FILES+=  arith13.0
 ${PACKAGE}FILES+=  arith14.0
 ${PACKAGE}FILES+=  arith15.0
+${PACKAGE}FILES+=  arith16.0
+${PACKAGE}FILES+=  arith17.0
 ${PACKAGE}FILES+=  assign1.0
 ${PACKAGE}FILES+=  cmdsubst1.0
 ${PACKAGE}FILES+=  cmdsubst2.0

Added: head/bin/sh/tests/expansion/arith16.0

svn commit: r343922 - head/sbin/dhclient

2019-02-08 Thread Jilles Tjoelker
Author: jilles
Date: Fri Feb  8 23:03:28 2019
New Revision: 343922
URL: https://svnweb.freebsd.org/changeset/base/343922

Log:
  dhclient: Return non-zero status when script exits due to a signal
  
  r343896 made it such that a non-zero exit status was passed through, but was
  still wrong if the script exits on a signal. POSIX does not say what the
  WEXITSTATUS macro returns in this case and in practice 0 is a common value.
  
  Instead, translate the wait status into 8 bits the same way as the shell
  calculates $?.
  
  Reviewed by:  kib, Nash Kaminski
  MFC after:1 week

Modified:
  head/sbin/dhclient/dhclient.c

Modified: head/sbin/dhclient/dhclient.c
==
--- head/sbin/dhclient/dhclient.c   Fri Feb  8 22:10:40 2019
(r343921)
+++ head/sbin/dhclient/dhclient.c   Fri Feb  8 23:03:28 2019
(r343922)
@@ -2348,7 +2348,8 @@ priv_script_go(void)
if (ip)
script_flush_env(ip->client);
 
-   return WEXITSTATUS(wstatus);
+   return (WIFEXITED(wstatus) ?
+   WEXITSTATUS(wstatus) : 128 + WTERMSIG(wstatus));
 }
 
 void
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r343896 - head/sbin/dhclient

2019-02-08 Thread Jilles Tjoelker
On Fri, Feb 08, 2019 at 07:36:08AM +, Konstantin Belousov wrote:
> Author: kib
> Date: Fri Feb  8 07:36:08 2019
> New Revision: 343896
> URL: https://svnweb.freebsd.org/changeset/base/343896

> Log:
>   Correctly return exit status from the exited process.

>   This is also OpenBSD rev. 1.117, as pointed out by
>   Ryan Moeller .

>   Submitted by:   Nash Kaminski 
>   MFC after:  1 week

> Modified:
>   head/sbin/dhclient/dhclient.c

> Modified: head/sbin/dhclient/dhclient.c
> ==
> --- head/sbin/dhclient/dhclient.c Fri Feb  8 06:19:28 2019
> (r343895)
> +++ head/sbin/dhclient/dhclient.c Fri Feb  8 07:36:08 2019
> (r343896)
> @@ -2348,7 +2348,7 @@ priv_script_go(void)
>   if (ip)
>   script_flush_env(ip->client);
>  
> - return (wstatus & 0xff);
> + return WEXITSTATUS(wstatus);
>  }
>  
>  void

This is probably a big improvement in practice, but it is still wrong if
the script exits on a signal. POSIX does not say what the WEXITSTATUS
macro returns in this case and in practice 0 is a common value. Perhaps
you want

return WIFEXITED(wstatus) ? WEXITSTATUS(wstatus) : 128 + WTERMSIG(wstatus);

imitating what the shell does to translate a wait status into 8 bits?

-- 
Jilles Tjoelker
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r343460 - stable/11/lib/libedit

2019-01-25 Thread Jilles Tjoelker
Author: jilles
Date: Fri Jan 25 22:52:49 2019
New Revision: 343460
URL: https://svnweb.freebsd.org/changeset/base/343460

Log:
  MFC r343105: libedit: Avoid out of bounds read in 'bind' command
  
  This is CVS revision 1.31 from NetBSD lib/libedit/chartype.c:
  Make sure that argv is NULL terminated since functions like tty_stty rely
  on it to be so (Gerry Swinslow)
  
  This broke when the wide-character support was enabled in libedit. The
  conversion from multibyte to wide-character did not supply the apparently
  expected terminating NULL in the new argv array.
  
  PR:   233343

Modified:
  stable/11/lib/libedit/chartype.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/lib/libedit/chartype.c
==
--- stable/11/lib/libedit/chartype.cFri Jan 25 22:22:29 2019
(r343459)
+++ stable/11/lib/libedit/chartype.cFri Jan 25 22:52:49 2019
(r343460)
@@ -157,7 +157,7 @@ ct_decode_argv(int argc, const char *argv[], ct_buffer
if (ct_conv_wbuff_resize(conv, bufspace + CT_BUFSIZ) == -1)
return NULL;
 
-   wargv = el_malloc((size_t)argc * sizeof(*wargv));
+   wargv = el_malloc((size_t)(argc + 1) * sizeof(*wargv));
 
for (i = 0, p = conv->wbuff; i < argc; ++i) {
if (!argv[i]) {   /* don't pass null pointers to mbstowcs */
@@ -175,6 +175,7 @@ ct_decode_argv(int argc, const char *argv[], ct_buffer
bufspace -= (size_t)bytes;
p += bytes;
}
+   wargv[i] = NULL;
 
return wargv;
 }
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r343415 - stable/12/lib/libedit

2019-01-24 Thread Jilles Tjoelker
Author: jilles
Date: Thu Jan 24 22:34:30 2019
New Revision: 343415
URL: https://svnweb.freebsd.org/changeset/base/343415

Log:
  MFC r343105: libedit: Avoid out of bounds read in 'bind' command
  
  This is CVS revision 1.31 from NetBSD lib/libedit/chartype.c:
  Make sure that argv is NULL terminated since functions like tty_stty rely
  on it to be so (Gerry Swinslow)
  
  This broke when the wide-character support was enabled in libedit. The
  conversion from multibyte to wide-character did not supply the apparently
  expected terminating NULL in the new argv array.
  
  PR:   233343

Modified:
  stable/12/lib/libedit/chartype.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/lib/libedit/chartype.c
==
--- stable/12/lib/libedit/chartype.cThu Jan 24 22:25:52 2019
(r343414)
+++ stable/12/lib/libedit/chartype.cThu Jan 24 22:34:30 2019
(r343415)
@@ -157,7 +157,7 @@ ct_decode_argv(int argc, const char *argv[], ct_buffer
if (ct_conv_wbuff_resize(conv, bufspace + CT_BUFSIZ) == -1)
return NULL;
 
-   wargv = el_malloc((size_t)argc * sizeof(*wargv));
+   wargv = el_malloc((size_t)(argc + 1) * sizeof(*wargv));
 
for (i = 0, p = conv->wbuff; i < argc; ++i) {
if (!argv[i]) {   /* don't pass null pointers to mbstowcs */
@@ -175,6 +175,7 @@ ct_decode_argv(int argc, const char *argv[], ct_buffer
bufspace -= (size_t)bytes;
p += bytes;
}
+   wargv[i] = NULL;
 
return wargv;
 }
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r343215 - head/bin/sh

2019-01-20 Thread Jilles Tjoelker
Author: jilles
Date: Sun Jan 20 14:25:25 2019
New Revision: 343215
URL: https://svnweb.freebsd.org/changeset/base/343215

Log:
  sh: Send libedit "ferr" output to fd 2
  
  The libedit "fout" output must be sent to fd 2 since it contains prompts
  that POSIX says must be sent to fd 2. However, the libedit "ferr" output
  receives error messages such as from "bind" that make no sense to send to fd
  1.

Modified:
  head/bin/sh/histedit.c

Modified: head/bin/sh/histedit.c
==
--- head/bin/sh/histedit.c  Sun Jan 20 14:02:54 2019(r343214)
+++ head/bin/sh/histedit.c  Sun Jan 20 14:25:25 2019(r343215)
@@ -67,7 +67,7 @@ __FBSDID("$FreeBSD$");
 History *hist; /* history cookie */
 EditLine *el;  /* editline cookie */
 int displayhist;
-static FILE *el_in, *el_out, *el_err;
+static FILE *el_in, *el_out;
 
 static char *fc_replace(const char *, char *, char *);
 static int not_fcnumber(const char *);
@@ -106,18 +106,16 @@ histedit(void)
INTOFF;
if (el_in == NULL)
el_in = fdopen(0, "r");
-   if (el_err == NULL)
-   el_err = fdopen(1, "w");
if (el_out == NULL)
el_out = fdopen(2, "w");
-   if (el_in == NULL || el_err == NULL || el_out == NULL)
+   if (el_in == NULL || el_out == NULL)
goto bad;
term = lookupvar("TERM");
if (term)
setenv("TERM", term, 1);
else
unsetenv("TERM");
-   el = el_init(arg0, el_in, el_out, el_err);
+   el = el_init(arg0, el_in, el_out, el_out);
if (el != NULL) {
if (hist)
el_set(el, EL_HIST, history, hist);
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r343105 - head/lib/libedit

2019-01-16 Thread Jilles Tjoelker
Author: jilles
Date: Wed Jan 16 21:59:18 2019
New Revision: 343105
URL: https://svnweb.freebsd.org/changeset/base/343105

Log:
  libedit: Avoid out of bounds read in 'bind' command
  
  This is CVS revision 1.31 from NetBSD lib/libedit/chartype.c:
  Make sure that argv is NULL terminated since functions like tty_stty rely
  on it to be so (Gerry Swinslow)
  
  This broke when the wide-character support was enabled in libedit. The
  conversion from multibyte to wide-character did not supply the apparently
  expected terminating NULL in the new argv array.
  
  PR:   233343
  Submitted by: Yuichiro NAITO
  Obtained from:NetBSD
  MFC after:1 week

Modified:
  head/lib/libedit/chartype.c

Modified: head/lib/libedit/chartype.c
==
--- head/lib/libedit/chartype.c Wed Jan 16 21:13:50 2019(r343104)
+++ head/lib/libedit/chartype.c Wed Jan 16 21:59:18 2019(r343105)
@@ -157,7 +157,7 @@ ct_decode_argv(int argc, const char *argv[], ct_buffer
if (ct_conv_wbuff_resize(conv, bufspace + CT_BUFSIZ) == -1)
return NULL;
 
-   wargv = el_malloc((size_t)argc * sizeof(*wargv));
+   wargv = el_malloc((size_t)(argc + 1) * sizeof(*wargv));
 
for (i = 0, p = conv->wbuff; i < argc; ++i) {
if (!argv[i]) {   /* don't pass null pointers to mbstowcs */
@@ -175,6 +175,7 @@ ct_decode_argv(int argc, const char *argv[], ct_buffer
bufspace -= (size_t)bytes;
p += bytes;
}
+   wargv[i] = NULL;
 
return wargv;
 }
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r343003 - stable/11/usr.bin/getconf

2019-01-13 Thread Jilles Tjoelker
Author: jilles
Date: Sun Jan 13 18:48:13 2019
New Revision: 343003
URL: https://svnweb.freebsd.org/changeset/base/343003

Log:
  MFC r342817: getconf(1): Minor mdoc fix

Modified:
  stable/11/usr.bin/getconf/getconf.1
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.bin/getconf/getconf.1
==
--- stable/11/usr.bin/getconf/getconf.1 Sun Jan 13 18:47:37 2019
(r343002)
+++ stable/11/usr.bin/getconf/getconf.1 Sun Jan 13 18:48:13 2019
(r343003)
@@ -70,7 +70,7 @@ Otherwise,
 all system configuration variables are reported using
 .Xr confstr 3
 and
-.Xr sysconf 3.
+.Xr sysconf 3 .
 .Pp
 The second form of the command, with two mandatory
 arguments, retrieves file- and file system-specific
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r343001 - stable/12/lib/libc/sys

2019-01-13 Thread Jilles Tjoelker
Author: jilles
Date: Sun Jan 13 13:57:56 2019
New Revision: 343001
URL: https://svnweb.freebsd.org/changeset/base/343001

Log:
  MFC r342816: thr_wake(2): Minor mdoc fixes

Modified:
  stable/12/lib/libc/sys/thr_wake.2
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/lib/libc/sys/thr_wake.2
==
--- stable/12/lib/libc/sys/thr_wake.2   Sun Jan 13 13:57:11 2019
(r343000)
+++ stable/12/lib/libc/sys/thr_wake.2   Sun Jan 13 13:57:56 2019
(r343001)
@@ -67,7 +67,7 @@ of that thread in the kernel to fail immediately with 
 .Er EINTR
 error.
 The flag is cleared by an interruptible sleep attempt or by a call to
-.Xr thr_suspend 2.
+.Xr thr_suspend 2 .
 This is used by the system threading library to implement cancellation.
 .Pp
 If
@@ -96,7 +96,7 @@ of the calling thread.
 .El
 .Sh SEE ALSO
 .Xr ps 1 ,
-.Xr thr_self 2
+.Xr thr_self 2 ,
 .Xr thr_suspend 2 ,
 .Xr pthread_cancel 3 ,
 .Xr pthread_resume_np 3 ,
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r343002 - stable/11/lib/libc/sys

2019-01-13 Thread Jilles Tjoelker
Author: jilles
Date: Sun Jan 13 18:47:37 2019
New Revision: 343002
URL: https://svnweb.freebsd.org/changeset/base/343002

Log:
  MFC r342816: thr_wake(2): Minor mdoc fixes

Modified:
  stable/11/lib/libc/sys/thr_wake.2
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/lib/libc/sys/thr_wake.2
==
--- stable/11/lib/libc/sys/thr_wake.2   Sun Jan 13 13:57:56 2019
(r343001)
+++ stable/11/lib/libc/sys/thr_wake.2   Sun Jan 13 18:47:37 2019
(r343002)
@@ -67,7 +67,7 @@ of that thread in the kernel to fail immediately with 
 .Er EINTR
 error.
 The flag is cleared by an interruptible sleep attempt or by a call to
-.Xr thr_suspend 2.
+.Xr thr_suspend 2 .
 This is used by the system threading library to implement cancellation.
 .Pp
 If
@@ -96,7 +96,7 @@ of the calling thread.
 .El
 .Sh SEE ALSO
 .Xr ps 1 ,
-.Xr thr_self 2
+.Xr thr_self 2 ,
 .Xr thr_suspend 2 ,
 .Xr pthread_cancel 3 ,
 .Xr pthread_resume_np 3 ,
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r343000 - stable/12/usr.bin/getconf

2019-01-13 Thread Jilles Tjoelker
Author: jilles
Date: Sun Jan 13 13:57:11 2019
New Revision: 343000
URL: https://svnweb.freebsd.org/changeset/base/343000

Log:
  MFC r342817: getconf(1): Minor mdoc fix

Modified:
  stable/12/usr.bin/getconf/getconf.1
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/usr.bin/getconf/getconf.1
==
--- stable/12/usr.bin/getconf/getconf.1 Sun Jan 13 12:13:08 2019
(r342999)
+++ stable/12/usr.bin/getconf/getconf.1 Sun Jan 13 13:57:11 2019
(r343000)
@@ -70,7 +70,7 @@ Otherwise,
 all system configuration variables are reported using
 .Xr confstr 3
 and
-.Xr sysconf 3.
+.Xr sysconf 3 .
 .Pp
 The second form of the command, with two mandatory
 arguments, retrieves file- and file system-specific
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r342817 - head/usr.bin/getconf

2019-01-06 Thread Jilles Tjoelker
Author: jilles
Date: Sun Jan  6 21:43:14 2019
New Revision: 342817
URL: https://svnweb.freebsd.org/changeset/base/342817

Log:
  getconf(1): Minor mdoc fix
  
  MFC after:1 week

Modified:
  head/usr.bin/getconf/getconf.1

Modified: head/usr.bin/getconf/getconf.1
==
--- head/usr.bin/getconf/getconf.1  Sun Jan  6 21:34:05 2019
(r342816)
+++ head/usr.bin/getconf/getconf.1  Sun Jan  6 21:43:14 2019
(r342817)
@@ -70,7 +70,7 @@ Otherwise,
 all system configuration variables are reported using
 .Xr confstr 3
 and
-.Xr sysconf 3.
+.Xr sysconf 3 .
 .Pp
 The second form of the command, with two mandatory
 arguments, retrieves file- and file system-specific
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r342816 - head/lib/libc/sys

2019-01-06 Thread Jilles Tjoelker
Author: jilles
Date: Sun Jan  6 21:34:05 2019
New Revision: 342816
URL: https://svnweb.freebsd.org/changeset/base/342816

Log:
  thr_wake(2): Minor mdoc fixes
  
  MFC after:1 week

Modified:
  head/lib/libc/sys/thr_wake.2

Modified: head/lib/libc/sys/thr_wake.2
==
--- head/lib/libc/sys/thr_wake.2Sun Jan  6 21:24:44 2019
(r342815)
+++ head/lib/libc/sys/thr_wake.2Sun Jan  6 21:34:05 2019
(r342816)
@@ -67,7 +67,7 @@ of that thread in the kernel to fail immediately with 
 .Er EINTR
 error.
 The flag is cleared by an interruptible sleep attempt or by a call to
-.Xr thr_suspend 2.
+.Xr thr_suspend 2 .
 This is used by the system threading library to implement cancellation.
 .Pp
 If
@@ -96,7 +96,7 @@ of the calling thread.
 .El
 .Sh SEE ALSO
 .Xr ps 1 ,
-.Xr thr_self 2
+.Xr thr_self 2 ,
 .Xr thr_suspend 2 ,
 .Xr pthread_cancel 3 ,
 .Xr pthread_resume_np 3 ,
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r342741 - head/bin/sh/tests/execution

2019-01-03 Thread Jilles Tjoelker
Author: jilles
Date: Thu Jan  3 20:23:12 2019
New Revision: 342741
URL: https://svnweb.freebsd.org/changeset/base/342741

Log:
  sh: Add test for exported but unset variables
  
  PR:   233545

Added:
  head/bin/sh/tests/execution/env1.0   (contents, props changed)
Modified:
  head/bin/sh/tests/execution/Makefile

Modified: head/bin/sh/tests/execution/Makefile
==
--- head/bin/sh/tests/execution/MakefileThu Jan  3 20:22:35 2019
(r342740)
+++ head/bin/sh/tests/execution/MakefileThu Jan  3 20:23:12 2019
(r342741)
@@ -17,6 +17,7 @@ ${PACKAGE}FILES+= bg7.0
 ${PACKAGE}FILES+=  bg8.0
 ${PACKAGE}FILES+=  bg9.0
 ${PACKAGE}FILES+=  bg10.0 bg10.0.stdout
+${PACKAGE}FILES+=  env1.0
 ${PACKAGE}FILES+=  fork1.0
 ${PACKAGE}FILES+=  fork2.0
 ${PACKAGE}FILES+=  fork3.0

Added: head/bin/sh/tests/execution/env1.0
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/bin/sh/tests/execution/env1.0  Thu Jan  3 20:23:12 2019
(r342741)
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+unset somestrangevar
+export somestrangevar
+[ "`$SH -c 'echo ${somestrangevar-unset}'`" = unset ]
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r342740 - head/bin/sh

2019-01-03 Thread Jilles Tjoelker
Author: jilles
Date: Thu Jan  3 20:22:35 2019
New Revision: 342740
URL: https://svnweb.freebsd.org/changeset/base/342740

Log:
  sh: Do not place exported but unset variables into the environment
  
  PR:   233545
  Submitted by: Jan Beich
  Obtained from:NetBSD

Modified:
  head/bin/sh/var.c

Modified: head/bin/sh/var.c
==
--- head/bin/sh/var.c   Thu Jan  3 19:35:07 2019(r342739)
+++ head/bin/sh/var.c   Thu Jan  3 20:22:35 2019(r342740)
@@ -558,13 +558,13 @@ environment(void)
nenv = 0;
for (vpp = vartab ; vpp < vartab + VTABSIZE ; vpp++) {
for (vp = *vpp ; vp ; vp = vp->next)
-   if (vp->flags & VEXPORT)
+   if ((vp->flags & (VEXPORT|VUNSET)) == VEXPORT)
nenv++;
}
ep = env = stalloc((nenv + 1) * sizeof *env);
for (vpp = vartab ; vpp < vartab + VTABSIZE ; vpp++) {
for (vp = *vpp ; vp ; vp = vp->next)
-   if (vp->flags & VEXPORT)
+   if ((vp->flags & (VEXPORT|VUNSET)) == VEXPORT)
*ep++ = vp->text;
}
*ep = NULL;
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r342572 - head/sys/kern

2018-12-28 Thread Jilles Tjoelker
Author: jilles
Date: Fri Dec 28 13:32:14 2018
New Revision: 342572
URL: https://svnweb.freebsd.org/changeset/base/342572

Log:
  pfind, pfind_any: Correct zombie logic
  
  SVN r340744 erroneously changed pfind() to return any process including
  zombies and pfind_any() to return only non-zombie processes.
  
  In particular, this caused kill() on a zombie process to fail with [ESRCH].
  There is no direct test case for this but /usr/tests/bin/sh/builtins/kill1.0
  occasionally triggers it (as reported by lwhsu).
  
  Conversely, returning zombies from pfind() seems likely to violate
  invariants and cause panics, but I have not looked at this.
  
  PR:   233646
  Reviewed by:  mjg, kib, ngie
  Differential Revision:https://reviews.freebsd.org/D18665

Modified:
  head/sys/kern/kern_proc.c

Modified: head/sys/kern/kern_proc.c
==
--- head/sys/kern/kern_proc.c   Fri Dec 28 10:10:16 2018(r342571)
+++ head/sys/kern/kern_proc.c   Fri Dec 28 13:32:14 2018(r342572)
@@ -388,7 +388,7 @@ _pfind(pid_t pid, bool zombie)
if (p->p_pid == pid) {
PROC_LOCK(p);
if (p->p_state == PRS_NEW ||
-   (zombie && p->p_state == PRS_ZOMBIE)) {
+   (!zombie && p->p_state == PRS_ZOMBIE)) {
PROC_UNLOCK(p);
p = NULL;
}
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r341767 - in stable/12/bin/sh: . tests/expansion

2018-12-09 Thread Jilles Tjoelker
Author: jilles
Date: Sun Dec  9 19:14:21 2018
New Revision: 341767
URL: https://svnweb.freebsd.org/changeset/base/341767

Log:
  MFC r341164: sh: Fix ${param?} default error message
  
  If word in ${param?word} is missing, the shell shall write a default error
  message. So expanding ${param?} when param is not set should write an error
  message like
  
  sh: param: parameter not set
  
  This was broken by r316417.
  
  PR:   233585

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

Modified: stable/12/bin/sh/expand.c
==
--- stable/12/bin/sh/expand.c   Sun Dec  9 17:55:10 2018(r341766)
+++ stable/12/bin/sh/expand.c   Sun Dec  9 19:14:21 2018(r341767)
@@ -623,10 +623,11 @@ static const char *
 subevalvar_misc(const char *p, struct nodelist **restrict argbackq,
 const char *var, int subtype, int startloc, int varflags)
 {
+   const char *end;
char *startp;
int amount;
 
-   p = argstr(p, argbackq, EXP_TILDE, NULL);
+   end = argstr(p, argbackq, EXP_TILDE, NULL);
STACKSTRNUL(expdest);
startp = stackblock() + startloc;
 
@@ -635,7 +636,7 @@ subevalvar_misc(const char *p, struct nodelist **restr
setvar(var, startp, 0);
amount = startp - expdest;
STADJUST(amount, expdest);
-   return p;
+   return end;
 
case VSQUESTION:
if (*p != CTLENDVAR) {

Modified: stable/12/bin/sh/tests/expansion/Makefile
==
--- stable/12/bin/sh/tests/expansion/Makefile   Sun Dec  9 17:55:10 2018
(r341766)
+++ stable/12/bin/sh/tests/expansion/Makefile   Sun Dec  9 19:14:21 2018
(r341767)
@@ -86,6 +86,7 @@ ${PACKAGE}FILES+= plus-minus7.0
 ${PACKAGE}FILES+=  plus-minus8.0
 ${PACKAGE}FILES+=  plus-minus9.0
 ${PACKAGE}FILES+=  question1.0
+${PACKAGE}FILES+=  question2.0
 ${PACKAGE}FILES+=  readonly1.0
 ${PACKAGE}FILES+=  redir1.0
 ${PACKAGE}FILES+=  set-u1.0

Copied: stable/12/bin/sh/tests/expansion/question2.0 (from r341164, 
head/bin/sh/tests/expansion/question2.0)
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/12/bin/sh/tests/expansion/question2.0Sun Dec  9 19:14:21 
2018(r341767, copy of r341164, head/bin/sh/tests/expansion/question2.0)
@@ -0,0 +1,11 @@
+# $FreeBSD$
+
+unset dummyvar
+msg=`(: ${dummyvar?}) 2>&1`
+r=$?
+[ "$r" != 0 ] && case $msg in
+*dummyvar?* | *?dummyvar*) : ;;
+*)
+   printf 'Bad message: [%s]\n' "$msg"
+   exit 1
+esac
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r341725 - head/bin/sh

2018-12-08 Thread Jilles Tjoelker
Author: jilles
Date: Sat Dec  8 12:49:19 2018
New Revision: 341725
URL: https://svnweb.freebsd.org/changeset/base/341725

Log:
  sh(1): Remove -c string from set builtin documentation
  
  Altering the -c string at run time does not make sense and is not possible.
  
  MFC after:1 week

Modified:
  head/bin/sh/sh.1

Modified: head/bin/sh/sh.1
==
--- head/bin/sh/sh.1Sat Dec  8 11:38:39 2018(r341724)
+++ head/bin/sh/sh.1Sat Dec  8 12:49:19 2018(r341725)
@@ -32,7 +32,7 @@
 .\"from: @(#)sh.1  8.6 (Berkeley) 5/4/95
 .\" $FreeBSD$
 .\"
-.Dd November 27, 2018
+.Dd December 8, 2018
 .Dt SH 1
 .Os
 .Sh NAME
@@ -2485,8 +2485,8 @@ lines, suitable for re-input to the shell.
 See the
 .Sx Functions
 subsection.
-.It Ic set Oo Fl /+abCEefIimnpTuVvx Oc Oo Fl /+o Ar longname Oc Oo
-.Fl c Ar string Oc Op Fl - Ar arg ...
+.It Ic set Oo Fl /+abCEefIimnpTuVvx Oc Oo Fl /+o Ar longname
+.Oc Op Fl - Ar arg ...
 The
 .Ic set
 command performs three different functions:
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r341164 - in head/bin/sh: . tests/expansion

2018-11-28 Thread Jilles Tjoelker
Author: jilles
Date: Wed Nov 28 20:03:53 2018
New Revision: 341164
URL: https://svnweb.freebsd.org/changeset/base/341164

Log:
  sh: Fix ${param?} default error message
  
  If word in ${param?word} is missing, the shell shall write a default error
  message. So expanding ${param?} when param is not set should write an error
  message like
  
  sh: param: parameter not set
  
  This was broken by r316417.
  
  PR:   233585

Added:
  head/bin/sh/tests/expansion/question2.0   (contents, props changed)
Modified:
  head/bin/sh/expand.c
  head/bin/sh/tests/expansion/Makefile

Modified: head/bin/sh/expand.c
==
--- head/bin/sh/expand.cWed Nov 28 19:54:02 2018(r341163)
+++ head/bin/sh/expand.cWed Nov 28 20:03:53 2018(r341164)
@@ -623,10 +623,11 @@ static const char *
 subevalvar_misc(const char *p, struct nodelist **restrict argbackq,
 const char *var, int subtype, int startloc, int varflags)
 {
+   const char *end;
char *startp;
int amount;
 
-   p = argstr(p, argbackq, EXP_TILDE, NULL);
+   end = argstr(p, argbackq, EXP_TILDE, NULL);
STACKSTRNUL(expdest);
startp = stackblock() + startloc;
 
@@ -635,7 +636,7 @@ subevalvar_misc(const char *p, struct nodelist **restr
setvar(var, startp, 0);
amount = startp - expdest;
STADJUST(amount, expdest);
-   return p;
+   return end;
 
case VSQUESTION:
if (*p != CTLENDVAR) {

Modified: head/bin/sh/tests/expansion/Makefile
==
--- head/bin/sh/tests/expansion/MakefileWed Nov 28 19:54:02 2018
(r341163)
+++ head/bin/sh/tests/expansion/MakefileWed Nov 28 20:03:53 2018
(r341164)
@@ -86,6 +86,7 @@ ${PACKAGE}FILES+= plus-minus7.0
 ${PACKAGE}FILES+=  plus-minus8.0
 ${PACKAGE}FILES+=  plus-minus9.0
 ${PACKAGE}FILES+=  question1.0
+${PACKAGE}FILES+=  question2.0
 ${PACKAGE}FILES+=  readonly1.0
 ${PACKAGE}FILES+=  redir1.0
 ${PACKAGE}FILES+=  set-u1.0

Added: head/bin/sh/tests/expansion/question2.0
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/bin/sh/tests/expansion/question2.0 Wed Nov 28 20:03:53 2018
(r341164)
@@ -0,0 +1,11 @@
+# $FreeBSD$
+
+unset dummyvar
+msg=`(: ${dummyvar?}) 2>&1`
+r=$?
+[ "$r" != 0 ] && case $msg in
+*dummyvar?* | *?dummyvar*) : ;;
+*)
+   printf 'Bad message: [%s]\n' "$msg"
+   exit 1
+esac
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r341097 - in head/bin/sh: . tests/errors

2018-11-27 Thread Jilles Tjoelker
Author: jilles
Date: Tue Nov 27 21:49:59 2018
New Revision: 341097
URL: https://svnweb.freebsd.org/changeset/base/341097

Log:
  sh: Use 126 and 127 exit status for failures opening a script
  
  This affects scripts named on the command line, named with a '.' special
  builtin and found via the PATH %func autoloading mechanism.
  
  PR:   231986

Added:
  head/bin/sh/tests/errors/script-error1.0   (contents, props changed)
Modified:
  head/bin/sh/input.c
  head/bin/sh/sh.1
  head/bin/sh/tests/errors/Makefile

Modified: head/bin/sh/input.c
==
--- head/bin/sh/input.c Tue Nov 27 21:40:51 2018(r341096)
+++ head/bin/sh/input.c Tue Nov 27 21:49:59 2018(r341097)
@@ -359,12 +359,16 @@ popstring(void)
 void
 setinputfile(const char *fname, int push)
 {
+   int e;
int fd;
int fd2;
 
INTOFF;
-   if ((fd = open(fname, O_RDONLY | O_CLOEXEC)) < 0)
-   error("cannot open %s: %s", fname, strerror(errno));
+   if ((fd = open(fname, O_RDONLY | O_CLOEXEC)) < 0) {
+   e = errno;
+   errorwithstatus(e == ENOENT || e == ENOTDIR ? 127 : 126,
+   "cannot open %s: %s", fname, strerror(e));
+   }
if (fd < 10) {
fd2 = fcntl(fd, F_DUPFD_CLOEXEC, 10);
close(fd);

Modified: head/bin/sh/sh.1
==
--- head/bin/sh/sh.1Tue Nov 27 21:40:51 2018(r341096)
+++ head/bin/sh/sh.1Tue Nov 27 21:49:59 2018(r341097)
@@ -32,7 +32,7 @@
 .\"from: @(#)sh.1  8.6 (Berkeley) 5/4/95
 .\" $FreeBSD$
 .\"
-.Dd July 19, 2018
+.Dd November 27, 2018
 .Dt SH 1
 .Os
 .Sh NAME
@@ -2819,7 +2819,11 @@ Shell database.
 Privileged shell profile.
 .El
 .Sh EXIT STATUS
-Errors that are detected by the shell, such as a syntax error, will
+If the
+.Ar script
+cannot be found, the exit status will be 127;
+if it cannot be opened for another reason, the exit status will be 126.
+Other errors that are detected by the shell, such as a syntax error, will
 cause the shell to exit with a non-zero exit status.
 If the shell is not an interactive shell, the execution of the shell
 file will be aborted.

Modified: head/bin/sh/tests/errors/Makefile
==
--- head/bin/sh/tests/errors/Makefile   Tue Nov 27 21:40:51 2018
(r341096)
+++ head/bin/sh/tests/errors/Makefile   Tue Nov 27 21:49:59 2018
(r341097)
@@ -30,6 +30,7 @@ ${PACKAGE}FILES+= redirection-error5.0
 ${PACKAGE}FILES+=  redirection-error6.0
 ${PACKAGE}FILES+=  redirection-error7.0
 ${PACKAGE}FILES+=  redirection-error8.0
+${PACKAGE}FILES+=  script-error1.0
 ${PACKAGE}FILES+=  write-error1.0
 
 .include 

Added: head/bin/sh/tests/errors/script-error1.0
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/bin/sh/tests/errors/script-error1.0Tue Nov 27 21:49:59 2018
(r341097)
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+{ stderr=$(${SH} /var/empty/nosuchscript 2>&1 >&3); } 3>&1
+r=$?
+[ -n "$stderr" ] && [ "$r" = 127 ]
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r340284 - head/bin/sh

2018-11-09 Thread Jilles Tjoelker
Author: jilles
Date: Fri Nov  9 14:58:24 2018
New Revision: 340284
URL: https://svnweb.freebsd.org/changeset/base/340284

Log:
  sh: Unify EXERROR and EXEXEC
  
  The difference between EXERROR and EXEXEC was that EXEXEC passed along
  exitstatus and EXERROR set exitstatus to 2 in the handling code.
  
  By changing the places that raised EXERROR to set exitstatus to 2, the
  handling of EXERROR and EXEXEC becomes the same.

Modified:
  head/bin/sh/TOUR
  head/bin/sh/error.c
  head/bin/sh/error.h
  head/bin/sh/eval.c
  head/bin/sh/exec.c
  head/bin/sh/jobs.c
  head/bin/sh/main.c

Modified: head/bin/sh/TOUR
==
--- head/bin/sh/TOURFri Nov  9 13:47:06 2018(r340283)
+++ head/bin/sh/TOURFri Nov  9 14:58:24 2018(r340284)
@@ -35,7 +35,7 @@ EXCEPTIONS:  Code for dealing with exceptions appears 
 exceptions.c.  The C language doesn't include exception handling,
 so I implement it using setjmp and longjmp.  The global variable
 exception contains the type of exception.  EXERROR is raised by
-calling error.  EXINT is an interrupt.
+calling error or errorwithstatus.  EXINT is an interrupt.
 
 INTERRUPTS:  In an interactive shell, an interrupt will cause an
 EXINT exception to return to the main command loop.  (Exception:

Modified: head/bin/sh/error.c
==
--- head/bin/sh/error.c Fri Nov  9 13:47:06 2018(r340283)
+++ head/bin/sh/error.c Fri Nov  9 14:58:24 2018(r340284)
@@ -67,7 +67,7 @@ volatile sig_atomic_t suppressint;
 volatile sig_atomic_t intpending;
 
 
-static void exverror(int, const char *, va_list) __printf0like(2, 0) __dead2;
+static void verrorwithstatus(int, const char *, va_list) __printf0like(2, 0) 
__dead2;
 
 /*
  * Called to raise an exception.  Since C doesn't include exceptions, we
@@ -154,7 +154,7 @@ warning(const char *msg, ...)
  * formatting.  It then raises the error exception.
  */
 static void
-exverror(int cond, const char *msg, va_list ap)
+verrorwithstatus(int status, const char *msg, va_list ap)
 {
/*
 * An interrupt trumps an error.  Certain places catch error
@@ -168,14 +168,17 @@ exverror(int cond, const char *msg, va_list ap)
 
 #ifdef DEBUG
if (msg)
-   TRACE(("exverror(%d, \"%s\") pid=%d\n", cond, msg, getpid()));
+   TRACE(("verrorwithstatus(%d, \"%s\") pid=%d\n",
+   status, msg, getpid()));
else
-   TRACE(("exverror(%d, NULL) pid=%d\n", cond, getpid()));
+   TRACE(("verrorwithstatus(%d, NULL) pid=%d\n",
+   status, getpid()));
 #endif
if (msg)
vwarning(msg, ap);
flushall();
-   exraise(cond);
+   exitstatus = status;
+   exraise(EXERROR);
 }
 
 
@@ -184,16 +187,16 @@ error(const char *msg, ...)
 {
va_list ap;
va_start(ap, msg);
-   exverror(EXERROR, msg, ap);
+   verrorwithstatus(2, msg, ap);
va_end(ap);
 }
 
 
 void
-exerror(int cond, const char *msg, ...)
+errorwithstatus(int status, const char *msg, ...)
 {
va_list ap;
va_start(ap, msg);
-   exverror(cond, msg, ap);
+   verrorwithstatus(status, msg, ap);
va_end(ap);
 }

Modified: head/bin/sh/error.h
==
--- head/bin/sh/error.h Fri Nov  9 13:47:06 2018(r340283)
+++ head/bin/sh/error.h Fri Nov  9 14:58:24 2018(r340284)
@@ -55,9 +55,8 @@ extern volatile sig_atomic_t exception;
 
 /* exceptions */
 #define EXINT 0/* SIGINT received */
-#define EXERROR 1  /* a generic error */
-#define EXEXEC 2   /* command execution failed */
-#define EXEXIT 3   /* call exitshell(exitstatus) */
+#define EXERROR 1  /* a generic error with exitstatus */
+#define EXEXIT 2   /* call exitshell(exitstatus) */
 
 
 /*
@@ -83,7 +82,7 @@ void exraise(int) __dead2;
 void onint(void) __dead2;
 void warning(const char *, ...) __printflike(1, 2);
 void error(const char *, ...) __printf0like(1, 2) __dead2;
-void exerror(int, const char *, ...) __printf0like(2, 3) __dead2;
+void errorwithstatus(int, const char *, ...) __printf0like(2, 3) __dead2;
 
 
 /*

Modified: head/bin/sh/eval.c
==
--- head/bin/sh/eval.c  Fri Nov  9 13:47:06 2018(r340283)
+++ head/bin/sh/eval.c  Fri Nov  9 14:58:24 2018(r340284)
@@ -466,13 +466,9 @@ evalredir(union node *n, int flags)
handler = savehandler;
e = exception;
popredir();
-   if (e == EXERROR || e == EXEXEC) {
-   if (in_redirect) {
-   if (e == EXERROR)
-   exitstatus = 2;
-   FORCEINTON;
-   return;
-   

svn commit: r339822 - head/bin/sh

2018-10-27 Thread Jilles Tjoelker
Author: jilles
Date: Sat Oct 27 20:17:57 2018
New Revision: 339822
URL: https://svnweb.freebsd.org/changeset/base/339822

Log:
  sh: Use exitstatus instead of exerrno to pass EXEXEC status
  
  No functional change is intended.

Modified:
  head/bin/sh/eval.c
  head/bin/sh/exec.c
  head/bin/sh/exec.h
  head/bin/sh/jobs.c
  head/bin/sh/main.c

Modified: head/bin/sh/eval.c
==
--- head/bin/sh/eval.c  Sat Oct 27 19:08:06 2018(r339821)
+++ head/bin/sh/eval.c  Sat Oct 27 20:17:57 2018(r339822)
@@ -468,7 +468,8 @@ evalredir(union node *n, int flags)
popredir();
if (e == EXERROR || e == EXEXEC) {
if (in_redirect) {
-   exitstatus = 2;
+   if (e == EXERROR)
+   exitstatus = 2;
FORCEINTON;
return;
}
@@ -669,8 +670,10 @@ evalbackcmd(union node *n, struct backcmd *result)
forcelocal++;
savehandler = handler;
if (setjmp(jmploc.loc)) {
-   if (exception == EXERROR || exception == EXEXEC)
+   if (exception == EXERROR)
exitstatus = 2;
+   else if (exception == EXEXEC)
+   /* nothing */;
else if (exception != 0) {
handler = savehandler;
forcelocal--;
@@ -1089,7 +1092,7 @@ evalcommand(union node *cmd, int flags, struct backcmd
e = exception;
if (e == EXINT)
exitstatus = SIGINT+128;
-   else if (e != EXEXIT)
+   else if (e != EXEXEC && e != EXEXIT)
exitstatus = 2;
goto cmddone;
}

Modified: head/bin/sh/exec.c
==
--- head/bin/sh/exec.c  Sat Oct 27 19:08:06 2018(r339821)
+++ head/bin/sh/exec.c  Sat Oct 27 20:17:57 2018(r339822)
@@ -91,7 +91,6 @@ struct tblentry {
 
 static struct tblentry *cmdtable[CMDTABLESIZE];
 static int cmdtable_cd = 0;/* cmdtable contains cd-dependent entries */
-int exerrno = 0;   /* Last exec error */
 
 
 static void tryexec(char *, char **, char **);
@@ -135,10 +134,10 @@ shellexec(char **argv, char **envp, const char *path, 
 
/* Map to POSIX errors */
if (e == ENOENT || e == ENOTDIR) {
-   exerrno = 127;
+   exitstatus = 127;
exerror(EXEXEC, "%s: not found", argv[0]);
} else {
-   exerrno = 126;
+   exitstatus = 126;
exerror(EXEXEC, "%s: %s", argv[0], strerror(e));
}
 }

Modified: head/bin/sh/exec.h
==
--- head/bin/sh/exec.h  Sat Oct 27 19:08:06 2018(r339821)
+++ head/bin/sh/exec.h  Sat Oct 27 20:17:57 2018(r339822)
@@ -61,8 +61,6 @@ struct cmdentry {
 #define DO_ERR 0x01/* prints errors */
 #define DO_NOFUNC  0x02/* don't return shell functions, for command */
 
-extern int exerrno;/* last exec error */
-
 void shellexec(char **, char **, const char *, int) __dead2;
 char *padvance(const char **, const char **, const char *);
 void find_command(const char *, struct cmdentry *, int, const char *);

Modified: head/bin/sh/jobs.c
==
--- head/bin/sh/jobs.c  Sat Oct 27 19:08:06 2018(r339821)
+++ head/bin/sh/jobs.c  Sat Oct 27 20:17:57 2018(r339822)
@@ -73,6 +73,7 @@ __FBSDID("$FreeBSD$");
 #include "mystring.h"
 #include "var.h"
 #include "builtins.h"
+#include "eval.h"
 
 
 /*
@@ -1005,7 +1006,7 @@ vforkexecshell(struct job *jp, char **argv, char **env
if (pid == 0) {
TRACE(("Child shell %d\n", (int)getpid()));
if (setjmp(jmploc.loc))
-   _exit(exception == EXEXEC ? exerrno : 2);
+   _exit(exception == EXEXEC ? exitstatus : 2);
if (pip != NULL) {
close(pip[0]);
if (pip[1] != 1) {

Modified: head/bin/sh/main.c
==
--- head/bin/sh/main.c  Sat Oct 27 19:08:06 2018(r339821)
+++ head/bin/sh/main.c  Sat Oct 27 20:17:57 2018(r339822)
@@ -106,10 +106,6 @@ main(int argc, char *argv[])
state = 0;
if (setjmp(main_handler.loc)) {
switch (exception) {
-   case EXEXEC:
-   exitstatus = exerrno;
-   break;

svn commit: r338995 - stable/11/bin/sh

2018-09-28 Thread Jilles Tjoelker
Author: jilles
Date: Fri Sep 28 12:29:53 2018
New Revision: 338995
URL: https://svnweb.freebsd.org/changeset/base/338995

Log:
  MFC r338473: sh: Fix formal overflow in pointer arithmetic
  
  The intention is to lower the value of the pointer, which according to ubsan
  cannot be done by adding an unsigned quantity.
  
  Reported by:  kevans

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

Modified: stable/11/bin/sh/expand.c
==
--- stable/11/bin/sh/expand.c   Fri Sep 28 11:57:40 2018(r338994)
+++ stable/11/bin/sh/expand.c   Fri Sep 28 12:29:53 2018(r338995)
@@ -896,7 +896,7 @@ reprocess(int startloc, int flag, int subtype, int quo
 
startp = stackblock() + startloc;
len = expdest - startp;
-   if (len >= SIZE_MAX / 2)
+   if (len >= SIZE_MAX / 2 || len > PTRDIFF_MAX)
abort();
INTOFF;
if (len >= buflen) {
@@ -912,7 +912,7 @@ reprocess(int startloc, int flag, int subtype, int quo
INTON;
memcpy(buf, startp, len);
buf[len] = '\0';
-   STADJUST(-len, expdest);
+   STADJUST(-(ptrdiff_t)len, expdest);
for (zpos = 0;;) {
zlen = strlen(buf + zpos);
strtodest(buf + zpos, flag, subtype, quoted, dst);
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r338473 - head/bin/sh

2018-09-05 Thread Jilles Tjoelker
Author: jilles
Date: Wed Sep  5 19:16:09 2018
New Revision: 338473
URL: https://svnweb.freebsd.org/changeset/base/338473

Log:
  sh: Fix formal overflow in pointer arithmetic
  
  The intention is to lower the value of the pointer, which according to ubsan
  cannot be done by adding an unsigned quantity.
  
  Reported by:  kevans
  Approved by:  re (kib)
  MFC after:1 week

Modified:
  head/bin/sh/expand.c

Modified: head/bin/sh/expand.c
==
--- head/bin/sh/expand.cWed Sep  5 19:05:30 2018(r338472)
+++ head/bin/sh/expand.cWed Sep  5 19:16:09 2018(r338473)
@@ -896,7 +896,7 @@ reprocess(int startloc, int flag, int subtype, int quo
 
startp = stackblock() + startloc;
len = expdest - startp;
-   if (len >= SIZE_MAX / 2)
+   if (len >= SIZE_MAX / 2 || len > PTRDIFF_MAX)
abort();
INTOFF;
if (len >= buflen) {
@@ -912,7 +912,7 @@ reprocess(int startloc, int flag, int subtype, int quo
INTON;
memcpy(buf, startp, len);
buf[len] = '\0';
-   STADJUST(-len, expdest);
+   STADJUST(-(ptrdiff_t)len, expdest);
for (zpos = 0;;) {
zlen = strlen(buf + zpos);
strtodest(buf + zpos, flag, subtype, quoted, dst);
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r337728 - head/usr.bin/printf/tests

2018-08-13 Thread Jilles Tjoelker
Author: jilles
Date: Mon Aug 13 21:54:27 2018
New Revision: 337728
URL: https://svnweb.freebsd.org/changeset/base/337728

Log:
  printf: Add test for width and precision in %b format
  
  PR:   229641
  Submitted by: pfg

Added:
  head/usr.bin/printf/tests/regress.bwidth.out   (contents, props changed)
Modified:
  head/usr.bin/printf/tests/Makefile
  head/usr.bin/printf/tests/regress.sh

Modified: head/usr.bin/printf/tests/Makefile
==
--- head/usr.bin/printf/tests/Makefile  Mon Aug 13 21:53:18 2018
(r337727)
+++ head/usr.bin/printf/tests/Makefile  Mon Aug 13 21:54:27 2018
(r337728)
@@ -5,6 +5,7 @@ PACKAGE=tests
 TAP_TESTS_SH=  legacy_test
 
 ${PACKAGE}FILES+=  regress.b.out
+${PACKAGE}FILES+=  regress.bwidth.out
 ${PACKAGE}FILES+=  regress.d.out
 ${PACKAGE}FILES+=  regress.f.out
 ${PACKAGE}FILES+=  regress.l1.out

Added: head/usr.bin/printf/tests/regress.bwidth.out
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/usr.bin/printf/tests/regress.bwidth.outMon Aug 13 21:54:27 
2018(r337728)
@@ -0,0 +1 @@
+  a

Modified: head/usr.bin/printf/tests/regress.sh
==
--- head/usr.bin/printf/tests/regress.shMon Aug 13 21:53:18 2018
(r337727)
+++ head/usr.bin/printf/tests/regress.shMon Aug 13 21:54:27 2018
(r337728)
@@ -2,7 +2,7 @@
 
 REGRESSION_START($1)
 
-echo '1..23'
+echo '1..24'
 
 REGRESSION_TEST(`b', `printf "abc%b%b" "def\n" "\cghi"')
 REGRESSION_TEST(`d', `printf "%d,%5d,%.5d,%0*d,%.*d\n" 123 123 123 5 123 5 
123')
@@ -27,5 +27,6 @@ REGRESSION_TEST(`missingpos1', `printf "%*.*1\$s" 1 1 
 REGRESSION_TEST(`missingpos1', `printf "%1\$*2\$.*s" 1 1 1 2>&1')
 REGRESSION_TEST(`missingpos1', `printf "%*1\$.*2\$s" 1 1 1 2>&1')
 REGRESSION_TEST(`missingpos1', `printf "%1\$*.*2\$s" 1 1 1 2>&1')
+REGRESSION_TEST(`bwidth', `printf "%8.2b" "a\nb\n"')
 
 REGRESSION_END()
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r337618 - head/usr.bin/printf

2018-08-11 Thread Jilles Tjoelker
Author: jilles
Date: Sat Aug 11 11:13:34 2018
New Revision: 337618
URL: https://svnweb.freebsd.org/changeset/base/337618

Log:
  printf: Fix \c in %b in printf builtin exiting the shell after r337458
  
  SVN r337458 erroneously partially reverted r265885.
  
  This is immediately visible when running the Kyua/ATF tests for
  usr.bin/printf, which actually test sh's printf builtin.
  
  PR:   229641

Modified:
  head/usr.bin/printf/printf.c

Modified: head/usr.bin/printf/printf.c
==
--- head/usr.bin/printf/printf.cSat Aug 11 11:05:22 2018
(r337617)
+++ head/usr.bin/printf/printf.cSat Aug 11 11:13:34 2018
(r337618)
@@ -388,7 +388,7 @@ printf_doformat(char *fmt, int *rval)
 
free(p);
if (getout)
-   exit(*rval);
+   return (end_fmt);
break;
}
case 'c': {
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r336320 - in head/bin/sh: . tests/builtins

2018-07-15 Thread Jilles Tjoelker
Author: jilles
Date: Sun Jul 15 21:55:17 2018
New Revision: 336320
URL: https://svnweb.freebsd.org/changeset/base/336320

Log:
  sh: Don't treat % specially in CDPATH

Added:
  head/bin/sh/tests/builtins/cd11.0   (contents, props changed)
Modified:
  head/bin/sh/cd.c
  head/bin/sh/exec.c
  head/bin/sh/exec.h
  head/bin/sh/main.c
  head/bin/sh/tests/builtins/Makefile

Modified: head/bin/sh/cd.c
==
--- head/bin/sh/cd.cSun Jul 15 21:10:19 2018(r336319)
+++ head/bin/sh/cd.cSun Jul 15 21:55:17 2018(r336320)
@@ -120,7 +120,7 @@ cdcmd(int argc __unused, char **argv __unused)
(dest[0] == '.' && dest[1] == '.' && (dest[2] == '/' || dest[2] == 
'\0')) ||
(path = bltinlookup("CDPATH", 1)) == NULL)
path = "";
-   while ((p = padvance(, dest)) != NULL) {
+   while ((p = padvance(, NULL, dest)) != NULL) {
if (stat(p, ) < 0) {
if (errno != ENOENT)
errno1 = errno;

Modified: head/bin/sh/exec.c
==
--- head/bin/sh/exec.c  Sun Jul 15 21:10:19 2018(r336319)
+++ head/bin/sh/exec.c  Sun Jul 15 21:55:17 2018(r336320)
@@ -113,6 +113,7 @@ void
 shellexec(char **argv, char **envp, const char *path, int idx)
 {
char *cmdname;
+   const char *opt;
int e;
 
if (strchr(argv[0], '/') != NULL) {
@@ -120,8 +121,8 @@ shellexec(char **argv, char **envp, const char *path, 
e = errno;
} else {
e = ENOENT;
-   while ((cmdname = padvance(, argv[0])) != NULL) {
-   if (--idx < 0 && pathopt == NULL) {
+   while ((cmdname = padvance(, , argv[0])) != NULL) {
+   if (--idx < 0 && opt == NULL) {
tryexec(cmdname, argv, envp);
if (errno != ENOENT && errno != ENOTDIR)
e = errno;
@@ -174,16 +175,14 @@ tryexec(char *cmd, char **argv, char **envp)
  * Do a path search.  The variable path (passed by reference) should be
  * set to the start of the path before the first call; padvance will update
  * this value as it proceeds.  Successive calls to padvance will return
- * the possible path expansions in sequence.  If an option (indicated by
- * a percent sign) appears in the path entry then the global variable
- * pathopt will be set to point to it; otherwise pathopt will be set to
- * NULL.
+ * the possible path expansions in sequence.  If popt is not NULL, options
+ * are processed: if an option (indicated by a percent sign) appears in
+ * the path entry then *popt will be set to point to it; else *popt will be
+ * set to NULL.  If popt is NULL, percent signs are not special.
  */
 
-const char *pathopt;
-
 char *
-padvance(const char **path, const char *name)
+padvance(const char **path, const char **popt, const char *name)
 {
const char *p, *start;
char *q;
@@ -192,8 +191,12 @@ padvance(const char **path, const char *name)
if (*path == NULL)
return NULL;
start = *path;
-   for (p = start; *p && *p != ':' && *p != '%'; p++)
-   ; /* nothing */
+   if (popt != NULL)
+   for (p = start; *p && *p != ':' && *p != '%'; p++)
+   ; /* nothing */
+   else
+   for (p = start; *p && *p != ':'; p++)
+   ; /* nothing */
namelen = strlen(name);
len = p - start + namelen + 2;  /* "2" is for '/' and '\0' */
STARTSTACKSTR(q);
@@ -204,10 +207,12 @@ padvance(const char **path, const char *name)
*q++ = '/';
}
memcpy(q, name, namelen + 1);
-   pathopt = NULL;
-   if (*p == '%') {
-   pathopt = ++p;
-   while (*p && *p != ':')  p++;
+   if (popt != NULL) {
+   if (*p == '%') {
+   *popt = ++p;
+   while (*p && *p != ':')  p++;
+   } else
+   *popt = NULL;
}
if (*p == ':')
*path = p + 1;
@@ -277,14 +282,14 @@ static void
 printentry(struct tblentry *cmdp, int verbose)
 {
int idx;
-   const char *path;
+   const char *path, *opt;
char *name;
 
if (cmdp->cmdtype == CMDNORMAL) {
idx = cmdp->param.index;
path = pathval();
do {
-   name = padvance(, cmdp->cmdname);
+   name = padvance(, , cmdp->cmdname);
stunalloc(name);
} while (--idx >= 0);
out1str(name);
@@ -321,6 +326,7 @@ find_command(const char *name, struct cmdentry *entry,
 {
struct tblentry *cmdp, loc_cmd;
int idx;
+   const char *opt;
char 

svn commit: r336303 - head/bin/sh

2018-07-15 Thread Jilles Tjoelker
Author: jilles
Date: Sun Jul 15 09:14:30 2018
New Revision: 336303
URL: https://svnweb.freebsd.org/changeset/base/336303

Log:
  sh: Don't use padvance() for MAIL/MAILPATH
  
  Using padvance() requires undoing its append of '/' and prevents adjusting
  its '%' logic to allow most directories with '%' in PATH.
  
  No functional change is intended.

Modified:
  head/bin/sh/mail.c

Modified: head/bin/sh/mail.c
==
--- head/bin/sh/mail.c  Sun Jul 15 05:29:39 2018(r336302)
+++ head/bin/sh/mail.c  Sun Jul 15 09:14:30 2018(r336303)
@@ -43,7 +43,6 @@ __FBSDID("$FreeBSD$");
  */
 
 #include "shell.h"
-#include "exec.h"  /* defines padvance() */
 #include "mail.h"
 #include "var.h"
 #include "output.h"
@@ -72,9 +71,9 @@ void
 chkmail(int silent)
 {
int i;
-   const char *mpath;
+   char *mpath;
char *p;
-   char *q;
+   char *msg;
struct stackmark smark;
struct stat statb;
 
@@ -83,22 +82,25 @@ chkmail(int silent)
if (nmboxes == 0)
return;
setstackmark();
-   mpath = mpathset()? mpathval() : mailval();
+   mpath = stsavestr(mpathset()? mpathval() : mailval());
for (i = 0 ; i < nmboxes ; i++) {
-   p = padvance(, "");
-   if (p == NULL)
-   break;
+   p = mpath;
if (*p == '\0')
-   continue;
-   for (q = p ; *q ; q++);
-   if (q[-1] != '/')
-   abort();
-   q[-1] = '\0';   /* delete trailing '/' */
+   break;
+   mpath = strchrnul(mpath, ':');
+   if (*mpath != '\0') {
+   *mpath++ = '\0';
+   if (p == mpath - 1)
+   continue;
+   }
+   msg = strchr(p, '%');
+   if (msg != NULL)
+   *msg++ = '\0';
 #ifdef notdef /* this is what the System V shell claims to do (it lies) */
if (stat(p, ) < 0)
statb.st_mtime = 0;
if (statb.st_mtime > mailtime[i] && ! silent) {
-   out2str(pathopt? pathopt : "you have mail");
+   out2str(msg? msg : "you have mail");
out2c('\n');
}
mailtime[i] = statb.st_mtime;
@@ -106,7 +108,7 @@ chkmail(int silent)
if (stat(p, ) < 0)
statb.st_size = 0;
if (statb.st_size > mailtime[i] && ! silent) {
-   out2str(pathopt? pathopt : "you have mail");
+   out2str(msg? msg : "you have mail");
out2c('\n');
}
mailtime[i] = statb.st_size;
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r335836 - head/usr.bin/top

2018-07-03 Thread Jilles Tjoelker
On Tue, Jul 03, 2018 at 02:09:56AM +0900, Hiroki Sato wrote:
> 後藤大地  wrote
>   in <459bd898-8072-426e-a968-96c1382ac...@icloud.com>:
> da> > 2018/07/02 15:55、Hiroki Sato のメール:

> da> > Eitan Adler  wrote
> da> >  in 
> :

> da> > li> On 1 July 2018 at 10:08, Conrad Meyer  wrote:

> da> > li> > I don't think code to decode UTF-8 belongs in top(1).  I don't 
> know
> da> > li> > what the goal of this routine is, but I doubt this is the right 
> way to
> da> > li> > accomplish it.
> da> > li>
> da> > li> For the record, I agree. This is why I didn't click "accept" on the
> da> > li> revision. I don't fully oppose leaving it in top(1) for now as we 
> work
> da> > li> out the API, but long term its the wrong place.
> da> > li>
> da> > li> https://reviews.freebsd.org/D16058 is the review.

> da> > I strongly object this kind of encoding-specific routine.  Please
> da> > back out it.  The problem is that top(1) does not support multibyte
> da> > encoding in functions for printing, and using C99 wide/multibyte
> da> > character manipulation API such as iswprint(3) is the way to solve
> da> > it.  Doing getenv("LANG") and assuming an encoding based on it is a
> da> > very bad practice to internationalize software.

> da> I respect what you mean.

> da> Once I back out, I will begin implementing it in a different way.
> da> Please advise which function should be used for implementation
> da> (iswprint (3) and what other functions should be used?)

>  Roughly speaking, POSIX/XPG/C99 I18N model requires the following
>  steps:

>  1. Call setlocale(LC_ALL, "") first.

>  2. Use mbs<->wcs and/or mb<->wc conversion functions in C95/C99 to
> manipulate characters and strings depending on what you want to
> do.  The printable() function should use mbtowc(3) and
> iswprint(3), for example.  And wcslen(3) should be used to
> determine the length of characters to be printed instead of
> strlen().

> Note that if mbs->wcs or mb->wc conversion fails with EILSEQ at
> some point, some of the character(s) are invalid for printing.
> This can happen because command-line parameters in top(1) are not
> always encoded in one specified in LC_CTYPE or LANG.  It should
> also be handled as non-printable.  However, to make matters worse,
> each process does not always use a single, same locale as top(1).
> A process invoked with LANG=ja_JP.eucJP may have EUC-JP characters
> in its ARGV array even if top(1) runs by another user whose LANG
> is en_US.UTF-8.  You have to determine which locale should be used
> before doing mb->wc conversion.  It is not so simple.

>  3. Print the multibyte characters by using strvisx(3) family, which
> supports multibyte character, or swprintf(3) family if you want to
> format wide characters directly.  Note that buffer length for
> strvisx(3) must be calculated by using MB_LEN_MAX.

In this case, calling setlocale() and then using strvisx() seems the
right solution. If locales differ across processes this may result in
mojibake but that cannot really be helped. Even analyzing other
processes' locale variables is not fully reliable, since strings may be
incorrectly encoded even in the process's real locale, environment
variables cannot be read across users and the environment block may be
overwritten by a program.

In general, although using conversion to wide characters allows users a
lot of flexibility, I don't think it is the best in all situations:

* The result of mbstowcs() is a UTF-32 string which consumes a lot of
  memory. A loop with mbrtowc() may also be slow. Many operations can be
  done directly on UTF-8 strings with no or little additional complexity
  compared to byte strings.

* If there is an invalid multibyte character, there is little
  flexibility to handle this usefully and securely, since so little is
  known about the encoding. The best handling may depend on the context.

Therefore, in /bin/sh, I have only implemented multibyte support for
UTF-8. All other encodings have bytes treated as characters.

However, I do agree that getenv("LANG") is bad. Instead, setlocale()
should be used. After that, nl_langinfo(CODESET) can be called and the
result compared to "UTF-8".

-- 
Jilles Tjoelker
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r335905 - head/usr.bin/rup

2018-07-03 Thread Jilles Tjoelker
Author: jilles
Date: Tue Jul  3 19:09:46 2018
New Revision: 335905
URL: https://svnweb.freebsd.org/changeset/base/335905

Log:
  rup: Fix -Wcast-align warnings
  
  Fix possible strict aliasing issue (if time_t is the same size as int but
  not int but for example long) which also resulted in a false positive
  warning on systems with 64-bit time_t. Pointer casts are bad; we can just
  copy the time_t.
  
  Elsewhere, avoid casting char * to int * by using memcpy().
  
  Reviewed by:  eadler
  Differential Revision:https://reviews.freebsd.org/D16075

Modified:
  head/usr.bin/rup/Makefile
  head/usr.bin/rup/rup.c

Modified: head/usr.bin/rup/Makefile
==
--- head/usr.bin/rup/Makefile   Tue Jul  3 18:45:04 2018(r335904)
+++ head/usr.bin/rup/Makefile   Tue Jul  3 19:09:46 2018(r335905)
@@ -4,6 +4,4 @@ PROG=   rup
 
 LIBADD=rpcsvc
 
-NO_WCAST_ALIGN=# Size is explicitly handled
-
 .include 

Modified: head/usr.bin/rup/rup.c
==
--- head/usr.bin/rup/rup.c  Tue Jul  3 18:45:04 2018(r335904)
+++ head/usr.bin/rup/rup.c  Tue Jul  3 19:09:46 2018(r335905)
@@ -120,27 +120,16 @@ rstat_reply(statstime *host_stat, struct sockaddr_in *
 
printf("%-*s\t", HOST_WIDTH, host);
 
-   if (sizeof(time_t) == sizeof(host_stat->curtime.tv_sec)) {
-   tmp_time = localtime((time_t *)_stat->curtime.tv_sec);
-   host_time = *tmp_time;
+   tmp_time_t = host_stat->curtime.tv_sec;
+   tmp_time = localtime(_time_t);
+   host_time = *tmp_time;
 
-   host_stat->curtime.tv_sec -= host_stat->boottime.tv_sec;
+   host_stat->curtime.tv_sec -= host_stat->boottime.tv_sec;
 
-   tmp_time = gmtime((time_t *)_stat->curtime.tv_sec);
-   host_uptime = *tmp_time;
-   }
-   else {  /* non-32-bit time_t */
-   tmp_time_t = host_stat->curtime.tv_sec;
-   tmp_time = localtime(_time_t);
-   host_time = *tmp_time;
+   tmp_time_t = host_stat->curtime.tv_sec;
+   tmp_time = gmtime(_time_t);
+   host_uptime = *tmp_time;
 
-   host_stat->curtime.tv_sec -= host_stat->boottime.tv_sec;
-
-   tmp_time_t = host_stat->curtime.tv_sec;
-   tmp_time = gmtime(_time_t);
-   host_uptime = *tmp_time;
-   }
-
#define updays (host_stat->curtime.tv_sec  / 86400)
if (host_uptime.tm_yday != 0)
sprintf(days_buf, "%3d day%s, ", updays,
@@ -205,7 +194,7 @@ onehost(char *host)
return(-1);
}
 
-   addr.sin_addr.s_addr = *(int *)hp->h_addr;
+   memcpy(_addr.s_addr, hp->h_addr, sizeof(int));
rstat_reply(_stat, );
clnt_destroy(rstat_clnt);
return (0);
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r335041 - head/lib/libc/stdlib

2018-06-13 Thread Jilles Tjoelker
On Wed, Jun 13, 2018 at 08:03:13PM +1000, Bruce Evans wrote:
> On Wed, 13 Jun 2018, Eitan Adler wrote:

> > Log:
> >  libc: remove explicit cast NULL in atoi

> >  There isn't any reason to cast NULL so just remove it. Noticed when
> >  cleaning up top.

> There are many reasons to cast NULL for all members of the ato*() family:
> - it is required if no prototype is in scope
> - C99 specifies ato*() in terms of strtol*() and uses the cast to NULL,
>probably because this is simplest.  Omitting the cast is just wrong
>if no prototype is in scope.  Writing the explicit cast is simpler than
>writing caveats that the stated equivalence is only valid if a prototype
>is in scope.
> - POSIX specifies ato*() in terms of strtol*() and uses the cast to NULL,
>exactly as in C99, probably because it defers to the C standard and
>doesn't and doesn't risk breaking it by changing its wording except when
>extending it.

These reasons can be summarized to a single reason: the cast is required
if no prototype is in scope.

I think it is unwise to call any function without a prototype in scope,
since this runs a risk of undefined behaviour if you get the types
wrong.

For the code in libc, we ensure a prototype is in scope and no cast is
required. For the code in the man page, I doubt we should allow for
programmers that play tricks by declaring system functions manually
using K declarations or (even worse) call functions without
declaring them at all.

Note that NULL may still need a cast when passed to a function with
variable number of parameters. Ideally these types are also checked
using attributes.

> FreeBSD used to do the same here, and should do the same here and
> elsewhere by copying better wording from POSIX whenever possible.

For some reason, the FreeBSD text does not have the exception about
error handling. This exception permits an implementation like musl's
which calculates using int and hard-codes base 10, even if the compiler
documents a cast from long to int as truncating bits. I don't think we
should take advantage of this, though, since making atoi() faster than
strtol() may encourage people to use atoi().

-- 
Jilles Tjoelker
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r334008 - head/bin/sh

2018-05-22 Thread Jilles Tjoelker
On Tue, May 22, 2018 at 10:17:41AM +0200, O. Hartmann wrote:
> On Mon, 21 May 2018 21:45:53 -0700
> Cy Schubert <cy.schub...@cschubert.com> wrote:
> > In message <20180522061339.21497...@freyja.zeit4.iv.bundesimmobilien.de>
> > , "O. H
> > artmann" writes:
> > > On Mon, 21 May 2018 21:52:48 + (UTC)
> > > Jilles Tjoelker <jil...@freebsd.org> wrote:

> > > > Author: jilles
> > > > Date: Mon May 21 21:52:48 2018
> > > > New Revision: 334008
> > > > URL: https://svnweb.freebsd.org/changeset/base/334008

> > > > Log:
> > > >   sh: Split CNL syntax category to avoid a check on state[level].syntax

> > > >   No functional change is intended.

> > > > Modified:
> > > >   head/bin/sh/mksyntax.c
> > > >   head/bin/sh/parser.c
> [snip]

> > > Have this been tested? Doesn't compile for me:

> > > [...]
> > > Building /usr/obj/usr/src/amd64.amd64/kerberos5/libexec/hprop/hprop
> > > --- all_subdir_rescue ---
> > > --- parser.o ---
> > > /usr/src/bin/sh/parser.c:1440:9: error: use of undeclared identifier 
> > > 'CQNL'
> > > case CQNL:
> > >  ^
> > > --- all_subdir_gnu ---
> > > Building 
> > > /usr/obj/usr/src/amd64.amd64/gnu/usr.bin/gdb/libgdb/amd64bsd-nat.o
> > > --- all_subdir_rescue ---
> > > 1 error generated.
> > > *** [parser.o] Error code 1

> > > make[6]: stopped in /usr/src/bin/sh

> > CQNL is defined in /usr/obj/opt/src/svn-current/amd64.amd64/bin/sh/synta
> > x.h, generated by mksyntax.

> > slippy$ ag -s CQNL /export/obj/opt/src/svn-current/amd64.amd64/bin/sh/*.
> > h
> > /export/obj/opt/src/svn-current/amd64.amd64/bin/sh/syntax.h
> > 11:#define CQNL 2   /* newline character in quotes */
> > slippy$ 

> > Remove the file if it's not defined in your syntax.h.

> > Just out of interest, do you use meta mode?

> I think such a question is of common interest if errors/bugs like that occur:
> Yes, I use/compile world/kernel with META mode.

The change itself is fine. It built for me and for Jenkins
(ci.freebsd.org). What is not fine is an incremental build with meta
mode. Apparently, the  syntax.h: .NOMETA  rule added in r301285 causes
bmake to build some files against the old syntax.h, even though syntax.c
and syntax.h will be rebuilt.

To fix this, it may be possible to generate a meta file for syntax.h
based on the one for syntax.c. The same would be done for builtins.[ch]
and nodes.[ch].

Conceptually simpler is accepting what make would like: one command
generates one file only. This is not really new with meta mode since a
somewhat ugly .ORDER declaration had been necessary before. The .c
content can go inside a #ifdef in the .h file so the .c file need not be
autogenerated, or the tools can be run twice, once to generate the .c
file and once to generate the .h file. In both cases, the tools will be
somewhat uglier in order to simplify the build system.

-- 
Jilles Tjoelker
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r334008 - head/bin/sh

2018-05-21 Thread Jilles Tjoelker
Author: jilles
Date: Mon May 21 21:52:48 2018
New Revision: 334008
URL: https://svnweb.freebsd.org/changeset/base/334008

Log:
  sh: Split CNL syntax category to avoid a check on state[level].syntax
  
  No functional change is intended.

Modified:
  head/bin/sh/mksyntax.c
  head/bin/sh/parser.c

Modified: head/bin/sh/mksyntax.c
==
--- head/bin/sh/mksyntax.c  Mon May 21 21:44:47 2018(r334007)
+++ head/bin/sh/mksyntax.c  Mon May 21 21:52:48 2018(r334008)
@@ -65,6 +65,7 @@ struct synclass {
 static const struct synclass synclass[] = {
{ "CWORD",  "character is nothing special" },
{ "CNL","newline character" },
+   { "CQNL",   "newline character in quotes" },
{ "CBACK",  "a backslash character" },
{ "CSBACK", "a backslash character in single quotes" },
{ "CSQUOTE","single quote" },
@@ -185,7 +186,7 @@ main(int argc __unused, char **argv __unused)
fputs("\n/* syntax table used when in double quotes */\n", cfile);
init("dqsyntax");
add_default();
-   add("\n", "CNL");
+   add("\n", "CQNL");
add("\\", "CBACK");
add("\"", "CENDQUOTE");
add("`", "CBQUOTE");
@@ -198,7 +199,7 @@ main(int argc __unused, char **argv __unused)
fputs("\n/* syntax table used when in single quotes */\n", cfile);
init("sqsyntax");
add_default();
-   add("\n", "CNL");
+   add("\n", "CQNL");
add("\\", "CSBACK");
add("'", "CENDQUOTE");
/* ':/' for tilde expansion, '-^]' for [a\-x] pattern ranges */
@@ -208,7 +209,7 @@ main(int argc __unused, char **argv __unused)
fputs("\n/* syntax table used when in arithmetic */\n", cfile);
init("arisyntax");
add_default();
-   add("\n", "CNL");
+   add("\n", "CQNL");
add("\\", "CBACK");
add("`", "CBQUOTE");
add("\"", "CIGN");

Modified: head/bin/sh/parser.c
==
--- head/bin/sh/parser.cMon May 21 21:44:47 2018(r334007)
+++ head/bin/sh/parser.cMon May 21 21:52:48 2018(r334008)
@@ -1434,9 +1434,10 @@ readtoken1(int firstc, char const *initialsyntax, cons
 
switch(synentry) {
case CNL:   /* '\n' */
-   if (level == 0 &&
-   state[level].syntax == BASESYNTAX)
+   if (level == 0)
goto endword;   /* exit outer loop */
+   /* FALLTHROUGH */
+   case CQNL:
USTPUTC(c, out);
plinno++;
if (doprompt)
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r333927 - in head/bin/sh: . tests/expansion

2018-05-20 Thread Jilles Tjoelker
Author: jilles
Date: Sun May 20 17:25:52 2018
New Revision: 333927
URL: https://svnweb.freebsd.org/changeset/base/333927

Log:
  sh: Allow unquoted newlines in word in ${param+word} etc.
  
  POSIX requires accepting unquoted newlines in word in parameter expansions
  like ${param+word}, ${param#word}, although the Bourne shell did not support
  it, it is not commonly used and might make it harder to find a missing
  closing brace.
  
  It was also strange that something like
  
  foo="${bar#
  }"
  
  was rejected.
  
  Reported by:  Martijn Dekker via Robert Elz

Added:
  head/bin/sh/tests/expansion/plus-minus9.0   (contents, props changed)
  head/bin/sh/tests/expansion/trim10.0   (contents, props changed)
  head/bin/sh/tests/expansion/trim11.0   (contents, props changed)
Modified:
  head/bin/sh/parser.c
  head/bin/sh/tests/expansion/Makefile

Modified: head/bin/sh/parser.c
==
--- head/bin/sh/parser.cSun May 20 16:03:21 2018(r333926)
+++ head/bin/sh/parser.cSun May 20 17:25:52 2018(r333927)
@@ -1434,7 +1434,8 @@ readtoken1(int firstc, char const *initialsyntax, cons
 
switch(synentry) {
case CNL:   /* '\n' */
-   if (state[level].syntax == BASESYNTAX)
+   if (level == 0 &&
+   state[level].syntax == BASESYNTAX)
goto endword;   /* exit outer loop */
USTPUTC(c, out);
plinno++;

Modified: head/bin/sh/tests/expansion/Makefile
==
--- head/bin/sh/tests/expansion/MakefileSun May 20 16:03:21 2018
(r333926)
+++ head/bin/sh/tests/expansion/MakefileSun May 20 17:25:52 2018
(r333927)
@@ -84,6 +84,7 @@ ${PACKAGE}FILES+= plus-minus5.0
 ${PACKAGE}FILES+=  plus-minus6.0
 ${PACKAGE}FILES+=  plus-minus7.0
 ${PACKAGE}FILES+=  plus-minus8.0
+${PACKAGE}FILES+=  plus-minus9.0
 ${PACKAGE}FILES+=  question1.0
 ${PACKAGE}FILES+=  readonly1.0
 ${PACKAGE}FILES+=  redir1.0
@@ -101,5 +102,7 @@ ${PACKAGE}FILES+=   trim6.0
 ${PACKAGE}FILES+=  trim7.0
 ${PACKAGE}FILES+=  trim8.0
 ${PACKAGE}FILES+=  trim9.0
+${PACKAGE}FILES+=  trim10.0
+${PACKAGE}FILES+=  trim11.0
 
 .include 

Added: head/bin/sh/tests/expansion/plus-minus9.0
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/bin/sh/tests/expansion/plus-minus9.0   Sun May 20 17:25:52 2018
(r333927)
@@ -0,0 +1,8 @@
+# $FreeBSD$
+
+a=1
+b=${a+
+}
+n='
+'
+[ "$b" = "$n" ]

Added: head/bin/sh/tests/expansion/trim10.0
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/bin/sh/tests/expansion/trim10.0Sun May 20 17:25:52 2018
(r333927)
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+a='z
+'
+b=${a%
+}
+[ "$b" = z ]

Added: head/bin/sh/tests/expansion/trim11.0
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/bin/sh/tests/expansion/trim11.0Sun May 20 17:25:52 2018
(r333927)
@@ -0,0 +1,7 @@
+# $FreeBSD$
+
+a='z
+'
+b="${a%
+}"
+[ "$b" = z ]
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r333507 - head/bin/sh/tests/parser

2018-05-11 Thread Jilles Tjoelker
Author: jilles
Date: Fri May 11 21:56:01 2018
New Revision: 333507
URL: https://svnweb.freebsd.org/changeset/base/333507

Log:
  sh: Test that backslash-newline within single-quotes is not special
  
  This works correctly, but the test may be helpful when modifying the parser.

Added:
  head/bin/sh/tests/parser/line-cont12.0   (contents, props changed)
Modified:
  head/bin/sh/tests/parser/Makefile

Modified: head/bin/sh/tests/parser/Makefile
==
--- head/bin/sh/tests/parser/Makefile   Fri May 11 21:46:53 2018
(r333506)
+++ head/bin/sh/tests/parser/Makefile   Fri May 11 21:56:01 2018
(r333507)
@@ -74,6 +74,7 @@ ${PACKAGE}FILES+= line-cont8.0
 ${PACKAGE}FILES+=  line-cont9.0
 ${PACKAGE}FILES+=  line-cont10.0
 ${PACKAGE}FILES+=  line-cont11.0
+${PACKAGE}FILES+=  line-cont12.0
 ${PACKAGE}FILES+=  no-space1.0
 ${PACKAGE}FILES+=  no-space2.0
 ${PACKAGE}FILES+=  nul1.0

Added: head/bin/sh/tests/parser/line-cont12.0
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/bin/sh/tests/parser/line-cont12.0  Fri May 11 21:56:01 2018
(r333507)
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+[ '\
+' = "\\
+" ]
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r333224 - in stable/11/bin/sh: . tests/builtins

2018-05-03 Thread Jilles Tjoelker
Author: jilles
Date: Thu May  3 19:47:25 2018
New Revision: 333224
URL: https://svnweb.freebsd.org/changeset/base/333224

Log:
  MFC r333092: sh: Don't have [ match any [[:class:]]

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

Modified: stable/11/bin/sh/expand.c
==
--- stable/11/bin/sh/expand.c   Thu May  3 19:45:48 2018(r333223)
+++ stable/11/bin/sh/expand.c   Thu May  3 19:47:25 2018(r333224)
@@ -1342,8 +1342,10 @@ patmatch(const char *pattern, const char *string)
}
if (c == '[' && *p == ':') {
found |= match_charclass(p, chr, );
-   if (end != NULL)
+   if (end != NULL) {
p = end;
+   continue;
+   }
}
if (c == CTLESC)
c = *p++;

Modified: stable/11/bin/sh/tests/builtins/Makefile
==
--- stable/11/bin/sh/tests/builtins/MakefileThu May  3 19:45:48 2018
(r333223)
+++ stable/11/bin/sh/tests/builtins/MakefileThu May  3 19:47:25 2018
(r333224)
@@ -40,6 +40,7 @@ ${PACKAGE}FILES+= case17.0
 ${PACKAGE}FILES+=  case18.0
 ${PACKAGE}FILES+=  case19.0
 ${PACKAGE}FILES+=  case20.0
+${PACKAGE}FILES+=  case23.0
 ${PACKAGE}FILES+=  cd1.0
 ${PACKAGE}FILES+=  cd2.0
 ${PACKAGE}FILES+=  cd3.0

Copied: stable/11/bin/sh/tests/builtins/case23.0 (from r333092, 
head/bin/sh/tests/builtins/case23.0)
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ stable/11/bin/sh/tests/builtins/case23.0Thu May  3 19:47:25 2018
(r333224, copy of r333092, head/bin/sh/tests/builtins/case23.0)
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+case [ in
+[[:alpha:]]) echo bad
+esac
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r333092 - in head/bin/sh: . tests/builtins

2018-04-29 Thread Jilles Tjoelker
Author: jilles
Date: Sun Apr 29 17:46:08 2018
New Revision: 333092
URL: https://svnweb.freebsd.org/changeset/base/333092

Log:
  sh: Don't have [ match any [[:class:]]
  
  Submitted by: Robert Elz
  MFC after:3 days

Added:
  head/bin/sh/tests/builtins/case23.0   (contents, props changed)
Modified:
  head/bin/sh/expand.c
  head/bin/sh/tests/builtins/Makefile

Modified: head/bin/sh/expand.c
==
--- head/bin/sh/expand.cSun Apr 29 12:43:08 2018(r333091)
+++ head/bin/sh/expand.cSun Apr 29 17:46:08 2018(r333092)
@@ -1342,8 +1342,10 @@ patmatch(const char *pattern, const char *string)
}
if (c == '[' && *p == ':') {
found |= match_charclass(p, chr, );
-   if (end != NULL)
+   if (end != NULL) {
p = end;
+   continue;
+   }
}
if (c == CTLESC)
c = *p++;

Modified: head/bin/sh/tests/builtins/Makefile
==
--- head/bin/sh/tests/builtins/Makefile Sun Apr 29 12:43:08 2018
(r333091)
+++ head/bin/sh/tests/builtins/Makefile Sun Apr 29 17:46:08 2018
(r333092)
@@ -42,6 +42,7 @@ ${PACKAGE}FILES+= case19.0
 ${PACKAGE}FILES+=  case20.0
 ${PACKAGE}FILES+=  case21.0
 ${PACKAGE}FILES+=  case22.0
+${PACKAGE}FILES+=  case23.0
 ${PACKAGE}FILES+=  cd1.0
 ${PACKAGE}FILES+=  cd2.0
 ${PACKAGE}FILES+=  cd3.0

Added: head/bin/sh/tests/builtins/case23.0
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/bin/sh/tests/builtins/case23.0 Sun Apr 29 17:46:08 2018
(r333092)
@@ -0,0 +1,5 @@
+# $FreeBSD$
+
+case [ in
+[[:alpha:]]) echo bad
+esac
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r331955 - head/share/man/man8

2018-04-03 Thread Jilles Tjoelker
Author: jilles
Date: Tue Apr  3 21:44:43 2018
New Revision: 331955
URL: https://svnweb.freebsd.org/changeset/base/331955

Log:
  rc.subr.8: Improve documentation of ${name}_limits and ${name}_login_class
  
  Submitted by: 0mp
  Differential Revision:https://reviews.freebsd.org/D14928

Modified:
  head/share/man/man8/rc.subr.8

Modified: head/share/man/man8/rc.subr.8
==
--- head/share/man/man8/rc.subr.8   Tue Apr  3 21:38:11 2018
(r331954)
+++ head/share/man/man8/rc.subr.8   Tue Apr  3 21:44:43 2018
(r331955)
@@ -29,7 +29,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd September 18, 2016
+.Dd April 3, 2018
 .Dt RC.SUBR 8
 .Os
 .Sh NAME
@@ -584,21 +584,27 @@ Only supported after
 .Pa /usr
 is mounted.
 .It Va ${name}_limits
-.Xr limits 1
-to apply to
+Resource limits to apply to
 .Va command .
 This will be passed as arguments to the
 .Xr limits 1
 utility.
+By default, the resource limits are based on the login class defined in
+.Va ${name}_login_class .
+.It Va ${name}_login_class
+Login class to use with
+.Va ${name}_limits .
+Defaults to
+.Dq Li daemon .
 .It Va ${name}_oomprotect
 .Xr protect 1
 .Va command
 from being killed when swap space is exhausted.
 If
-.Em YES
+.Dq Li YES
 is used, no child processes are protected.
 If
-.Em ALL ,
+.Dq Li ALL ,
 protect all child processes.
 .It Va ${name}_program
 Full path to the command.
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r328818 - head/bin/sh

2018-02-02 Thread Jilles Tjoelker
Author: jilles
Date: Fri Feb  2 22:53:58 2018
New Revision: 328818
URL: https://svnweb.freebsd.org/changeset/base/328818

Log:
  sh: Refactor job status printing, preparing for -o pipefail and similar
  
  No functional change is intended.

Modified:
  head/bin/sh/jobs.c

Modified: head/bin/sh/jobs.c
==
--- head/bin/sh/jobs.c  Fri Feb  2 22:28:12 2018(r328817)
+++ head/bin/sh/jobs.c  Fri Feb  2 22:53:58 2018(r328818)
@@ -362,7 +362,7 @@ showjob(struct job *jp, int mode)
const char *statestr, *coredump;
struct procstat *ps;
struct job *j;
-   int col, curr, i, jobno, prev, procno;
+   int col, curr, i, jobno, prev, procno, status;
char c;
 
procno = (mode == SHOWJOBS_PGIDS) ? 1 : jp->nprocs;
@@ -376,11 +376,12 @@ showjob(struct job *jp, int mode)
}
 #endif
coredump = "";
-   ps = jp->ps + jp->nprocs - 1;
+   status = jp->ps[jp->nprocs - 1].status;
if (jp->state == 0) {
statestr = "Running";
 #if JOBS
} else if (jp->state == JOBSTOPPED) {
+   ps = jp->ps + jp->nprocs - 1;
while (!WIFSTOPPED(ps->status) && ps > jp->ps)
ps--;
if (WIFSTOPPED(ps->status))
@@ -391,20 +392,20 @@ showjob(struct job *jp, int mode)
if (statestr == NULL)
statestr = "Suspended";
 #endif
-   } else if (WIFEXITED(ps->status)) {
-   if (WEXITSTATUS(ps->status) == 0)
+   } else if (WIFEXITED(status)) {
+   if (WEXITSTATUS(status) == 0)
statestr = "Done";
else {
fmtstr(statebuf, sizeof(statebuf), "Done(%d)",
-   WEXITSTATUS(ps->status));
+   WEXITSTATUS(status));
statestr = statebuf;
}
} else {
-   i = WTERMSIG(ps->status);
+   i = WTERMSIG(status);
statestr = strsignal(i);
if (statestr == NULL)
statestr = "Unknown signal";
-   if (WCOREDUMP(ps->status))
+   if (WCOREDUMP(status))
coredump = " (core dumped)";
}
 
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r328060 - head/usr.sbin/service

2018-01-16 Thread Jilles Tjoelker
On Tue, Jan 16, 2018 at 08:14:31PM +, Kyle Evans wrote:
> Author: kevans
> Date: Tue Jan 16 20:14:31 2018
> New Revision: 328060
> URL: https://svnweb.freebsd.org/changeset/base/328060

> Log:
>   service(8): Reset OPTIND properly now that we're parsing args twice

>   r328032 introduced a second round of argument parsing to proxy the request
>   through to a jail as needed, but failed to reset OPTIND before getting to
>   the second round of parsing to allow other flags to be set.

>   Reported by:Oleg Ginzburg 

> Modified:
>   head/usr.sbin/service/service.sh

> Modified: head/usr.sbin/service/service.sh
> ==
> --- head/usr.sbin/service/service.sh  Tue Jan 16 20:02:07 2018
> (r328059)
> +++ head/usr.sbin/service/service.sh  Tue Jan 16 20:14:31 2018
> (r328060)
> @@ -79,6 +79,7 @@ if [ -n "$JAIL" ]; then
>   exit $?
>  fi
>  
> +OPTIND=1
>  while getopts ${accepted_argstr} COMMAND_LINE_ARGUMENT ; do
>   case "${COMMAND_LINE_ARGUMENT}" in
>   e)  ENABLED=eopt ;;

Hi,

Although this solves the immediate problem of all existing options
becoming no-ops, the new -j option still behaves strangely if it is not
used with "-j" and the jail name as the first two arguments, since the
shift commands will shift away other arguments.

One way to fix this avoids depending on the exact options known by the
jailed service(8) and accepts that the -j option must be first (either
-j JAIL as two arguments or -jJAIL as one argument). This parsing would
be open-coded and there would be only one getopts loop.

Another way to fix this allows using the -j option as any other option.
This would also use one getopts loop and reconstruct a command line for
the jailed service(8) based on the variables like ENABLED (the values
for set options can be changed to simplify this since the rest of the
script only cares about non-empty or not).

-- 
Jilles Tjoelker
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r327652 - stable/11/usr.sbin/nandtool

2018-01-06 Thread Jilles Tjoelker
Author: jilles
Date: Sat Jan  6 22:59:10 2018
New Revision: 327652
URL: https://svnweb.freebsd.org/changeset/base/327652

Log:
  MFC r327211: nandtool: Add missing mode for open() with O_CREAT
  
  If O_CREAT is given, open() needs a mode argument. Follow the umask by
  passing 0666.

Modified:
  stable/11/usr.sbin/nandtool/nand_read.c
  stable/11/usr.sbin/nandtool/nand_readoob.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.sbin/nandtool/nand_read.c
==
--- stable/11/usr.sbin/nandtool/nand_read.c Sat Jan  6 22:56:48 2018
(r327651)
+++ stable/11/usr.sbin/nandtool/nand_read.c Sat Jan  6 22:59:10 2018
(r327652)
@@ -50,7 +50,7 @@ int nand_read(struct cmd_param *params)
}
 
if ((out = param_get_string(params, "out"))) {
-   out_fd = open(out, O_WRONLY|O_CREAT);
+   out_fd = open(out, O_WRONLY|O_CREAT, 0666);
if (out_fd == -1) {
perrorf("Cannot open %s for writing", out);
return (1);

Modified: stable/11/usr.sbin/nandtool/nand_readoob.c
==
--- stable/11/usr.sbin/nandtool/nand_readoob.c  Sat Jan  6 22:56:48 2018
(r327651)
+++ stable/11/usr.sbin/nandtool/nand_readoob.c  Sat Jan  6 22:59:10 2018
(r327652)
@@ -57,7 +57,7 @@ int nand_read_oob(struct cmd_param *params)
}
 
if ((out = param_get_string(params, "out"))) {
-   if ((fd_out = open(out, O_WRONLY | O_CREAT)) == -1) {
+   if ((fd_out = open(out, O_WRONLY | O_CREAT, 0666)) == -1) {
perrorf("Cannot open %s", out);
ret = 1;
goto out;
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r327565 - head/usr.bin/find/tests

2018-01-04 Thread Jilles Tjoelker
Author: jilles
Date: Thu Jan  4 22:59:24 2018
New Revision: 327565
URL: https://svnweb.freebsd.org/changeset/base/327565

Log:
  find: Speed up tests by using touch -d instead of sleep for timestamps
  
  I have verified that the tests still detect the absence of the r327362 fix.

Modified:
  head/usr.bin/find/tests/find_test.sh

Modified: head/usr.bin/find/tests/find_test.sh
==
--- head/usr.bin/find/tests/find_test.shThu Jan  4 22:38:01 2018
(r327564)
+++ head/usr.bin/find/tests/find_test.shThu Jan  4 22:59:24 2018
(r327565)
@@ -36,10 +36,9 @@ find_newer_link_body()
 {
atf_check -s exit:0 mkdir test
atf_check -s exit:0 ln -s file1 test/link
-   atf_check -s exit:0 sleep 1.1
-   atf_check -s exit:0 touch test/file2
-   atf_check -s exit:0 sleep 1.1
-   atf_check -s exit:0 touch test/file1
+   atf_check -s exit:0 touch -d 2017-12-31T10:00:00Z -h test/link
+   atf_check -s exit:0 touch -d 2017-12-31T11:00:00Z test/file2
+   atf_check -s exit:0 touch -d 2017-12-31T12:00:00Z test/file1
 
# find(1) should evaluate 'link' as a symlink rather than its target
# (with -P / without -L flags).  Since link was created first, the
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r325726 - head/sys/kern

2018-01-01 Thread Jilles Tjoelker
On Thu, Dec 28, 2017 at 05:25:25PM +0100, Jilles Tjoelker wrote:
> On Thu, Dec 28, 2017 at 12:40:31PM +, Antoine Brodin wrote:
> > On Sat, Nov 11, 2017 at 10:39 PM, Mateusz Guzik <m...@freebsd.org> wrote:
> > > Author: mjg
> > > Date: Sat Nov 11 22:39:33 2017
> > > New Revision: 325726
> > > URL: https://svnweb.freebsd.org/changeset/base/325726

> > > Log:
> > >   Avoid locking and refing in sysctl_kern_proc_args if possible.

> > >   Turns out the sysctl is called a lot e.g. by pkg-static.

> > > Modified:
> > >   head/sys/kern/kern_proc.c

> > There is a regression after this commit: x11-toolkits/gnustep-gui no
> > longer builds.
> > You can find a failure log at
> > http://pb2.nyi.freebsd.org/data/111i386-default-PR224618/2017-12-28_12h28m51s/logs/errors/gnustep-gui-0.25.1_3.log
> > The failure seems to be from lang/gnustep-base:

> >   /* get the argument vectors */
> >   vectors = kvm_getargv(kptr, proc_ptr, 0);

> It looks like the new fast path only works properly if p->p_args is not
> NULL. If p->p_args is NULL, this usually means that the arguments are
> longer than ps_arg_cache_limit and must be retrieved from (pageable)
> process memory and not wired p->p_args->ar_args. It is possible to
> duplicate that piece of code as well but that is probably not worth it.

I created a review that fixes the problem, but I am not completely sure
that it preserves the original intent of the optimization:
https://reviews.freebsd.org/D13729

-- 
Jilles Tjoelker
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r327475 - head/bin/sh

2018-01-01 Thread Jilles Tjoelker
Author: jilles
Date: Mon Jan  1 22:31:52 2018
New Revision: 327475
URL: https://svnweb.freebsd.org/changeset/base/327475

Log:
  sh: Move various structs from jobs.h to jobs.c
  
  These implementation details of jobs.c need not be exposed.

Modified:
  head/bin/sh/jobs.c
  head/bin/sh/jobs.h

Modified: head/bin/sh/jobs.c
==
--- head/bin/sh/jobs.c  Mon Jan  1 22:10:21 2018(r327474)
+++ head/bin/sh/jobs.c  Mon Jan  1 22:31:52 2018(r327475)
@@ -75,6 +75,42 @@ __FBSDID("$FreeBSD$");
 #include "builtins.h"
 
 
+/*
+ * A job structure contains information about a job.  A job is either a
+ * single process or a set of processes contained in a pipeline.  In the
+ * latter case, pidlist will be non-NULL, and will point to a -1 terminated
+ * array of pids.
+ */
+
+struct procstat {
+   pid_t pid;  /* process id */
+   int status; /* status flags (defined above) */
+   char *cmd;  /* text of command being run */
+};
+
+
+/* states */
+#define JOBSTOPPED 1   /* all procs are stopped */
+#define JOBDONE 2  /* all procs are completed */
+
+
+struct job {
+   struct procstat ps0;/* status of process */
+   struct procstat *ps;/* status or processes when more than one */
+   short nprocs;   /* number of processes */
+   pid_t pgrp; /* process group of this job */
+   char state; /* true if job is finished */
+   char used;  /* true if this entry is in used */
+   char changed;   /* true if status has changed */
+   char foreground;/* true if running in the foreground */
+   char remembered;/* true if $! referenced */
+#if JOBS
+   char jobctl;/* job running under job control */
+   struct job *next;   /* job used after this one */
+#endif
+};
+
+
 static struct job *jobtab; /* array of jobs */
 static int njobs;  /* size of array */
 static pid_t backgndpid = -1;  /* pid of last background process */

Modified: head/bin/sh/jobs.h
==
--- head/bin/sh/jobs.h  Mon Jan  1 22:10:21 2018(r327474)
+++ head/bin/sh/jobs.h  Mon Jan  1 22:31:52 2018(r327475)
@@ -40,40 +40,7 @@
 
 #include /* for sig_atomic_t */
 
-/*
- * A job structure contains information about a job.  A job is either a
- * single process or a set of processes contained in a pipeline.  In the
- * latter case, pidlist will be non-NULL, and will point to a -1 terminated
- * array of pids.
- */
-
-struct procstat {
-   pid_t pid;  /* process id */
-   int status; /* status flags (defined above) */
-   char *cmd;  /* text of command being run */
-};
-
-
-/* states */
-#define JOBSTOPPED 1   /* all procs are stopped */
-#define JOBDONE 2  /* all procs are completed */
-
-
-struct job {
-   struct procstat ps0;/* status of process */
-   struct procstat *ps;/* status or processes when more than one */
-   short nprocs;   /* number of processes */
-   pid_t pgrp; /* process group of this job */
-   char state; /* true if job is finished */
-   char used;  /* true if this entry is in used */
-   char changed;   /* true if status has changed */
-   char foreground;/* true if running in the foreground */
-   char remembered;/* true if $! referenced */
-#if JOBS
-   char jobctl;/* job running under job control */
-   struct job *next;   /* job used after this one */
-#endif
-};
+struct job;
 
 enum {
SHOWJOBS_DEFAULT,   /* job number, status, command */
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r327440 - in head: etc/mtree usr.bin/find

2017-12-31 Thread Jilles Tjoelker
Author: jilles
Date: Sun Dec 31 19:24:13 2017
New Revision: 327440
URL: https://svnweb.freebsd.org/changeset/base/327440

Log:
  find: Link tests to the build

Modified:
  head/etc/mtree/BSD.tests.dist
  head/usr.bin/find/Makefile

Modified: head/etc/mtree/BSD.tests.dist
==
--- head/etc/mtree/BSD.tests.dist   Sun Dec 31 18:53:13 2017
(r327439)
+++ head/etc/mtree/BSD.tests.dist   Sun Dec 31 19:24:13 2017
(r327440)
@@ -664,6 +664,8 @@
 ..
 file2c
 ..
+find
+..
 fold
 ..
 getconf

Modified: head/usr.bin/find/Makefile
==
--- head/usr.bin/find/Makefile  Sun Dec 31 18:53:13 2017(r327439)
+++ head/usr.bin/find/Makefile  Sun Dec 31 19:24:13 2017(r327440)
@@ -1,6 +1,8 @@
 #  @(#)Makefile8.1 (Berkeley) 6/6/93
 # $FreeBSD$
 
+.include 
+
 PROG=  find
 SRCS=  find.c function.c ls.c main.c misc.c operator.c option.c \
getdate.y
@@ -8,7 +10,7 @@ YFLAGS=
 
 NO_WMISSING_VARIABLE_DECLARATIONS=
 
-#HAS_TESTS=
-#SUBDIR.${MK_TESTS}+= tests
+HAS_TESTS=
+SUBDIR.${MK_TESTS}+= tests
 
 .include 
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r325726 - head/sys/kern

2017-12-28 Thread Jilles Tjoelker
On Thu, Dec 28, 2017 at 12:40:31PM +, Antoine Brodin wrote:
> On Sat, Nov 11, 2017 at 10:39 PM, Mateusz Guzik <m...@freebsd.org> wrote:
> > Author: mjg
> > Date: Sat Nov 11 22:39:33 2017
> > New Revision: 325726
> > URL: https://svnweb.freebsd.org/changeset/base/325726

> > Log:
> >   Avoid locking and refing in sysctl_kern_proc_args if possible.

> >   Turns out the sysctl is called a lot e.g. by pkg-static.

> > Modified:
> >   head/sys/kern/kern_proc.c

> There is a regression after this commit: x11-toolkits/gnustep-gui no
> longer builds.
> You can find a failure log at
> http://pb2.nyi.freebsd.org/data/111i386-default-PR224618/2017-12-28_12h28m51s/logs/errors/gnustep-gui-0.25.1_3.log
> The failure seems to be from lang/gnustep-base:

>   /* get the argument vectors */
>   vectors = kvm_getargv(kptr, proc_ptr, 0);

It looks like the new fast path only works properly if p->p_args is not
NULL. If p->p_args is NULL, this usually means that the arguments are
longer than ps_arg_cache_limit and must be retrieved from (pageable)
process memory and not wired p->p_args->ar_args. It is possible to
duplicate that piece of code as well but that is probably not worth it.

A simple reproducer is

sh -c 'n=$(sysctl -n kern.ps_arg_cache_limit);
exec ps -p "$$" -o "args=$(printf "%0${n}d" 0)"'

On head, the second line is [ps] indicating that KERN_PROC_ARGS did not
return the expected string. On stable/10 and stable/11, the second line
is a truncated version of the command line like
ps -p 86963 -o args=00

A prerequisite for this reproducer is that kern.ps_arg_cache_limit is
not set so high that it is impractical to exceed it but not {ARG_MAX}.

-- 
Jilles Tjoelker
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r327212 - head/bin/sh

2017-12-26 Thread Jilles Tjoelker
Author: jilles
Date: Tue Dec 26 16:23:18 2017
New Revision: 327212
URL: https://svnweb.freebsd.org/changeset/base/327212

Log:
  sh: Don't leak wait* implementation details from jobs.c

Modified:
  head/bin/sh/eval.c
  head/bin/sh/jobs.c

Modified: head/bin/sh/eval.c
==
--- head/bin/sh/eval.c  Tue Dec 26 16:20:38 2017(r327211)
+++ head/bin/sh/eval.c  Tue Dec 26 16:23:18 2017(r327212)
@@ -43,7 +43,6 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
-#include  /* For WIFSIGNALED(status) */
 #include 
 
 /*
@@ -840,7 +839,7 @@ evalcommand(union node *cmd, int flags, struct backcmd
struct parsefile *savetopfile;
volatile int e;
char *lastarg;
-   int realstatus;
+   int signaled;
int do_clearcmdentry;
const char *path = pathval();
int i;
@@ -1163,9 +1162,9 @@ cmddone:
 parent:/* parent process gets here (if we forked) */
if (mode == FORK_FG) {  /* argument to fork */
INTOFF;
-   exitstatus = waitforjob(jp, );
+   exitstatus = waitforjob(jp, );
INTON;
-   if (iflag && loopnest > 0 && WIFSIGNALED(realstatus)) {
+   if (iflag && loopnest > 0 && signaled) {
evalskip = SKIPBREAK;
skipcount = loopnest;
}

Modified: head/bin/sh/jobs.c
==
--- head/bin/sh/jobs.c  Tue Dec 26 16:20:38 2017(r327211)
+++ head/bin/sh/jobs.c  Tue Dec 26 16:23:18 2017(r327212)
@@ -1016,7 +1016,7 @@ vforkexecshell(struct job *jp, char **argv, char **env
  */
 
 int
-waitforjob(struct job *jp, int *origstatus)
+waitforjob(struct job *jp, int *signaled)
 {
 #if JOBS
int propagate_int = jp->jobctl && jp->foreground;
@@ -1039,8 +1039,8 @@ waitforjob(struct job *jp, int *origstatus)
setcurjob(jp);
 #endif
status = jp->ps[jp->nprocs - 1].status;
-   if (origstatus != NULL)
-   *origstatus = status;
+   if (signaled != NULL)
+   *signaled = WIFSIGNALED(status);
/* convert to 8 bits */
if (WIFEXITED(status))
st = WEXITSTATUS(status);
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r327211 - head/usr.sbin/nandtool

2017-12-26 Thread Jilles Tjoelker
Author: jilles
Date: Tue Dec 26 16:20:38 2017
New Revision: 327211
URL: https://svnweb.freebsd.org/changeset/base/327211

Log:
  nandtool: Add missing mode for open() with O_CREAT
  
  If O_CREAT is given, open() needs a mode argument. Follow the umask by
  passing 0666.
  
  Reviewed by:  imp
  MFC after:1 week
  Differential Revision:https://reviews.freebsd.org/D13607

Modified:
  head/usr.sbin/nandtool/nand_read.c
  head/usr.sbin/nandtool/nand_readoob.c

Modified: head/usr.sbin/nandtool/nand_read.c
==
--- head/usr.sbin/nandtool/nand_read.c  Tue Dec 26 16:13:20 2017
(r327210)
+++ head/usr.sbin/nandtool/nand_read.c  Tue Dec 26 16:20:38 2017
(r327211)
@@ -52,7 +52,7 @@ int nand_read(struct cmd_param *params)
}
 
if ((out = param_get_string(params, "out"))) {
-   out_fd = open(out, O_WRONLY|O_CREAT);
+   out_fd = open(out, O_WRONLY|O_CREAT, 0666);
if (out_fd == -1) {
perrorf("Cannot open %s for writing", out);
return (1);

Modified: head/usr.sbin/nandtool/nand_readoob.c
==
--- head/usr.sbin/nandtool/nand_readoob.c   Tue Dec 26 16:13:20 2017
(r327210)
+++ head/usr.sbin/nandtool/nand_readoob.c   Tue Dec 26 16:20:38 2017
(r327211)
@@ -59,7 +59,7 @@ int nand_read_oob(struct cmd_param *params)
}
 
if ((out = param_get_string(params, "out"))) {
-   if ((fd_out = open(out, O_WRONLY | O_CREAT)) == -1) {
+   if ((fd_out = open(out, O_WRONLY | O_CREAT, 0666)) == -1) {
perrorf("Cannot open %s", out);
ret = 1;
goto out;
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r327121 - head/bin/sh

2017-12-23 Thread Jilles Tjoelker
Author: jilles
Date: Sat Dec 23 22:58:19 2017
New Revision: 327121
URL: https://svnweb.freebsd.org/changeset/base/327121

Log:
  sh(1): Markup and spelling fixes

Modified:
  head/bin/sh/sh.1

Modified: head/bin/sh/sh.1
==
--- head/bin/sh/sh.1Sat Dec 23 22:57:14 2017(r327120)
+++ head/bin/sh/sh.1Sat Dec 23 22:58:19 2017(r327121)
@@ -343,7 +343,7 @@ Write each command
 variable subjected to parameter expansion and arithmetic expansion)
 to standard error before it is executed.
 Useful for debugging.
-.It nolog
+.It Li nolog
 Another do-nothing option for
 .Tn POSIX
 compliance.
@@ -2739,7 +2739,7 @@ were a known job that exited with exit status 127.
 If no operands are given, wait for all jobs to complete
 and return an exit status of zero.
 .El
-.Ss Commandline Editing
+.Ss Command Line Editing
 When
 .Nm
 is being used interactively from a terminal, the current command
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r326603 - head/contrib/mdocml

2017-12-05 Thread Jilles Tjoelker
Author: jilles
Date: Tue Dec  5 23:06:15 2017
New Revision: 326603
URL: https://svnweb.freebsd.org/changeset/base/326603

Log:
  mdoc(7): Update .Dd for previous commit

Modified:
  head/contrib/mdocml/mdoc.7

Modified: head/contrib/mdocml/mdoc.7
==
--- head/contrib/mdocml/mdoc.7  Tue Dec  5 23:02:31 2017(r326602)
+++ head/contrib/mdocml/mdoc.7  Tue Dec  5 23:06:15 2017(r326603)
@@ -15,7 +15,7 @@
 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 .\"
-.Dd $Mdocdate: July 20 2017 $
+.Dd $Mdocdate: December 5 2017 $
 .Dt MDOC 7
 .Os
 .Sh NAME
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r326601 - head/contrib/mdocml

2017-12-05 Thread Jilles Tjoelker
Author: jilles
Date: Tue Dec  5 23:00:41 2017
New Revision: 326601
URL: https://svnweb.freebsd.org/changeset/base/326601

Log:
  mdocml: Add IEEE Std 1003.1-2008, 2016 edition
  
  Also document IEEE Std 1003.1-2008, 2013 edition in mdoc(7) (as well as the
  2016 edition).
  
  Submitted by: Yuri Pankov
  Reviewed by:  bjk
  Differential Revision:https://reviews.freebsd.org/D13349

Modified:
  head/contrib/mdocml/mdoc.7
  head/contrib/mdocml/st.in

Modified: head/contrib/mdocml/mdoc.7
==
--- head/contrib/mdocml/mdoc.7  Tue Dec  5 22:24:20 2017(r326600)
+++ head/contrib/mdocml/mdoc.7  Tue Dec  5 23:00:41 2017(r326601)
@@ -2575,6 +2575,17 @@ The second and last Technical Corrigendum.
 .br
 This standard is also called
 X/Open Portability Guide version 7.
+.Pp
+.It \-p1003.1-2013
+.St -p1003.1-2013
+.br
+The 2013 edition incorporates Technical Corrigendum 1.
+.Pp
+.It \-p1003.1-2016
+.St -p1003.1-2016
+.br
+The 2016 edition incorporates Technical Corrigendum 1 and
+Technical Corrigendum 2.
 .El
 .It Other standards
 .Pp

Modified: head/contrib/mdocml/st.in
==
--- head/contrib/mdocml/st.in   Tue Dec  5 22:24:20 2017(r326600)
+++ head/contrib/mdocml/st.in   Tue Dec  5 23:00:41 2017(r326601)
@@ -35,6 +35,7 @@ LINE("-p1003.1-2001", "IEEE Std 1003.1-2001 (\\(LqPOSI
 LINE("-p1003.1-2004",  "IEEE Std 1003.1-2004 (\\(LqPOSIX.1\\(Rq)")
 LINE("-p1003.1-2008",  "IEEE Std 1003.1-2008 (\\(LqPOSIX.1\\(Rq)")
 LINE("-p1003.1-2013",  "IEEE Std 1003.1-2008, 2013 Edition 
(\\(LqPOSIX.1\\(Rq)")
+LINE("-p1003.1-2016",  "IEEE Std 1003.1-2008, 2016 Edition 
(\\(LqPOSIX.1\\(Rq)")
 LINE("-p1003.1",   "IEEE Std 1003.1 (\\(LqPOSIX.1\\(Rq)")
 LINE("-p1003.1b",  "IEEE Std 1003.1b (\\(LqPOSIX.1b\\(Rq)")
 LINE("-p1003.1b-93",   "IEEE Std 1003.1b-1993 (\\(LqPOSIX.1b\\(Rq)")
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


  1   2   3   4   5   6   7   8   9   10   >