Skip to content

Commit

Permalink
Fix bug with systemvpe()
Browse files Browse the repository at this point in the history
See #1253
  • Loading branch information
jart committed Jan 2, 2025
1 parent fde03f8 commit 8db646f
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 16 deletions.
28 changes: 15 additions & 13 deletions libc/calls/struct/sigset.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ COSMOPOLITAN_C_START_

typedef uint64_t sigset_t;

int sigaddset(sigset_t *, int) paramsnonnull();
int sigdelset(sigset_t *, int) paramsnonnull();
int sigemptyset(sigset_t *) paramsnonnull();
int sigfillset(sigset_t *) paramsnonnull();
int sigandset(sigset_t *, const sigset_t *, const sigset_t *) paramsnonnull();
int sigorset(sigset_t *, const sigset_t *, const sigset_t *) paramsnonnull();
int sigisemptyset(const sigset_t *) paramsnonnull() nosideeffect;
int sigismember(const sigset_t *, int) paramsnonnull() nosideeffect;
int sigcountset(const sigset_t *) paramsnonnull() nosideeffect;
int sigprocmask(int, const sigset_t *, sigset_t *);
int sigsuspend(const sigset_t *);
int sigpending(sigset_t *);
int pthread_sigmask(int, const sigset_t *, sigset_t *);
/* clang-format off */
int sigaddset(sigset_t *, int) libcesque paramsnonnull();
int sigdelset(sigset_t *, int) libcesque paramsnonnull();
int sigemptyset(sigset_t *) libcesque paramsnonnull();
int sigfillset(sigset_t *) libcesque paramsnonnull();
int sigandset(sigset_t *, const sigset_t *, const sigset_t *) libcesque paramsnonnull();
int sigorset(sigset_t *, const sigset_t *, const sigset_t *) libcesque paramsnonnull();
int sigisemptyset(const sigset_t *) libcesque paramsnonnull() nosideeffect;
int sigismember(const sigset_t *, int) libcesque paramsnonnull() nosideeffect;
int sigcountset(const sigset_t *) libcesque paramsnonnull() nosideeffect;
int sigprocmask(int, const sigset_t *, sigset_t *) dontthrow;
int sigsuspend(const sigset_t *) dontthrow;
int sigpending(sigset_t *) libcesque;
int pthread_sigmask(int, const sigset_t *, sigset_t *) dontthrow;
/* clang-format on */

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGSET_H_ */
5 changes: 2 additions & 3 deletions libc/system/systemvpe.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,16 @@ int systemvpe(const char *prog, char *const argv[], char *const envp[]) {
int pid, wstatus;
char pathbuf[PATH_MAX + 1];
sigset_t chldmask, savemask;
if (!(exe = commandv(prog, pathbuf, sizeof(pathbuf)))) {
if (!(exe = commandv(prog, pathbuf, sizeof(pathbuf))))
return -1;
}
sigemptyset(&chldmask);
sigaddset(&chldmask, SIGINT);
sigaddset(&chldmask, SIGQUIT);
sigaddset(&chldmask, SIGCHLD);
sigprocmask(SIG_BLOCK, &chldmask, &savemask);
if (!(pid = vfork())) {
sigprocmask(SIG_SETMASK, &savemask, 0);
execve(prog, argv, envp);
execve(exe, argv, envp);
_Exit(127);
} else if (pid == -1) {
wstatus = -1;
Expand Down
11 changes: 11 additions & 0 deletions test/libc/system/BUILD.mk
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ o/$(MODE)/test/libc/system/trace_test.dbg: \
$(APE_NO_MODIFY_SELF)
@$(APELINK)

o/$(MODE)/test/libc/system/systemvpe_test.dbg: \
$(TEST_LIBC_SYSTEM_DEPS) \
o/$(MODE)/test/libc/system/systemvpe_test.o \
o/$(MODE)/test/libc/system/system.pkg \
o/$(MODE)/test/libc/proc/life.zip.o \
$(LIBC_TESTMAIN) \
$(CRT) \
$(APE_NO_MODIFY_SELF)
@$(APELINK)


o/$(MODE)/test/libc/system/popen_test.zip.o: private ZIPOBJ_FLAGS += -B
o/$(MODE)/test/libc/system/popen_test.dbg.zip.o: private ZIPOBJ_FLAGS += -B

Expand Down
34 changes: 34 additions & 0 deletions test/libc/system/systemvpe_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2024 Justine Alexandra Roberts Tunney │
│ │
│ Permission to use, copy, modify, and/or distribute this software for │
│ any purpose with or without fee is hereby granted, provided that the │
│ above copyright notice and this permission notice appear in all copies. │
│ │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/calls/calls.h"
#include "libc/cosmo.h"
#include "libc/runtime/runtime.h"
#include "libc/testlib/testlib.h"

void SetUpOnce(void) {
testlib_enable_tmp_setup_teardown();
}

TEST(systemvpe, test) {
ASSERT_SYS(0, 0, mkdir("bin", 0755));
ASSERT_SYS(0, 0, setenv("PATH", "bin", true));
testlib_extract("/zip/life", "bin/life", 0755);
ASSERT_SYS(0, 42 << 8,
systemvpe("life", (char *[]){"life", 0}, (char *[]){0}));
}

0 comments on commit 8db646f

Please sign in to comment.