diff options
author | Havoc Pennington <hp@redhat.com> | 2003-04-06 23:15:41 +0000 |
---|---|---|
committer | Havoc Pennington <hp@redhat.com> | 2003-04-06 23:15:41 +0000 |
commit | 856361ff5b8ce701cdb447085931d3076ee52008 (patch) | |
tree | 05aa6d44983e8eff29bc45b9dc94ff8b7998fe3c /bus/bus.c | |
parent | c8991b0f95a3b53bc98de9e029780bbe0a0b3114 (diff) |
2003-04-06 Havoc Pennington <hp@pobox.com>
* dbus/dbus-sysdeps.c (_dbus_become_daemon): write the pidfile
here in the parent process, so we can return an error if it
fails. Also, move some of the code into the child so the parent
is less hosed if we fail midway through.
* bus/bus.c (bus_context_new): move pidfile detection further up
in the function, before we start overwriting sockets and such.
* bus/messagebus.in: adjust this a bit, not sure if it will work.
* configure.in: add --with-system-pid-file and --with-system-socket
2003-04-06 Colin Walters <walters@verbum.org>
* configure.in (DBUS_SYSTEM_PID_FILE): New variable.
* bus/system.conf.in: Declare a pidfile.
* bus/bus.c (bus_context_new): Test for an existing pid file, and
create one (if appropriate).
* bus/config-parser.c (enum ElementType) [ELEMENT_PIDFILE]: New.
(struct BusConfigParser) [pidfile]: New.
(element_type_to_name, merge_included, start_busconfig_child)
(bus_config_parser_end_element, bus_config_parser_content): Handle it.
(bus_config_parser_unref): Free it.
(bus_config_parser_get_pidfile): New function.
* bus/config-parser.h (_dbus_write_pid_file): Prototype.
* dbus/dbus-errors.h (DBUS_ERROR_PIDFILE_EXISTS): New error.
* dbus/dbus-sysdeps.c (_dbus_write_pid_file): New function.
* dbus/dbus-sysdeps.h: Prototype it.
Diffstat (limited to 'bus/bus.c')
-rw-r--r-- | bus/bus.c | 47 |
1 files changed, 45 insertions, 2 deletions
@@ -306,7 +306,7 @@ bus_context_new (const DBusString *config_file, DBusList **addresses; BusConfigParser *parser; DBusString full_address; - const char *user; + const char *user, *pidfile; char **auth_mechanisms; DBusList **auth_mechanisms_list; int len; @@ -333,6 +333,31 @@ bus_context_new (const DBusString *config_file, parser = bus_config_load (config_file, error); if (parser == NULL) goto failed; + + /* Check for an existing pid file. Of course this is a race; + * we'd have to use fcntl() locks on the pid file to + * avoid that. But we want to check for the pid file + * before overwriting any existing sockets, etc. + */ + pidfile = bus_config_parser_get_pidfile (parser); + if (pidfile != NULL) + { + DBusString u; + DBusStat stbuf; + DBusError tmp_error; + + dbus_error_init (&tmp_error); + _dbus_string_init_const (&u, pidfile); + + if (_dbus_stat (&u, &stbuf, &tmp_error)) + { + dbus_set_error (error, DBUS_ERROR_FAILED, + "The pid file \"%s\" exists, if the message bus is not running, remove this file", + pidfile); + dbus_error_free (&tmp_error); + goto failed; + } + } context = dbus_new0 (BusContext, 1); if (context == NULL) @@ -587,9 +612,27 @@ bus_context_new (const DBusString *config_file, /* Now become a daemon if appropriate */ if (bus_config_parser_get_fork (parser)) { - if (!_dbus_become_daemon (error)) + DBusString u; + + if (pidfile) + _dbus_string_init_const (&u, pidfile); + + if (!_dbus_become_daemon (pidfile ? &u : NULL, error)) goto failed; } + else + { + /* Need to write PID file for ourselves, not for the child process */ + if (pidfile != NULL) + { + DBusString u; + + _dbus_string_init_const (&u, pidfile); + + if (!_dbus_write_pid_file (&u, _dbus_getpid (), error)) + goto failed; + } + } bus_config_parser_unref (parser); _dbus_string_free (&full_address); |