Coverage report for bus/main.c.gcov
-: 0:Source:main.c
-: 0:Graph:main.gcno
-: 0:Data:main.gcda
-: 0:Runs:2
-: 0:Programs:1
-: 1:/* -*- mode: C; c-file-style: "gnu" -*- */
-: 2:/* main.c main() for message bus
-: 3: *
-: 4: * Copyright (C) 2003 Red Hat, Inc.
-: 5: *
-: 6: * Licensed under the Academic Free License version 2.1
-: 7: *
-: 8: * This program is free software; you can redistribute it and/or modify
-: 9: * it under the terms of the GNU General Public License as published by
-: 10: * the Free Software Foundation; either version 2 of the License, or
-: 11: * (at your option) any later version.
-: 12: *
-: 13: * This program is distributed in the hope that it will be useful,
-: 14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
-: 15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-: 16: * GNU General Public License for more details.
-: 17: *
-: 18: * You should have received a copy of the GNU General Public License
-: 19: * along with this program; if not, write to the Free Software
-: 20: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-: 21: *
-: 22: */
-: 23:#include "bus.h"
-: 24:#include <dbus/dbus-internals.h>
-: 25:#include <dbus/dbus-watch.h>
-: 26:#include <stdio.h>
-: 27:#include <stdlib.h>
-: 28:#include <string.h>
-: 29:#include <signal.h>
-: 30:#include <errno.h>
-: 31:#include "selinux.h"
-: 32:
-: 33:static BusContext *context;
-: 34:
-: 35:static int reload_pipe[2];
-: 36:#define RELOAD_READ_END 0
-: 37:#define RELOAD_WRITE_END 1
-: 38:
-: 39:
-: 40:static void
-: 41:signal_handler (int sig)
function signal_handler called 1 returned 100% blocks executed 40%
1: 42:{
-: 43: DBusString str;
-: 44:
1: 45: switch (sig)
branch 0 taken 0%
branch 1 taken 100%
branch 2 taken 0%
-: 46: {
-: 47:#ifdef DBUS_BUS_ENABLE_DNOTIFY_ON_LINUX
-: 48: case SIGIO:
-: 49: /* explicit fall-through */
-: 50:#endif /* DBUS_BUS_ENABLE_DNOTIFY_ON_LINUX */
-: 51: case SIGHUP:
#####: 52: _dbus_string_init_const (&str, "foo");
call 0 never executed
#####: 53: if (!_dbus_write (reload_pipe[RELOAD_WRITE_END], &str, 0, 1))
call 0 never executed
branch 1 never executed
branch 2 never executed
-: 54: {
#####: 55: _dbus_warn ("Unable to write to reload pipe.\n");
call 0 never executed
#####: 56: exit (1);
call 0 never executed
-: 57: }
#####: 58: break;
-: 59:
-: 60: case SIGTERM:
1: 61: _dbus_loop_quit (bus_context_get_loop (context));
call 0 returned 100%
call 1 returned 100%
-: 62: break;
-: 63: }
1: 64:}
-: 65:
-: 66:static void
-: 67:usage (void)
function usage called 0 returned 0% blocks executed 0%
#####: 68:{
#####: 69: fprintf (stderr, DAEMON_NAME " [--version] [--session] [--system] [--config-file=FILE] [--print-address[=DESCRIPTOR]] [--print-pid[=DESCRIPTOR]] [--fork] [--nofork]\n");
call 0 never executed
#####: 70: exit (1);
call 0 never executed
-: 71:}
-: 72:
-: 73:static void
-: 74:version (void)
function version called 0 returned 0% blocks executed 0%
#####: 75:{
#####: 76: printf ("D-BUS Message Bus Daemon %s\n"
call 0 never executed
-: 77: "Copyright (C) 2002, 2003 Red Hat, Inc., CodeFactory AB, and others\n"
-: 78: "This is free software; see the source for copying conditions.\n"
-: 79: "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
-: 80: VERSION);
#####: 81: exit (0);
call 0 never executed
-: 82:}
-: 83:
-: 84:static void
-: 85:check_two_config_files (const DBusString *config_file,
-: 86: const char *extra_arg)
function check_two_config_files called 1 returned 100% blocks executed 50%
1: 87:{
1: 88: if (_dbus_string_get_length (config_file) > 0)
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
-: 89: {
#####: 90: fprintf (stderr, "--%s specified but configuration file %s already requested\n",
call 0 never executed
call 1 never executed
-: 91: extra_arg, _dbus_string_get_const_data (config_file));
#####: 92: exit (1);
call 0 never executed
-: 93: }
1: 94:}
-: 95:
-: 96:static void
-: 97:check_two_addr_descriptors (const DBusString *addr_fd,
-: 98: const char *extra_arg)
function check_two_addr_descriptors called 1 returned 100% blocks executed 50%
1: 99:{
1: 100: if (_dbus_string_get_length (addr_fd) > 0)
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
-: 101: {
#####: 102: fprintf (stderr, "--%s specified but printing address to %s already requested\n",
call 0 never executed
call 1 never executed
-: 103: extra_arg, _dbus_string_get_const_data (addr_fd));
#####: 104: exit (1);
call 0 never executed
-: 105: }
1: 106:}
-: 107:
-: 108:static void
-: 109:check_two_pid_descriptors (const DBusString *pid_fd,
-: 110: const char *extra_arg)
function check_two_pid_descriptors called 1 returned 100% blocks executed 50%
1: 111:{
1: 112: if (_dbus_string_get_length (pid_fd) > 0)
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
-: 113: {
#####: 114: fprintf (stderr, "--%s specified but printing pid to %s already requested\n",
call 0 never executed
call 1 never executed
-: 115: extra_arg, _dbus_string_get_const_data (pid_fd));
#####: 116: exit (1);
call 0 never executed
-: 117: }
1: 118:}
-: 119:
-: 120:static dbus_bool_t
-: 121:handle_reload_watch (DBusWatch *watch,
-: 122: unsigned int flags,
-: 123: void *data)
function handle_reload_watch called 0 returned 0% blocks executed 0%
#####: 124:{
-: 125: DBusError error;
-: 126: DBusString str;
#####: 127: _dbus_string_init (&str);
call 0 never executed
#####: 128: if (_dbus_read (reload_pipe[RELOAD_READ_END], &str, 1) != 1)
call 0 never executed
branch 1 never executed
branch 2 never executed
-: 129: {
#####: 130: _dbus_warn ("Couldn't read from reload pipe.\n");
call 0 never executed
#####: 131: exit (1);
call 0 never executed
-: 132: }
#####: 133: _dbus_string_free (&str);
call 0 never executed
-: 134:
#####: 135: dbus_error_init (&error);
call 0 never executed
#####: 136: if (! bus_context_reload_config (context, &error))
call 0 never executed
branch 1 never executed
branch 2 never executed
-: 137: {
#####: 138: _dbus_warn ("Unable to reload configuration: %s\n",
call 0 never executed
-: 139: error.message);
#####: 140: dbus_error_free (&error);
call 0 never executed
#####: 141: exit (1);
call 0 never executed
-: 142: }
#####: 143: return TRUE;
-: 144:}
-: 145:
-: 146:static dbus_bool_t
-: 147:reload_watch_callback (DBusWatch *watch,
-: 148: unsigned int condition,
-: 149: void *data)
function reload_watch_callback called 0 returned 0% blocks executed 0%
#####: 150:{
#####: 151: return dbus_watch_handle (watch, condition);
call 0 never executed
-: 152:}
-: 153:
-: 154:static void
-: 155:setup_reload_pipe (DBusLoop *loop)
function setup_reload_pipe called 1 returned 100% blocks executed 47%
1: 156:{
-: 157: DBusError error;
-: 158: DBusWatch *watch;
-: 159:
1: 160: dbus_error_init (&error);
call 0 returned 100%
-: 161:
1: 162: if (!_dbus_full_duplex_pipe (&reload_pipe[0], &reload_pipe[1],
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
-: 163: TRUE, &error))
-: 164: {
#####: 165: _dbus_warn ("Unable to create reload pipe: %s\n",
call 0 never executed
-: 166: error.message);
#####: 167: dbus_error_free (&error);
call 0 never executed
#####: 168: exit (1);
call 0 never executed
-: 169: }
-: 170:
1: 171: watch = _dbus_watch_new (reload_pipe[RELOAD_READ_END],
call 0 returned 100%
-: 172: DBUS_WATCH_READABLE, TRUE,
-: 173: handle_reload_watch, NULL, NULL);
-: 174:
1: 175: if (watch == NULL)
branch 0 taken 0% (fallthrough)
branch 1 taken 100%
-: 176: {
#####: 177: _dbus_warn ("Unable to create reload watch: %s\n",
call 0 never executed
-: 178: error.message);
#####: 179: dbus_error_free (&error);
call 0 never executed
#####: 180: exit (1);
call 0 never executed
-: 181: }
-: 182:
1: 183: if (!_dbus_loop_add_watch (loop, watch, reload_watch_callback,
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
-: 184: NULL, NULL))
-: 185: {
#####: 186: _dbus_warn ("Unable to add reload watch to main loop: %s\n",
call 0 never executed
-: 187: error.message);
#####: 188: dbus_error_free (&error);
call 0 never executed
#####: 189: exit (1);
call 0 never executed
-: 190: }
-: 191:
1: 192:}
-: 193:
-: 194:int
-: 195:main (int argc, char **argv)
function main called 1 returned 100% blocks executed 67%
1: 196:{
-: 197: DBusError error;
-: 198: DBusString config_file;
-: 199: DBusString addr_fd;
-: 200: DBusString pid_fd;
-: 201: const char *prev_arg;
-: 202: int print_addr_fd;
-: 203: int print_pid_fd;
-: 204: int i;
-: 205: dbus_bool_t print_address;
-: 206: dbus_bool_t print_pid;
-: 207: int force_fork;
-: 208:
1: 209: if (!_dbus_string_init (&config_file))
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
#####: 210: return 1;
-: 211:
1: 212: if (!_dbus_string_init (&addr_fd))
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
#####: 213: return 1;
-: 214:
1: 215: if (!_dbus_string_init (&pid_fd))
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
#####: 216: return 1;
-: 217:
1: 218: print_address = FALSE;
1: 219: print_pid = FALSE;
1: 220: force_fork = FORK_FOLLOW_CONFIG_FILE;
-: 221:
1: 222: prev_arg = NULL;
1: 223: i = 1;
9: 224: while (i < argc)
branch 0 taken 88%
branch 1 taken 13% (fallthrough)
-: 225: {
7: 226: const char *arg = argv[i];
-: 227:
7: 228: if (strcmp (arg, "--help") == 0 ||
call 0 returned 100%
branch 1 taken 100% (fallthrough)
branch 2 taken 0%
call 3 returned 100%
branch 4 taken 100% (fallthrough)
branch 5 taken 0%
call 6 returned 100%
branch 7 taken 0% (fallthrough)
branch 8 taken 100%
-: 229: strcmp (arg, "-h") == 0 ||
-: 230: strcmp (arg, "-?") == 0)
#####: 231: usage ();
call 0 never executed
7: 232: else if (strcmp (arg, "--version") == 0)
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
#####: 233: version ();
call 0 never executed
7: 234: else if (strcmp (arg, "--nofork") == 0)
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
#####: 235: force_fork = FORK_NEVER;
7: 236: else if (strcmp (arg, "--fork") == 0)
call 0 returned 100%
branch 1 taken 14% (fallthrough)
branch 2 taken 86%
1: 237: force_fork = FORK_ALWAYS;
6: 238: else if (strcmp (arg, "--system") == 0)
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
-: 239: {
#####: 240: check_two_config_files (&config_file, "system");
call 0 never executed
-: 241:
#####: 242: if (!_dbus_string_append (&config_file, DBUS_SYSTEM_CONFIG_FILE))
call 0 never executed
branch 1 never executed
branch 2 never executed
#####: 243: exit (1);
call 0 never executed
-: 244: }
6: 245: else if (strcmp (arg, "--session") == 0)
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
-: 246: {
#####: 247: check_two_config_files (&config_file, "session");
call 0 never executed
-: 248:
#####: 249: if (!_dbus_string_append (&config_file, DBUS_SESSION_CONFIG_FILE))
call 0 never executed
branch 1 never executed
branch 2 never executed
#####: 250: exit (1);
call 0 never executed
-: 251: }
6: 252: else if (strstr (arg, "--config-file=") == arg)
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
-: 253: {
-: 254: const char *file;
-: 255:
#####: 256: check_two_config_files (&config_file, "config-file");
call 0 never executed
-: 257:
#####: 258: file = strchr (arg, '=');
call 0 never executed
#####: 259: ++file;
-: 260:
#####: 261: if (!_dbus_string_append (&config_file, file))
call 0 never executed
branch 1 never executed
branch 2 never executed
#####: 262: exit (1);
call 0 never executed
-: 263: }
7: 264: else if (prev_arg &&
branch 0 taken 100% (fallthrough)
branch 1 taken 0%
call 2 returned 100%
branch 3 taken 17% (fallthrough)
branch 4 taken 83%
-: 265: strcmp (prev_arg, "--config-file") == 0)
-: 266: {
1: 267: check_two_config_files (&config_file, "config-file");
call 0 returned 100%
-: 268:
1: 269: if (!_dbus_string_append (&config_file, arg))
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
#####: 270: exit (1);
call 0 never executed
-: 271: }
5: 272: else if (strcmp (arg, "--config-file") == 0)
call 0 returned 100%
branch 1 taken 80% (fallthrough)
branch 2 taken 20%
-: 273: ; /* wait for next arg */
4: 274: else if (strstr (arg, "--print-address=") == arg)
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
-: 275: {
-: 276: const char *desc;
-: 277:
#####: 278: check_two_addr_descriptors (&addr_fd, "print-address");
call 0 never executed
-: 279:
#####: 280: desc = strchr (arg, '=');
call 0 never executed
#####: 281: ++desc;
-: 282:
#####: 283: if (!_dbus_string_append (&addr_fd, desc))
call 0 never executed
branch 1 never executed
branch 2 never executed
#####: 284: exit (1);
call 0 never executed
-: 285:
#####: 286: print_address = TRUE;
-: 287: }
5: 288: else if (prev_arg &&
branch 0 taken 100% (fallthrough)
branch 1 taken 0%
call 2 returned 100%
branch 3 taken 25% (fallthrough)
branch 4 taken 75%
-: 289: strcmp (prev_arg, "--print-address") == 0)
-: 290: {
1: 291: check_two_addr_descriptors (&addr_fd, "print-address");
call 0 returned 100%
-: 292:
1: 293: if (!_dbus_string_append (&addr_fd, arg))
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
#####: 294: exit (1);
call 0 never executed
-: 295:
1: 296: print_address = TRUE;
-: 297: }
3: 298: else if (strcmp (arg, "--print-address") == 0)
call 0 returned 100%
branch 1 taken 33% (fallthrough)
branch 2 taken 67%
1: 299: print_address = TRUE; /* and we'll get the next arg if appropriate */
2: 300: else if (strstr (arg, "--print-pid=") == arg)
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
-: 301: {
-: 302: const char *desc;
-: 303:
#####: 304: check_two_pid_descriptors (&pid_fd, "print-pid");
call 0 never executed
-: 305:
#####: 306: desc = strchr (arg, '=');
call 0 never executed
#####: 307: ++desc;
-: 308:
#####: 309: if (!_dbus_string_append (&pid_fd, desc))
call 0 never executed
branch 1 never executed
branch 2 never executed
#####: 310: exit (1);
call 0 never executed
-: 311:
#####: 312: print_pid = TRUE;
-: 313: }
3: 314: else if (prev_arg &&
branch 0 taken 100% (fallthrough)
branch 1 taken 0%
call 2 returned 100%
branch 3 taken 50% (fallthrough)
branch 4 taken 50%
-: 315: strcmp (prev_arg, "--print-pid") == 0)
-: 316: {
1: 317: check_two_pid_descriptors (&pid_fd, "print-pid");
call 0 returned 100%
-: 318:
1: 319: if (!_dbus_string_append (&pid_fd, arg))
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
#####: 320: exit (1);
call 0 never executed
-: 321:
1: 322: print_pid = TRUE;
-: 323: }
1: 324: else if (strcmp (arg, "--print-pid") == 0)
call 0 returned 100%
branch 1 taken 100% (fallthrough)
branch 2 taken 0%
1: 325: print_pid = TRUE; /* and we'll get the next arg if appropriate */
-: 326: else
#####: 327: usage ();
call 0 never executed
-: 328:
7: 329: prev_arg = arg;
-: 330:
7: 331: ++i;
-: 332: }
-: 333:
1: 334: if (_dbus_string_get_length (&config_file) == 0)
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
-: 335: {
#####: 336: fprintf (stderr, "No configuration file specified.\n");
call 0 never executed
#####: 337: usage ();
call 0 never executed
-: 338: }
-: 339:
1: 340: print_addr_fd = -1;
1: 341: if (print_address)
branch 0 taken 100% (fallthrough)
branch 1 taken 0%
-: 342: {
1: 343: print_addr_fd = 1; /* stdout */
1: 344: if (_dbus_string_get_length (&addr_fd) > 0)
call 0 returned 100%
branch 1 taken 100% (fallthrough)
branch 2 taken 0%
-: 345: {
-: 346: long val;
-: 347: int end;
1: 348: if (!_dbus_string_parse_int (&addr_fd, 0, &val, &end) ||
call 0 returned 100%
branch 1 taken 100% (fallthrough)
branch 2 taken 0%
call 3 returned 100%
branch 4 taken 100% (fallthrough)
branch 5 taken 0%
branch 6 taken 100% (fallthrough)
branch 7 taken 0%
branch 8 taken 0% (fallthrough)
branch 9 taken 100%
-: 349: end != _dbus_string_get_length (&addr_fd) ||
-: 350: val < 0 || val > _DBUS_INT_MAX)
-: 351: {
#####: 352: fprintf (stderr, "Invalid file descriptor: \"%s\"\n",
call 0 never executed
call 1 never executed
-: 353: _dbus_string_get_const_data (&addr_fd));
#####: 354: exit (1);
call 0 never executed
-: 355: }
-: 356:
1: 357: print_addr_fd = val;
-: 358: }
-: 359: }
1: 360: _dbus_string_free (&addr_fd);
call 0 returned 100%
-: 361:
1: 362: print_pid_fd = -1;
1: 363: if (print_pid)
branch 0 taken 100% (fallthrough)
branch 1 taken 0%
-: 364: {
1: 365: print_pid_fd = 1; /* stdout */
1: 366: if (_dbus_string_get_length (&pid_fd) > 0)
call 0 returned 100%
branch 1 taken 100% (fallthrough)
branch 2 taken 0%
-: 367: {
-: 368: long val;
-: 369: int end;
1: 370: if (!_dbus_string_parse_int (&pid_fd, 0, &val, &end) ||
call 0 returned 100%
branch 1 taken 100% (fallthrough)
branch 2 taken 0%
call 3 returned 100%
branch 4 taken 100% (fallthrough)
branch 5 taken 0%
branch 6 taken 100% (fallthrough)
branch 7 taken 0%
branch 8 taken 0% (fallthrough)
branch 9 taken 100%
-: 371: end != _dbus_string_get_length (&pid_fd) ||
-: 372: val < 0 || val > _DBUS_INT_MAX)
-: 373: {
#####: 374: fprintf (stderr, "Invalid file descriptor: \"%s\"\n",
call 0 never executed
call 1 never executed
-: 375: _dbus_string_get_const_data (&pid_fd));
#####: 376: exit (1);
call 0 never executed
-: 377: }
-: 378:
1: 379: print_pid_fd = val;
-: 380: }
-: 381: }
1: 382: _dbus_string_free (&pid_fd);
call 0 returned 100%
-: 383:
1: 384: if (!bus_selinux_pre_init ())
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
-: 385: {
#####: 386: _dbus_warn ("SELinux pre-initialization failed\n");
call 0 never executed
#####: 387: exit (1);
call 0 never executed
-: 388: }
-: 389:
1: 390: dbus_error_init (&error);
call 0 returned 100%
1: 391: context = bus_context_new (&config_file, force_fork,
call 0 returned 100%
-: 392: print_addr_fd, print_pid_fd,
-: 393: &error);
1: 394: _dbus_string_free (&config_file);
call 0 returned 100%
1: 395: if (context == NULL)
branch 0 taken 0% (fallthrough)
branch 1 taken 100%
-: 396: {
#####: 397: _dbus_warn ("Failed to start message bus: %s\n",
call 0 never executed
-: 398: error.message);
#####: 399: dbus_error_free (&error);
call 0 never executed
#####: 400: exit (1);
call 0 never executed
-: 401: }
-: 402:
1: 403: setup_reload_pipe (bus_context_get_loop (context));
call 0 returned 100%
call 1 returned 100%
-: 404:
1: 405: _dbus_set_signal_handler (SIGHUP, signal_handler);
call 0 returned 100%
1: 406: _dbus_set_signal_handler (SIGTERM, signal_handler);
call 0 returned 100%
-: 407:#ifdef DBUS_BUS_ENABLE_DNOTIFY_ON_LINUX
1: 408: _dbus_set_signal_handler (SIGIO, signal_handler);
call 0 returned 100%
-: 409:#endif /* DBUS_BUS_ENABLE_DNOTIFY_ON_LINUX */
-: 410:
1: 411: _dbus_verbose ("We are on D-Bus...\n");
call 0 returned 100%
1: 412: _dbus_loop_run (bus_context_get_loop (context));
call 0 returned 100%
call 1 returned 100%
-: 413:
1: 414: bus_context_shutdown (context);
call 0 returned 100%
1: 415: bus_context_unref (context);
call 0 returned 100%
1: 416: bus_selinux_shutdown ();
call 0 returned 100%
-: 417:
1: 418: return 0;
-: 419:}