Skip to content

Commit

Permalink
Add Cosmopolitan to uname()
Browse files Browse the repository at this point in the history
  • Loading branch information
jart committed Sep 22, 2023
1 parent ed31649 commit 3ffc17c
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 14 deletions.
1 change: 1 addition & 0 deletions libc/calls/sigtimedwait.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);

Expand Down
26 changes: 26 additions & 0 deletions libc/calls/sigwait.c
Original file line number Diff line number Diff line change
@@ -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;
}
25 changes: 18 additions & 7 deletions libc/calls/uname.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -166,14 +166,25 @@ 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);
rc = 0;
} 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),
Expand Down
2 changes: 0 additions & 2 deletions libc/intrin/cxaatexit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions libc/intrin/cxafinalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 0 additions & 2 deletions libc/intrin/pthread_mutex_unlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

/**
Expand Down
1 change: 1 addition & 0 deletions libc/isystem/wchar.h
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
9 changes: 9 additions & 0 deletions third_party/musl/grp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion third_party/musl/passwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
Expand Down

0 comments on commit 3ffc17c

Please sign in to comment.