int main(int argc, char **argv) { char *hide = "\x1b[2J\x1b[H\x1b[?25l"; char *show = "\x1b[?25h"; char **args = argv + 1; if (fb_init(FBDEV)) { fprintf(stderr, "fbpad: failed to initialize the framebuffer\n"); return 1; } if (sizeof(fbval_t) != FBM_BPP(fb_mode())) { fprintf(stderr, "fbpad: fbval_t does not match framebuffer depth\n"); return 1; } if (pad_init()) { fprintf(stderr, "fbpad: cannot find fonts\n"); return 1; } write(1, hide, strlen(hide)); signalsetup(); fcntl(0, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK); while (args[0] && args[0][0] == '-') args++; mainloop(args[0] ? args : NULL); write(1, show, strlen(show)); pad_free(); scr_done(); fb_free(); return 0; }
int main (void) { char *backp; sigset_t blockmask; pid_t childpid; struct sigaction defhandler; int inbackground; char inbuf[MAX_CANON]; int len; if (signalsetup(&defhandler, &blockmask, jumphd) == -1) { perror("Failed to set up shell signal handling"); return 1; } for( ; ; ) { if ((sigsetjmp(jumptoprompt, 1)) && /* if return from signal, newline */ (fputs("\n", stdout) == EOF) ) continue; okaytojump = 1; printf("%d",(int)getpid()); if (fputs(PROMPT_STRING, stdout) == EOF) continue; if (fgets(inbuf, MAX_CANON, stdin) == NULL) continue; len = strlen(inbuf); if (inbuf[len - 1] == '\n') inbuf[len - 1] = 0; if (strcmp(inbuf, QUIT_STRING) == 0) break; if ((backp = strchr(inbuf, BACK_SYMBOL)) == NULL) inbackground = 0; else { inbackground = 1; *backp = 0; } if (sigprocmask(SIG_BLOCK, &blockmask, NULL) == -1) perror("Failed to block signals"); if ((childpid = fork()) == -1) perror("Failed to fork"); else if (childpid == 0) { if (inbackground && (setpgid(0, 0) == -1)) return 1; if ((sigaction(SIGINT, &defhandler, NULL) == -1) || (sigaction(SIGQUIT, &defhandler, NULL) == -1) || (sigprocmask(SIG_UNBLOCK, &blockmask, NULL) == -1)) { perror("Failed to set signal handling for command "); return 1; } executecmd(inbuf); return 1; } if (sigprocmask(SIG_UNBLOCK, &blockmask, NULL) == -1) perror("Failed to unblock signals"); if (!inbackground) /* wait explicitly for the foreground process */ waitpid(childpid, NULL, 0); while (waitpid(-1, NULL, WNOHANG) > 0); /* wait for background procs */ } return 0; }
int main (void) { sigset_t blockmask; pid_t childpid; struct sigaction defaction; char inbuf[MAX_CANON]; int len; if (signalsetup(&defaction, &blockmask, SIG_IGN) == -1) { perror("Failed to set up shell signal handling"); return 1; } if (sigprocmask(SIG_BLOCK, &blockmask, NULL) == -1) { perror("Failed to block signals"); return 1; } for( ; ; ) { if (fputs(PROMPT_STRING, stdout) == EOF) continue; if (fgets(inbuf, MAX_CANON, stdin) == NULL) continue; len = strlen(inbuf); if (inbuf[len - 1] == '\n') inbuf[len - 1] = 0; if (strcmp(inbuf, QUIT_STRING) == 0) break; if ((childpid = fork()) == -1) { perror("Failed to fork child to execute command"); } else if (childpid == 0) { if ((sigaction(SIGINT, &defaction, NULL) == -1) || (sigaction(SIGQUIT, &defaction, NULL) == -1) || (sigprocmask(SIG_UNBLOCK, &blockmask, NULL) == -1)) { perror("Failed to set signal handling for command "); return 1; } executecmd(inbuf); return 1; } wait(NULL); } return 0; }
int main (void) { char *backp; sigset_t blockmask; pid_t childpid; struct sigaction defhandler; int inbackground; int len; char inbuf[MAX_CANON]; if (signalsetup(&defhandler, &blockmask, jumphd) == -1) { perror("Failed to set up shell signal handling"); return 1; } for( ; ; ) { if ((sigsetjmp(jumptoprompt, 1)) && /* if return from signal, \n */ (fputs("\n", stdout) == EOF) ) continue; okaytojump = 1; printf("%d",(int)getpid()); if (fputs(PROMPT_STRING, stdout) == EOF) continue; if (fgets(inbuf, MAX_CANON, stdin) == NULL) continue; len = strlen(inbuf); if (inbuf[len - 1] == '\n') inbuf[len - 1] = 0; if (strcmp(inbuf, QUIT_STRING) == 0) break; if ((backp = strchr(inbuf, BACK_SYMBOL)) == NULL) inbackground = 0; else { inbackground = 1; *backp = 0; } if (sigprocmask(SIG_BLOCK, &blockmask, NULL) == -1) perror("Failed to block signals"); if ((childpid = fork()) == -1) perror("Failed to fork"); else if (childpid == 0) { if (inbackground) { /* child creates another process */ if ((childpid = fork()) == -1) { perror("Second fork failed"); return 1; } if (childpid > 0) return 0; if (setpgid(0, 0) == -1) { perror("setpgod failed"); return 1; } } if ((sigaction(SIGINT, &defhandler, NULL) < 0) || (sigaction(SIGQUIT, &defhandler, NULL) < 0) || (sigprocmask(SIG_UNBLOCK, &blockmask, NULL) == -1)) { perror("Failed to set signal handling for command "); return 1; } executecmd(inbuf); perror("Failed to execute command"); return 1; } if (sigprocmask(SIG_UNBLOCK, &blockmask, NULL) == -1) perror("Failed to unblock signals"); wait(NULL); } return 0; }