Share file offset across execve() on Windows

This is a breaking change. It defines the new environment variable named
_COSMO_FDS_V2 which is used for inheriting non-stdio file descriptors on
execve() or posix_spawn(). No effort has been spent thus far integrating
with the older variable. If a new binary launches the older ones or vice
versa they'll only be able to pass stdin / stdout / stderr to each other
therefore it's important that you upgrade all your cosmo binaries if you
depend on this functionality. You'll be glad you did because inheritance
of file descriptors is more aligned with the POSIX standard than before.
This commit is contained in:
Justine Tunney 2024-08-03 17:48:00 -07:00
parent 761c6ad615
commit 3f26dfbb31
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
29 changed files with 572 additions and 249 deletions

View file

@ -1,6 +1,5 @@
#ifndef COSMOPOLITAN_LIBC_CALLS_STRUCT_FD_INTERNAL_H_
#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FD_INTERNAL_H_
#include "libc/atomic.h"
#include "libc/thread/thread.h"
COSMOPOLITAN_C_START_
@ -15,14 +14,18 @@ COSMOPOLITAN_C_START_
#define kFdDevNull 9
#define kFdDevRandom 10
struct Cursor {
struct CursorShared {
pthread_mutex_t lock;
long pointer;
};
struct Cursor {
struct CursorShared *shared;
_Atomic(int) refs;
};
struct Fd {
char kind;
bool isdup;
bool isbound;
unsigned flags;
unsigned mode;
@ -33,7 +36,7 @@ struct Fd {
unsigned rcvtimeo; /* millis; 0 means wait forever */
unsigned sndtimeo; /* millis; 0 means wait forever */
void *connect_op;
struct Cursor *shared;
struct Cursor *cursor;
};
struct Fds {
@ -42,9 +45,11 @@ struct Fds {
struct Fd *p, *e;
};
void __fd_lock(struct Fd *);
void __fd_unlock(struct Fd *);
struct Cursor *__cursor_new(void);
void __cursor_ref(struct Cursor *);
int __cursor_unref(struct Cursor *);
void __cursor_lock(struct Cursor *);
void __cursor_unlock(struct Cursor *);
COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_CALLS_STRUCT_FD_INTERNAL_H_ */