mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-06 03:08:31 +00:00
Further improve usability of cosmocc
- Support -s flag in cosmocc - Support posix_spawn() setsid() feature - Disable monorepo debug path prefix stripping
This commit is contained in:
parent
f7ae50462a
commit
ee6566a152
9 changed files with 40 additions and 15 deletions
|
@ -18,6 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
|
||||
/**
|
||||
|
@ -26,7 +27,11 @@
|
|||
*/
|
||||
int setsid(void) {
|
||||
int rc;
|
||||
rc = sys_setsid();
|
||||
if (!IsWindows() && !IsMetal()) {
|
||||
rc = sys_setsid();
|
||||
} else {
|
||||
rc = 0;
|
||||
}
|
||||
STRACE("setsid() → %d% m", rc);
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -735,7 +735,6 @@ void abort(void) wontreturn;
|
|||
#pragma GCC diagnostic error "-Wnonnull"
|
||||
#pragma GCC diagnostic error "-Wunused-result"
|
||||
#pragma GCC diagnostic error "-Wstrict-aliasing"
|
||||
#pragma GCC diagnostic error "-Wshift-negative-value"
|
||||
#ifndef __cplusplus
|
||||
#pragma GCC diagnostic error "-Wimplicit-function-declaration"
|
||||
#if __GNUC__ >= 6
|
||||
|
|
|
@ -84,6 +84,12 @@ int posix_spawn(int *pid, const char *path,
|
|||
if (!(child = vfork())) {
|
||||
if (attrp && *attrp) {
|
||||
posix_spawnattr_getflags(attrp, &flags);
|
||||
if (flags & POSIX_SPAWN_SETSID) {
|
||||
if (setsid()) {
|
||||
STRACE("posix_spawn fail #%d", 1);
|
||||
_Exit(127);
|
||||
}
|
||||
}
|
||||
if (flags & POSIX_SPAWN_SETPGROUP) {
|
||||
if (setpgid(0, (*attrp)->pgroup)) {
|
||||
STRACE("posix_spawn fail #%d", 1);
|
||||
|
|
|
@ -3,12 +3,13 @@
|
|||
#include "libc/calls/struct/sched_param.h"
|
||||
#include "libc/calls/struct/sigset.h"
|
||||
|
||||
#define POSIX_SPAWN_RESETIDS 0x01
|
||||
#define POSIX_SPAWN_SETPGROUP 0x02
|
||||
#define POSIX_SPAWN_SETSIGDEF 0x04
|
||||
#define POSIX_SPAWN_SETSIGMASK 0x08
|
||||
#define POSIX_SPAWN_SETSCHEDPARAM 0x10
|
||||
#define POSIX_SPAWN_SETSCHEDULER 0x20
|
||||
#define POSIX_SPAWN_RESETIDS 1
|
||||
#define POSIX_SPAWN_SETPGROUP 2
|
||||
#define POSIX_SPAWN_SETSIGDEF 4
|
||||
#define POSIX_SPAWN_SETSIGMASK 8
|
||||
#define POSIX_SPAWN_SETSCHEDPARAM 16
|
||||
#define POSIX_SPAWN_SETSCHEDULER 32
|
||||
#define POSIX_SPAWN_SETSID 128
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
|
|
@ -89,6 +89,7 @@ int posix_spawnattr_getflags(const posix_spawnattr_t *attr, short *flags) {
|
|||
* - `POSIX_SPAWN_SETSIGMASK`
|
||||
* - `POSIX_SPAWN_SETSCHEDPARAM`
|
||||
* - `POSIX_SPAWN_SETSCHEDULER`
|
||||
* - `POSIX_SPAWN_SETSID`
|
||||
* @return 0 on success, or errno on error
|
||||
* @raise EINVAL if `flags` has invalid bits
|
||||
*/
|
||||
|
@ -96,9 +97,10 @@ int posix_spawnattr_setflags(posix_spawnattr_t *attr, short flags) {
|
|||
if (!(IsLinux() || IsFreebsd() || IsNetbsd())) {
|
||||
flags &= ~(POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER);
|
||||
}
|
||||
if (flags & ~(POSIX_SPAWN_RESETIDS | POSIX_SPAWN_SETPGROUP |
|
||||
POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK |
|
||||
POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER)) {
|
||||
if (flags &
|
||||
~(POSIX_SPAWN_RESETIDS | POSIX_SPAWN_SETPGROUP | POSIX_SPAWN_SETSIGDEF |
|
||||
POSIX_SPAWN_SETSIGMASK | POSIX_SPAWN_SETSCHEDPARAM |
|
||||
POSIX_SPAWN_SETSCHEDULER | POSIX_SPAWN_SETSID)) {
|
||||
return EINVAL;
|
||||
}
|
||||
(*attr)->flags = flags;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue