summaryrefslogtreecommitdiff
path: root/daemon
diff options
context:
space:
mode:
authorGeorge Lebl <jirka@5z.com>2002-07-16 17:01:58 +0000
committerGeorge Lebl <jirka@src.gnome.org>2002-07-16 17:01:58 +0000
commite647dc39595353d0c0368f7ff00870a85e472d99 (patch)
treea444a8259bec411f9de9bd5808f5b4fd72f13f08 /daemon
parent9b0a8644606a6dbea1a3c9d9dba6a21633f4b351 (diff)
downloadgdm-e647dc39595353d0c0368f7ff00870a85e472d99.tar.gz
Make process invocation about 600us faster by making a helper function for
Tue Jul 16 10:14:08 2002 George Lebl <jirka@5z.com> * daemon/misc.[ch], daemon/display.c, daemon/errorgui.c, daemon/gdm.c daemon/server.c, daemon/slave.c: Make process invocation about 600us faster by making a helper function for closing all descriptors that is somewhat smarter then the inline code was, and on this occasion alsofix the failsafe question dialog to actually work. * daemon/server.c: fix debug output on stopping server
Diffstat (limited to 'daemon')
-rw-r--r--daemon/display.c6
-rw-r--r--daemon/errorgui.c16
-rw-r--r--daemon/gdm.c4
-rw-r--r--daemon/misc.c16
-rw-r--r--daemon/misc.h2
-rw-r--r--daemon/server.c6
-rw-r--r--daemon/slave.c30
7 files changed, 30 insertions, 50 deletions
diff --git a/daemon/display.c b/daemon/display.c
index e20785bf..832e3e2b 100644
--- a/daemon/display.c
+++ b/daemon/display.c
@@ -150,7 +150,6 @@ gboolean
gdm_display_manage (GdmDisplay *d)
{
pid_t pid;
- int i;
int fds[2];
if (!d)
@@ -198,10 +197,7 @@ gdm_display_manage (GdmDisplay *d)
closelog ();
/* Close everything */
- for (i = 0; i < sysconf (_SC_OPEN_MAX); i++) {
- if (i != fds[0])
- close(i);
- }
+ gdm_close_all_descriptors (0 /* from */, fds[0] /* except */);
/* No error checking here - if it's messed the best response
* is to ignore & try to continue */
diff --git a/daemon/errorgui.c b/daemon/errorgui.c
index 4394fff9..dafaf2ff 100644
--- a/daemon/errorgui.c
+++ b/daemon/errorgui.c
@@ -120,7 +120,6 @@ gdm_error_box_full (GdmDisplay *d, GtkMessageType type, const char *error,
if (pid == 0) {
guint sid;
- int i;
int argc = 1;
char **argv;
GtkWidget *dlg;
@@ -134,8 +133,7 @@ gdm_error_box_full (GdmDisplay *d, GtkMessageType type, const char *error,
closelog ();
- for (i = 0; i < sysconf (_SC_OPEN_MAX); i++)
- close(i);
+ gdm_close_all_descriptors (0 /* from */, -1 /* except */);
/* No error checking here - if it's messed the best response
* is to ignore & try to continue */
@@ -268,7 +266,6 @@ gdm_failsafe_question (GdmDisplay *d,
pid = gdm_fork_extra ();
if (pid == 0) {
guint sid;
- int i;
int argc = 1;
char **argv;
GtkWidget *dlg, *label, *entry;
@@ -281,8 +278,7 @@ gdm_failsafe_question (GdmDisplay *d,
closelog ();
- for (i = 0; i < sysconf (_SC_OPEN_MAX); i++)
- close(i);
+ gdm_close_all_descriptors (0 /* from */, p[1] /* except */);
/* No error checking here - if it's messed the best response
* is to ignore & try to continue */
@@ -371,7 +367,7 @@ gdm_failsafe_question (GdmDisplay *d,
loc = g_locale_from_utf8 (ve_sure_string (gtk_entry_get_text (GTK_ENTRY (entry))),
-1, NULL, NULL, NULL);
- gdm_fdprintf (STDOUT_FILENO, "%s", ve_sure_string (loc));
+ gdm_fdprintf (p[1], "%s", ve_sure_string (loc));
_exit (0);
} else if (pid > 0) {
@@ -408,7 +404,6 @@ gdm_failsafe_yesno (GdmDisplay *d,
pid = gdm_fork_extra ();
if (pid == 0) {
guint sid;
- int i;
int argc = 1;
char **argv;
GtkWidget *dlg;
@@ -421,10 +416,7 @@ gdm_failsafe_yesno (GdmDisplay *d,
closelog ();
- for (i = 0; i < sysconf (_SC_OPEN_MAX); i++) {
- if (p[1] != i)
- close(i);
- }
+ gdm_close_all_descriptors (0 /* from */, p[1] /* except */);
/* No error checking here - if it's messed the best response
* is to ignore & try to continue */
diff --git a/daemon/gdm.c b/daemon/gdm.c
index b757fba3..4acaae73 100644
--- a/daemon/gdm.c
+++ b/daemon/gdm.c
@@ -857,12 +857,10 @@ deal_with_x_crashes (GdmDisplay *d)
if (pid == 0) {
char *argv[2];
char *xlog = g_strconcat (GdmLogDir, "/", d->name, ".log", NULL);
- int ii;
closelog ();
- for (ii = 0; ii < sysconf (_SC_OPEN_MAX); ii++)
- close (ii);
+ gdm_close_all_descriptors (0 /* from */, -1 /* except */);
/* No error checking here - if it's messed the best response
* is to ignore & try to continue */
diff --git a/daemon/misc.c b/daemon/misc.c
index 471387d4..4bb9f92a 100644
--- a/daemon/misc.c
+++ b/daemon/misc.c
@@ -482,12 +482,9 @@ gdm_exec_wait (char * const *argv, gboolean no_display,
pid = gdm_fork_extra ();
if (pid == 0) {
- int i;
-
closelog ();
- for (i = 0; i < sysconf (_SC_OPEN_MAX); i++)
- close (i);
+ gdm_close_all_descriptors (0 /* from */, -1 /* except */);
/* No error checking here - if it's messed the best response
* is to ignore & try to continue */
@@ -969,4 +966,15 @@ gdm_fdgets (int fd)
}
}
+void
+gdm_close_all_descriptors (int from, int except)
+{
+ int i;
+ int max = sysconf (_SC_OPEN_MAX);
+ for (i = from; i < max; i++) {
+ if (i != except)
+ close(i);
+ }
+}
+
/* EOF */
diff --git a/daemon/misc.h b/daemon/misc.h
index 3eb72d7c..46622a69 100644
--- a/daemon/misc.h
+++ b/daemon/misc.h
@@ -73,6 +73,8 @@ void gdm_desetuid (void);
gboolean gdm_test_opt (const char *cmd, const char *help, const char *option);
+void gdm_close_all_descriptors (int from, int except);
+
#endif /* GDM_MISC_H */
/* EOF */
diff --git a/daemon/server.c b/daemon/server.c
index 1d5b629a..cb85b9b8 100644
--- a/daemon/server.c
+++ b/daemon/server.c
@@ -142,7 +142,8 @@ gdm_server_stop (GdmDisplay *disp)
if (disp->servpid != 0) {
pid_t servpid;
- gdm_debug ("gdm_server_stop: Killing server pid %d", (int)servpid);
+ gdm_debug ("gdm_server_stop: Killing server pid %d",
+ (int)disp->servpid);
/* avoid SIGCHLD race */
gdm_sigchld_block_push ();
@@ -729,8 +730,7 @@ gdm_server_spawn (GdmDisplay *d)
closelog ();
/* close things */
- for (i = 0; i < sysconf (_SC_OPEN_MAX); i++)
- close(i);
+ gdm_close_all_descriptors (0 /* from */, -1 /* except */);
/* No error checking here - if it's messed the best response
* is to ignore & try to continue */
diff --git a/daemon/slave.c b/daemon/slave.c
index 449ae118..2d683417 100644
--- a/daemon/slave.c
+++ b/daemon/slave.c
@@ -664,7 +664,6 @@ focus_first_x_window (const char *class_res_name)
pid_t pid;
Display *disp;
XWindowAttributes attribs = { 0, };
- int i;
pid = fork ();
if (pid < 0) {
@@ -678,8 +677,7 @@ focus_first_x_window (const char *class_res_name)
closelog ();
- for (i = 0; i < sysconf (_SC_OPEN_MAX); i++)
- close(i);
+ gdm_close_all_descriptors (0 /* from */, -1 /* except */);
/* No error checking here - if it's messed the best response
* is to ignore & try to continue */
@@ -759,7 +757,6 @@ run_config (GdmDisplay *display, struct passwd *pwent)
return;
}
if (pid == 0) {
- int i;
char **argv;
/* child */
@@ -784,8 +781,7 @@ run_config (GdmDisplay *display, struct passwd *pwent)
closelog ();
- for (i = 0; i < sysconf (_SC_OPEN_MAX); i++)
- close(i);
+ gdm_close_all_descriptors (0 /* from */, -1 /* except */);
/* No error checking here - if it's messed the best response
* is to ignore & try to continue */
@@ -1276,7 +1272,6 @@ gdm_slave_greeter (void)
gint pipe1[2], pipe2[2];
gchar **argv;
struct passwd *pwent;
- int i;
pid_t pid;
gdm_debug ("gdm_slave_greeter: Running greeter on %s", d->name);
@@ -1318,8 +1313,7 @@ gdm_slave_greeter (void)
closelog ();
- for (i = 2; i < sysconf (_SC_OPEN_MAX); i++)
- close(i);
+ gdm_close_all_descriptors (2 /* from */, -1 /* except */);
open ("/dev/null", O_RDWR); /* open stderr - fd 2 */
@@ -1632,7 +1626,6 @@ gdm_slave_chooser (void)
struct passwd *pwent;
char buf[1024];
size_t bytes;
- int i;
pid_t pid;
gdm_debug ("gdm_slave_chooser: Running chooser on %s", d->name);
@@ -1669,8 +1662,7 @@ gdm_slave_chooser (void)
closelog ();
close (0);
- for (i = 2; i < sysconf (_SC_OPEN_MAX); i++)
- close(i);
+ gdm_close_all_descriptors (2 /* from */, -1 /* except */);
open ("/dev/null", O_RDONLY); /* open stdin - fd 0 */
open ("/dev/null", O_RDWR); /* open stderr - fd 2 */
@@ -2060,7 +2052,6 @@ session_child_run (struct passwd *pwent,
{
sigset_t mask;
int logfd;
- int i;
gboolean failsafe = FALSE;
char *sesspath, *sessexec;
gboolean need_config_sync = FALSE;
@@ -2199,8 +2190,7 @@ session_child_run (struct passwd *pwent,
closelog ();
- for (i = 0; i < sysconf (_SC_OPEN_MAX); i++)
- close (i);
+ gdm_close_all_descriptors (0 /* from */, -1 /* except */);
/* No error checking here - if it's messed the best response
* is to ignore & try to continue */
@@ -3218,7 +3208,6 @@ gdm_slave_exec_script (GdmDisplay *d, const gchar *dir, const char *login,
const char *scr;
gchar **argv;
gint status;
- int i;
if (!d || !dir)
return EXIT_SUCCESS;
@@ -3243,8 +3232,7 @@ gdm_slave_exec_script (GdmDisplay *d, const gchar *dir, const char *login,
case 0:
closelog ();
- for (i = 0; i < sysconf (_SC_OPEN_MAX); i++)
- close (i);
+ gdm_close_all_descriptors (0 /* from */, -1 /* except */);
/* No error checking here - if it's messed the best response
* is to ignore & try to continue */
@@ -3382,7 +3370,6 @@ gdm_parse_enriched_login (const gchar *s, GdmDisplay *display)
if (pipe (pipe1) < 0) {
gdm_error (_("gdm_parse_enriched_login: Failed creating pipe"));
} else {
- int i;
pid = gdm_fork_extra ();
switch (pid) {
@@ -3397,10 +3384,7 @@ gdm_parse_enriched_login (const gchar *s, GdmDisplay *display)
closelog ();
- for (i = 3; i < sysconf (_SC_OPEN_MAX); i++) {
- if (pipe1[1] != i)
- close (i);
- }
+ gdm_close_all_descriptors (3 /* from */, pipe1[1] /* except */);
openlog ("gdm", LOG_PID, LOG_DAEMON);