Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Fri, 7 Feb 2020 21:22:01 +0300
From: Alexander Scherbatiy <>
Subject: fopen with "e" mode to close file descriptor in exec... functions


Below is a simple program without any errors handling that uses
fopen with "ae" mode to open a "test.log" file with append access
and call posix_spawn to create a child process and list all open files for
the child process.

The program output shows that the child process has "test.log" file as open.
I used docker with Alpine Linux 3.11.3 (musl libc x86_64 1.1.24).
Is it an expected behaviour for Alpine Linux?

The same program on my Ubuntu 19.10 (with "ash" changed to "bash") shows
the child process doesn't have  "test.log" file as open.


----------  posix_spawn_sample.c ----------
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <unistd.h>
#include <spawn.h>
#include <sys/wait.h>

extern char **environ;

int main()
    FILE* file = fopen("test.log", "ae");
    fprintf(file, "test line\n");

    pid_t pid;
    char *argv[] = {"bash", "-c", "echo PID=$$ && lsof -p $$", NULL};
    int status = posix_spawn(&pid, "/bin/sh", NULL, NULL, argv, environ);
    printf("Child pid: %i\n", pid);
    waitpid(pid, &status, 0);

    return 0;

Content of type "text/html" skipped

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.