GNOME Bugzilla – Bug 333186
esd should close file descriptors it doesn't need
Last modified: 2006-08-07 23:20:42 UTC
It's good behavior in a daemon to close all open file descriptors, in case the parent didn't intend to hand some of them over. In particular, https://bugzilla.novell.com/show_bug.cgi?id=154072 shows a problem when esd gets started by gnomesu; clicking "Cancel" won't work, because it closes a pipe and waits for the backend process to notice that and exit, but the backend process doesn't see the pipe get closed, because gnomesu's end of the pipe accidentally got handed off to esd, so it remains open even though gnomesu closed its copy of it. --- esd.c +++ esd.c @@ -816,6 +816,12 @@ } } + /* close any file descriptors that shouldn't be open */ + for (i = getdtablesize () - 1; i > STDERR_FILENO; i--) { + if (i != esd_spawnfd) + close (i); + } + /* open the listening socket */ listen_socket = open_listen_socket(hostname, esd_port ); if ( listen_socket < 0 ) {
Yup, this needs to be fixed. I fixed it slightly differently, though.