[MPlayer-dev-eng] [PATCH] Avoid resource lockup by xscreensaver

D Richard Felker III dalias at aerifal.cx
Sun Sep 29 17:21:10 CEST 2002


On Sun, Sep 29, 2002 at 10:54:08AM +0200, maf at tkrat.org wrote:
>      if (xscreensaver_was_running && stop_xscreensaver)
> -       system("xscreensaver -no-splash &");
> +    {
> +	if (0 == fork())
> +	{
> +	    struct rlimit rlim;
> +	    int i;
> +
> +	    /*
> +	     * Close all filedescriptors so that xscreensaver does not
> +	     * keep a lock on any device like the sound device.
> +	     */
> +	    getrlimit(RLIMIT_NOFILE, &rlim);
> +	    for (i=0; i < rlim.rlim_cur; i++)
> +		(void)close(i);
> +	    execlp("xscreensaver", "xscreensaver", "-no-splash", NULL);
> +	    exit(1);
> +	}
> +    }

IMHO this patch should not be committed as-is, since some broken
systems are missing various RLIMIT constants or missing getrlimit
entirely. (I think cygwin is one such system...) A much better
solution is just to set the close-on-exec flag properly on each fd
when it is opened.

Also you should never exec a program without fd 0, 1, and 2 opened to
*something*. /dev/null is of course ok. But if you start a program
with no fd 0-2, and then it opens a file for writing and subsequently
tries to write error output to stderr, it can trash its own file it
just opened. Very bad.

Rich





More information about the MPlayer-dev-eng mailing list