summaryrefslogtreecommitdiffstats
path: root/bus/config-parser.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-04-06 23:15:41 +0000
committerHavoc Pennington <hp@redhat.com>2003-04-06 23:15:41 +0000
commit856361ff5b8ce701cdb447085931d3076ee52008 (patch)
tree05aa6d44983e8eff29bc45b9dc94ff8b7998fe3c /bus/config-parser.c
parentc8991b0f95a3b53bc98de9e029780bbe0a0b3114 (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/config-parser.c')
-rw-r--r--bus/config-parser.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/bus/config-parser.c b/bus/config-parser.c
index f9473ff9..1052dc2d 100644
--- a/bus/config-parser.c
+++ b/bus/config-parser.c
@@ -40,6 +40,7 @@ typedef enum
ELEMENT_ALLOW,
ELEMENT_DENY,
ELEMENT_FORK,
+ ELEMENT_PIDFILE,
ELEMENT_SERVICEDIR,
ELEMENT_INCLUDEDIR,
ELEMENT_TYPE
@@ -94,6 +95,8 @@ struct BusConfigParser
DBusList *service_dirs; /**< Directories to look for services in */
unsigned int fork : 1; /**< TRUE to fork into daemon mode */
+
+ char *pidfile;
};
static const char*
@@ -123,6 +126,8 @@ element_type_to_name (ElementType type)
return "deny";
case ELEMENT_FORK:
return "fork";
+ case ELEMENT_PIDFILE:
+ return "pidfile";
case ELEMENT_SERVICEDIR:
return "servicedir";
case ELEMENT_INCLUDEDIR:
@@ -222,6 +227,13 @@ merge_included (BusConfigParser *parser,
if (included->fork)
parser->fork = TRUE;
+
+ if (included->pidfile != NULL)
+ {
+ dbus_free (parser->pidfile);
+ parser->pidfile = included->pidfile;
+ included->pidfile = NULL;
+ }
while ((link = _dbus_list_pop_first_link (&included->listen_on)))
_dbus_list_append_link (&parser->listen_on, link);
@@ -284,6 +296,7 @@ bus_config_parser_unref (BusConfigParser *parser)
dbus_free (parser->user);
dbus_free (parser->bus_type);
+ dbus_free (parser->pidfile);
_dbus_list_foreach (&parser->listen_on,
(DBusForeachFunction) dbus_free,
@@ -499,6 +512,19 @@ start_busconfig_child (BusConfigParser *parser,
return TRUE;
}
+ else if (strcmp (element_name, "pidfile") == 0)
+ {
+ if (!check_no_attributes (parser, "pidfile", attribute_names, attribute_values, error))
+ return FALSE;
+
+ if (push_element (parser, ELEMENT_PIDFILE) == NULL)
+ {
+ BUS_SET_OOM (error);
+ return FALSE;
+ }
+
+ return TRUE;
+ }
else if (strcmp (element_name, "listen") == 0)
{
if (!check_no_attributes (parser, "listen", attribute_names, attribute_values, error))
@@ -770,6 +796,7 @@ bus_config_parser_end_element (BusConfigParser *parser,
case ELEMENT_USER:
case ELEMENT_TYPE:
case ELEMENT_LISTEN:
+ case ELEMENT_PIDFILE:
case ELEMENT_AUTH:
case ELEMENT_SERVICEDIR:
case ELEMENT_INCLUDEDIR:
@@ -1004,6 +1031,20 @@ bus_config_parser_content (BusConfigParser *parser,
return FALSE;
}
+ case ELEMENT_PIDFILE:
+ {
+ char *s;
+
+ e->had_content = TRUE;
+
+ if (!_dbus_string_copy_data (content, &s))
+ goto nomem;
+
+ dbus_free (parser->pidfile);
+ parser->pidfile = s;
+ }
+ break;
+
case ELEMENT_INCLUDE:
{
DBusString full_path;
@@ -1222,6 +1263,12 @@ bus_config_parser_get_fork (BusConfigParser *parser)
return parser->fork;
}
+const char *
+bus_config_parser_get_pidfile (BusConfigParser *parser)
+{
+ return parser->pidfile;
+}
+
#ifdef DBUS_BUILD_TESTS
#include <stdio.h>