summaryrefslogtreecommitdiffstats
path: root/bus
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2007-08-17 16:43:57 +0000
committerHavoc Pennington <hp@redhat.com>2007-08-17 16:43:57 +0000
commit163555c7ab56132ee27e3e7d9a26eb985682c1b5 (patch)
tree6beb4d2f273fd36bff3c5bca6d5676759deaaa1c /bus
parentd9f2438806d0b2584003a3c3a54234c5a1fac4c2 (diff)
2007-08-17 Havoc Pennington <hp@redhat.com>
* tools/dbus-launch-x11.c (set_address_in_x11): fix from Michael Lorenz to use long not int with XChangeProperty format 32 * dbus/dbus-sysdeps-util-unix.c (_dbus_write_pid_to_file_and_pipe): factor this out, and use the same code in _dbus_become_daemon (where the parent writes the pid file and to the pid pipe) and in bus_context_new (where the daemon writes its own pid file and to its own pid pipe) * bus/bus.c (bus_context_new): close the pid pipe after we print to it. Also, don't write the pid to the pipe twice when we fork, someone reported this bug a long time ago.
Diffstat (limited to 'bus')
-rw-r--r--bus/bus.c116
-rw-r--r--bus/main.c4
2 files changed, 47 insertions, 73 deletions
diff --git a/bus/bus.c b/bus/bus.c
index 21e8037e..c2ea1157 100644
--- a/bus/bus.c
+++ b/bus/bus.c
@@ -665,7 +665,7 @@ bus_context_new (const DBusString *config_file,
if (!_dbus_pipe_is_stdout_or_stderr (print_addr_pipe))
_dbus_pipe_close (print_addr_pipe, NULL);
-
+
_dbus_string_free (&addr);
}
@@ -695,78 +695,48 @@ bus_context_new (const DBusString *config_file,
}
}
- /* Now become a daemon if appropriate */
- if ((force_fork != FORK_NEVER && context->fork) || force_fork == FORK_ALWAYS)
- {
- DBusString u;
-
- if (context->pidfile)
- _dbus_string_init_const (&u, context->pidfile);
-
- if (!_dbus_become_daemon (context->pidfile ? &u : NULL,
- print_pid_pipe,
- error))
- {
- _DBUS_ASSERT_ERROR_IS_SET (error);
- goto failed;
- }
- }
- else
- {
- /* Need to write PID file for ourselves, not for the child process */
- if (context->pidfile != NULL)
- {
- DBusString u;
-
- _dbus_string_init_const (&u, context->pidfile);
-
- if (!_dbus_write_pid_file (&u, _dbus_getpid (), error))
- {
- _DBUS_ASSERT_ERROR_IS_SET (error);
- goto failed;
- }
- }
- }
-
- /* Write PID if requested */
- if (print_pid_pipe != NULL && _dbus_pipe_is_valid (print_pid_pipe))
- {
- DBusString pid;
- int bytes;
-
- if (!_dbus_string_init (&pid))
- {
- BUS_SET_OOM (error);
- goto failed;
- }
-
- if (!_dbus_string_append_int (&pid, _dbus_getpid ()) ||
- !_dbus_string_append (&pid, "\n"))
- {
- _dbus_string_free (&pid);
- BUS_SET_OOM (error);
- goto failed;
- }
-
- bytes = _dbus_string_get_length (&pid);
- if (_dbus_pipe_write (print_pid_pipe, &pid, 0, bytes, error) != bytes)
- {
- /* pipe_write sets error on failure but not short write */
- if (error != NULL && !dbus_error_is_set (error))
- {
- dbus_set_error (error, DBUS_ERROR_FAILED,
- "Printing message bus PID: did not write enough bytes\n");
- }
- _dbus_string_free (&pid);
- goto failed;
- }
-
- if (!_dbus_pipe_is_stdout_or_stderr (print_pid_pipe))
- _dbus_pipe_close (print_pid_pipe, NULL);
-
- _dbus_string_free (&pid);
- }
-
+ /* Now become a daemon if appropriate and write out pid file in any case */
+ {
+ DBusString u;
+
+ if (context->pidfile)
+ _dbus_string_init_const (&u, context->pidfile);
+
+ if ((force_fork != FORK_NEVER && context->fork) || force_fork == FORK_ALWAYS)
+ {
+ _dbus_verbose ("Forking and becoming daemon\n");
+
+ if (!_dbus_become_daemon (context->pidfile ? &u : NULL,
+ print_pid_pipe,
+ error))
+ {
+ _DBUS_ASSERT_ERROR_IS_SET (error);
+ goto failed;
+ }
+ }
+ else
+ {
+ _dbus_verbose ("Fork not requested\n");
+
+ /* Need to write PID file and to PID pipe for ourselves,
+ * not for the child process. This is a no-op if the pidfile
+ * is NULL and print_pid_pipe is NULL.
+ */
+ if (!_dbus_write_pid_to_file_and_pipe (context->pidfile ? &u : NULL,
+ print_pid_pipe,
+ _dbus_getpid (),
+ error))
+ {
+ _DBUS_ASSERT_ERROR_IS_SET (error);
+ goto failed;
+ }
+ }
+ }
+
+ if (print_pid_pipe && _dbus_pipe_is_valid (print_pid_pipe) &&
+ !_dbus_pipe_is_stdout_or_stderr (print_pid_pipe))
+ _dbus_pipe_close (print_pid_pipe, NULL);
+
if (!process_config_postinit (context, parser, error))
{
_DBUS_ASSERT_ERROR_IS_SET (error);
diff --git a/bus/main.c b/bus/main.c
index 3652935e..161de19c 100644
--- a/bus/main.c
+++ b/bus/main.c
@@ -452,6 +452,10 @@ main (int argc, char **argv)
exit (1);
}
+ /* bus_context_new() closes the print_addr_pipe and
+ * print_pid_pipe
+ */
+
setup_reload_pipe (bus_context_get_loop (context));
_dbus_set_signal_handler (SIGHUP, signal_handler);