Fix bug with systemvpe()

See #1253
This commit is contained in:
Justine Tunney 2025-01-02 09:15:52 -08:00
parent fde03f8487
commit 8db646f6b2
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
4 changed files with 62 additions and 16 deletions

View file

@ -4,19 +4,21 @@ COSMOPOLITAN_C_START_
typedef uint64_t sigset_t; typedef uint64_t sigset_t;
int sigaddset(sigset_t *, int) paramsnonnull(); /* clang-format off */
int sigdelset(sigset_t *, int) paramsnonnull(); int sigaddset(sigset_t *, int) libcesque paramsnonnull();
int sigemptyset(sigset_t *) paramsnonnull(); int sigdelset(sigset_t *, int) libcesque paramsnonnull();
int sigfillset(sigset_t *) paramsnonnull(); int sigemptyset(sigset_t *) libcesque paramsnonnull();
int sigandset(sigset_t *, const sigset_t *, const sigset_t *) paramsnonnull(); int sigfillset(sigset_t *) libcesque paramsnonnull();
int sigorset(sigset_t *, const sigset_t *, const sigset_t *) paramsnonnull(); int sigandset(sigset_t *, const sigset_t *, const sigset_t *) libcesque paramsnonnull();
int sigisemptyset(const sigset_t *) paramsnonnull() nosideeffect; int sigorset(sigset_t *, const sigset_t *, const sigset_t *) libcesque paramsnonnull();
int sigismember(const sigset_t *, int) paramsnonnull() nosideeffect; int sigisemptyset(const sigset_t *) libcesque paramsnonnull() nosideeffect;
int sigcountset(const sigset_t *) paramsnonnull() nosideeffect; int sigismember(const sigset_t *, int) libcesque paramsnonnull() nosideeffect;
int sigprocmask(int, const sigset_t *, sigset_t *); int sigcountset(const sigset_t *) libcesque paramsnonnull() nosideeffect;
int sigsuspend(const sigset_t *); int sigprocmask(int, const sigset_t *, sigset_t *) dontthrow;
int sigpending(sigset_t *); int sigsuspend(const sigset_t *) dontthrow;
int pthread_sigmask(int, const sigset_t *, sigset_t *); int sigpending(sigset_t *) libcesque;
int pthread_sigmask(int, const sigset_t *, sigset_t *) dontthrow;
/* clang-format on */
COSMOPOLITAN_C_END_ COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGSET_H_ */ #endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGSET_H_ */

View file

@ -52,9 +52,8 @@ int systemvpe(const char *prog, char *const argv[], char *const envp[]) {
int pid, wstatus; int pid, wstatus;
char pathbuf[PATH_MAX + 1]; char pathbuf[PATH_MAX + 1];
sigset_t chldmask, savemask; sigset_t chldmask, savemask;
if (!(exe = commandv(prog, pathbuf, sizeof(pathbuf)))) { if (!(exe = commandv(prog, pathbuf, sizeof(pathbuf))))
return -1; return -1;
}
sigemptyset(&chldmask); sigemptyset(&chldmask);
sigaddset(&chldmask, SIGINT); sigaddset(&chldmask, SIGINT);
sigaddset(&chldmask, SIGQUIT); sigaddset(&chldmask, SIGQUIT);
@ -62,7 +61,7 @@ int systemvpe(const char *prog, char *const argv[], char *const envp[]) {
sigprocmask(SIG_BLOCK, &chldmask, &savemask); sigprocmask(SIG_BLOCK, &chldmask, &savemask);
if (!(pid = vfork())) { if (!(pid = vfork())) {
sigprocmask(SIG_SETMASK, &savemask, 0); sigprocmask(SIG_SETMASK, &savemask, 0);
execve(prog, argv, envp); execve(exe, argv, envp);
_Exit(127); _Exit(127);
} else if (pid == -1) { } else if (pid == -1) {
wstatus = -1; wstatus = -1;

View file

@ -94,6 +94,17 @@ o/$(MODE)/test/libc/system/trace_test.dbg: \
$(APE_NO_MODIFY_SELF) $(APE_NO_MODIFY_SELF)
@$(APELINK) @$(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.zip.o: private ZIPOBJ_FLAGS += -B
o/$(MODE)/test/libc/system/popen_test.dbg.zip.o: private ZIPOBJ_FLAGS += -B o/$(MODE)/test/libc/system/popen_test.dbg.zip.o: private ZIPOBJ_FLAGS += -B

View file

@ -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}));
}