Coverage report for dbus/dbus-server-debug-pipe.c.gcov
-: 0:Source:dbus-server-debug-pipe.c
-: 0:Graph:.libs/dbus-server-debug-pipe.gcno
-: 0:Data:.libs/dbus-server-debug-pipe.gcda
-: 0:Runs:11820
-: 0:Programs:5
-: 1:/* -*- mode: C; c-file-style: "gnu" -*- */
-: 2:/* dbus-server-debug-pipe.c In-proc debug server implementation
-: 3: *
-: 4: * Copyright (C) 2003 CodeFactory AB
-: 5: * Copyright (C) 2003, 2004 Red Hat, Inc.
-: 6: *
-: 7: * Licensed under the Academic Free License version 2.1
-: 8: *
-: 9: * This program is free software; you can redistribute it and/or modify
-: 10: * it under the terms of the GNU General Public License as published by
-: 11: * the Free Software Foundation; either version 2 of the License, or
-: 12: * (at your option) any later version.
-: 13: *
-: 14: * This program is distributed in the hope that it will be useful,
-: 15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
-: 16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-: 17: * GNU General Public License for more details.
-: 18: *
-: 19: * You should have received a copy of the GNU General Public License
-: 20: * along with this program; if not, write to the Free Software
-: 21: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-: 22: *
-: 23: */
-: 24:
-: 25:#include "dbus-internals.h"
-: 26:#include "dbus-server-debug-pipe.h"
-: 27:#include "dbus-transport-unix.h"
-: 28:#include "dbus-connection-internal.h"
-: 29:#include "dbus-hash.h"
-: 30:#include "dbus-string.h"
-: 31:#include "dbus-protocol.h"
-: 32:
-: 33:#ifdef DBUS_BUILD_TESTS
-: 34:
-: 35:/**
-: 36: * @defgroup DBusServerDebugPipe DBusServerDebugPipe
-: 37: * @ingroup DBusInternals
-: 38: * @brief In-process pipe debug server used in unit tests.
-: 39: *
-: 40: * Types and functions related to DBusServerDebugPipe.
-: 41: * This is used for unit testing.
-: 42: *
-: 43: * @{
-: 44: */
-: 45:
-: 46:/**
-: 47: * Opaque object representing a debug server implementation.
-: 48: */
-: 49:typedef struct DBusServerDebugPipe DBusServerDebugPipe;
-: 50:
-: 51:/**
-: 52: * Implementation details of DBusServerDebugPipe. All members
-: 53: * are private.
-: 54: */
-: 55:struct DBusServerDebugPipe
-: 56:{
-: 57: DBusServer base; /**< Parent class members. */
-: 58:
-: 59: char *name; /**< Server name. */
-: 60:
-: 61: dbus_bool_t disconnected; /**< TRUE if disconnect has been called */
-: 62:};
-: 63:
-: 64:/* FIXME not threadsafe (right now the test suite doesn't use threads anyhow ) */
-: 65:static DBusHashTable *server_pipe_hash;
-: 66:static int server_pipe_hash_refcount = 0;
-: 67:
-: 68:static dbus_bool_t
-: 69:pipe_hash_ref (void)
function pipe_hash_ref called 2 returned 100% blocks executed 86%
2: 70:{
2: 71: if (!server_pipe_hash)
branch 0 taken 100% (fallthrough)
branch 1 taken 0%
-: 72: {
2: 73: _dbus_assert (server_pipe_hash_refcount == 0);
call 0 returned 100%
-: 74:
2: 75: server_pipe_hash = _dbus_hash_table_new (DBUS_HASH_STRING, NULL, NULL);
call 0 returned 100%
-: 76:
2: 77: if (!server_pipe_hash)
branch 0 taken 0% (fallthrough)
branch 1 taken 100%
#####: 78: return FALSE;
-: 79: }
-: 80:
2: 81: server_pipe_hash_refcount = 1;
-: 82:
2: 83: return TRUE;
-: 84:}
-: 85:
-: 86:static void
-: 87:pipe_hash_unref (void)
function pipe_hash_unref called 2 returned 100% blocks executed 100%
2: 88:{
2: 89: _dbus_assert (server_pipe_hash != NULL);
call 0 returned 100%
2: 90: _dbus_assert (server_pipe_hash_refcount > 0);
call 0 returned 100%
-: 91:
2: 92: server_pipe_hash_refcount -= 1;
2: 93: if (server_pipe_hash_refcount == 0)
branch 0 taken 100% (fallthrough)
branch 1 taken 0%
-: 94: {
2: 95: _dbus_hash_table_unref (server_pipe_hash);
call 0 returned 100%
2: 96: server_pipe_hash = NULL;
-: 97: }
2: 98:}
-: 99:
-: 100:static void
-: 101:debug_finalize (DBusServer *server)
function debug_finalize called 2 returned 100% blocks executed 100%
2: 102:{
2: 103: DBusServerDebugPipe *debug_server = (DBusServerDebugPipe*) server;
-: 104:
2: 105: pipe_hash_unref ();
call 0 returned 100%
-: 106:
2: 107: _dbus_server_finalize_base (server);
call 0 returned 100%
-: 108:
2: 109: dbus_free (debug_server->name);
call 0 returned 100%
2: 110: dbus_free (server);
call 0 returned 100%
2: 111:}
-: 112:
-: 113:static void
-: 114:debug_disconnect (DBusServer *server)
function debug_disconnect called 2 returned 100% blocks executed 100%
2: 115:{
2: 116: ((DBusServerDebugPipe*)server)->disconnected = TRUE;
2: 117:}
-: 118:
-: 119:static DBusServerVTable debug_vtable = {
-: 120: debug_finalize,
-: 121: debug_disconnect
-: 122:};
-: 123:
-: 124:/**
-: 125: * Creates a new debug server using an in-process pipe
-: 126: *
-: 127: * @param server_name the name of the server.
-: 128: * @param error address where an error can be returned.
-: 129: * @returns a new server, or #NULL on failure.
-: 130: */
-: 131:DBusServer*
-: 132:_dbus_server_debug_pipe_new (const char *server_name,
-: 133: DBusError *error)
function _dbus_server_debug_pipe_new called 2 returned 100% blocks executed 61%
2: 134:{
-: 135: DBusServerDebugPipe *debug_server;
-: 136: DBusString address;
-: 137: DBusString name_str;
-: 138:
2: 139: _DBUS_ASSERT_ERROR_IS_CLEAR (error);
branch 0 taken 100% (fallthrough)
branch 1 taken 0%
call 2 returned 100%
branch 3 taken 100% (fallthrough)
branch 4 taken 0%
call 5 returned 100%
-: 140:
2: 141: if (!pipe_hash_ref ())
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
#####: 142: return NULL;
-: 143:
2: 144: if (_dbus_hash_table_lookup_string (server_pipe_hash, server_name) != NULL)
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
-: 145: {
#####: 146: dbus_set_error (error, DBUS_ERROR_ADDRESS_IN_USE, NULL);
call 0 never executed
#####: 147: pipe_hash_unref ();
call 0 never executed
#####: 148: return NULL;
-: 149: }
-: 150:
2: 151: debug_server = dbus_new0 (DBusServerDebugPipe, 1);
call 0 returned 100%
2: 152: if (debug_server == NULL)
branch 0 taken 0% (fallthrough)
branch 1 taken 100%
#####: 153: goto nomem_0;
-: 154:
2: 155: if (!_dbus_string_init (&address))
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
#####: 156: goto nomem_1;
-: 157:
2: 158: _dbus_string_init_const (&name_str, server_name);
call 0 returned 100%
2: 159: if (!_dbus_string_append (&address, "debug-pipe:name=") ||
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%
-: 160: !_dbus_address_append_escaped (&address, &name_str))
-: 161: goto nomem_2;
-: 162:
2: 163: debug_server->name = _dbus_strdup (server_name);
call 0 returned 100%
2: 164: if (debug_server->name == NULL)
branch 0 taken 0% (fallthrough)
branch 1 taken 100%
#####: 165: goto nomem_2;
-: 166:
2: 167: if (!_dbus_server_init_base (&debug_server->base,
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
-: 168: &debug_vtable, &address))
#####: 169: goto nomem_3;
-: 170:
2: 171: if (!_dbus_hash_table_insert_string (server_pipe_hash,
call 0 returned 100%
branch 1 taken 100% (fallthrough)
branch 2 taken 0%
-: 172: debug_server->name,
-: 173: debug_server))
#####: 174: goto nomem_4;
-: 175:
2: 176: _dbus_string_free (&address);
call 0 returned 100%
-: 177:
-: 178: /* server keeps the pipe hash ref */
-: 179:
2: 180: return (DBusServer *)debug_server;
-: 181:
#####: 182: nomem_4:
#####: 183: _dbus_server_finalize_base (&debug_server->base);
call 0 never executed
#####: 184: nomem_3:
#####: 185: dbus_free (debug_server->name);
call 0 never executed
#####: 186: nomem_2:
#####: 187: _dbus_string_free (&address);
call 0 never executed
#####: 188: nomem_1:
#####: 189: dbus_free (debug_server);
call 0 never executed
#####: 190: nomem_0:
#####: 191: pipe_hash_unref ();
call 0 never executed
#####: 192: dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
call 0 never executed
#####: 193: return NULL;
-: 194:}
-: 195:
-: 196:/**
-: 197: * Creates the client-side transport for
-: 198: * a debug-pipe connection connected to the
-: 199: * given debug-pipe server name.
-: 200: *
-: 201: * @param server_name name of server to connect to
-: 202: * @param error address where an error can be returned.
-: 203: * @returns #NULL on no memory or transport
-: 204: */
-: 205:DBusTransport*
-: 206:_dbus_transport_debug_pipe_new (const char *server_name,
-: 207: DBusError *error)
function _dbus_transport_debug_pipe_new called 5919 returned 100% blocks executed 86%
5919: 208:{
-: 209: DBusTransport *client_transport;
-: 210: DBusTransport *server_transport;
-: 211: DBusConnection *connection;
-: 212: int client_fd, server_fd;
-: 213: DBusServer *server;
-: 214: DBusString address;
-: 215:
5919: 216: _DBUS_ASSERT_ERROR_IS_CLEAR (error);
branch 0 taken 100% (fallthrough)
branch 1 taken 0%
call 2 returned 100%
branch 3 taken 100% (fallthrough)
branch 4 taken 0%
call 5 returned 100%
-: 217:
5919: 218: if (server_pipe_hash == NULL)
branch 0 taken 0% (fallthrough)
branch 1 taken 100%
-: 219: {
#####: 220: dbus_set_error (error, DBUS_ERROR_NO_SERVER, NULL);
call 0 never executed
#####: 221: return NULL;
-: 222: }
-: 223:
5919: 224: server = _dbus_hash_table_lookup_string (server_pipe_hash,
call 0 returned 100%
-: 225: server_name);
5919: 226: if (server == NULL ||
branch 0 taken 100% (fallthrough)
branch 1 taken 0%
branch 2 taken 0% (fallthrough)
branch 3 taken 100%
-: 227: ((DBusServerDebugPipe*)server)->disconnected)
-: 228: {
#####: 229: dbus_set_error (error, DBUS_ERROR_NO_SERVER, NULL);
call 0 never executed
#####: 230: return NULL;
-: 231: }
-: 232:
5919: 233: if (!_dbus_string_init (&address))
call 0 returned 100%
branch 1 taken 1% (fallthrough)
branch 2 taken 99%
-: 234: {
6: 235: dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
call 0 returned 100%
6: 236: return NULL;
-: 237: }
-: 238:
5913: 239: if (!_dbus_string_append (&address, "debug-pipe:name=") ||
call 0 returned 100%
branch 1 taken 99% (fallthrough)
branch 2 taken 1%
call 3 returned 100%
branch 4 taken 1% (fallthrough)
branch 5 taken 99%
-: 240: !_dbus_string_append (&address, server_name))
-: 241: {
12: 242: dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
call 0 returned 100%
12: 243: _dbus_string_free (&address);
call 0 returned 100%
12: 244: return NULL;
-: 245: }
-: 246:
5901: 247: if (!_dbus_full_duplex_pipe (&client_fd, &server_fd, FALSE,
call 0 returned 100%
branch 1 taken 0% (fallthrough)
branch 2 taken 100%
-: 248: NULL))
-: 249: {
#####: 250: _dbus_verbose ("failed to create full duplex pipe\n");
call 0 never executed
#####: 251: dbus_set_error (error, DBUS_ERROR_FAILED, "Could not create full-duplex pipe");
call 0 never executed
#####: 252: _dbus_string_free (&address);
call 0 never executed
#####: 253: return NULL;
-: 254: }
-: 255:
5901: 256: _dbus_fd_set_close_on_exec (client_fd);
call 0 returned 100%
5901: 257: _dbus_fd_set_close_on_exec (server_fd);
call 0 returned 100%
-: 258:
5901: 259: client_transport = _dbus_transport_new_for_fd (client_fd,
call 0 returned 100%
-: 260: FALSE, &address);
5901: 261: if (client_transport == NULL)
branch 0 taken 3% (fallthrough)
branch 1 taken 97%
-: 262: {
200: 263: _dbus_close (client_fd, NULL);
call 0 returned 100%
200: 264: _dbus_close (server_fd, NULL);
call 0 returned 100%
200: 265: dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
call 0 returned 100%
200: 266: _dbus_string_free (&address);
call 0 returned 100%
200: 267: return NULL;
-: 268: }
-: 269:
5701: 270: _dbus_string_free (&address);
call 0 returned 100%
-: 271:
5701: 272: client_fd = -1;
-: 273:
5701: 274: server_transport = _dbus_transport_new_for_fd (server_fd,
call 0 returned 100%
-: 275: &server->guid_hex, NULL);
5701: 276: if (server_transport == NULL)
branch 0 taken 2% (fallthrough)
branch 1 taken 98%
-: 277: {
104: 278: _dbus_transport_unref (client_transport);
call 0 returned 100%
104: 279: _dbus_close (server_fd, NULL);
call 0 returned 100%
104: 280: dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
call 0 returned 100%
104: 281: return NULL;
-: 282: }
-: 283:
5597: 284: server_fd = -1;
-: 285:
5597: 286: if (!_dbus_transport_set_auth_mechanisms (server_transport,
call 0 returned 100%
branch 1 taken 1% (fallthrough)
branch 2 taken 99%
-: 287: (const char**) server->auth_mechanisms))
-: 288: {
6: 289: dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
call 0 returned 100%
6: 290: _dbus_transport_unref (server_transport);
call 0 returned 100%
6: 291: _dbus_transport_unref (client_transport);
call 0 returned 100%
6: 292: return NULL;
-: 293: }
-: 294:
5591: 295: connection = _dbus_connection_new_for_transport (server_transport);
call 0 returned 100%
5591: 296: _dbus_transport_unref (server_transport);
call 0 returned 100%
5591: 297: server_transport = NULL;
-: 298:
5591: 299: if (connection == NULL)
branch 0 taken 1% (fallthrough)
branch 1 taken 99%
-: 300: {
70: 301: _dbus_transport_unref (client_transport);
call 0 returned 100%
70: 302: dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
call 0 returned 100%
70: 303: return NULL;
-: 304: }
-: 305:
-: 306: /* See if someone wants to handle this new connection,
-: 307: * self-referencing for paranoia
-: 308: */
5521: 309: if (server->new_connection_function)
branch 0 taken 100% (fallthrough)
branch 1 taken 0%
-: 310: {
5521: 311: dbus_server_ref (server);
call 0 returned 100%
5521: 312: (* server->new_connection_function) (server, connection,
call 0 returned 100%
-: 313: server->new_connection_data);
5521: 314: dbus_server_unref (server);
call 0 returned 100%
-: 315: }
-: 316:
-: 317: /* If no one grabbed a reference, the connection will die,
-: 318: * and the client transport will get an immediate disconnect
-: 319: */
5521: 320: dbus_connection_unref (connection);
call 0 returned 100%
-: 321:
5521: 322: return client_transport;
-: 323:}
-: 324:
-: 325:
-: 326:/** @} */
-: 327:
-: 328:#endif /* DBUS_BUILD_TESTS */
-: 329: