From 9b20c0064cf69f368e8e7ec445b27c632204a77a Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sat, 12 Nov 2005 20:04:29 +0000 Subject: [PATCH] r4228: Bugfix: If stdin wasn't set when ROX-Filer was started it could get used for the X connection, before ROX-Filer got around to replacing it with /dev/null (Thomas Leonard). --- ROX-Filer/Help/Changes | 3 +++ ROX-Filer/src/main.c | 26 ++++++++++++++------------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/ROX-Filer/Help/Changes b/ROX-Filer/Help/Changes index 541c4605..89e31ec4 100644 --- a/ROX-Filer/Help/Changes +++ b/ROX-Filer/Help/Changes @@ -7,6 +7,9 @@ Added initial support for .desktop files (Thomas Leonard). They are now shown as executable, with the appropriate icons, and clicking on them runs the application. You cannot yet drag to them, and there are no tooltips. +Bugfix: If stdin wasn't set when ROX-Filer was started it could get used for + the X connection, before ROX-Filer got around to replacing it with + /dev/null (Thomas Leonard). 28-Oct-2005 ~~~~~~~~~~~ diff --git a/ROX-Filer/src/main.c b/ROX-Filer/src/main.c index 8bceca74..73513263 100644 --- a/ROX-Filer/src/main.c +++ b/ROX-Filer/src/main.c @@ -256,6 +256,20 @@ int main(int argc, char **argv) gboolean show_user = FALSE; xmlDocPtr rpc, soap_rpc = NULL, reply; xmlNodePtr body; + int fd; + + /* Close stdin. We don't need it, and it can cause problems if + * a child process wants a password, etc... + * Do this BEFORE opening anything (e.g., the X connection), in + * case fd 0 isn't open at this point. + */ + fd = open("/dev/null", O_RDONLY); + if (fd > 0) + { + close(0); + dup2(fd, 0); + close(fd); + } home_dir = g_get_home_dir(); home_dir_len = strlen(home_dir); @@ -530,7 +544,6 @@ int main(int argc, char **argv) */ if (!new_copy) { - int fd; pid_t child; child = fork(); @@ -539,17 +552,6 @@ int main(int argc, char **argv) /* Otherwise we're the child (or an error occurred - ignore * it!). */ - - /* Close stdin. We don't need it, and it can cause problems if - * a child process wants a password, etc... - */ - fd = open("/dev/null", O_RDONLY); - if (fd > 0) - { - close(0); - dup2(fd, 0); - close(fd); - } } /* Initialize the rest of the filer... */ -- 2.11.4.GIT