sync with OpenBSD -current

This commit is contained in:
purplerain 2024-07-28 17:18:17 +00:00
parent f4c73361e2
commit aa342b6fac
Signed by: purplerain
GPG Key ID: F42C07F07E2E35B7
5 changed files with 35 additions and 13 deletions

View File

@ -1,4 +1,4 @@
/* $OpenBSD: csh.c,v 1.50 2023/03/08 04:43:04 guenther Exp $ */ /* $OpenBSD: csh.c,v 1.51 2024/07/28 15:31:22 deraadt Exp $ */
/* $NetBSD: csh.c,v 1.14 1995/04/29 23:21:28 mycroft Exp $ */ /* $NetBSD: csh.c,v 1.14 1995/04/29 23:21:28 mycroft Exp $ */
/*- /*-
@ -900,9 +900,7 @@ exitstat(void)
static void static void
phup(int sig) phup(int sig)
{ {
/* XXX sigh, everything after this is a signal race */ rechist(); /* XXX big signal race */
rechist();
/* /*
* We kill the last foreground process group. It then becomes * We kill the last foreground process group. It then becomes

View File

@ -1,4 +1,4 @@
/* $OpenBSD: proc.c,v 1.35 2023/03/08 04:43:04 guenther Exp $ */ /* $OpenBSD: proc.c,v 1.36 2024/07/28 15:31:22 deraadt Exp $ */
/* $NetBSD: proc.c,v 1.9 1995/04/29 23:21:33 mycroft Exp $ */ /* $NetBSD: proc.c,v 1.9 1995/04/29 23:21:33 mycroft Exp $ */
/*- /*-
@ -207,6 +207,7 @@ pnote(void)
neednote = 0; neednote = 0;
sigemptyset(&sigset); sigemptyset(&sigset);
sigaddset(&sigset, SIGCHLD); sigaddset(&sigset, SIGCHLD);
sigaddset(&sigset, SIGHUP);
for (pp = proclist.p_next; pp != NULL; pp = pp->p_next) { for (pp = proclist.p_next; pp != NULL; pp = pp->p_next) {
if (pp->p_flags & PNEEDNOTE) { if (pp->p_flags & PNEEDNOTE) {
sigprocmask(SIG_BLOCK, &sigset, &osigset); sigprocmask(SIG_BLOCK, &sigset, &osigset);
@ -234,6 +235,7 @@ pwait(void)
*/ */
sigemptyset(&sigset); sigemptyset(&sigset);
sigaddset(&sigset, SIGCHLD); sigaddset(&sigset, SIGCHLD);
sigaddset(&sigset, SIGHUP);
sigprocmask(SIG_BLOCK, &sigset, &osigset); sigprocmask(SIG_BLOCK, &sigset, &osigset);
for (pp = (fp = &proclist)->p_next; pp != NULL; pp = (fp = pp)->p_next) for (pp = (fp = &proclist)->p_next; pp != NULL; pp = (fp = pp)->p_next)
if (pp->p_pid == 0) { if (pp->p_pid == 0) {
@ -276,10 +278,12 @@ pjwait(struct process *pp)
fp = pp; fp = pp;
sigemptyset(&sigset); sigemptyset(&sigset);
sigaddset(&sigset, SIGCHLD); sigaddset(&sigset, SIGCHLD);
sigaddset(&sigset, SIGHUP);
sigprocmask(SIG_BLOCK, &sigset, &osigset); sigprocmask(SIG_BLOCK, &sigset, &osigset);
for (;;) { for (;;) {
sigemptyset(&sigset); sigemptyset(&sigset);
sigaddset(&sigset, SIGCHLD); sigaddset(&sigset, SIGCHLD);
sigaddset(&sigset, SIGHUP);
sigprocmask(SIG_BLOCK, &sigset, NULL); sigprocmask(SIG_BLOCK, &sigset, NULL);
jobflags = 0; jobflags = 0;
do do
@ -289,6 +293,7 @@ pjwait(struct process *pp)
break; break;
sigset = osigset; sigset = osigset;
sigdelset(&sigset, SIGCHLD); sigdelset(&sigset, SIGCHLD);
sigdelset(&sigset, SIGHUP);
sigsuspend(&sigset); sigsuspend(&sigset);
} }
sigprocmask(SIG_SETMASK, &osigset, NULL); sigprocmask(SIG_SETMASK, &osigset, NULL);
@ -352,6 +357,7 @@ dowait(Char **v, struct command *t)
pjobs++; pjobs++;
sigemptyset(&sigset); sigemptyset(&sigset);
sigaddset(&sigset, SIGCHLD); sigaddset(&sigset, SIGCHLD);
sigaddset(&sigset, SIGHUP);
sigprocmask(SIG_BLOCK, &sigset, &osigset); sigprocmask(SIG_BLOCK, &sigset, &osigset);
loop: loop:
for (pp = proclist.p_next; pp; pp = pp->p_next) for (pp = proclist.p_next; pp; pp = pp->p_next)
@ -1004,6 +1010,7 @@ pkill(Char **v, int signum)
sigemptyset(&sigset); sigemptyset(&sigset);
sigaddset(&sigset, SIGCHLD); sigaddset(&sigset, SIGCHLD);
sigaddset(&sigset, SIGHUP);
if (setintr) if (setintr)
sigaddset(&sigset, SIGINT); sigaddset(&sigset, SIGINT);
sigprocmask(SIG_BLOCK, &sigset, NULL); sigprocmask(SIG_BLOCK, &sigset, NULL);
@ -1095,6 +1102,7 @@ pstart(struct process *pp, int foregnd)
sigemptyset(&sigset); sigemptyset(&sigset);
sigaddset(&sigset, SIGCHLD); sigaddset(&sigset, SIGCHLD);
sigaddset(&sigset, SIGHUP);
sigprocmask(SIG_BLOCK, &sigset, &osigset); sigprocmask(SIG_BLOCK, &sigset, &osigset);
np = pp; np = pp;
do { do {
@ -1255,10 +1263,11 @@ pfork(struct command *t, int wanttty)
if (child == 16) if (child == 16)
stderror(ERR_NESTING, 16); stderror(ERR_NESTING, 16);
/* /*
* Hold SIGCHLD until we have the process installed in our table. * Hold SIGCHLD/SIGHUP until we have the process installed in our table.
*/ */
sigemptyset(&sigset); sigemptyset(&sigset);
sigaddset(&sigset, SIGCHLD); sigaddset(&sigset, SIGCHLD);
sigaddset(&sigset, SIGHUP);
sigprocmask(SIG_BLOCK, &sigset, &osigset); sigprocmask(SIG_BLOCK, &sigset, &osigset);
while ((pid = fork()) == -1) while ((pid = fork()) == -1)
if (setintr == 0) if (setintr == 0)

View File

@ -1,4 +1,4 @@
/* $OpenBSD: sem.c,v 1.23 2019/06/28 13:34:58 deraadt Exp $ */ /* $OpenBSD: sem.c,v 1.24 2024/07/28 15:31:22 deraadt Exp $ */
/* $NetBSD: sem.c,v 1.9 1995/09/27 00:38:50 jtc Exp $ */ /* $NetBSD: sem.c,v 1.9 1995/09/27 00:38:50 jtc Exp $ */
/*- /*-
@ -196,12 +196,13 @@ execute(struct command *t, int wanttty, int *pipein, int *pipeout)
t->t_dflg & (F_REPEAT | F_AMPERSAND) || bifunc) { t->t_dflg & (F_REPEAT | F_AMPERSAND) || bifunc) {
forked++; forked++;
/* /*
* We need to block SIGCHLD here, so that if the process does * We need to block SIGCHLD/SIGHUP here, so that if the process does
* not die before we can set the process group * not die before we can set the process group
*/ */
if (wanttty >= 0 && !nosigchld) { if (wanttty >= 0 && !nosigchld) {
sigemptyset(&sigset); sigemptyset(&sigset);
sigaddset(&sigset, SIGCHLD); sigaddset(&sigset, SIGCHLD);
sigaddset(&sigset, SIGHUP);
sigprocmask(SIG_BLOCK, &sigset, &csigset); sigprocmask(SIG_BLOCK, &sigset, &csigset);
nosigchld = 1; nosigchld = 1;
} }
@ -231,11 +232,13 @@ execute(struct command *t, int wanttty, int *pipein, int *pipeout)
if (wanttty >= 0 && !nosigchld && !noexec) { if (wanttty >= 0 && !nosigchld && !noexec) {
sigemptyset(&sigset); sigemptyset(&sigset);
sigaddset(&sigset, SIGCHLD); sigaddset(&sigset, SIGCHLD);
sigaddset(&sigset, SIGHUP);
sigprocmask(SIG_BLOCK, &sigset, &csigset); sigprocmask(SIG_BLOCK, &sigset, &csigset);
nosigchld = 1; nosigchld = 1;
} }
sigemptyset(&sigset); sigemptyset(&sigset);
sigaddset(&sigset, SIGCHLD); sigaddset(&sigset, SIGCHLD);
sigaddset(&sigset, SIGHUP);
sigaddset(&sigset, SIGINT); sigaddset(&sigset, SIGINT);
sigprocmask(SIG_BLOCK, &sigset, &osigset); sigprocmask(SIG_BLOCK, &sigset, &osigset);
ochild = child; ochild = child;

12
usr.bin/env/env.1 vendored
View File

@ -1,4 +1,4 @@
.\" $OpenBSD: env.1,v 1.20 2015/01/12 21:42:53 deraadt Exp $ .\" $OpenBSD: env.1,v 1.21 2024/07/28 10:08:44 kn Exp $
.\" Copyright (c) 1980, 1990 The Regents of the University of California. .\" Copyright (c) 1980, 1990 The Regents of the University of California.
.\" All rights reserved. .\" All rights reserved.
.\" .\"
@ -30,7 +30,7 @@
.\" .\"
.\" from: @(#)printenv.1 6.7 (Berkeley) 7/28/91 .\" from: @(#)printenv.1 6.7 (Berkeley) 7/28/91
.\" .\"
.Dd $Mdocdate: January 12 2015 $ .Dd $Mdocdate: July 28 2024 $
.Dt ENV 1 .Dt ENV 1
.Os .Os
.Sh NAME .Sh NAME
@ -39,6 +39,7 @@
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm env .Nm env
.Op Fl i .Op Fl i
.Op Fl u Ar name
.Oo .Oo
.Ar name Ns = Ns Ar value ... .Ar name Ns = Ns Ar value ...
.Oc .Oc
@ -66,6 +67,10 @@ The options are as follows:
Causes Causes
.Nm .Nm
to completely ignore the environment it inherits. to completely ignore the environment it inherits.
.It Fl u Ar name
Remove
.Ar name
from the environment.
.El .El
.Pp .Pp
If no If no
@ -121,6 +126,9 @@ The
utility is compliant with the utility is compliant with the
.St -p1003.1-2008 .St -p1003.1-2008
specification. specification.
The flag
.Op Fl u
is an extension to that specification.
.Pp .Pp
The historic The historic
.Fl .Fl

10
usr.bin/env/env.c vendored
View File

@ -1,4 +1,4 @@
/* $OpenBSD: env.c,v 1.17 2016/10/28 07:22:59 schwarze Exp $ */ /* $OpenBSD: env.c,v 1.18 2024/07/28 10:08:44 kn Exp $ */
/* /*
* Copyright (c) 1988, 1993, 1994 * Copyright (c) 1988, 1993, 1994
@ -49,13 +49,17 @@ main(int argc, char *argv[])
if (pledge("stdio exec", NULL) == -1) if (pledge("stdio exec", NULL) == -1)
err(1, "pledge"); err(1, "pledge");
while ((ch = getopt(argc, argv, "i-")) != -1) while ((ch = getopt(argc, argv, "-iu:")) != -1)
switch(ch) { switch(ch) {
case '-': /* obsolete */ case '-': /* obsolete */
case 'i': case 'i':
if ((environ = calloc(1, sizeof(char *))) == NULL) if ((environ = calloc(1, sizeof(char *))) == NULL)
err(126, "calloc"); err(126, "calloc");
break; break;
case 'u':
if (unsetenv(optarg) == -1)
err(126, "unsetenv");
break;
default: default:
usage(); usage();
} }
@ -91,7 +95,7 @@ usage(void)
{ {
extern char *__progname; extern char *__progname;
(void)fprintf(stderr, "usage: %s [-i] [name=value ...] " (void)fprintf(stderr, "usage: %s [-i] [-u name] [name=value ...] "
"[utility [argument ...]]\n", __progname); "[utility [argument ...]]\n", __progname);
exit(1); exit(1);
} }