mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] fopen with "e" mode to close file descriptor in exec... functions
@ 2020-02-07 18:22 Alexander Scherbatiy
  2020-02-07 21:03 ` Rich Felker
  0 siblings, 1 reply; 6+ messages in thread
From: Alexander Scherbatiy @ 2020-02-07 18:22 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 1146 bytes --]

Hello,

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
that
the child process doesn't have  "test.log" file as open.

Thanks,
Alexander.

----------  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);

    fclose(file);
    return 0;
}
--------------------------

[-- Attachment #2: Type: text/html, Size: 1691 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-02-10 14:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-07 18:22 [musl] fopen with "e" mode to close file descriptor in exec... functions Alexander Scherbatiy
2020-02-07 21:03 ` Rich Felker
2020-02-08  7:45   ` Alexander Scherbatiy
2020-02-08 16:19     ` Rich Felker
2020-02-10  9:57       ` Alexander Scherbatiy
2020-02-10 14:56         ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).