diff --git a/libc/calls/sigtimedwait.h b/libc/calls/sigtimedwait.h index 1c37888764e..0f8cd86fb5c 100644 --- a/libc/calls/sigtimedwait.h +++ b/libc/calls/sigtimedwait.h @@ -6,6 +6,7 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ +int sigwait(const sigset_t *, int *); int sigtimedwait(const sigset_t *, siginfo_t *, const struct timespec *); int sigwaitinfo(const sigset_t *, siginfo_t *); diff --git a/libc/calls/sigwait.c b/libc/calls/sigwait.c new file mode 100644 index 00000000000..32b6b5e644b --- /dev/null +++ b/libc/calls/sigwait.c @@ -0,0 +1,26 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2023 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/sigtimedwait.h" + +int sigwait(const sigset_t *mask, int *sig) { + siginfo_t si; + if (sigtimedwait(mask, &si, 0) < 0) return -1; + *sig = si.si_signo; + return 0; +} diff --git a/libc/calls/uname.c b/libc/calls/uname.c index de964564bcf..c3a3136daab 100644 --- a/libc/calls/uname.c +++ b/libc/calls/uname.c @@ -145,12 +145,12 @@ int uname(struct utsname *uts) { } else if (IsLinux()) { struct utsname_linux linux; if (!(rc = sys_uname_linux(&linux))) { - stpcpy(uts->sysname, linux.sysname); - stpcpy(uts->nodename, linux.nodename); - stpcpy(uts->release, linux.release); - stpcpy(uts->version, linux.version); - stpcpy(uts->machine, linux.machine); - stpcpy(uts->domainname, linux.domainname); + strlcpy(uts->sysname, linux.sysname, SYS_NMLN); + strlcpy(uts->nodename, linux.nodename, SYS_NMLN); + strlcpy(uts->release, linux.release, SYS_NMLN); + strlcpy(uts->version, linux.version, SYS_NMLN); + strlcpy(uts->machine, linux.machine, SYS_NMLN); + strlcpy(uts->domainname, linux.domainname, SYS_NMLN); if (!strcmp(uts->domainname, "(none)")) { uts->domainname[0] = 0; } @@ -166,7 +166,6 @@ int uname(struct utsname *uts) { } else if (IsWindows()) { stpcpy(uts->sysname, "Windows"); stpcpy(uts->machine, "x86_64"); - GetNtVersion(stpcpy(uts->version, "Windows ")); GetNtVersion(uts->release); GetNtName(uts->nodename, kNtComputerNamePhysicalDnsHostname); GetNtName(uts->domainname, kNtComputerNamePhysicalDnsDomain); @@ -174,6 +173,18 @@ int uname(struct utsname *uts) { } else { rc = enosys(); } + if (!rc) { + char buf[SYS_NMLN]; + stpcpy(buf, "Cosmopolitan 3.0-alpha"); + if (*MODE) { + strlcat(buf, " MODE=" MODE, SYS_NMLN); + } + if (*uts->version) { + strlcat(buf, "; ", SYS_NMLN); + strlcat(buf, uts->version, SYS_NMLN); + } + strlcpy(uts->version, buf, SYS_NMLN); + } STRACE("uname([{%#s, %#s, %#s, %#s, %#s, %#s}]) → %d% m", Str(rc, uts->sysname), Str(rc, uts->nodename), Str(rc, uts->release), Str(rc, uts->version), Str(rc, uts->machine), Str(rc, uts->domainname), diff --git a/libc/intrin/cxaatexit.c b/libc/intrin/cxaatexit.c index fcc809096df..c10d1bf65ac 100644 --- a/libc/intrin/cxaatexit.c +++ b/libc/intrin/cxaatexit.c @@ -16,7 +16,6 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/assert.h" #include "libc/intrin/bsr.h" #include "libc/intrin/cxaatexit.internal.h" #include "libc/intrin/strace.internal.h" @@ -60,7 +59,6 @@ int __cxa_atexit(void *fp, void *arg, void *pred) { } } i = _bsr(~b->mask); - unassert(i < ARRAYLEN(b->p)); b->mask |= 1u << i; b->p[i].fp = fp; b->p[i].arg = arg; diff --git a/libc/intrin/cxafinalize.c b/libc/intrin/cxafinalize.c index 064399c9d6a..eee304ad1e9 100644 --- a/libc/intrin/cxafinalize.c +++ b/libc/intrin/cxafinalize.c @@ -16,7 +16,6 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/assert.h" #include "libc/intrin/bsf.h" #include "libc/intrin/cxaatexit.internal.h" #include "libc/intrin/strace.internal.h" @@ -60,7 +59,6 @@ void __cxa_finalize(void *pred) { if (!pred) { b2 = b->next; if (b2) { - unassert(b != &__cxa_blocks.root); if (_weaken(free)) { _weaken(free)(b); } diff --git a/libc/intrin/pthread_mutex_unlock.c b/libc/intrin/pthread_mutex_unlock.c index c5b3bac3737..44bbe36770d 100644 --- a/libc/intrin/pthread_mutex_unlock.c +++ b/libc/intrin/pthread_mutex_unlock.c @@ -17,14 +17,12 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" -#include "libc/calls/state.internal.h" #include "libc/errno.h" #include "libc/intrin/atomic.h" #include "libc/intrin/strace.internal.h" #include "libc/intrin/weaken.h" #include "libc/runtime/internal.h" #include "libc/thread/thread.h" -#include "libc/thread/tls.h" #include "third_party/nsync/mu.h" /** diff --git a/libc/isystem/wchar.h b/libc/isystem/wchar.h index 0d0fc0fdf93..ecf5ecada9d 100644 --- a/libc/isystem/wchar.h +++ b/libc/isystem/wchar.h @@ -1,6 +1,7 @@ #ifndef _WCHAR_H #define _WCHAR_H #include "libc/fmt/conv.h" +#include "libc/mem/mem.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/str/unicode.h" diff --git a/third_party/musl/grp.c b/third_party/musl/grp.c index 9a1e9269987..a1a5e06be88 100644 --- a/third_party/musl/grp.c +++ b/third_party/musl/grp.c @@ -25,11 +25,13 @@ │ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │ │ │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/calls/calls.h" #include "libc/calls/weirdtypes.h" #include "libc/errno.h" #include "libc/mem/mem.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" +#include "libc/sysv/consts/limits.h" #include "libc/thread/thread.h" #include "third_party/musl/passwd.h" @@ -246,3 +248,10 @@ struct group *getgrnam(const char *name) { &g_getgrent->mem, &nmem, &res); return res; } + +int initgroups(const char *user, gid_t gid) { + gid_t groups[NGROUPS_MAX]; + int count = NGROUPS_MAX; + if (getgrouplist(user, gid, groups, &count) < 0) return -1; + return setgroups(count, groups); +} diff --git a/third_party/musl/passwd.h b/third_party/musl/passwd.h index 4de9bd83ad5..0fffc42bc7d 100644 --- a/third_party/musl/passwd.h +++ b/third_party/musl/passwd.h @@ -43,7 +43,7 @@ void setgrent(void); struct group *fgetgrent(struct FILE *); int putgrent(const struct group *, struct FILE *); int getgrouplist(const char *, gid_t, gid_t *, int *); -int initgroups(const char *, int32_t); +int initgroups(const char *, gid_t); COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */