Skip to content

Commit d38c24a

Browse files
committed
libinitramfs/logging: Do not reassign stderr
Reassigning stdin, stdout,stderr is not a portable solution. The standard streams can be made to refer to different files with help of the library function freopen(3), specially introduced to make it possible to reassign stdin, stdout, and stderr. Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
1 parent a6060e5 commit d38c24a

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

runtime/src/libinitramfs/logging.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,6 @@ void rd_log_setup_stderr(const char *logfile)
143143
if (rdlog && !strcasecmp(rdlog, "console"))
144144
logfile = "/dev/console";
145145

146-
FILE *cons = fopen(logfile, "w+");
147-
if (!cons)
148-
rd_fatal("open(%s): %m", logfile);
149-
150-
fclose(stderr);
151-
stderr = cons;
146+
if (!freopen(logfile, "w+", stderr))
147+
rd_fatal("freopen(%s): %m", logfile);
152148
}

0 commit comments

Comments
 (0)