diff options
Diffstat (limited to '')
| -rw-r--r-- | src/got-diminished-login.c | 72 |
1 files changed, 34 insertions, 38 deletions
diff --git a/src/got-diminished-login.c b/src/got-diminished-login.c index 28c70fd..e4df8f2 100644 --- a/src/got-diminished-login.c +++ b/src/got-diminished-login.c @@ -1,7 +1,7 @@ /** * got-diminished – Extension for gates-of-tartaros to minimise memory usage after logging in * - * Copyright © 2013, 2014 Mattias Andrée (maandree@member.fsf.org) + * Copyright © 2013, 2014 Mattias Andrée (m@maandree.se) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,43 +22,39 @@ #include <stdio.h> -int main(int argc, char** argv) +int +main(int argc, char *argv[]) { - pid_t pid = vfork(); - if (pid == -1) - { - perror("vfork"); - return 1; - } - - if (pid) - { - waitpid(pid, &pid, 0); - { - size_t n = 0, i; - char* stty = *(argv + 2); - char* stty_cmd; - - while (*(stty + n++)) - ; - - stty_cmd = malloc((5 + n) * sizeof(char)); - for (i = 0; i < 5; i++) - *(stty_cmd + i) = *("stty " + i); - stty_cmd += 5; - for (i = 0; i < n; i++) - *(stty_cmd + i) = *(stty + i); - stty_cmd -= 5; + pid_t pid = vfork(); + if (pid == -1) { + perror("vfork"); + return 1; + } + + if (pid) { + size_t n = 0, i; + char *stty = argv[2]; + char *stty_cmd; + + waitpid(pid, &pid, 0); - system(stty_cmd); - free(stty_cmd); - } - } - else - execlp("setsid", "setsid", "-c", "login", "--", *(argv + 1), NULL); - - return 0; - - (void) argc; -} + while (stty[n++]); + stty_cmd = malloc((5 + n) * sizeof(char)); + for (i = 0; i < 5; i++) + stty_cmd[i] = "stty "[i]; + stty_cmd += 5; + for (i = 0; i < n; i++) + stty_cmd[i] = stty[i]; + stty_cmd -= 5; + + system(stty_cmd); + free(stty_cmd); + } else { + execlp("setsid", "setsid", "-c", "login", "--", *(argv + 1), NULL); + } + + return 0; + + (void) argc; +} |
