Improve system call polyfills

- Polyfill open() w/ O_CLOEXEC on RHEL5
- Remove old workaround from rmdir() on the New Technology
- preadv() and pwritev() are now smarter about demodernization
- preadv() and pwritev() are now available on the New Technology
This commit is contained in:
Justine Tunney 2021-03-08 10:07:02 -08:00
parent 816b0e1851
commit 0ad609268f
21 changed files with 260 additions and 117 deletions

View file

@ -37,7 +37,6 @@
* @see getline(), gettok_r()
*/
ssize_t getdelim(char **line, size_t *n, int delim, FILE *f) {
STATIC_YOINK("realloc");
assert((*line && *n) || (!*line && !*n));
ssize_t rc = -1;
size_t i = 0;

View file

@ -66,8 +66,7 @@ int posix_spawn(int *pid, const char *path,
}
}
if (file_actions) {
p = *file_actions;
while (*p != '\0') {
for (p = *file_actions; *p; p = strchr(p, ')') + 1) {
if (!strncmp(p, "close(", 6)) {
if (sscanf(p + 6, "%d)", &fd) != 1) _exit(127);
if (close(fd) == -1) _exit(127);
@ -92,7 +91,6 @@ int posix_spawn(int *pid, const char *path,
} else {
_exit(127);
}
p = strchr(p, ')') + 1;
}
}
if (attrp) {

View file

@ -16,12 +16,18 @@ COSMOPOLITAN_C_START_
typedef char *posix_spawn_file_actions_t;
typedef struct _posix_spawnattr posix_spawnattr_t;
int posix_spawn(int *, const char *, const posix_spawn_file_actions_t *,
const posix_spawnattr_t *, char *const[], char *const[]);
int posix_spawnp(int *, const char *, const posix_spawn_file_actions_t *,
const posix_spawnattr_t *, char *const[], char *const[]);
int posix_spawn_file_actions_init(posix_spawn_file_actions_t *);
int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *);
int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *, int);
int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *, int, int);
int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *, int,
const char *, int, unsigned);
int posix_spawnattr_init(posix_spawnattr_t *);
int posix_spawnattr_destroy(posix_spawnattr_t *);
int posix_spawnattr_getflags(const posix_spawnattr_t *, short *);
@ -38,10 +44,6 @@ int posix_spawnattr_getsigmask(const posix_spawnattr_t *, sigset_t *);
int posix_spawnattr_setsigmask(posix_spawnattr_t *, const sigset_t *);
int posix_spawnattr_getdefault(const posix_spawnattr_t *, sigset_t *);
int posix_spawnattr_setsigdefault(posix_spawnattr_t *, const sigset_t *);
int posix_spawn(int *, const char *, const posix_spawn_file_actions_t *,
const posix_spawnattr_t *, char *const[], char *const[]);
int posix_spawnp(int *, const char *, const posix_spawn_file_actions_t *,
const posix_spawnattr_t *, char *const[], char *const[]);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */