Replace a series of booleans, all (apparently) alike, with flags

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>
This commit is contained in:
Simon McVittie 2012-02-10 12:44:19 +00:00
parent 267dbff1ea
commit 05cc2c3348
4 changed files with 63 additions and 38 deletions

View file

@ -269,8 +269,7 @@ static dbus_bool_t
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;
@ -290,7 +289,10 @@ process_config_first_time_only (BusContext *context,
_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
@ -298,7 +300,7 @@ process_config_first_time_only (BusContext *context,
* 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)
@ -698,17 +700,18 @@ process_config_postinit (BusContext *context,
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;
@ -757,7 +760,7 @@ bus_context_new (const DBusString *config_file,
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;
@ -852,7 +855,8 @@ bus_context_new (const DBusString *config_file,
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");

View file

@ -66,18 +66,18 @@ typedef struct
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);

View file

@ -355,9 +355,7 @@ main (int argc, char **argv)
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;
@ -373,9 +371,8 @@ main (int argc, char **argv)
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;
@ -386,19 +383,35 @@ main (int argc, char **argv)
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");
@ -434,7 +447,9 @@ main (int argc, char **argv)
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;
@ -456,7 +471,9 @@ main (int argc, char **argv)
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;
@ -482,7 +499,9 @@ main (int argc, char **argv)
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;
@ -508,9 +527,13 @@ main (int argc, char **argv)
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;
@ -574,11 +597,9 @@ main (int argc, char **argv)
}
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)

View file

@ -292,7 +292,7 @@ bus_context_new_test (const DBusString *test_data_dir,
}
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);