X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=driver%2Fsubprocs.c;h=b2b341a8fde7e2af2f00e1dd423367e1f4cba260;hb=0bd2eabab3e404c6769fe8f59b639275e960c415;hp=9070b81bb829537b440baa7e0d492011f9559ec0;hpb=6bb727f03bff0389fbb1349d7df4c9d8d7532959;p=xscreensaver diff --git a/driver/subprocs.c b/driver/subprocs.c index 9070b81b..b2b341a8 100644 --- a/driver/subprocs.c +++ b/driver/subprocs.c @@ -76,7 +76,7 @@ extern int kill (pid_t, int); /* signal() is in sys/signal.h... */ extern saver_info *global_si_kludge; /* I hate C so much... */ -static void hack_environment (saver_screen_info *ssi); +static void hack_subproc_environment (saver_screen_info *ssi); static void @@ -301,8 +301,8 @@ struct screenhack_job { static struct screenhack_job *jobs = 0; -#ifdef DEBUG -static void +/* for debugging -- nothing calls this, but it's useful to invoke from gdb. */ +void show_job_list (void) { struct screenhack_job *job; @@ -317,7 +317,6 @@ show_job_list (void) job->name); fprintf (stderr, "\n"); } -#endif static void clean_job_list (void); @@ -533,11 +532,9 @@ sigchld_handler (int sig) { saver_info *si = global_si_kludge; /* I hate C so much... */ -#ifdef DEBUG if (si->prefs.debug_p) fprintf(stderr, "%s: got SIGCHLD%s\n", progname, (block_sigchld_handler ? " (blocked)" : "")); -#endif /* DEBUG */ if (block_sigchld_handler < 0) abort(); @@ -564,14 +561,16 @@ await_dying_children (saver_info *si) errno = 0; kid = waitpid (-1, &wait_status, WNOHANG|WUNTRACED); -#ifdef DEBUG + if (si->prefs.debug_p) - if (kid < 0 && errno) - fprintf (stderr, "%s: waitpid(-1) ==> %ld (%d)\n", progname, - (long) kid, errno); - else - fprintf (stderr, "%s: waitpid(-1) ==> %ld\n", progname, (long) kid); -#endif /* DEBUG */ + { + if (kid < 0 && errno) + fprintf (stderr, "%s: waitpid(-1) ==> %ld (%d)\n", progname, + (long) kid, errno); + else + fprintf (stderr, "%s: waitpid(-1) ==> %ld\n", progname, + (long) kid); + } /* 0 means no more children to reap. -1 means error -- except "interrupted system call" isn't a "real" @@ -832,7 +831,7 @@ spawn_screenhack_1 (saver_screen_info *ssi, Bool first_time_p) case 0: close (ConnectionNumber (si->dpy)); /* close display fd */ nice_subproc (p->nice_inferior); /* change process priority */ - hack_environment (ssi); /* set $DISPLAY */ + hack_subproc_environment (ssi); /* set $DISPLAY */ exec_screenhack (si, hack); /* this does not return */ abort(); break; @@ -850,6 +849,15 @@ void spawn_screenhack (saver_info *si, Bool first_time_p) { int i; + + if (!monitor_powered_on_p (si)) + { + if (si->prefs.verbose_p) + printf ("%s: server reports that monitor has powered down; " + "not launching a new hack.\n", progname); + return; + } + for (i = 0; i < si->nscreens; i++) { saver_screen_info *ssi = &si->screens[i]; @@ -960,8 +968,8 @@ demo_mode_restart_process (saver_info *si) { int i; for (i = 0; saved_argv [i]; i++); - /* add the -demo switch; save_argv() left room for this. */ - saved_argv [i] = "-demo"; + /* add the -initial-demo-mode switch; save_argv() left room for this. */ + saved_argv [i] = "-initial-demo-mode"; saved_argv [i+1] = 0; restart_process (si); /* shouldn't return */ saved_argv [i] = 0; @@ -969,7 +977,7 @@ demo_mode_restart_process (saver_info *si) } static void -hack_environment (saver_screen_info *ssi) +hack_subproc_environment (saver_screen_info *ssi) { /* Store $DISPLAY into the environment, so that the $DISPLAY variable that the spawned processes inherit is correct. First, it must be on the same @@ -1010,6 +1018,28 @@ hack_environment (saver_screen_info *ssi) #endif /* HAVE_PUTENV */ } + +void +hack_environment (saver_info *si) +{ +#if defined(HAVE_PUTENV) && defined(DEFAULT_PATH_PREFIX) + static const char *def_path = DEFAULT_PATH_PREFIX; + if (def_path && *def_path) + { + const char *opath = getenv("PATH"); + char *npath = (char *) malloc(strlen(def_path) + strlen(opath) + 20); + strcpy (npath, "PATH="); + strcat (npath, def_path); + strcat (npath, ":"); + strcat (npath, opath); + + if (putenv (npath)) + abort (); + } +#endif /* HAVE_PUTENV && DEFAULT_PATH_PREFIX */ +} + + /* Change the uid/gid of the screensaver process, so that it is safe for it to run setuid root (which it needs to do on some systems to read the