mirror of
https://github.com/troglobit/finit.git
synced 2026-12-05 22:08:20 +00: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:
1 parent
143a257c25
commit
7cf7591f0a
1 file changed
+9
-5
@@ -511,7 +511,7 @@ pid_t run_getty(char *cmd, char *args[], int console)
|
|||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
|
|
||||||
if (!pid) {
|
if (!pid) {
|
||||||
int i;
|
int i, fd;
|
||||||
char c;
|
char c;
|
||||||
sigset_t nmask;
|
sigset_t nmask;
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
@@ -520,12 +520,13 @@ pid_t run_getty(char *cmd, char *args[], int console)
|
|||||||
/* Detach from initial controlling TTY */
|
/* Detach from initial controlling TTY */
|
||||||
vhangup();
|
vhangup();
|
||||||
|
|
||||||
close(2);
|
close(STDERR_FILENO);
|
||||||
close(1);
|
close(STDOUT_FILENO);
|
||||||
close(0);
|
close(STDIN_FILENO);
|
||||||
|
|
||||||
/* Attach TTY to console */
|
/* Attach TTY to console */
|
||||||
if (open(CONSOLE, O_RDWR) != 0)
|
fd = open(CONSOLE, O_RDWR);
|
||||||
|
if (fd != STDIN_FILENO)
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
dup2(0, STDIN_FILENO);
|
dup2(0, STDIN_FILENO);
|
||||||
@@ -561,6 +562,9 @@ pid_t run_getty(char *cmd, char *args[], int console)
|
|||||||
execv(cmd, args);
|
execv(cmd, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (console)
|
||||||
|
close(fd);
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user