Upodated stuff

This commit is contained in:
Maieul BOYER 2024-09-05 19:04:57 +00:00
parent c5bc77f467
commit 7401038bf7
5 changed files with 397 additions and 399 deletions

View file

@ -10,9 +10,13 @@
/* */
/* ************************************************************************** */
#include "fcntl.h"
#include "me/fs/fs.h"
#include "me/os/os.h"
#include "me/str/str.h"
#include "me/string/string.h"
#include "me/printf/printf.h"
#include "unistd.h"
static t_error _pipe_get_fd_slot(struct s_file_slot **read,
struct s_file_slot **write)
@ -28,6 +32,25 @@ static t_error _pipe_get_fd_slot(struct s_file_slot **read,
return (NO_ERROR);
}
static void _pipe_set_close_exec(t_fd *fd)
{
t_string s;
int new_fd;
int fd_perm;
s = string_new(16);
me_printf_str(&s, "/proc/self/fd/%i", fd->fd);
fd_perm = O_RDONLY;
if (fd->perms == FD_WRITE)
fd_perm = O_WRONLY;
new_fd = open(s.buf, fd_perm | O_CLOEXEC);
string_free(s);
if (new_fd == -1)
me_abort("pipe close_on_exec failed");
close(fd->fd);
fd->fd = new_fd;
}
t_error create_pipe(t_pipe *out)
{
int fd[2];
@ -52,5 +75,6 @@ t_error create_pipe(t_pipe *out)
write->slot.fd.name = str_clone("<pipe[write]>");
out->read = &read->slot.fd;
out->write = &write->slot.fd;
(_pipe_set_close_exec(out->read), _pipe_set_close_exec(out->write));
return (NO_ERROR);
}