mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 11:37:35 +00:00
3f26dfbb31
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.
63 lines
1.6 KiB
C
63 lines
1.6 KiB
C
// Copyright 2024 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 <stdatomic.h>
|
|
#include <stdlib.h>
|
|
#include <sys/mman.h>
|
|
#include <unistd.h>
|
|
|
|
// subprogram for testing that lseek() is shared across execve()
|
|
|
|
atomic_int *phase;
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
if (argc != 3)
|
|
return 101;
|
|
|
|
int fd = atoi(argv[1]);
|
|
int mapfd = atoi(argv[2]);
|
|
|
|
if ((phase = mmap(0, sizeof(atomic_int), PROT_READ | PROT_WRITE, MAP_SHARED,
|
|
mapfd, 0)) == MAP_FAILED)
|
|
return 102;
|
|
|
|
if (write(fd, "1", 1) != 1)
|
|
return 103;
|
|
if (lseek(fd, 0, SEEK_CUR) != 2)
|
|
return 104;
|
|
|
|
*phase = 1;
|
|
for (;;)
|
|
if (*phase == 2)
|
|
break;
|
|
|
|
if (write(fd, "3", 1) != 1)
|
|
return 105;
|
|
if (lseek(fd, 0, SEEK_CUR) != 4)
|
|
return 106;
|
|
|
|
*phase = 3;
|
|
for (;;)
|
|
if (*phase == 4)
|
|
break;
|
|
|
|
if (munmap(phase, sizeof(atomic_int)))
|
|
return 107;
|
|
if (close(mapfd))
|
|
return 108;
|
|
if (close(fd))
|
|
return 109;
|
|
}
|