diff options
| author | Mattias Andrée <maandree@operamail.com> | 2014-10-29 21:54:55 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@operamail.com> | 2014-10-29 21:55:11 +0100 |
| commit | 3b0aa46ba276e5a3559ec2859a16b579f3d15273 (patch) | |
| tree | 17c54c7509c9d0bdfcc209ed13eb082f142b189f /src/cerberus.c | |
| parent | doc hooks (diff) | |
| download | cerberus-3b0aa46ba276e5a3559ec2859a16b579f3d15273.tar.gz cerberus-3b0aa46ba276e5a3559ec2859a16b579f3d15273.tar.bz2 cerberus-3b0aa46ba276e5a3559ec2859a16b579f3d15273.tar.xz | |
fixs stdin problems on successful login, we needed to wait for the child, but I do not understand why,
although we shoul have done that anyway, I just forgot it
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/cerberus.c')
| -rw-r--r-- | src/cerberus.c | 49 |
1 files changed, 37 insertions, 12 deletions
diff --git a/src/cerberus.c b/src/cerberus.c index 1479771..7195f80 100644 --- a/src/cerberus.c +++ b/src/cerberus.c @@ -71,11 +71,7 @@ int main(int argc, char** argv) signal(SIGINT, SIG_IGN); /* Run login hook */ - if (fork() == 0) - { - exec_hook(HOOK_LOGIN, argc, argv); - return 0; - } + fork_exec_wait_hook(HOOK_LOGIN, argc, argv); /* Wait for the login shell and all grandchildren to exit */ while ((wait(NULL) == -1) && (errno == EINTR)) @@ -118,10 +114,10 @@ void exec_hook(int hook, int argc, char** argv) [HOOK_LOGOUT] = "logout", [HOOK_DENIED] = "denied", }; - - char** args = malloc((size_t)(argc + 2) * sizeof(char*)); + char** args; int i; + args = malloc((size_t)(argc + 2) * sizeof(char*)); if (args == NULL) { perror("malloc"); @@ -139,6 +135,39 @@ void exec_hook(int hook, int argc, char** argv) /** + * Fork-exec-wait /etc/cerberusrc + * + * @param hook The ID of the hook to run + * @param argc The number of command line arguments + * @param argv The command line arguments + */ +void fork_exec_wait_hook(int hook, int argc, char** argv) +{ + pid_t pid, reaped; + pid = fork(); + if (pid == -1) + return; + if (pid == 0) + { + close(STDIN_FILENO); + exec_hook(hook, argc, argv); + _exit(1); + } + for (;;) + { + reaped = wait(NULL); + if (reaped == -1) + { + perror("wait"); + return; + } + if (reaped == pid) + return; + } +} + + +/** * Do everything before the fork and do everything the exec fork * * @param argc The number of command line arguments @@ -303,11 +332,7 @@ void do_login(int argc, char** argv) printf("(auto-authenticated)\n"); if (ret == 0) { - if (fork() == 0) - { - exec_hook(HOOK_DENIED, argc, argv); - _exit(0); - } + fork_exec_wait_hook(HOOK_DENIED, argc, argv); sleep(FAILURE_SLEEP); _exit(1); } |
