mirror of
https://github.com/troglobit/finit.git
synced 2026-10-03 06:23:11 +07:00
run_getty(): Handle STDIO descriptors better.
The cppcheck tool raised an alert to the missing close() for stdin when a console is opened for a getty. This patch fixes that warning and also makes the code slighlty more readable. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
@@ -511,7 +511,7 @@ pid_t run_getty(char *cmd, char *args[], int console)
|
||||
pid_t pid = fork();
|
||||
|
||||
if (!pid) {
|
||||
int i;
|
||||
int i, fd;
|
||||
char c;
|
||||
sigset_t nmask;
|
||||
struct sigaction sa;
|
||||
@@ -520,12 +520,13 @@ pid_t run_getty(char *cmd, char *args[], int console)
|
||||
/* Detach from initial controlling TTY */
|
||||
vhangup();
|
||||
|
||||
close(2);
|
||||
close(1);
|
||||
close(0);
|
||||
close(STDERR_FILENO);
|
||||
close(STDOUT_FILENO);
|
||||
close(STDIN_FILENO);
|
||||
|
||||
/* Attach TTY to console */
|
||||
if (open(CONSOLE, O_RDWR) != 0)
|
||||
fd = open(CONSOLE, O_RDWR);
|
||||
if (fd != STDIN_FILENO)
|
||||
exit(1);
|
||||
|
||||
dup2(0, STDIN_FILENO);
|
||||
@@ -561,6 +562,9 @@ pid_t run_getty(char *cmd, char *args[], int console)
|
||||
execv(cmd, args);
|
||||
}
|
||||
|
||||
if (console)
|
||||
close(fd);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user