Skip to content

Commit 8db646f

Browse files
committed
Fix bug with systemvpe()
See #1253
1 parent fde03f8 commit 8db646f

File tree

4 files changed

+62
-16
lines changed

4 files changed

+62
-16
lines changed

libc/calls/struct/sigset.h

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@ COSMOPOLITAN_C_START_
44

55
typedef uint64_t sigset_t;
66

7-
int sigaddset(sigset_t *, int) paramsnonnull();
8-
int sigdelset(sigset_t *, int) paramsnonnull();
9-
int sigemptyset(sigset_t *) paramsnonnull();
10-
int sigfillset(sigset_t *) paramsnonnull();
11-
int sigandset(sigset_t *, const sigset_t *, const sigset_t *) paramsnonnull();
12-
int sigorset(sigset_t *, const sigset_t *, const sigset_t *) paramsnonnull();
13-
int sigisemptyset(const sigset_t *) paramsnonnull() nosideeffect;
14-
int sigismember(const sigset_t *, int) paramsnonnull() nosideeffect;
15-
int sigcountset(const sigset_t *) paramsnonnull() nosideeffect;
16-
int sigprocmask(int, const sigset_t *, sigset_t *);
17-
int sigsuspend(const sigset_t *);
18-
int sigpending(sigset_t *);
19-
int pthread_sigmask(int, const sigset_t *, sigset_t *);
7+
/* clang-format off */
8+
int sigaddset(sigset_t *, int) libcesque paramsnonnull();
9+
int sigdelset(sigset_t *, int) libcesque paramsnonnull();
10+
int sigemptyset(sigset_t *) libcesque paramsnonnull();
11+
int sigfillset(sigset_t *) libcesque paramsnonnull();
12+
int sigandset(sigset_t *, const sigset_t *, const sigset_t *) libcesque paramsnonnull();
13+
int sigorset(sigset_t *, const sigset_t *, const sigset_t *) libcesque paramsnonnull();
14+
int sigisemptyset(const sigset_t *) libcesque paramsnonnull() nosideeffect;
15+
int sigismember(const sigset_t *, int) libcesque paramsnonnull() nosideeffect;
16+
int sigcountset(const sigset_t *) libcesque paramsnonnull() nosideeffect;
17+
int sigprocmask(int, const sigset_t *, sigset_t *) dontthrow;
18+
int sigsuspend(const sigset_t *) dontthrow;
19+
int sigpending(sigset_t *) libcesque;
20+
int pthread_sigmask(int, const sigset_t *, sigset_t *) dontthrow;
21+
/* clang-format on */
2022

2123
COSMOPOLITAN_C_END_
2224
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGSET_H_ */

libc/system/systemvpe.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,16 @@ int systemvpe(const char *prog, char *const argv[], char *const envp[]) {
5252
int pid, wstatus;
5353
char pathbuf[PATH_MAX + 1];
5454
sigset_t chldmask, savemask;
55-
if (!(exe = commandv(prog, pathbuf, sizeof(pathbuf)))) {
55+
if (!(exe = commandv(prog, pathbuf, sizeof(pathbuf))))
5656
return -1;
57-
}
5857
sigemptyset(&chldmask);
5958
sigaddset(&chldmask, SIGINT);
6059
sigaddset(&chldmask, SIGQUIT);
6160
sigaddset(&chldmask, SIGCHLD);
6261
sigprocmask(SIG_BLOCK, &chldmask, &savemask);
6362
if (!(pid = vfork())) {
6463
sigprocmask(SIG_SETMASK, &savemask, 0);
65-
execve(prog, argv, envp);
64+
execve(exe, argv, envp);
6665
_Exit(127);
6766
} else if (pid == -1) {
6867
wstatus = -1;

test/libc/system/BUILD.mk

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ o/$(MODE)/test/libc/system/trace_test.dbg: \
9494
$(APE_NO_MODIFY_SELF)
9595
@$(APELINK)
9696

97+
o/$(MODE)/test/libc/system/systemvpe_test.dbg: \
98+
$(TEST_LIBC_SYSTEM_DEPS) \
99+
o/$(MODE)/test/libc/system/systemvpe_test.o \
100+
o/$(MODE)/test/libc/system/system.pkg \
101+
o/$(MODE)/test/libc/proc/life.zip.o \
102+
$(LIBC_TESTMAIN) \
103+
$(CRT) \
104+
$(APE_NO_MODIFY_SELF)
105+
@$(APELINK)
106+
107+
97108
o/$(MODE)/test/libc/system/popen_test.zip.o: private ZIPOBJ_FLAGS += -B
98109
o/$(MODE)/test/libc/system/popen_test.dbg.zip.o: private ZIPOBJ_FLAGS += -B
99110

test/libc/system/systemvpe_test.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
2+
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
3+
╞══════════════════════════════════════════════════════════════════════════════╡
4+
│ Copyright 2024 Justine Alexandra Roberts Tunney │
5+
│ │
6+
│ Permission to use, copy, modify, and/or distribute this software for │
7+
│ any purpose with or without fee is hereby granted, provided that the │
8+
│ above copyright notice and this permission notice appear in all copies. │
9+
│ │
10+
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
11+
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
12+
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
13+
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
14+
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
15+
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
16+
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
17+
│ PERFORMANCE OF THIS SOFTWARE. │
18+
╚─────────────────────────────────────────────────────────────────────────────*/
19+
#include "libc/calls/calls.h"
20+
#include "libc/cosmo.h"
21+
#include "libc/runtime/runtime.h"
22+
#include "libc/testlib/testlib.h"
23+
24+
void SetUpOnce(void) {
25+
testlib_enable_tmp_setup_teardown();
26+
}
27+
28+
TEST(systemvpe, test) {
29+
ASSERT_SYS(0, 0, mkdir("bin", 0755));
30+
ASSERT_SYS(0, 0, setenv("PATH", "bin", true));
31+
testlib_extract("/zip/life", "bin/life", 0755);
32+
ASSERT_SYS(0, 42 << 8,
33+
systemvpe("life", (char *[]){"life", 0}, (char *[]){0}));
34+
}

0 commit comments

Comments
 (0)