From 541cb14f1cf2d77f76b6cec665466a1685ff9b65 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 16 Oct 2018 10:21:16 +0200 Subject: Add ungrab command, respawn hack before password prompt --- driver/subprocs.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'driver/subprocs.c') diff --git a/driver/subprocs.c b/driver/subprocs.c index 4f327e9..13b47a4 100644 --- a/driver/subprocs.c +++ b/driver/subprocs.c @@ -916,6 +916,66 @@ fork_and_exec (saver_screen_info *ssi, const char *command) } +/* Execute command in another process and wait for it to + * finish. Return exit code of process, or -1 on error + * with fork() or exec(). + */ +int +exec_and_wait (saver_info *si, const char *command) +{ + pid_t forked; + saver_preferences *p = &si->prefs; + + switch ((int) (forked = fork ())) + { + case -1: + { + char buf [255]; + sprintf (buf, "%s: couldn't fork", blurb()); + perror (buf); + return -1; + } + + case 0: + close (ConnectionNumber (si->dpy)); /* close display fd */ + limit_subproc_memory (p->inferior_memory_limit, p->verbose_p); + + if (p->verbose_p) + fprintf (stderr, "%s: spawning \"%s\" in pid %lu.\n", + blurb(), command, + (unsigned long) getpid ()); + + exec_command (p->shell, command, 0); + + /* If that returned, we were unable to exec the subprocess. + Print an error message, if desired. + */ + print_path_error (command); + + exit (-1); /* exits child fork */ + break; + + default: /* parent */ + { + pid_t retpid; + int wstatus; + while ((retpid = waitpid (forked, &wstatus, 0)) == -1) { + if (errno == EINTR) + continue; + perror ("Could not waitpid for child."); + return -1; + } + if (WIFEXITED(wstatus)) + return WEXITSTATUS(wstatus); + if (WIFSIGNALED(wstatus)) + return WTERMSIG(wstatus) + 128; + return -1; + } + } + return -1; +} + + void spawn_screenhack (saver_screen_info *ssi) { -- cgit v1.2.3-55-g7522