This makes it a bit clearer what's going on.
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Lennart Poettering <lennart@poettering.net>
process_config_first_time_only (BusContext *context,
BusConfigParser *parser,
const DBusString *address,
- dbus_bool_t systemd_activation,
- dbus_bool_t write_pidfile,
+ BusContextFlags flags,
DBusError *error)
{
DBusString log_prefix;
_dbus_init_system_log ();
- context->systemd_activation = systemd_activation;
+ if (flags & BUS_CONTEXT_FLAG_SYSTEMD_ACTIVATION)
+ context->systemd_activation = TRUE;
+ else
+ context->systemd_activation = FALSE;
/* Check for an existing pid file. Of course this is a race;
* we'd have to use fcntl() locks on the pid file to
* before overwriting any existing sockets, etc.
*/
- if (write_pidfile)
+ if (flags & BUS_CONTEXT_FLAG_WRITE_PID_FILE)
pidfile = bus_config_parser_get_pidfile (parser);
if (pidfile != NULL)
BusContext*
bus_context_new (const DBusString *config_file,
- ForceForkSetting force_fork,
+ BusContextFlags flags,
DBusPipe *print_addr_pipe,
DBusPipe *print_pid_pipe,
const DBusString *address,
- dbus_bool_t systemd_activation,
- dbus_bool_t write_pidfile,
DBusError *error)
{
BusContext *context;
BusConfigParser *parser;
+ _dbus_assert ((flags & BUS_CONTEXT_FLAG_FORK_NEVER) == 0 ||
+ (flags & BUS_CONTEXT_FLAG_FORK_ALWAYS) == 0);
+
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
context = NULL;
goto failed;
}
- if (!process_config_first_time_only (context, parser, address, systemd_activation, write_pidfile, error))
+ if (!process_config_first_time_only (context, parser, address, flags, error))
{
_DBUS_ASSERT_ERROR_IS_SET (error);
goto failed;
if (context->pidfile)
_dbus_string_init_const (&u, context->pidfile);
- if ((force_fork != FORK_NEVER && context->fork) || force_fork == FORK_ALWAYS)
+ if (((flags & BUS_CONTEXT_FLAG_FORK_NEVER) == 0 && context->fork) ||
+ (flags & BUS_CONTEXT_FLAG_FORK_ALWAYS))
{
_dbus_verbose ("Forking and becoming daemon\n");
typedef enum
{
- FORK_FOLLOW_CONFIG_FILE,
- FORK_ALWAYS,
- FORK_NEVER
-} ForceForkSetting;
+ BUS_CONTEXT_FLAG_NONE = 0,
+ BUS_CONTEXT_FLAG_FORK_ALWAYS = (1 << 1),
+ BUS_CONTEXT_FLAG_FORK_NEVER = (1 << 2),
+ BUS_CONTEXT_FLAG_WRITE_PID_FILE = (1 << 3),
+ BUS_CONTEXT_FLAG_SYSTEMD_ACTIVATION = (1 << 4)
+} BusContextFlags;
BusContext* bus_context_new (const DBusString *config_file,
- ForceForkSetting force_fork,
+ BusContextFlags flags,
DBusPipe *print_addr_pipe,
DBusPipe *print_pid_pipe,
const DBusString *address,
- dbus_bool_t systemd_activation,
- dbus_bool_t write_pidfile,
DBusError *error);
dbus_bool_t bus_context_reload_config (BusContext *context,
DBusError *error);
int i;
dbus_bool_t print_address;
dbus_bool_t print_pid;
- int force_fork;
- dbus_bool_t systemd_activation;
- dbus_bool_t write_pidfile;
+ BusContextFlags flags;
if (!_dbus_string_init (&config_file))
return 1;
print_address = FALSE;
print_pid = FALSE;
- force_fork = FORK_FOLLOW_CONFIG_FILE;
- systemd_activation = FALSE;
- write_pidfile = TRUE;
+
+ flags = BUS_CONTEXT_FLAG_WRITE_PID_FILE;
prev_arg = NULL;
i = 1;
if (strcmp (arg, "--help") == 0 ||
strcmp (arg, "-h") == 0 ||
strcmp (arg, "-?") == 0)
- usage ();
+ {
+ usage ();
+ }
else if (strcmp (arg, "--version") == 0)
- version ();
+ {
+ version ();
+ }
else if (strcmp (arg, "--introspect") == 0)
- introspect ();
+ {
+ introspect ();
+ }
else if (strcmp (arg, "--nofork") == 0)
- force_fork = FORK_NEVER;
+ {
+ flags &= ~BUS_CONTEXT_FLAG_FORK_ALWAYS;
+ flags |= BUS_CONTEXT_FLAG_FORK_NEVER;
+ }
else if (strcmp (arg, "--fork") == 0)
- force_fork = FORK_ALWAYS;
+ {
+ flags &= ~BUS_CONTEXT_FLAG_FORK_NEVER;
+ flags |= BUS_CONTEXT_FLAG_FORK_ALWAYS;
+ }
else if (strcmp (arg, "--nopidfile") == 0)
- write_pidfile = FALSE;
+ {
+ flags &= ~BUS_CONTEXT_FLAG_WRITE_PID_FILE;
+ }
else if (strcmp (arg, "--systemd-activation") == 0)
- systemd_activation = TRUE;
+ {
+ flags |= BUS_CONTEXT_FLAG_SYSTEMD_ACTIVATION;
+ }
else if (strcmp (arg, "--system") == 0)
{
check_two_config_files (&config_file, "system");
exit (1);
}
else if (strcmp (arg, "--config-file") == 0)
- ; /* wait for next arg */
+ {
+ /* wait for next arg */
+ }
else if (strstr (arg, "--address=") == arg)
{
const char *file;
exit (1);
}
else if (strcmp (arg, "--address") == 0)
- ; /* wait for next arg */
+ {
+ /* wait for next arg */
+ }
else if (strstr (arg, "--print-address=") == arg)
{
const char *desc;
print_address = TRUE;
}
else if (strcmp (arg, "--print-address") == 0)
- print_address = TRUE; /* and we'll get the next arg if appropriate */
+ {
+ print_address = TRUE; /* and we'll get the next arg if appropriate */
+ }
else if (strstr (arg, "--print-pid=") == arg)
{
const char *desc;
print_pid = TRUE;
}
else if (strcmp (arg, "--print-pid") == 0)
- print_pid = TRUE; /* and we'll get the next arg if appropriate */
+ {
+ print_pid = TRUE; /* and we'll get the next arg if appropriate */
+ }
else
- usage ();
+ {
+ usage ();
+ }
prev_arg = arg;
}
dbus_error_init (&error);
- context = bus_context_new (&config_file, force_fork,
+ context = bus_context_new (&config_file, flags,
&print_addr_pipe, &print_pid_pipe,
_dbus_string_get_length(&address) > 0 ? &address : NULL,
- systemd_activation,
- write_pidfile,
&error);
_dbus_string_free (&config_file);
if (context == NULL)
}
dbus_error_init (&error);
- context = bus_context_new (&config_file, FALSE, NULL, NULL, NULL, FALSE, FALSE, &error);
+ context = bus_context_new (&config_file, BUS_CONTEXT_FLAG_NONE, NULL, NULL, NULL, &error);
if (context == NULL)
{
_DBUS_ASSERT_ERROR_IS_SET (&error);