Coverage report for dbus/dbus-sysdeps.c.gcov

        -:    0:Source:dbus-sysdeps.c
        -:    0:Graph:.libs/dbus-sysdeps.gcno
        -:    0:Data:.libs/dbus-sysdeps.gcda
        -:    0:Runs:11810
        -:    0:Programs:5
        -:    1:/* -*- mode: C; c-file-style: "gnu" -*- */
        -:    2:/* dbus-sysdeps.c Wrappers around system/libc features (internal to D-BUS implementation)
        -:    3: * 
        -:    4: * Copyright (C) 2002, 2003  Red Hat, Inc.
        -:    5: * Copyright (C) 2003 CodeFactory AB
        -:    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-sysdeps.h"
        -:   27:#include "dbus-threads.h"
        -:   28:#include "dbus-protocol.h"
        -:   29:#include "dbus-string.h"
        -:   30:#include <sys/types.h>
        -:   31:#include <stdlib.h>
        -:   32:#include <string.h>
        -:   33:#include <signal.h>
        -:   34:#include <unistd.h>
        -:   35:#include <stdio.h>
        -:   36:#include <errno.h>
        -:   37:#include <fcntl.h>
        -:   38:#include <sys/socket.h>
        -:   39:#include <dirent.h>
        -:   40:#include <sys/un.h>
        -:   41:#include <pwd.h>
        -:   42:#include <time.h>
        -:   43:#include <locale.h>
        -:   44:#include <sys/time.h>
        -:   45:#include <sys/stat.h>
        -:   46:#include <sys/wait.h>
        -:   47:#include <netinet/in.h>
        -:   48:#include <netdb.h>
        -:   49:#include <grp.h>
        -:   50:
        -:   51:#ifdef HAVE_WRITEV
        -:   52:#include <sys/uio.h>
        -:   53:#endif
        -:   54:#ifdef HAVE_POLL
        -:   55:#include <sys/poll.h>
        -:   56:#endif
        -:   57:#ifdef HAVE_BACKTRACE
        -:   58:#include <execinfo.h>
        -:   59:#endif
        -:   60:#ifdef HAVE_GETPEERUCRED
        -:   61:#include <ucred.h>
        -:   62:#endif
        -:   63:
        -:   64:#ifndef O_BINARY
        -:   65:#define O_BINARY 0
        -:   66:#endif
        -:   67:
        -:   68:#ifndef HAVE_SOCKLEN_T
        -:   69:#define socklen_t int
        -:   70:#endif
        -:   71:
        -:   72:/**
        -:   73: * @addtogroup DBusInternalsUtils
        -:   74: * @{
        -:   75: */
        -:   76:#ifndef DBUS_DISABLE_ASSERT
        -:   77:/**
        -:   78: * Aborts the program with SIGABRT (dumping core).
        -:   79: */
        -:   80:void
        -:   81:_dbus_abort (void)
function _dbus_abort called 0 returned 0% blocks executed 0%
    #####:   82:{
        -:   83:#ifdef DBUS_ENABLE_VERBOSE_MODE
        -:   84:  const char *s;
    #####:   85:  s = _dbus_getenv ("DBUS_PRINT_BACKTRACE");
call    0 never executed
    #####:   86:  if (s && *s)
branch  0 never executed
branch  1 never executed
branch  2 never executed
branch  3 never executed
    #####:   87:    _dbus_print_backtrace ();
call    0 never executed
        -:   88:#endif
    #####:   89:  abort ();
call    0 never executed
        -:   90:  _exit (1); /* in case someone manages to ignore SIGABRT */
        -:   91:}
        -:   92:#endif
        -:   93:
        -:   94:/**
        -:   95: * Wrapper for setenv(). If the value is #NULL, unsets
        -:   96: * the environment variable.
        -:   97: *
        -:   98: * @todo if someone can verify it's safe, we could avoid the
        -:   99: * memleak when doing an unset.
        -:  100: *
        -:  101: * @param varname name of environment variable
        -:  102: * @param value value of environment variable
        -:  103: * @returns #TRUE on success.
        -:  104: */
        -:  105:dbus_bool_t
        -:  106:_dbus_setenv (const char *varname,
        -:  107:              const char *value)
function _dbus_setenv called 4765 returned 100% blocks executed 100%
     4765:  108:{
     4765:  109:  _dbus_assert (varname != NULL);
call    0 returned 100%
        -:  110:  
     4765:  111:  if (value == NULL)
branch  0 taken 39% (fallthrough)
branch  1 taken 61%
        -:  112:    {
        -:  113:#ifdef HAVE_UNSETENV
     1858:  114:      unsetenv (varname);
call    0 returned 100%
     1858:  115:      return TRUE;
        -:  116:#else
        -:  117:      char *putenv_value;
        -:  118:      size_t len;
        -:  119:
        -:  120:      len = strlen (varname);
        -:  121:
        -:  122:      /* Use system malloc to avoid memleaks that dbus_malloc
        -:  123:       * will get upset about.
        -:  124:       */
        -:  125:      
        -:  126:      putenv_value = malloc (len + 1);
        -:  127:      if (putenv_value == NULL)
        -:  128:        return FALSE;
        -:  129:
        -:  130:      strcpy (putenv_value, varname);
        -:  131:      
        -:  132:      return (putenv (putenv_value) == 0);
        -:  133:#endif
        -:  134:    }
        -:  135:  else
        -:  136:    {
        -:  137:#ifdef HAVE_SETENV
     2907:  138:      return (setenv (varname, value, TRUE) == 0);
call    0 returned 100%
        -:  139:#else
        -:  140:      char *putenv_value;
        -:  141:      size_t len;
        -:  142:      size_t varname_len;
        -:  143:      size_t value_len;
        -:  144:
        -:  145:      varname_len = strlen (varname);
        -:  146:      value_len = strlen (value);
        -:  147:      
        -:  148:      len = varname_len + value_len + 1 /* '=' */ ;
        -:  149:
        -:  150:      /* Use system malloc to avoid memleaks that dbus_malloc
        -:  151:       * will get upset about.
        -:  152:       */
        -:  153:      
        -:  154:      putenv_value = malloc (len + 1);
        -:  155:      if (putenv_value == NULL)
        -:  156:        return FALSE;
        -:  157:
        -:  158:      strcpy (putenv_value, varname);
        -:  159:      strcpy (putenv_value + varname_len, "=");
        -:  160:      strcpy (putenv_value + varname_len + 1, value);
        -:  161:      
        -:  162:      return (putenv (putenv_value) == 0);
        -:  163:#endif
        -:  164:    }
        -:  165:}
        -:  166:
        -:  167:/**
        -:  168: * Wrapper for getenv().
        -:  169: *
        -:  170: * @param varname name of environment variable
        -:  171: * @returns value of environment variable or #NULL if unset
        -:  172: */
        -:  173:const char*
        -:  174:_dbus_getenv (const char *varname)
function _dbus_getenv called 16262 returned 100% blocks executed 100%
    16262:  175:{  
    16262:  176:  return getenv (varname);
call    0 returned 100%
        -:  177:}
        -:  178:
        -:  179:/**
        -:  180: * Thin wrapper around the read() system call that appends
        -:  181: * the data it reads to the DBusString buffer. It appends
        -:  182: * up to the given count, and returns the same value
        -:  183: * and same errno as read(). The only exception is that
        -:  184: * _dbus_read() handles EINTR for you. _dbus_read() can
        -:  185: * return ENOMEM, even though regular UNIX read doesn't.
        -:  186: *
        -:  187: * @param fd the file descriptor to read from
        -:  188: * @param buffer the buffer to append data to
        -:  189: * @param count the amount of data to read
        -:  190: * @returns the number of bytes read or -1
        -:  191: */
        -:  192:int
        -:  193:_dbus_read (int               fd,
        -:  194:            DBusString       *buffer,
        -:  195:            int               count)
function _dbus_read called 163347 returned 100% blocks executed 94%
   163347:  196:{
        -:  197:  int bytes_read;
        -:  198:  int start;
        -:  199:  char *data;
        -:  200:
   163347:  201:  _dbus_assert (count >= 0);
call    0 returned 100%
        -:  202:  
   163347:  203:  start = _dbus_string_get_length (buffer);
call    0 returned 100%
        -:  204:
   163347:  205:  if (!_dbus_string_lengthen (buffer, count))
call    0 returned 100%
branch  1 taken 1% (fallthrough)
branch  2 taken 99%
        -:  206:    {
      528:  207:      errno = ENOMEM;
call    0 returned 100%
      528:  208:      return -1;
        -:  209:    }
        -:  210:
   162819:  211:  data = _dbus_string_get_data_len (buffer, start, count);
call    0 returned 100%
        -:  212:
   162819:  213: again:
        -:  214:  
   162819:  215:  bytes_read = read (fd, data, count);
call    0 returned 100%
        -:  216:
   162819:  217:  if (bytes_read < 0)
branch  0 taken 32% (fallthrough)
branch  1 taken 68%
        -:  218:    {
    51999:  219:      if (errno == EINTR)
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  220:        goto again;
        -:  221:      else
        -:  222:        {
        -:  223:          /* put length back (note that this doesn't actually realloc anything) */
    51999:  224:          _dbus_string_set_length (buffer, start);
call    0 returned 100%
    51999:  225:          return -1;
        -:  226:        }
        -:  227:    }
        -:  228:  else
        -:  229:    {
        -:  230:      /* put length back (doesn't actually realloc) */
   110820:  231:      _dbus_string_set_length (buffer, start + bytes_read);
call    0 returned 100%
        -:  232:
        -:  233:#if 0
        -:  234:      if (bytes_read > 0)
        -:  235:        _dbus_verbose_bytes_of_string (buffer, start, bytes_read);
        -:  236:#endif
        -:  237:      
   110820:  238:      return bytes_read;
        -:  239:    }
        -:  240:}
        -:  241:
        -:  242:/**
        -:  243: * Thin wrapper around the write() system call that writes a part of a
        -:  244: * DBusString and handles EINTR for you.
        -:  245: * 
        -:  246: * @param fd the file descriptor to write
        -:  247: * @param buffer the buffer to write data from
        -:  248: * @param start the first byte in the buffer to write
        -:  249: * @param len the number of bytes to try to write
        -:  250: * @returns the number of bytes written or -1 on error
        -:  251: */
        -:  252:int
        -:  253:_dbus_write (int               fd,
        -:  254:             const DBusString *buffer,
        -:  255:             int               start,
        -:  256:             int               len)
function _dbus_write called 32590 returned 100% blocks executed 63%
    32590:  257:{
        -:  258:  const char *data;
        -:  259:  int bytes_written;
        -:  260:  
    32590:  261:  data = _dbus_string_get_const_data_len (buffer, start, len);
call    0 returned 100%
        -:  262:  
    32590:  263: again:
        -:  264:
    32590:  265:  bytes_written = write (fd, data, len);
call    0 returned 100%
        -:  266:
    32590:  267:  if (bytes_written < 0 && errno == EINTR)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
call    2 never executed
branch  3 never executed
branch  4 never executed
    #####:  268:    goto again;
        -:  269:
        -:  270:#if 0
        -:  271:  if (bytes_written > 0)
        -:  272:    _dbus_verbose_bytes_of_string (buffer, start, bytes_written);
        -:  273:#endif
        -:  274:  
    32590:  275:  return bytes_written;
        -:  276:}
        -:  277:
        -:  278:/**
        -:  279: * Like _dbus_write() but will use writev() if possible
        -:  280: * to write both buffers in sequence. The return value
        -:  281: * is the number of bytes written in the first buffer,
        -:  282: * plus the number written in the second. If the first
        -:  283: * buffer is written successfully and an error occurs
        -:  284: * writing the second, the number of bytes in the first
        -:  285: * is returned (i.e. the error is ignored), on systems that
        -:  286: * don't have writev. Handles EINTR for you.
        -:  287: * The second buffer may be #NULL.
        -:  288: *
        -:  289: * @param fd the file descriptor
        -:  290: * @param buffer1 first buffer
        -:  291: * @param start1 first byte to write in first buffer
        -:  292: * @param len1 number of bytes to write from first buffer
        -:  293: * @param buffer2 second buffer, or #NULL
        -:  294: * @param start2 first byte to write in second buffer
        -:  295: * @param len2 number of bytes to write in second buffer
        -:  296: * @returns total bytes written from both buffers, or -1 on error
        -:  297: */
        -:  298:int
        -:  299:_dbus_write_two (int               fd,
        -:  300:                 const DBusString *buffer1,
        -:  301:                 int               start1,
        -:  302:                 int               len1,
        -:  303:                 const DBusString *buffer2,
        -:  304:                 int               start2,
        -:  305:                 int               len2)
function _dbus_write_two called 73947 returned 100% blocks executed 85%
    73947:  306:{
    73947:  307:  _dbus_assert (buffer1 != NULL);
call    0 returned 100%
    73947:  308:  _dbus_assert (start1 >= 0);
call    0 returned 100%
    73947:  309:  _dbus_assert (start2 >= 0);
call    0 returned 100%
    73947:  310:  _dbus_assert (len1 >= 0);
call    0 returned 100%
    73947:  311:  _dbus_assert (len2 >= 0);
call    0 returned 100%
        -:  312:  
        -:  313:#ifdef HAVE_WRITEV
        -:  314:  {
        -:  315:    struct iovec vectors[2];
        -:  316:    const char *data1;
        -:  317:    const char *data2;
        -:  318:    int bytes_written;
        -:  319:
    73947:  320:    data1 = _dbus_string_get_const_data_len (buffer1, start1, len1);
call    0 returned 100%
        -:  321:
    73947:  322:    if (buffer2 != NULL)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
    73947:  323:      data2 = _dbus_string_get_const_data_len (buffer2, start2, len2);
call    0 returned 100%
        -:  324:    else
        -:  325:      {
    #####:  326:        data2 = NULL;
    #####:  327:        start2 = 0;
    #####:  328:        len2 = 0;
        -:  329:      }
        -:  330:   
    73947:  331:    vectors[0].iov_base = (char*) data1;
    73947:  332:    vectors[0].iov_len = len1;
    73947:  333:    vectors[1].iov_base = (char*) data2;
    73947:  334:    vectors[1].iov_len = len2;
        -:  335:
    73947:  336:  again:
        -:  337:   
    73947:  338:    bytes_written = writev (fd,
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
call    2 returned 100%
        -:  339:                            vectors,
        -:  340:                            data2 ? 2 : 1);
        -:  341:
    73947:  342:    if (bytes_written < 0 && errno == EINTR)
branch  0 taken 1% (fallthrough)
branch  1 taken 99%
call    2 returned 100%
branch  3 taken 0% (fallthrough)
branch  4 taken 100%
    #####:  343:      goto again;
        -:  344:   
    73947:  345:    return bytes_written;
        -:  346:  }
        -:  347:#else /* HAVE_WRITEV */
        -:  348:  {
        -:  349:    int ret1;
        -:  350:    
        -:  351:    ret1 = _dbus_write (fd, buffer1, start1, len1);
        -:  352:    if (ret1 == len1 && buffer2 != NULL)
        -:  353:      {
        -:  354:        ret2 = _dbus_write (fd, buffer2, start2, len2);
        -:  355:        if (ret2 < 0)
        -:  356:          ret2 = 0; /* we can't report an error as the first write was OK */
        -:  357:       
        -:  358:        return ret1 + ret2;
        -:  359:      }
        -:  360:    else
        -:  361:      return ret1;
        -:  362:  }
        -:  363:#endif /* !HAVE_WRITEV */   
        -:  364:}
        -:  365:
        -:  366:#define _DBUS_MAX_SUN_PATH_LENGTH 99
        -:  367:
        -:  368:/**
        -:  369: * @def _DBUS_MAX_SUN_PATH_LENGTH
        -:  370: *
        -:  371: * Maximum length of the path to a UNIX domain socket,
        -:  372: * sockaddr_un::sun_path member. POSIX requires that all systems
        -:  373: * support at least 100 bytes here, including the nul termination.
        -:  374: * We use 99 for the max value to allow for the nul.
        -:  375: *
        -:  376: * We could probably also do sizeof (addr.sun_path)
        -:  377: * but this way we are the same on all platforms
        -:  378: * which is probably a good idea.
        -:  379: */
        -:  380:
        -:  381:/**
        -:  382: * Creates a socket and connects it to the UNIX domain socket at the
        -:  383: * given path.  The connection fd is returned, and is set up as
        -:  384: * nonblocking.
        -:  385: * 
        -:  386: * Uses abstract sockets instead of filesystem-linked sockets if
        -:  387: * requested (it's possible only on Linux; see "man 7 unix" on Linux).
        -:  388: * On non-Linux abstract socket usage always fails.
        -:  389: *
        -:  390: * @param path the path to UNIX domain socket
        -:  391: * @param abstract #TRUE to use abstract namespace
        -:  392: * @param error return location for error code
        -:  393: * @returns connection file descriptor or -1 on error
        -:  394: */
        -:  395:int
        -:  396:_dbus_connect_unix_socket (const char     *path,
        -:  397:                           dbus_bool_t     abstract,
        -:  398:                           DBusError      *error)
function _dbus_connect_unix_socket called 929 returned 100% blocks executed 39%
      929:  399:{
        -:  400:  int fd;
        -:  401:  size_t path_len;
        -:  402:  struct sockaddr_un addr;  
        -:  403:
      929:  404:  _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%
        -:  405:
      929:  406:  _dbus_verbose ("connecting to unix socket %s abstract=%d\n",
call    0 returned 100%
        -:  407:                 path, abstract);
        -:  408:  
      929:  409:  fd = socket (PF_UNIX, SOCK_STREAM, 0);
call    0 returned 100%
        -:  410:  
      929:  411:  if (fd < 0)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  412:    {
    #####:  413:      dbus_set_error (error,
call    0 never executed
call    1 never executed
call    2 never executed
call    3 never executed
call    4 never executed
        -:  414:                      _dbus_error_from_errno (errno),
        -:  415:                      "Failed to create socket: %s",
        -:  416:                      _dbus_strerror (errno)); 
        -:  417:      
    #####:  418:      return -1;
        -:  419:    }
        -:  420:
      929:  421:  _DBUS_ZERO (addr);
call    0 returned 100%
      929:  422:  addr.sun_family = AF_UNIX;
      929:  423:  path_len = strlen (path);
call    0 returned 100%
        -:  424:
      929:  425:  if (abstract)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        -:  426:    {
        -:  427:#ifdef HAVE_ABSTRACT_SOCKETS
      929:  428:      addr.sun_path[0] = '\0'; /* this is what says "use abstract" */
      929:  429:      path_len++; /* Account for the extra nul byte added to the start of sun_path */
        -:  430:
      929:  431:      if (path_len > _DBUS_MAX_SUN_PATH_LENGTH)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  432:        {
    #####:  433:          dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS,
call    0 never executed
        -:  434:                      "Abstract socket name too long\n");
    #####:  435:          close (fd);
call    0 never executed
    #####:  436:          return -1;
        -:  437:	}
        -:  438:	
      929:  439:      strncpy (&addr.sun_path[1], path, path_len);
call    0 returned 100%
        -:  440:      /* _dbus_verbose_bytes (addr.sun_path, sizeof (addr.sun_path)); */
        -:  441:#else /* HAVE_ABSTRACT_SOCKETS */
        -:  442:      dbus_set_error (error, DBUS_ERROR_NOT_SUPPORTED,
        -:  443:                      "Operating system does not support abstract socket namespace\n");
        -:  444:      close (fd);
        -:  445:      return -1;
        -:  446:#endif /* ! HAVE_ABSTRACT_SOCKETS */
        -:  447:    }
        -:  448:  else
        -:  449:    {
    #####:  450:      if (path_len > _DBUS_MAX_SUN_PATH_LENGTH)
branch  0 never executed
branch  1 never executed
        -:  451:        {
    #####:  452:          dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS,
call    0 never executed
        -:  453:                      "Socket name too long\n");
    #####:  454:          close (fd);
call    0 never executed
    #####:  455:          return -1;
        -:  456:	}
        -:  457:
    #####:  458:      strncpy (addr.sun_path, path, path_len);
call    0 never executed
        -:  459:    }
        -:  460:  
      929:  461:  if (connect (fd, (struct sockaddr*) &addr, _DBUS_STRUCT_OFFSET (struct sockaddr_un, sun_path) + path_len) < 0)
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  462:    {      
    #####:  463:      dbus_set_error (error,
call    0 never executed
call    1 never executed
call    2 never executed
call    3 never executed
call    4 never executed
        -:  464:                      _dbus_error_from_errno (errno),
        -:  465:                      "Failed to connect to socket %s: %s",
        -:  466:                      path, _dbus_strerror (errno));
        -:  467:
    #####:  468:      close (fd);
call    0 never executed
    #####:  469:      fd = -1;
        -:  470:      
    #####:  471:      return -1;
        -:  472:    }
        -:  473:
      929:  474:  if (!_dbus_set_fd_nonblocking (fd, error))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  475:    {
    #####:  476:      _DBUS_ASSERT_ERROR_IS_SET (error);
branch  0 never executed
branch  1 never executed
call    2 never executed
branch  3 never executed
branch  4 never executed
call    5 never executed
        -:  477:      
    #####:  478:      close (fd);
call    0 never executed
    #####:  479:      fd = -1;
        -:  480:
    #####:  481:      return -1;
        -:  482:    }
        -:  483:
      929:  484:  return fd;
        -:  485:}
        -:  486:
        -:  487:/**
        -:  488: * Creates a socket and binds it to the given path,
        -:  489: * then listens on the socket. The socket is
        -:  490: * set to be nonblocking.
        -:  491: *
        -:  492: * Uses abstract sockets instead of filesystem-linked
        -:  493: * sockets if requested (it's possible only on Linux;
        -:  494: * see "man 7 unix" on Linux).
        -:  495: * On non-Linux abstract socket usage always fails.
        -:  496: *
        -:  497: * @param path the socket name
        -:  498: * @param abstract #TRUE to use abstract namespace
        -:  499: * @param error return location for errors
        -:  500: * @returns the listening file descriptor or -1 on error
        -:  501: */
        -:  502:int
        -:  503:_dbus_listen_unix_socket (const char     *path,
        -:  504:                          dbus_bool_t     abstract,
        -:  505:                          DBusError      *error)
function _dbus_listen_unix_socket called 5 returned 100% blocks executed 42%
        5:  506:{
        -:  507:  int listen_fd;
        -:  508:  struct sockaddr_un addr;
        -:  509:  size_t path_len;
        -:  510:
        5:  511:  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
branch  0 taken 60% (fallthrough)
branch  1 taken 40%
call    2 returned 100%
branch  3 taken 100% (fallthrough)
branch  4 taken 0%
call    5 returned 100%
        -:  512:
        5:  513:  _dbus_verbose ("listening on unix socket %s abstract=%d\n",
call    0 returned 100%
        -:  514:                 path, abstract);
        -:  515:  
        5:  516:  listen_fd = socket (PF_UNIX, SOCK_STREAM, 0);
call    0 returned 100%
        -:  517:  
        5:  518:  if (listen_fd < 0)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  519:    {
    #####:  520:      dbus_set_error (error, _dbus_error_from_errno (errno),
call    0 never executed
call    1 never executed
call    2 never executed
call    3 never executed
call    4 never executed
        -:  521:                      "Failed to create socket \"%s\": %s",
        -:  522:                      path, _dbus_strerror (errno));
    #####:  523:      return -1;
        -:  524:    }
        -:  525:
        5:  526:  _DBUS_ZERO (addr);
call    0 returned 100%
        5:  527:  addr.sun_family = AF_UNIX;
        5:  528:  path_len = strlen (path);
call    0 returned 100%
        -:  529:  
        5:  530:  if (abstract)
branch  0 taken 60% (fallthrough)
branch  1 taken 40%
        -:  531:    {
        -:  532:#ifdef HAVE_ABSTRACT_SOCKETS
        -:  533:      /* remember that abstract names aren't nul-terminated so we rely
        -:  534:       * on sun_path being filled in with zeroes above.
        -:  535:       */
        3:  536:      addr.sun_path[0] = '\0'; /* this is what says "use abstract" */
        3:  537:      path_len++; /* Account for the extra nul byte added to the start of sun_path */
        -:  538:
        3:  539:      if (path_len > _DBUS_MAX_SUN_PATH_LENGTH)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  540:        {
    #####:  541:          dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS,
call    0 never executed
        -:  542:                      "Abstract socket name too long\n");
    #####:  543:          close (listen_fd);
call    0 never executed
    #####:  544:          return -1;
        -:  545:	}
        -:  546:      
        3:  547:      strncpy (&addr.sun_path[1], path, path_len);
call    0 returned 100%
        -:  548:      /* _dbus_verbose_bytes (addr.sun_path, sizeof (addr.sun_path)); */
        -:  549:#else /* HAVE_ABSTRACT_SOCKETS */
        -:  550:      dbus_set_error (error, DBUS_ERROR_NOT_SUPPORTED,
        -:  551:                      "Operating system does not support abstract socket namespace\n");
        -:  552:      close (listen_fd);
        -:  553:      return -1;
        -:  554:#endif /* ! HAVE_ABSTRACT_SOCKETS */
        -:  555:    }
        -:  556:  else
        -:  557:    {
        -:  558:      /* FIXME discussed security implications of this with Nalin,
        -:  559:       * and we couldn't think of where it would kick our ass, but
        -:  560:       * it still seems a bit sucky. It also has non-security suckage;
        -:  561:       * really we'd prefer to exit if the socket is already in use.
        -:  562:       * But there doesn't seem to be a good way to do this.
        -:  563:       *
        -:  564:       * Just to be extra careful, I threw in the stat() - clearly
        -:  565:       * the stat() can't *fix* any security issue, but it at least
        -:  566:       * avoids inadvertent/accidental data loss.
        -:  567:       */
        -:  568:      {
        -:  569:        struct stat sb;
        -:  570:
        2:  571:        if (stat (path, &sb) == 0 &&
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
branch  3 never executed
branch  4 never executed
        -:  572:            S_ISSOCK (sb.st_mode))
    #####:  573:          unlink (path);
call    0 never executed
        -:  574:      }
        -:  575:
        2:  576:      if (path_len > _DBUS_MAX_SUN_PATH_LENGTH)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  577:        {
    #####:  578:          dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS,
call    0 never executed
        -:  579:                      "Abstract socket name too long\n");
    #####:  580:          close (listen_fd);
call    0 never executed
    #####:  581:          return -1;
        -:  582:	}
        -:  583:	
        2:  584:      strncpy (addr.sun_path, path, path_len);
call    0 returned 100%
        -:  585:    }
        -:  586:  
        5:  587:  if (bind (listen_fd, (struct sockaddr*) &addr, _DBUS_STRUCT_OFFSET (struct sockaddr_un, sun_path) + path_len) < 0)
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  588:    {
    #####:  589:      dbus_set_error (error, _dbus_error_from_errno (errno),
call    0 never executed
call    1 never executed
call    2 never executed
call    3 never executed
call    4 never executed
        -:  590:                      "Failed to bind socket \"%s\": %s",
        -:  591:                      path, _dbus_strerror (errno));
    #####:  592:      close (listen_fd);
call    0 never executed
    #####:  593:      return -1;
        -:  594:    }
        -:  595:
        5:  596:  if (listen (listen_fd, 30 /* backlog */) < 0)
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  597:    {
    #####:  598:      dbus_set_error (error, _dbus_error_from_errno (errno),
call    0 never executed
call    1 never executed
call    2 never executed
call    3 never executed
call    4 never executed
        -:  599:                      "Failed to listen on socket \"%s\": %s",
        -:  600:                      path, _dbus_strerror (errno));
    #####:  601:      close (listen_fd);
call    0 never executed
    #####:  602:      return -1;
        -:  603:    }
        -:  604:
        5:  605:  if (!_dbus_set_fd_nonblocking (listen_fd, error))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  606:    {
    #####:  607:      _DBUS_ASSERT_ERROR_IS_SET (error);
branch  0 never executed
branch  1 never executed
call    2 never executed
branch  3 never executed
branch  4 never executed
call    5 never executed
    #####:  608:      close (listen_fd);
call    0 never executed
    #####:  609:      return -1;
        -:  610:    }
        -:  611:  
        -:  612:  /* Try opening up the permissions, but if we can't, just go ahead
        -:  613:   * and continue, maybe it will be good enough.
        -:  614:   */
        5:  615:  if (!abstract && chmod (path, 0777) < 0)
branch  0 taken 40% (fallthrough)
branch  1 taken 60%
call    2 returned 100%
branch  3 taken 0% (fallthrough)
branch  4 taken 100%
    #####:  616:    _dbus_warn ("Could not set mode 0777 on socket %s\n",
call    0 never executed
        -:  617:                path);
        -:  618:  
        5:  619:  return listen_fd;
        -:  620:}
        -:  621:
        -:  622:/**
        -:  623: * Creates a socket and connects to a socket at the given host 
        -:  624: * and port. The connection fd is returned, and is set up as
        -:  625: * nonblocking.
        -:  626: *
        -:  627: * @param host the host name to connect to
        -:  628: * @param port the prot to connect to
        -:  629: * @param error return location for error code
        -:  630: * @returns connection file descriptor or -1 on error
        -:  631: */
        -:  632:int
        -:  633:_dbus_connect_tcp_socket (const char     *host,
        -:  634:                          dbus_uint32_t   port,
        -:  635:                          DBusError      *error)
function _dbus_connect_tcp_socket called 0 returned 0% blocks executed 0%
    #####:  636:{
        -:  637:  int fd;
        -:  638:  struct sockaddr_in addr;
        -:  639:  struct hostent *he;
        -:  640:  struct in_addr *haddr;
        -:  641:
    #####:  642:  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
branch  0 never executed
branch  1 never executed
call    2 never executed
branch  3 never executed
branch  4 never executed
call    5 never executed
        -:  643:  
    #####:  644:  fd = socket (AF_INET, SOCK_STREAM, 0);
call    0 never executed
        -:  645:  
    #####:  646:  if (fd < 0)
branch  0 never executed
branch  1 never executed
        -:  647:    {
    #####:  648:      dbus_set_error (error,
call    0 never executed
call    1 never executed
call    2 never executed
call    3 never executed
call    4 never executed
        -:  649:                      _dbus_error_from_errno (errno),
        -:  650:                      "Failed to create socket: %s",
        -:  651:                      _dbus_strerror (errno)); 
        -:  652:      
    #####:  653:      return -1;
        -:  654:    }
        -:  655:
    #####:  656:  if (host == NULL)
branch  0 never executed
branch  1 never executed
    #####:  657:    host = "localhost";
        -:  658:
    #####:  659:  he = gethostbyname (host);
call    0 never executed
    #####:  660:  if (he == NULL) 
branch  0 never executed
branch  1 never executed
        -:  661:    {
    #####:  662:      dbus_set_error (error,
call    0 never executed
call    1 never executed
call    2 never executed
        -:  663:                      _dbus_error_from_errno (errno),
        -:  664:                      "Failed to lookup hostname: %s",
        -:  665:                      host);
    #####:  666:      close (fd);
call    0 never executed
    #####:  667:      return -1;
        -:  668:    }
        -:  669:  
    #####:  670:  haddr = ((struct in_addr *) (he->h_addr_list)[0]);
        -:  671:
    #####:  672:  _DBUS_ZERO (addr);
call    0 never executed
    #####:  673:  memcpy (&addr.sin_addr, haddr, sizeof(struct in_addr));
call    0 never executed
    #####:  674:  addr.sin_family = AF_INET;
    #####:  675:  addr.sin_port = htons (port);
call    0 never executed
        -:  676:  
    #####:  677:  if (connect (fd, (struct sockaddr*) &addr, sizeof (addr)) < 0)
call    0 never executed
branch  1 never executed
branch  2 never executed
        -:  678:    {      
    #####:  679:      dbus_set_error (error,
call    0 never executed
call    1 never executed
call    2 never executed
call    3 never executed
call    4 never executed
        -:  680:                       _dbus_error_from_errno (errno),
        -:  681:                      "Failed to connect to socket %s: %s:%d",
        -:  682:                      host, _dbus_strerror (errno), port);
        -:  683:
    #####:  684:      close (fd);
call    0 never executed
    #####:  685:      fd = -1;
        -:  686:      
    #####:  687:      return -1;
        -:  688:    }
        -:  689:
    #####:  690:  if (!_dbus_set_fd_nonblocking (fd, error))
call    0 never executed
branch  1 never executed
branch  2 never executed
        -:  691:    {
    #####:  692:      close (fd);
call    0 never executed
    #####:  693:      fd = -1;
        -:  694:
    #####:  695:      return -1;
        -:  696:    }
        -:  697:
    #####:  698:  return fd;
        -:  699:}
        -:  700:
        -:  701:/**
        -:  702: * Creates a socket and binds it to the given path,
        -:  703: * then listens on the socket. The socket is
        -:  704: * set to be nonblocking. 
        -:  705: *
        -:  706: * @param host the host name to listen on
        -:  707: * @param port the prot to listen on
        -:  708: * @param error return location for errors
        -:  709: * @returns the listening file descriptor or -1 on error
        -:  710: */
        -:  711:int
        -:  712:_dbus_listen_tcp_socket (const char     *host,
        -:  713:                         dbus_uint32_t   port,
        -:  714:                         DBusError      *error)
function _dbus_listen_tcp_socket called 8 returned 100% blocks executed 38%
        8:  715:{
        -:  716:  int listen_fd;
        -:  717:  struct sockaddr_in addr;
        -:  718:  struct hostent *he;
        -:  719:  struct in_addr *haddr;
        -:  720:
        8:  721:  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
call    2 never executed
branch  3 never executed
branch  4 never executed
call    5 returned 100%
        -:  722:  
        8:  723:  listen_fd = socket (AF_INET, SOCK_STREAM, 0);
call    0 returned 100%
        -:  724:  
        8:  725:  if (listen_fd < 0)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  726:    {
    #####:  727:      dbus_set_error (error, _dbus_error_from_errno (errno),
call    0 never executed
call    1 never executed
call    2 never executed
call    3 never executed
call    4 never executed
        -:  728:                      "Failed to create socket \"%s:%d\": %s",
        -:  729:                      host, port, _dbus_strerror (errno));
    #####:  730:      return -1;
        -:  731:    }
        -:  732:
        8:  733:  he = gethostbyname (host);
call    0 returned 100%
        8:  734:  if (he == NULL) 
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  735:    {
    #####:  736:      dbus_set_error (error,
call    0 never executed
call    1 never executed
call    2 never executed
        -:  737:                      _dbus_error_from_errno (errno),
        -:  738:                      "Failed to lookup hostname: %s",
        -:  739:                      host);
    #####:  740:      close (listen_fd);
call    0 never executed
    #####:  741:      return -1;
        -:  742:    }
        -:  743:  
        8:  744:  haddr = ((struct in_addr *) (he->h_addr_list)[0]);
        -:  745:
        8:  746:  _DBUS_ZERO (addr);
call    0 returned 100%
        8:  747:  memcpy (&addr.sin_addr, haddr, sizeof (struct in_addr));
call    0 returned 100%
        8:  748:  addr.sin_family = AF_INET;
        8:  749:  addr.sin_port = htons (port);
call    0 returned 100%
        -:  750:
        8:  751:  if (bind (listen_fd, (struct sockaddr*) &addr, sizeof (struct sockaddr)))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  752:    {
    #####:  753:      dbus_set_error (error, _dbus_error_from_errno (errno),
call    0 never executed
call    1 never executed
call    2 never executed
call    3 never executed
call    4 never executed
        -:  754:                      "Failed to bind socket \"%s:%d\": %s",
        -:  755:                      host, port, _dbus_strerror (errno));
    #####:  756:      close (listen_fd);
call    0 never executed
    #####:  757:      return -1;
        -:  758:    }
        -:  759:
        8:  760:  if (listen (listen_fd, 30 /* backlog */) < 0)
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  761:    {
    #####:  762:      dbus_set_error (error, _dbus_error_from_errno (errno),  
call    0 never executed
call    1 never executed
call    2 never executed
call    3 never executed
call    4 never executed
        -:  763:                      "Failed to listen on socket \"%s:%d\": %s",
        -:  764:                      host, port, _dbus_strerror (errno));
    #####:  765:      close (listen_fd);
call    0 never executed
    #####:  766:      return -1;
        -:  767:    }
        -:  768:
        8:  769:  if (!_dbus_set_fd_nonblocking (listen_fd, error))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  770:    {
    #####:  771:      close (listen_fd);
call    0 never executed
    #####:  772:      return -1;
        -:  773:    }
        -:  774:  
        8:  775:  return listen_fd;
        -:  776:}
        -:  777:
        -:  778:static dbus_bool_t
        -:  779:write_credentials_byte (int             server_fd,
        -:  780:                        DBusError      *error)
function write_credentials_byte called 6292 returned 100% blocks executed 76%
     6292:  781:{
        -:  782:  int bytes_written;
     6292:  783:  char buf[1] = { '\0' };
        -:  784:#if defined(HAVE_CMSGCRED) && !defined(LOCAL_CREDS)
        -:  785:  struct {
        -:  786:	  struct cmsghdr hdr;
        -:  787:	  struct cmsgcred cred;
        -:  788:  } cmsg;
        -:  789:  struct iovec iov;
        -:  790:  struct msghdr msg;
        -:  791:#endif
        -:  792:
        -:  793:#if defined(HAVE_CMSGCRED) && !defined(LOCAL_CREDS)
        -:  794:  iov.iov_base = buf;
        -:  795:  iov.iov_len = 1;
        -:  796:
        -:  797:  memset (&msg, 0, sizeof (msg));
        -:  798:  msg.msg_iov = &iov;
        -:  799:  msg.msg_iovlen = 1;
        -:  800:
        -:  801:  msg.msg_control = &cmsg;
        -:  802:  msg.msg_controllen = sizeof (cmsg);
        -:  803:  memset (&cmsg, 0, sizeof (cmsg));
        -:  804:  cmsg.hdr.cmsg_len = sizeof (cmsg);
        -:  805:  cmsg.hdr.cmsg_level = SOL_SOCKET;
        -:  806:  cmsg.hdr.cmsg_type = SCM_CREDS;
        -:  807:#endif
        -:  808:
     6292:  809:  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
call    2 never executed
branch  3 never executed
branch  4 never executed
call    5 returned 100%
        -:  810:  
     6292:  811: again:
        -:  812:
        -:  813:#if defined(HAVE_CMSGCRED) && !defined(LOCAL_CREDS)
        -:  814:  bytes_written = sendmsg (server_fd, &msg, 0);
        -:  815:#else
     6292:  816:  bytes_written = write (server_fd, buf, 1);
call    0 returned 100%
        -:  817:#endif
        -:  818:
     6292:  819:  if (bytes_written < 0 && errno == EINTR)
branch  0 taken 2% (fallthrough)
branch  1 taken 98%
call    2 returned 100%
branch  3 taken 0% (fallthrough)
branch  4 taken 100%
    #####:  820:    goto again;
        -:  821:
     6292:  822:  if (bytes_written < 0)
branch  0 taken 2% (fallthrough)
branch  1 taken 98%
        -:  823:    {
      109:  824:      dbus_set_error (error, _dbus_error_from_errno (errno),
call    0 returned 100%
call    1 returned 100%
call    2 returned 100%
call    3 returned 100%
call    4 returned 100%
        -:  825:                      "Failed to write credentials byte: %s",
        -:  826:                     _dbus_strerror (errno));
      109:  827:      return FALSE;
        -:  828:    }
     6183:  829:  else if (bytes_written == 0)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  830:    {
    #####:  831:      dbus_set_error (error, DBUS_ERROR_IO_ERROR,
call    0 never executed
        -:  832:                      "wrote zero bytes writing credentials byte");
    #####:  833:      return FALSE;
        -:  834:    }
        -:  835:  else
        -:  836:    {
     6183:  837:      _dbus_assert (bytes_written == 1);
call    0 returned 100%
     6183:  838:      _dbus_verbose ("wrote credentials byte\n");
call    0 returned 100%
     6183:  839:      return TRUE;
        -:  840:    }
        -:  841:}
        -:  842:
        -:  843:/**
        -:  844: * Reads a single byte which must be nul (an error occurs otherwise),
        -:  845: * and reads unix credentials if available. Fills in pid/uid/gid with
        -:  846: * -1 if no credentials are available. Return value indicates whether
        -:  847: * a byte was read, not whether we got valid credentials. On some
        -:  848: * systems, such as Linux, reading/writing the byte isn't actually
        -:  849: * required, but we do it anyway just to avoid multiple codepaths.
        -:  850: * 
        -:  851: * Fails if no byte is available, so you must select() first.
        -:  852: *
        -:  853: * The point of the byte is that on some systems we have to
        -:  854: * use sendmsg()/recvmsg() to transmit credentials.
        -:  855: *
        -:  856: * @param client_fd the client file descriptor
        -:  857: * @param credentials struct to fill with credentials of client
        -:  858: * @param error location to store error code
        -:  859: * @returns #TRUE on success
        -:  860: */
        -:  861:dbus_bool_t
        -:  862:_dbus_read_credentials_unix_socket  (int              client_fd,
        -:  863:                                     DBusCredentials *credentials,
        -:  864:                                     DBusError       *error)
function _dbus_read_credentials_unix_socket called 7811 returned 100% blocks executed 54%
     7811:  865:{
        -:  866:  struct msghdr msg;
        -:  867:  struct iovec iov;
        -:  868:  char buf;
        -:  869:
        -:  870:#ifdef HAVE_CMSGCRED 
        -:  871:  struct {
        -:  872:	  struct cmsghdr hdr;
        -:  873:	  struct cmsgcred cred;
        -:  874:  } cmsg;
        -:  875:#endif
        -:  876:
     7811:  877:  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
call    2 never executed
branch  3 never executed
branch  4 never executed
call    5 returned 100%
        -:  878:  
        -:  879:  /* The POSIX spec certainly doesn't promise this, but
        -:  880:   * we need these assertions to fail as soon as we're wrong about
        -:  881:   * it so we can do the porting fixups
        -:  882:   */
     7811:  883:  _dbus_assert (sizeof (pid_t) <= sizeof (credentials->pid));
call    0 returned 100%
     7811:  884:  _dbus_assert (sizeof (uid_t) <= sizeof (credentials->uid));
call    0 returned 100%
     7811:  885:  _dbus_assert (sizeof (gid_t) <= sizeof (credentials->gid));
call    0 returned 100%
        -:  886:
     7811:  887:  _dbus_credentials_clear (credentials);
call    0 returned 100%
        -:  888:
        -:  889:#if defined(LOCAL_CREDS) && defined(HAVE_CMSGCRED)
        -:  890:  /* Set the socket to receive credentials on the next message */
        -:  891:  {
        -:  892:    int on = 1;
        -:  893:    if (setsockopt (client_fd, 0, LOCAL_CREDS, &on, sizeof (on)) < 0)
        -:  894:      {
        -:  895:	_dbus_verbose ("Unable to set LOCAL_CREDS socket option\n");
        -:  896:	return FALSE;
        -:  897:      }
        -:  898:  }
        -:  899:#endif
        -:  900:
     7811:  901:  iov.iov_base = &buf;
     7811:  902:  iov.iov_len = 1;
        -:  903:
     7811:  904:  memset (&msg, 0, sizeof (msg));
call    0 returned 100%
     7811:  905:  msg.msg_iov = &iov;
     7811:  906:  msg.msg_iovlen = 1;
        -:  907:
        -:  908:#ifdef HAVE_CMSGCRED
        -:  909:  memset (&cmsg, 0, sizeof (cmsg));
        -:  910:  msg.msg_control = &cmsg;
        -:  911:  msg.msg_controllen = sizeof (cmsg);
        -:  912:#endif
        -:  913:
     7811:  914: again:
     7811:  915:  if (recvmsg (client_fd, &msg, 0) < 0)
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  916:    {
    #####:  917:      if (errno == EINTR)
call    0 never executed
branch  1 never executed
branch  2 never executed
    #####:  918:	goto again;
        -:  919:
    #####:  920:      dbus_set_error (error, _dbus_error_from_errno (errno),
call    0 never executed
call    1 never executed
call    2 never executed
call    3 never executed
call    4 never executed
        -:  921:                      "Failed to read credentials byte: %s",
        -:  922:                      _dbus_strerror (errno));
    #####:  923:      return FALSE;
        -:  924:    }
        -:  925:
     7811:  926:  if (buf != '\0')
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  927:    {
    #####:  928:      dbus_set_error (error, DBUS_ERROR_FAILED,
call    0 never executed
        -:  929:                      "Credentials byte was not nul");
    #####:  930:      return FALSE;
        -:  931:    }
        -:  932:
        -:  933:#ifdef HAVE_CMSGCRED
        -:  934:  if (cmsg.hdr.cmsg_len < sizeof (cmsg) || cmsg.hdr.cmsg_type != SCM_CREDS)
        -:  935:    {
        -:  936:      dbus_set_error (error, DBUS_ERROR_FAILED,
        -:  937:                      "Message from recvmsg() was not SCM_CREDS");
        -:  938:      return FALSE;
        -:  939:    }
        -:  940:#endif
        -:  941:
     7811:  942:  _dbus_verbose ("read credentials byte\n");
call    0 returned 100%
        -:  943:
        -:  944:  {
        -:  945:#ifdef SO_PEERCRED
        -:  946:    struct ucred cr;   
     7811:  947:    int cr_len = sizeof (cr);
        -:  948:   
    15622:  949:    if (getsockopt (client_fd, SOL_SOCKET, SO_PEERCRED, &cr, &cr_len) == 0 &&
call    0 returned 100%
branch  1 taken 100% (fallthrough)
branch  2 taken 0%
branch  3 taken 100% (fallthrough)
branch  4 taken 0%
        -:  950:	cr_len == sizeof (cr))
        -:  951:      {
     7811:  952:	credentials->pid = cr.pid;
     7811:  953:	credentials->uid = cr.uid;
     7811:  954:	credentials->gid = cr.gid;
        -:  955:      }
        -:  956:    else
        -:  957:      {
    #####:  958:	_dbus_verbose ("Failed to getsockopt() credentials, returned len %d/%d: %s\n",
call    0 never executed
call    1 never executed
call    2 never executed
        -:  959:		       cr_len, (int) sizeof (cr), _dbus_strerror (errno));
        -:  960:      }
        -:  961:#elif defined(HAVE_CMSGCRED)
        -:  962:    credentials->pid = cmsg.cred.cmcred_pid;
        -:  963:    credentials->uid = cmsg.cred.cmcred_euid;
        -:  964:    credentials->gid = cmsg.cred.cmcred_groups[0];
        -:  965:#elif defined(HAVE_GETPEEREID)
        -:  966:    uid_t euid;
        -:  967:    gid_t egid;
        -:  968:    if (getpeereid (client_fd, &euid, &egid) == 0)
        -:  969:      {
        -:  970:        credentials->uid = euid;
        -:  971:        credentials->gid = egid;
        -:  972:      }
        -:  973:    else
        -:  974:      {
        -:  975:        _dbus_verbose ("Failed to getpeereid() credentials: %s\n", _dbus_strerror (errno));
        -:  976:      }
        -:  977:#elif defined(HAVE_GETPEERUCRED)
        -:  978:    ucred_t * ucred = NULL;
        -:  979:    if (getpeerucred (client_fd, &ucred) == 0)
        -:  980:      {
        -:  981:        credentials->pid = ucred_getpid (ucred);
        -:  982:        credentials->uid = ucred_geteuid (ucred);
        -:  983:        credentials->gid = ucred_getegid (ucred);
        -:  984:      }
        -:  985:    else
        -:  986:      {
        -:  987:        _dbus_verbose ("Failed to getpeerucred() credentials: %s\n", _dbus_strerror (errno));
        -:  988:      }
        -:  989:    if (ucred != NULL)
        -:  990:      ucred_free (ucred);
        -:  991:#else /* !SO_PEERCRED && !HAVE_CMSGCRED && !HAVE_GETPEEREID && !HAVE_GETPEERUCRED */
        -:  992:    _dbus_verbose ("Socket credentials not supported on this OS\n");
        -:  993:#endif
        -:  994:  }
        -:  995:
     7811:  996:  _dbus_verbose ("Credentials:"
call    0 returned 100%
        -:  997:                 "  pid "DBUS_PID_FORMAT
        -:  998:                 "  uid "DBUS_UID_FORMAT
        -:  999:                 "  gid "DBUS_GID_FORMAT"\n",
        -: 1000:		 credentials->pid,
        -: 1001:		 credentials->uid,
        -: 1002:		 credentials->gid);
        -: 1003:    
     7811: 1004:  return TRUE;
        -: 1005:}
        -: 1006:
        -: 1007:/**
        -: 1008: * Sends a single nul byte with our UNIX credentials as ancillary
        -: 1009: * data.  Returns #TRUE if the data was successfully written.  On
        -: 1010: * systems that don't support sending credentials, just writes a byte,
        -: 1011: * doesn't send any credentials.  On some systems, such as Linux,
        -: 1012: * reading/writing the byte isn't actually required, but we do it
        -: 1013: * anyway just to avoid multiple codepaths.
        -: 1014: *
        -: 1015: * Fails if no byte can be written, so you must select() first.
        -: 1016: *
        -: 1017: * The point of the byte is that on some systems we have to
        -: 1018: * use sendmsg()/recvmsg() to transmit credentials.
        -: 1019: *
        -: 1020: * @param server_fd file descriptor for connection to server
        -: 1021: * @param error return location for error code
        -: 1022: * @returns #TRUE if the byte was sent
        -: 1023: */
        -: 1024:dbus_bool_t
        -: 1025:_dbus_send_credentials_unix_socket  (int              server_fd,
        -: 1026:                                     DBusError       *error)
function _dbus_send_credentials_unix_socket called 6292 returned 100% blocks executed 73%
     6292: 1027:{
     6292: 1028:  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
call    2 never executed
branch  3 never executed
branch  4 never executed
call    5 returned 100%
        -: 1029:  
     6292: 1030:  if (write_credentials_byte (server_fd, error))
call    0 returned 100%
branch  1 taken 98% (fallthrough)
branch  2 taken 2%
     6183: 1031:    return TRUE;
        -: 1032:  else
      109: 1033:    return FALSE;
        -: 1034:}
        -: 1035:
        -: 1036:/**
        -: 1037: * Accepts a connection on a listening socket.
        -: 1038: * Handles EINTR for you.
        -: 1039: *
        -: 1040: * @param listen_fd the listen file descriptor
        -: 1041: * @returns the connection fd of the client, or -1 on error
        -: 1042: */
        -: 1043:int
        -: 1044:_dbus_accept  (int listen_fd)
function _dbus_accept called 2467 returned 100% blocks executed 57%
     2467: 1045:{
        -: 1046:  int client_fd;
        -: 1047:  struct sockaddr addr;
        -: 1048:  socklen_t addrlen;
        -: 1049:
     2467: 1050:  addrlen = sizeof (addr);
        -: 1051:  
     2467: 1052: retry:
     2467: 1053:  client_fd = accept (listen_fd, &addr, &addrlen);
call    0 returned 100%
        -: 1054:  
     2467: 1055:  if (client_fd < 0)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -: 1056:    {
    #####: 1057:      if (errno == EINTR)
call    0 never executed
branch  1 never executed
branch  2 never executed
    #####: 1058:        goto retry;
        -: 1059:    }
        -: 1060:  
     2467: 1061:  return client_fd;
        -: 1062:}
        -: 1063:
        -: 1064:/** @} */
        -: 1065:
        -: 1066:/**
        -: 1067: * @addtogroup DBusString
        -: 1068: *
        -: 1069: * @{
        -: 1070: */
        -: 1071:/**
        -: 1072: * Appends an integer to a DBusString.
        -: 1073: * 
        -: 1074: * @param str the string
        -: 1075: * @param value the integer value
        -: 1076: * @returns #FALSE if not enough memory or other failure.
        -: 1077: */
        -: 1078:dbus_bool_t
        -: 1079:_dbus_string_append_int (DBusString *str,
        -: 1080:                         long        value)
function _dbus_string_append_int called 21992 returned 100% blocks executed 100%
    21992: 1081:{
        -: 1082:  /* this calculation is from comp.lang.c faq */
        -: 1083:#define MAX_LONG_LEN ((sizeof (long) * 8 + 2) / 3 + 1)  /* +1 for '-' */
        -: 1084:  int orig_len;
        -: 1085:  int i;
        -: 1086:  char *buf;
        -: 1087:  
    21992: 1088:  orig_len = _dbus_string_get_length (str);
call    0 returned 100%
        -: 1089:
    21992: 1090:  if (!_dbus_string_lengthen (str, MAX_LONG_LEN))
call    0 returned 100%
branch  1 taken 1% (fallthrough)
branch  2 taken 99%
       16: 1091:    return FALSE;
        -: 1092:
    21976: 1093:  buf = _dbus_string_get_data_len (str, orig_len, MAX_LONG_LEN);
call    0 returned 100%
        -: 1094:
    21976: 1095:  snprintf (buf, MAX_LONG_LEN, "%ld", value);
call    0 returned 100%
        -: 1096:
    21976: 1097:  i = 0;
   169126: 1098:  while (*buf)
branch  0 taken 85%
branch  1 taken 15% (fallthrough)
        -: 1099:    {
   125174: 1100:      ++buf;
   125174: 1101:      ++i;
        -: 1102:    }
        -: 1103:  
    21976: 1104:  _dbus_string_shorten (str, MAX_LONG_LEN - i);
call    0 returned 100%
        -: 1105:  
    21976: 1106:  return TRUE;
        -: 1107:}
        -: 1108:
        -: 1109:/**
        -: 1110: * Appends an unsigned integer to a DBusString.
        -: 1111: * 
        -: 1112: * @param str the string
        -: 1113: * @param value the integer value
        -: 1114: * @returns #FALSE if not enough memory or other failure.
        -: 1115: */
        -: 1116:dbus_bool_t
        -: 1117:_dbus_string_append_uint (DBusString    *str,
        -: 1118:                          unsigned long  value)
function _dbus_string_append_uint called 6726 returned 100% blocks executed 100%
     6726: 1119:{
        -: 1120:  /* this is wrong, but definitely on the high side. */
        -: 1121:#define MAX_ULONG_LEN (MAX_LONG_LEN * 2)
        -: 1122:  int orig_len;
        -: 1123:  int i;
        -: 1124:  char *buf;
        -: 1125:  
     6726: 1126:  orig_len = _dbus_string_get_length (str);
call    0 returned 100%
        -: 1127:
     6726: 1128:  if (!_dbus_string_lengthen (str, MAX_ULONG_LEN))
call    0 returned 100%
branch  1 taken 1% (fallthrough)
branch  2 taken 99%
        6: 1129:    return FALSE;
        -: 1130:
     6720: 1131:  buf = _dbus_string_get_data_len (str, orig_len, MAX_ULONG_LEN);
call    0 returned 100%
        -: 1132:
     6720: 1133:  snprintf (buf, MAX_ULONG_LEN, "%lu", value);
call    0 returned 100%
        -: 1134:
     6720: 1135:  i = 0;
    33604: 1136:  while (*buf)
branch  0 taken 75%
branch  1 taken 25% (fallthrough)
        -: 1137:    {
    20164: 1138:      ++buf;
    20164: 1139:      ++i;
        -: 1140:    }
        -: 1141:  
     6720: 1142:  _dbus_string_shorten (str, MAX_ULONG_LEN - i);
call    0 returned 100%
        -: 1143:  
     6720: 1144:  return TRUE;
        -: 1145:}
        -: 1146:
        -: 1147:#ifdef DBUS_BUILD_TESTS
        -: 1148:/**
        -: 1149: * Appends a double to a DBusString.
        -: 1150: * 
        -: 1151: * @param str the string
        -: 1152: * @param value the floating point value
        -: 1153: * @returns #FALSE if not enough memory or other failure.
        -: 1154: */
        -: 1155:dbus_bool_t
        -: 1156:_dbus_string_append_double (DBusString *str,
        -: 1157:                            double      value)
function _dbus_string_append_double called 1 returned 100% blocks executed 92%
        1: 1158:{
        -: 1159:#define MAX_DOUBLE_LEN 64 /* this is completely made up :-/ */
        -: 1160:  int orig_len;
        -: 1161:  char *buf;
        -: 1162:  int i;
        -: 1163:  
        1: 1164:  orig_len = _dbus_string_get_length (str);
call    0 returned 100%
        -: 1165:
        1: 1166:  if (!_dbus_string_lengthen (str, MAX_DOUBLE_LEN))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####: 1167:    return FALSE;
        -: 1168:
        1: 1169:  buf = _dbus_string_get_data_len (str, orig_len, MAX_DOUBLE_LEN);
call    0 returned 100%
        -: 1170:
        1: 1171:  snprintf (buf, MAX_LONG_LEN, "%g", value);
call    0 returned 100%
        -: 1172:
        1: 1173:  i = 0;
        6: 1174:  while (*buf)
branch  0 taken 80%
branch  1 taken 20% (fallthrough)
        -: 1175:    {
        4: 1176:      ++buf;
        4: 1177:      ++i;
        -: 1178:    }
        -: 1179:  
        1: 1180:  _dbus_string_shorten (str, MAX_DOUBLE_LEN - i);
call    0 returned 100%
        -: 1181:  
        1: 1182:  return TRUE;
        -: 1183:}
        -: 1184:#endif /* DBUS_BUILD_TESTS */
        -: 1185:
        -: 1186:/**
        -: 1187: * Parses an integer contained in a DBusString. Either return parameter
        -: 1188: * may be #NULL if you aren't interested in it. The integer is parsed
        -: 1189: * and stored in value_return. Return parameters are not initialized
        -: 1190: * if the function returns #FALSE.
        -: 1191: *
        -: 1192: * @param str the string
        -: 1193: * @param start the byte index of the start of the integer
        -: 1194: * @param value_return return location of the integer value or #NULL
        -: 1195: * @param end_return return location of the end of the integer, or #NULL
        -: 1196: * @returns #TRUE on success
        -: 1197: */
        -: 1198:dbus_bool_t
        -: 1199:_dbus_string_parse_int (const DBusString *str,
        -: 1200:                        int               start,
        -: 1201:                        long             *value_return,
        -: 1202:                        int              *end_return)
function _dbus_string_parse_int called 158506 returned 100% blocks executed 100%
   158506: 1203:{
        -: 1204:  long v;
        -: 1205:  const char *p;
        -: 1206:  char *end;
        -: 1207:
   158506: 1208:  p = _dbus_string_get_const_data_len (str, start,
call    0 returned 100%
call    1 returned 100%
        -: 1209:                                       _dbus_string_get_length (str) - start);
        -: 1210:
   158506: 1211:  end = NULL;
   158506: 1212:  errno = 0;
call    0 returned 100%
   158506: 1213:  v = strtol (p, &end, 0);
call    0 returned 100%
   158506: 1214:  if (end == NULL || end == p || errno != 0)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 95% (fallthrough)
branch  3 taken 5%
call    4 returned 100%
branch  5 taken 0% (fallthrough)
branch  6 taken 100%
     7793: 1215:    return FALSE;
        -: 1216:
   150713: 1217:  if (value_return)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
   150713: 1218:    *value_return = v;
   150713: 1219:  if (end_return)
branch  0 taken 97% (fallthrough)
branch  1 taken 3%
   146518: 1220:    *end_return = start + (end - p);
        -: 1221:
   150713: 1222:  return TRUE;
        -: 1223:}
        -: 1224:
        -: 1225:/**
        -: 1226:* Checks to make sure the given directory is 
        -: 1227:* private to the user 
        -: 1228:*
        -: 1229:* @param dir the name of the directory
        -: 1230:* @param error error return
        -: 1231:* @returns #FALSE on failure
        -: 1232:**/
        -: 1233:dbus_bool_t
        -: 1234:_dbus_check_dir_is_private_to_user (DBusString *dir, DBusError *error)
function _dbus_check_dir_is_private_to_user called 7387 returned 100% blocks executed 87%
     7387: 1235:{
        -: 1236:  const char *directory;
        -: 1237:  struct stat sb;
        -: 1238:	
     7387: 1239:  _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%
        -: 1240:    
     7387: 1241:  directory = _dbus_string_get_const_data (dir);
call    0 returned 100%
        -: 1242:	
     7387: 1243:  if (stat (directory, &sb) < 0)
call    0 returned 100%
branch  1 taken 1% (fallthrough)
branch  2 taken 99%
        -: 1244:    {
        1: 1245:      dbus_set_error (error, _dbus_error_from_errno (errno),
call    0 returned 100%
call    1 returned 100%
call    2 returned 100%
call    3 returned 100%
call    4 returned 100%
        -: 1246:                      "%s", _dbus_strerror (errno));
        -: 1247:   
        1: 1248:      return FALSE;
        -: 1249:    }
        -: 1250:    
     7386: 1251:  if ((S_IROTH & sb.st_mode) || (S_IWOTH & sb.st_mode) ||
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
branch  4 taken 100% (fallthrough)
branch  5 taken 0%
branch  6 taken 0% (fallthrough)
branch  7 taken 100%
        -: 1252:      (S_IRGRP & sb.st_mode) || (S_IWGRP & sb.st_mode))
        -: 1253:    {
    #####: 1254:      dbus_set_error (error, DBUS_ERROR_FAILED,
call    0 never executed
        -: 1255:                     "%s directory is not private to the user", directory);
    #####: 1256:      return FALSE;
        -: 1257:    }
        -: 1258:    
     7386: 1259:  return TRUE;
        -: 1260:}
        -: 1261:
        -: 1262:/**
        -: 1263: * Parses an unsigned integer contained in a DBusString. Either return
        -: 1264: * parameter may be #NULL if you aren't interested in it. The integer
        -: 1265: * is parsed and stored in value_return. Return parameters are not
        -: 1266: * initialized if the function returns #FALSE.
        -: 1267: *
        -: 1268: * @param str the string
        -: 1269: * @param start the byte index of the start of the integer
        -: 1270: * @param value_return return location of the integer value or #NULL
        -: 1271: * @param end_return return location of the end of the integer, or #NULL
        -: 1272: * @returns #TRUE on success
        -: 1273: */
        -: 1274:dbus_bool_t
        -: 1275:_dbus_string_parse_uint (const DBusString *str,
        -: 1276:                         int               start,
        -: 1277:                         unsigned long    *value_return,
        -: 1278:                         int              *end_return)
function _dbus_string_parse_uint called 25657 returned 100% blocks executed 100%
    25657: 1279:{
        -: 1280:  unsigned long v;
        -: 1281:  const char *p;
        -: 1282:  char *end;
        -: 1283:
    25657: 1284:  p = _dbus_string_get_const_data_len (str, start,
call    0 returned 100%
call    1 returned 100%
        -: 1285:                                       _dbus_string_get_length (str) - start);
        -: 1286:
    25657: 1287:  end = NULL;
    25657: 1288:  errno = 0;
call    0 returned 100%
    25657: 1289:  v = strtoul (p, &end, 0);
call    0 returned 100%
    25657: 1290:  if (end == NULL || end == p || errno != 0)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 87% (fallthrough)
branch  3 taken 13%
call    4 returned 100%
branch  5 taken 0% (fallthrough)
branch  6 taken 100%
     3248: 1291:    return FALSE;
        -: 1292:
    22409: 1293:  if (value_return)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
    22409: 1294:    *value_return = v;
    22409: 1295:  if (end_return)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
    22409: 1296:    *end_return = start + (end - p);
        -: 1297:
    22409: 1298:  return TRUE;
        -: 1299:}
        -: 1300:
        -: 1301:#ifdef DBUS_BUILD_TESTS
        -: 1302:static dbus_bool_t
        -: 1303:ascii_isspace (char c)
function ascii_isspace called 0 returned 0% blocks executed 0%
    #####: 1304:{
    #####: 1305:  return (c == ' ' ||
branch  0 never executed
branch  1 never executed
branch  2 never executed
branch  3 never executed
branch  4 never executed
branch  5 never executed
branch  6 never executed
branch  7 never executed
branch  8 never executed
branch  9 never executed
branch 10 never executed
branch 11 never executed
        -: 1306:	  c == '\f' ||
        -: 1307:	  c == '\n' ||
        -: 1308:	  c == '\r' ||
        -: 1309:	  c == '\t' ||
        -: 1310:	  c == '\v');
        -: 1311:}
        -: 1312:#endif /* DBUS_BUILD_TESTS */
        -: 1313:
        -: 1314:#ifdef DBUS_BUILD_TESTS
        -: 1315:static dbus_bool_t
        -: 1316:ascii_isdigit (char c)
function ascii_isdigit called 0 returned 0% blocks executed 0%
    #####: 1317:{
    #####: 1318:  return c >= '0' && c <= '9';
branch  0 never executed
branch  1 never executed
branch  2 never executed
branch  3 never executed
        -: 1319:}
        -: 1320:#endif /* DBUS_BUILD_TESTS */
        -: 1321:
        -: 1322:#ifdef DBUS_BUILD_TESTS
        -: 1323:static dbus_bool_t
        -: 1324:ascii_isxdigit (char c)
function ascii_isxdigit called 0 returned 0% blocks executed 0%
    #####: 1325:{
    #####: 1326:  return (ascii_isdigit (c) ||
call    0 never executed
branch  1 never executed
branch  2 never executed
branch  3 never executed
branch  4 never executed
branch  5 never executed
branch  6 never executed
branch  7 never executed
branch  8 never executed
branch  9 never executed
branch 10 never executed
        -: 1327:	  (c >= 'a' && c <= 'f') ||
        -: 1328:	  (c >= 'A' && c <= 'F'));
        -: 1329:}
        -: 1330:#endif /* DBUS_BUILD_TESTS */
        -: 1331:
        -: 1332:#ifdef DBUS_BUILD_TESTS
        -: 1333:/* Calls strtod in a locale-independent fashion, by looking at
        -: 1334: * the locale data and patching the decimal comma to a point.
        -: 1335: *
        -: 1336: * Relicensed from glib.
        -: 1337: */
        -: 1338:static double
        -: 1339:ascii_strtod (const char *nptr,
        -: 1340:	      char      **endptr)
function ascii_strtod called 3 returned 100% blocks executed 16%
        3: 1341:{
        -: 1342:  char *fail_pos;
        -: 1343:  double val;
        -: 1344:  struct lconv *locale_data;
        -: 1345:  const char *decimal_point;
        -: 1346:  int decimal_point_len;
        -: 1347:  const char *p, *decimal_point_pos;
        3: 1348:  const char *end = NULL; /* Silence gcc */
        -: 1349:
        3: 1350:  fail_pos = NULL;
        -: 1351:
        3: 1352:  locale_data = localeconv ();
call    0 returned 100%
        3: 1353:  decimal_point = locale_data->decimal_point;
        3: 1354:  decimal_point_len = strlen (decimal_point);
call    0 returned 100%
        -: 1355:
        3: 1356:  _dbus_assert (decimal_point_len != 0);
call    0 returned 100%
        -: 1357:  
        3: 1358:  decimal_point_pos = NULL;
        3: 1359:  if (decimal_point[0] != '.' ||
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 0% (fallthrough)
branch  3 taken 100%
        -: 1360:      decimal_point[1] != 0)
        -: 1361:    {
    #####: 1362:      p = nptr;
        -: 1363:      /* Skip leading space */
    #####: 1364:      while (ascii_isspace (*p))
call    0 never executed
branch  1 never executed
branch  2 never executed
    #####: 1365:	p++;
        -: 1366:      
        -: 1367:      /* Skip leading optional sign */
    #####: 1368:      if (*p == '+' || *p == '-')
branch  0 never executed
branch  1 never executed
branch  2 never executed
branch  3 never executed
    #####: 1369:	p++;
        -: 1370:      
    #####: 1371:      if (p[0] == '0' &&
branch  0 never executed
branch  1 never executed
branch  2 never executed
branch  3 never executed
branch  4 never executed
branch  5 never executed
        -: 1372:	  (p[1] == 'x' || p[1] == 'X'))
        -: 1373:	{
    #####: 1374:	  p += 2;
        -: 1375:	  /* HEX - find the (optional) decimal point */
        -: 1376:	  
    #####: 1377:	  while (ascii_isxdigit (*p))
call    0 never executed
branch  1 never executed
branch  2 never executed
    #####: 1378:	    p++;
        -: 1379:	  
    #####: 1380:	  if (*p == '.')
branch  0 never executed
branch  1 never executed
        -: 1381:	    {
    #####: 1382:	      decimal_point_pos = p++;
        -: 1383:	      
    #####: 1384:	      while (ascii_isxdigit (*p))
call    0 never executed
branch  1 never executed
branch  2 never executed
    #####: 1385:		p++;
        -: 1386:	      
    #####: 1387:	      if (*p == 'p' || *p == 'P')
branch  0 never executed
branch  1 never executed
branch  2 never executed
branch  3 never executed
    #####: 1388:		p++;
    #####: 1389:	      if (*p == '+' || *p == '-')
branch  0 never executed
branch  1 never executed
branch  2 never executed
branch  3 never executed
    #####: 1390:		p++;
    #####: 1391:	      while (ascii_isdigit (*p))
call    0 never executed
branch  1 never executed
branch  2 never executed
    #####: 1392:		p++;
    #####: 1393:	      end = p;
        -: 1394:	    }
        -: 1395:	}
        -: 1396:      else
        -: 1397:	{
    #####: 1398:	  while (ascii_isdigit (*p))
call    0 never executed
branch  1 never executed
branch  2 never executed
    #####: 1399:	    p++;
        -: 1400:	  
    #####: 1401:	  if (*p == '.')
branch  0 never executed
branch  1 never executed
        -: 1402:	    {
    #####: 1403:	      decimal_point_pos = p++;
        -: 1404:	      
    #####: 1405:	      while (ascii_isdigit (*p))
call    0 never executed
branch  1 never executed
branch  2 never executed
    #####: 1406:		p++;
        -: 1407:	      
    #####: 1408:	      if (*p == 'e' || *p == 'E')
branch  0 never executed
branch  1 never executed
branch  2 never executed
branch  3 never executed
    #####: 1409:		p++;
    #####: 1410:	      if (*p == '+' || *p == '-')
branch  0 never executed
branch  1 never executed
branch  2 never executed
branch  3 never executed
    #####: 1411:		p++;
    #####: 1412:	      while (ascii_isdigit (*p))
call    0 never executed
branch  1 never executed
branch  2 never executed
    #####: 1413:		p++;
    #####: 1414:	      end = p;
        -: 1415:	    }
        -: 1416:	}
        -: 1417:      /* For the other cases, we need not convert the decimal point */
        -: 1418:    }
        -: 1419:
        -: 1420:  /* Set errno to zero, so that we can distinguish zero results
        -: 1421:     and underflows */
        3: 1422:  errno = 0;
call    0 returned 100%
        -: 1423:  
        3: 1424:  if (decimal_point_pos)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -: 1425:    {
        -: 1426:      char *copy, *c;
        -: 1427:
        -: 1428:      /* We need to convert the '.' to the locale specific decimal point */
    #####: 1429:      copy = dbus_malloc (end - nptr + 1 + decimal_point_len);
call    0 never executed
        -: 1430:      
    #####: 1431:      c = copy;
    #####: 1432:      memcpy (c, nptr, decimal_point_pos - nptr);
call    0 never executed
    #####: 1433:      c += decimal_point_pos - nptr;
    #####: 1434:      memcpy (c, decimal_point, decimal_point_len);
call    0 never executed
    #####: 1435:      c += decimal_point_len;
    #####: 1436:      memcpy (c, decimal_point_pos + 1, end - (decimal_point_pos + 1));
call    0 never executed
    #####: 1437:      c += end - (decimal_point_pos + 1);
    #####: 1438:      *c = 0;
        -: 1439:
    #####: 1440:      val = strtod (copy, &fail_pos);
call    0 never executed
        -: 1441:
    #####: 1442:      if (fail_pos)
branch  0 never executed
branch  1 never executed
        -: 1443:	{
    #####: 1444:	  if (fail_pos > decimal_point_pos)
branch  0 never executed
branch  1 never executed
    #####: 1445:	    fail_pos = (char *)nptr + (fail_pos - copy) - (decimal_point_len - 1);
        -: 1446:	  else
    #####: 1447:	    fail_pos = (char *)nptr + (fail_pos - copy);
        -: 1448:	}
        -: 1449:      
    #####: 1450:      dbus_free (copy);
call    0 never executed
        -: 1451:	  
        -: 1452:    }
        -: 1453:  else
        3: 1454:    val = strtod (nptr, &fail_pos);
call    0 returned 100%
        -: 1455:
        3: 1456:  if (endptr)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        3: 1457:    *endptr = fail_pos;
        -: 1458:  
        3: 1459:  return val;
        -: 1460:}
        -: 1461:#endif /* DBUS_BUILD_TESTS */
        -: 1462:
        -: 1463:#ifdef DBUS_BUILD_TESTS
        -: 1464:/**
        -: 1465: * Parses a floating point number contained in a DBusString. Either
        -: 1466: * return parameter may be #NULL if you aren't interested in it. The
        -: 1467: * integer is parsed and stored in value_return. Return parameters are
        -: 1468: * not initialized if the function returns #FALSE.
        -: 1469: *
        -: 1470: * @param str the string
        -: 1471: * @param start the byte index of the start of the float
        -: 1472: * @param value_return return location of the float value or #NULL
        -: 1473: * @param end_return return location of the end of the float, or #NULL
        -: 1474: * @returns #TRUE on success
        -: 1475: */
        -: 1476:dbus_bool_t
        -: 1477:_dbus_string_parse_double (const DBusString *str,
        -: 1478:                           int               start,
        -: 1479:                           double           *value_return,
        -: 1480:                           int              *end_return)
function _dbus_string_parse_double called 3 returned 100% blocks executed 93%
        3: 1481:{
        -: 1482:  double v;
        -: 1483:  const char *p;
        -: 1484:  char *end;
        -: 1485:
        3: 1486:  p = _dbus_string_get_const_data_len (str, start,
call    0 returned 100%
call    1 returned 100%
        -: 1487:                                       _dbus_string_get_length (str) - start);
        -: 1488:
        3: 1489:  end = NULL;
        3: 1490:  errno = 0;
call    0 returned 100%
        3: 1491:  v = ascii_strtod (p, &end);
call    0 returned 100%
        3: 1492:  if (end == NULL || end == p || errno != 0)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
call    4 returned 100%
branch  5 taken 0% (fallthrough)
branch  6 taken 100%
    #####: 1493:    return FALSE;
        -: 1494:
        3: 1495:  if (value_return)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        3: 1496:    *value_return = v;
        3: 1497:  if (end_return)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        3: 1498:    *end_return = start + (end - p);
        -: 1499:
        3: 1500:  return TRUE;
        -: 1501:}
        -: 1502:#endif /* DBUS_BUILD_TESTS */
        -: 1503:
        -: 1504:/** @} */ /* DBusString group */
        -: 1505:
        -: 1506:/**
        -: 1507: * @addtogroup DBusInternalsUtils
        -: 1508: * @{
        -: 1509: */
        -: 1510:static dbus_bool_t
        -: 1511:fill_user_info_from_passwd (struct passwd *p,
        -: 1512:                            DBusUserInfo  *info,
        -: 1513:                            DBusError     *error)
function fill_user_info_from_passwd called 11 returned 100% blocks executed 80%
       11: 1514:{
       11: 1515:  _dbus_assert (p->pw_name != NULL);
call    0 returned 100%
       11: 1516:  _dbus_assert (p->pw_dir != NULL);
call    0 returned 100%
        -: 1517:  
       11: 1518:  info->uid = p->pw_uid;
       11: 1519:  info->primary_gid = p->pw_gid;
       11: 1520:  info->username = _dbus_strdup (p->pw_name);
call    0 returned 100%
       11: 1521:  info->homedir = _dbus_strdup (p->pw_dir);
call    0 returned 100%
        -: 1522:  
       11: 1523:  if (info->username == NULL ||
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 0% (fallthrough)
branch  3 taken 100%
        -: 1524:      info->homedir == NULL)
        -: 1525:    {
    #####: 1526:      dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
call    0 never executed
    #####: 1527:      return FALSE;
        -: 1528:    }
        -: 1529:
       11: 1530:  return TRUE;
        -: 1531:}
        -: 1532:
        -: 1533:static dbus_bool_t
        -: 1534:fill_user_info (DBusUserInfo       *info,
        -: 1535:                dbus_uid_t          uid,
        -: 1536:                const DBusString   *username,
        -: 1537:                DBusError          *error)
function fill_user_info called 11 returned 100% blocks executed 48%
       11: 1538:{
        -: 1539:  const char *username_c;
        -: 1540:  
        -: 1541:  /* exactly one of username/uid provided */
       11: 1542:  _dbus_assert (username != NULL || uid != DBUS_UID_UNSET);
branch  0 taken 91% (fallthrough)
branch  1 taken 9%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
call    4 returned 100%
       11: 1543:  _dbus_assert (username == NULL || uid == DBUS_UID_UNSET);
branch  0 taken 9% (fallthrough)
branch  1 taken 91%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
call    4 returned 100%
        -: 1544:
       11: 1545:  info->uid = DBUS_UID_UNSET;
       11: 1546:  info->primary_gid = DBUS_GID_UNSET;
       11: 1547:  info->group_ids = NULL;
       11: 1548:  info->n_group_ids = 0;
       11: 1549:  info->username = NULL;
       11: 1550:  info->homedir = NULL;
        -: 1551:  
       11: 1552:  if (username != NULL)
branch  0 taken 9% (fallthrough)
branch  1 taken 91%
        1: 1553:    username_c = _dbus_string_get_const_data (username);
call    0 returned 100%
        -: 1554:  else
       10: 1555:    username_c = NULL;
        -: 1556:
        -: 1557:  /* For now assuming that the getpwnam() and getpwuid() flavors
        -: 1558:   * are always symmetrical, if not we have to add more configure
        -: 1559:   * checks
        -: 1560:   */
        -: 1561:  
        -: 1562:#if defined (HAVE_POSIX_GETPWNAM_R) || defined (HAVE_NONPOSIX_GETPWNAM_R)
        -: 1563:  {
        -: 1564:    struct passwd *p;
        -: 1565:    int result;
        -: 1566:    char buf[1024];
        -: 1567:    struct passwd p_str;
        -: 1568:
       11: 1569:    p = NULL;
        -: 1570:#ifdef HAVE_POSIX_GETPWNAM_R
       11: 1571:    if (uid != DBUS_UID_UNSET)
branch  0 taken 91% (fallthrough)
branch  1 taken 9%
       10: 1572:      result = getpwuid_r (uid, &p_str, buf, sizeof (buf),
call    0 returned 100%
        -: 1573:                           &p);
        -: 1574:    else
        1: 1575:      result = getpwnam_r (username_c, &p_str, buf, sizeof (buf),
call    0 returned 100%
        -: 1576:                           &p);
        -: 1577:#else
        -: 1578:    if (uid != DBUS_UID_UNSET)
        -: 1579:      p = getpwuid_r (uid, &p_str, buf, sizeof (buf));
        -: 1580:    else
        -: 1581:      p = getpwnam_r (username_c, &p_str, buf, sizeof (buf));
        -: 1582:    result = 0;
        -: 1583:#endif /* !HAVE_POSIX_GETPWNAM_R */
       11: 1584:    if (result == 0 && p == &p_str)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
        -: 1585:      {
       11: 1586:        if (!fill_user_info_from_passwd (p, info, error))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####: 1587:          return FALSE;
        -: 1588:      }
        -: 1589:    else
        -: 1590:      {
    #####: 1591:        dbus_set_error (error, _dbus_error_from_errno (errno),
branch  0 never executed
branch  1 never executed
call    2 never executed
call    3 never executed
call    4 never executed
        -: 1592:                        "User \"%s\" unknown or no memory to allocate password entry\n",
        -: 1593:                        username_c ? username_c : "???");
    #####: 1594:        _dbus_verbose ("User %s unknown\n", username_c ? username_c : "???");
branch  0 never executed
branch  1 never executed
call    2 never executed
    #####: 1595:        return FALSE;
        -: 1596:      }
        -: 1597:  }
        -: 1598:#else /* ! HAVE_GETPWNAM_R */
        -: 1599:  {
        -: 1600:    /* I guess we're screwed on thread safety here */
        -: 1601:    struct passwd *p;
        -: 1602:
        -: 1603:    if (uid != DBUS_UID_UNSET)
        -: 1604:      p = getpwuid (uid);
        -: 1605:    else
        -: 1606:      p = getpwnam (username_c);
        -: 1607:
        -: 1608:    if (p != NULL)
        -: 1609:      {
        -: 1610:        if (!fill_user_info_from_passwd (p, info, error))
        -: 1611:          return FALSE;
        -: 1612:      }
        -: 1613:    else
        -: 1614:      {
        -: 1615:        dbus_set_error (error, _dbus_error_from_errno (errno),
        -: 1616:                        "User \"%s\" unknown or no memory to allocate password entry\n",
        -: 1617:                        username_c ? username_c : "???");
        -: 1618:        _dbus_verbose ("User %s unknown\n", username_c ? username_c : "???");
        -: 1619:        return FALSE;
        -: 1620:      }
        -: 1621:  }
        -: 1622:#endif  /* ! HAVE_GETPWNAM_R */
        -: 1623:
        -: 1624:  /* Fill this in so we can use it to get groups */
       11: 1625:  username_c = info->username;
        -: 1626:  
        -: 1627:#ifdef HAVE_GETGROUPLIST
        -: 1628:  {
        -: 1629:    gid_t *buf;
        -: 1630:    int buf_count;
        -: 1631:    int i;
        -: 1632:    
       11: 1633:    buf_count = 17;
       11: 1634:    buf = dbus_new (gid_t, buf_count);
call    0 returned 100%
       11: 1635:    if (buf == NULL)
branch  0 taken 0%
branch  1 taken 100%
        -: 1636:      {
    #####: 1637:        dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
call    0 never executed
    #####: 1638:        goto failed;
        -: 1639:      }
        -: 1640:    
       11: 1641:    if (getgrouplist (username_c,
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -: 1642:                      info->primary_gid,
        -: 1643:                      buf, &buf_count) < 0)
        -: 1644:      {
    #####: 1645:        gid_t *new = dbus_realloc (buf, buf_count * sizeof (buf[0]));
call    0 never executed
    #####: 1646:        if (new == NULL)
branch  0 never executed
branch  1 never executed
        -: 1647:          {
    #####: 1648:            dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
call    0 never executed
    #####: 1649:            dbus_free (buf);
call    0 never executed
    #####: 1650:            goto failed;
        -: 1651:          }
        -: 1652:        
    #####: 1653:        buf = new;
        -: 1654:
    #####: 1655:        errno = 0;
call    0 never executed
    #####: 1656:        if (getgrouplist (username_c, info->primary_gid, buf, &buf_count) < 0)
call    0 never executed
branch  1 never executed
branch  2 never executed
        -: 1657:          {
    #####: 1658:            dbus_set_error (error,
call    0 never executed
call    1 never executed
call    2 never executed
call    3 never executed
call    4 never executed
        -: 1659:                            _dbus_error_from_errno (errno),
        -: 1660:                            "Failed to get groups for username \"%s\" primary GID "
        -: 1661:                            DBUS_GID_FORMAT ": %s\n",
        -: 1662:                            username_c, info->primary_gid,
        -: 1663:                            _dbus_strerror (errno));
    #####: 1664:            dbus_free (buf);
call    0 never executed
    #####: 1665:            goto failed;
        -: 1666:          }
        -: 1667:      }
        -: 1668:
       11: 1669:    info->group_ids = dbus_new (dbus_gid_t, buf_count);
call    0 returned 100%
       11: 1670:    if (info->group_ids == NULL)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -: 1671:      {
    #####: 1672:        dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
call    0 never executed
    #####: 1673:        dbus_free (buf);
call    0 never executed
    #####: 1674:        goto failed;
        -: 1675:      }
        -: 1676:    
       38: 1677:    for (i = 0; i < buf_count; ++i)
branch  0 taken 71%
branch  1 taken 29% (fallthrough)
       27: 1678:      info->group_ids[i] = buf[i];
        -: 1679:
       11: 1680:    info->n_group_ids = buf_count;
        -: 1681:    
       11: 1682:    dbus_free (buf);
call    0 returned 100%
        -: 1683:  }
        -: 1684:#else  /* HAVE_GETGROUPLIST */
        -: 1685:  {
        -: 1686:    /* We just get the one group ID */
        -: 1687:    info->group_ids = dbus_new (dbus_gid_t, 1);
        -: 1688:    if (info->group_ids == NULL)
        -: 1689:      {
        -: 1690:        dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
        -: 1691:        goto failed;
        -: 1692:      }
        -: 1693:
        -: 1694:    info->n_group_ids = 1;
        -: 1695:
        -: 1696:    (info->group_ids)[0] = info->primary_gid;
        -: 1697:  }
        -: 1698:#endif /* HAVE_GETGROUPLIST */
        -: 1699:
       11: 1700:  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
branch  0 taken 64% (fallthrough)
branch  1 taken 36%
call    2 returned 100%
branch  3 taken 100% (fallthrough)
branch  4 taken 0%
call    5 returned 100%
        -: 1701:  
       11: 1702:  return TRUE;
        -: 1703:  
    #####: 1704: failed:
    #####: 1705:  _DBUS_ASSERT_ERROR_IS_SET (error);
branch  0 never executed
branch  1 never executed
call    2 never executed
branch  3 never executed
branch  4 never executed
call    5 never executed
    #####: 1706:  return FALSE;
        -: 1707:}
        -: 1708:
        -: 1709:/**
        -: 1710: * Gets user info for the given username.
        -: 1711: *
        -: 1712: * @param info user info object to initialize
        -: 1713: * @param username the username
        -: 1714: * @param error error return
        -: 1715: * @returns #TRUE on success
        -: 1716: */
        -: 1717:dbus_bool_t
        -: 1718:_dbus_user_info_fill (DBusUserInfo     *info,
        -: 1719:                      const DBusString *username,
        -: 1720:                      DBusError        *error)
function _dbus_user_info_fill called 1 returned 100% blocks executed 100%
        1: 1721:{
        1: 1722:  return fill_user_info (info, DBUS_UID_UNSET,
call    0 returned 100%
        -: 1723:                         username, error);
        -: 1724:}
        -: 1725:
        -: 1726:/**
        -: 1727: * Gets user info for the given user ID.
        -: 1728: *
        -: 1729: * @param info user info object to initialize
        -: 1730: * @param uid the user ID
        -: 1731: * @param error error return
        -: 1732: * @returns #TRUE on success
        -: 1733: */
        -: 1734:dbus_bool_t
        -: 1735:_dbus_user_info_fill_uid (DBusUserInfo *info,
        -: 1736:                          dbus_uid_t    uid,
        -: 1737:                          DBusError    *error)
function _dbus_user_info_fill_uid called 10 returned 100% blocks executed 100%
       10: 1738:{
       10: 1739:  return fill_user_info (info, uid,
call    0 returned 100%
        -: 1740:                         NULL, error);
        -: 1741:}
        -: 1742:
        -: 1743:/**
        -: 1744: * Frees the members of info
        -: 1745: * (but not info itself)
        -: 1746: * @param info the user info struct
        -: 1747: */
        -: 1748:void
        -: 1749:_dbus_user_info_free (DBusUserInfo *info)
function _dbus_user_info_free called 10 returned 100% blocks executed 100%
       10: 1750:{
       10: 1751:  dbus_free (info->group_ids);
call    0 returned 100%
       10: 1752:  dbus_free (info->username);
call    0 returned 100%
       10: 1753:  dbus_free (info->homedir);
call    0 returned 100%
       10: 1754:}
        -: 1755:
        -: 1756:/**
        -: 1757: * Frees the members of info (but not info itself).
        -: 1758: *
        -: 1759: * @param info the group info
        -: 1760: */
        -: 1761:void
        -: 1762:_dbus_group_info_free (DBusGroupInfo    *info)
function _dbus_group_info_free called 0 returned 0% blocks executed 0%
    #####: 1763:{
    #####: 1764:  dbus_free (info->groupname);
call    0 never executed
    #####: 1765:}
        -: 1766:
        -: 1767:/**
        -: 1768: * Sets fields in DBusCredentials to DBUS_PID_UNSET,
        -: 1769: * DBUS_UID_UNSET, DBUS_GID_UNSET.
        -: 1770: *
        -: 1771: * @param credentials the credentials object to fill in
        -: 1772: */
        -: 1773:void
        -: 1774:_dbus_credentials_clear (DBusCredentials *credentials)
function _dbus_credentials_clear called 116851 returned 100% blocks executed 100%
   116851: 1775:{
   116851: 1776:  credentials->pid = DBUS_PID_UNSET;
   116851: 1777:  credentials->uid = DBUS_UID_UNSET;
   116851: 1778:  credentials->gid = DBUS_GID_UNSET;
   116851: 1779:}
        -: 1780:
        -: 1781:/**
        -: 1782: * Gets the credentials of the current process.
        -: 1783: *
        -: 1784: * @param credentials credentials to fill in.
        -: 1785: */
        -: 1786:void
        -: 1787:_dbus_credentials_from_current_process (DBusCredentials *credentials)
function _dbus_credentials_from_current_process called 13 returned 100% blocks executed 100%
       13: 1788:{
        -: 1789:  /* The POSIX spec certainly doesn't promise this, but
        -: 1790:   * we need these assertions to fail as soon as we're wrong about
        -: 1791:   * it so we can do the porting fixups
        -: 1792:   */
       13: 1793:  _dbus_assert (sizeof (pid_t) <= sizeof (credentials->pid));
call    0 returned 100%
       13: 1794:  _dbus_assert (sizeof (uid_t) <= sizeof (credentials->uid));
call    0 returned 100%
       13: 1795:  _dbus_assert (sizeof (gid_t) <= sizeof (credentials->gid));
call    0 returned 100%
        -: 1796:  
       13: 1797:  credentials->pid = getpid ();
call    0 returned 100%
       13: 1798:  credentials->uid = getuid ();
call    0 returned 100%
       13: 1799:  credentials->gid = getgid ();
call    0 returned 100%
       13: 1800:}
        -: 1801:
        -: 1802:/**
        -: 1803: * Checks whether the provided_credentials are allowed to log in
        -: 1804: * as the expected_credentials.
        -: 1805: *
        -: 1806: * @param expected_credentials credentials we're trying to log in as
        -: 1807: * @param provided_credentials credentials we have
        -: 1808: * @returns #TRUE if we can log in
        -: 1809: */
        -: 1810:dbus_bool_t
        -: 1811:_dbus_credentials_match (const DBusCredentials *expected_credentials,
        -: 1812:                         const DBusCredentials *provided_credentials)
function _dbus_credentials_match called 3841 returned 100% blocks executed 80%
     3841: 1813:{
     3841: 1814:  if (provided_credentials->uid == DBUS_UID_UNSET)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####: 1815:    return FALSE;
     3841: 1816:  else if (expected_credentials->uid == DBUS_UID_UNSET)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####: 1817:    return FALSE;
     3841: 1818:  else if (provided_credentials->uid == 0)
branch  0 taken 1% (fallthrough)
branch  1 taken 99%
        1: 1819:    return TRUE;
     3840: 1820:  else if (provided_credentials->uid == expected_credentials->uid)
branch  0 taken 99% (fallthrough)
branch  1 taken 1%
     3839: 1821:    return TRUE;
        -: 1822:  else
        1: 1823:    return FALSE;
        -: 1824:}
        -: 1825:
        -: 1826:/**
        -: 1827: * Gets our process ID
        -: 1828: * @returns process ID
        -: 1829: */
        -: 1830:unsigned long
        -: 1831:_dbus_getpid (void)
function _dbus_getpid called 3080 returned 100% blocks executed 100%
     3080: 1832:{
     3080: 1833:  return getpid ();
call    0 returned 100%
        -: 1834:}
        -: 1835:
        -: 1836:/** Gets our UID
        -: 1837: * @returns process UID
        -: 1838: */
        -: 1839:dbus_uid_t
        -: 1840:_dbus_getuid (void)
function _dbus_getuid called 12934 returned 100% blocks executed 100%
    12934: 1841:{
    12934: 1842:  return getuid ();
call    0 returned 100%
        -: 1843:}
        -: 1844:
        -: 1845:#ifdef DBUS_BUILD_TESTS
        -: 1846:/** Gets our GID
        -: 1847: * @returns process GID
        -: 1848: */
        -: 1849:dbus_gid_t
        -: 1850:_dbus_getgid (void)
function _dbus_getgid called 0 returned 0% blocks executed 0%
    #####: 1851:{
    #####: 1852:  return getgid ();
call    0 never executed
        -: 1853:}
        -: 1854:#endif
        -: 1855:
        -: 1856:_DBUS_DEFINE_GLOBAL_LOCK (atomic);
        -: 1857:
        -: 1858:#ifdef DBUS_USE_ATOMIC_INT_486
        -: 1859:/* Taken from CVS version 1.7 of glibc's sysdeps/i386/i486/atomicity.h */
        -: 1860:/* Since the asm stuff here is gcc-specific we go ahead and use "inline" also */
        -: 1861:static inline dbus_int32_t
        -: 1862:atomic_exchange_and_add (DBusAtomic            *atomic,
        -: 1863:                         volatile dbus_int32_t  val)
        -: 1864:{
        -: 1865:  register dbus_int32_t result;
        -: 1866:
        -: 1867:  __asm__ __volatile__ ("lock; xaddl %0,%1"
        -: 1868:                        : "=r" (result), "=m" (atomic->value)
        -: 1869:			: "0" (val), "m" (atomic->value));
        -: 1870:  return result;
        -: 1871:}
        -: 1872:#endif
        -: 1873:
        -: 1874:/**
        -: 1875: * Atomically increments an integer
        -: 1876: *
        -: 1877: * @param atomic pointer to the integer to increment
        -: 1878: * @returns the value before incrementing
        -: 1879: *
        -: 1880: * @todo implement arch-specific faster atomic ops
        -: 1881: */
        -: 1882:dbus_int32_t
        -: 1883:_dbus_atomic_inc (DBusAtomic *atomic)
function _dbus_atomic_inc called 182588 returned 100% blocks executed 100%
   182588: 1884:{
        -: 1885:#ifdef DBUS_USE_ATOMIC_INT_486
        -: 1886:  return atomic_exchange_and_add (atomic, 1);
        -: 1887:#else
        -: 1888:  dbus_int32_t res;
   182588: 1889:  _DBUS_LOCK (atomic);
call    0 returned 100%
   182588: 1890:  res = atomic->value;
   182588: 1891:  atomic->value += 1;
   182588: 1892:  _DBUS_UNLOCK (atomic);
call    0 returned 100%
   182588: 1893:  return res;
        -: 1894:#endif
        -: 1895:}
        -: 1896:
        -: 1897:/**
        -: 1898: * Atomically decrement an integer
        -: 1899: *
        -: 1900: * @param atomic pointer to the integer to decrement
        -: 1901: * @returns the value before decrementing
        -: 1902: *
        -: 1903: * @todo implement arch-specific faster atomic ops
        -: 1904: */
        -: 1905:dbus_int32_t
        -: 1906:_dbus_atomic_dec (DBusAtomic *atomic)
function _dbus_atomic_dec called 574758 returned 100% blocks executed 100%
   574758: 1907:{
        -: 1908:#ifdef DBUS_USE_ATOMIC_INT_486
        -: 1909:  return atomic_exchange_and_add (atomic, -1);
        -: 1910:#else
        -: 1911:  dbus_int32_t res;
        -: 1912:  
   574758: 1913:  _DBUS_LOCK (atomic);
call    0 returned 100%
   574758: 1914:  res = atomic->value;
   574758: 1915:  atomic->value -= 1;
   574758: 1916:  _DBUS_UNLOCK (atomic);
call    0 returned 100%
   574758: 1917:  return res;
        -: 1918:#endif
        -: 1919:}
        -: 1920:
        -: 1921:/**
        -: 1922: * Wrapper for poll().
        -: 1923: *
        -: 1924: * @param fds the file descriptors to poll
        -: 1925: * @param n_fds number of descriptors in the array
        -: 1926: * @param timeout_milliseconds timeout or -1 for infinite
        -: 1927: * @returns numbers of fds with revents, or <0 on error
        -: 1928: */
        -: 1929:int
        -: 1930:_dbus_poll (DBusPollFD *fds,
        -: 1931:            int         n_fds,
        -: 1932:            int         timeout_milliseconds)
function _dbus_poll called 1304454 returned 100% blocks executed 100%
  1304454: 1933:{
        -: 1934:#ifdef HAVE_POLL
        -: 1935:  /* This big thing is a constant expression and should get optimized
        -: 1936:   * out of existence. So it's more robust than a configure check at
        -: 1937:   * no cost.
        -: 1938:   */
        -: 1939:  if (_DBUS_POLLIN == POLLIN &&
        -: 1940:      _DBUS_POLLPRI == POLLPRI &&
        -: 1941:      _DBUS_POLLOUT == POLLOUT &&
        -: 1942:      _DBUS_POLLERR == POLLERR &&
        -: 1943:      _DBUS_POLLHUP == POLLHUP &&
        -: 1944:      _DBUS_POLLNVAL == POLLNVAL &&
        -: 1945:      sizeof (DBusPollFD) == sizeof (struct pollfd) &&
        -: 1946:      _DBUS_STRUCT_OFFSET (DBusPollFD, fd) ==
        -: 1947:      _DBUS_STRUCT_OFFSET (struct pollfd, fd) &&
        -: 1948:      _DBUS_STRUCT_OFFSET (DBusPollFD, events) ==
        -: 1949:      _DBUS_STRUCT_OFFSET (struct pollfd, events) &&
        -: 1950:      _DBUS_STRUCT_OFFSET (DBusPollFD, revents) ==
        -: 1951:      _DBUS_STRUCT_OFFSET (struct pollfd, revents))
        -: 1952:    {
  1304454: 1953:      return poll ((struct pollfd*) fds,
call    0 returned 100%
        -: 1954:                   n_fds, 
        -: 1955:                   timeout_milliseconds);
        -: 1956:    }
        -: 1957:  else
        -: 1958:    {
        -: 1959:      /* We have to convert the DBusPollFD to an array of
        -: 1960:       * struct pollfd, poll, and convert back.
        -: 1961:       */
        -: 1962:      _dbus_warn ("didn't implement poll() properly for this system yet\n");
        -: 1963:      return -1;
        -: 1964:    }
        -: 1965:#else /* ! HAVE_POLL */
        -: 1966:
        -: 1967:  fd_set read_set, write_set, err_set;
        -: 1968:  int max_fd = 0;
        -: 1969:  int i;
        -: 1970:  struct timeval tv;
        -: 1971:  int ready;
        -: 1972:  
        -: 1973:  FD_ZERO (&read_set);
        -: 1974:  FD_ZERO (&write_set);
        -: 1975:  FD_ZERO (&err_set);
        -: 1976:
        -: 1977:  for (i = 0; i < n_fds; i++)
        -: 1978:    {
        -: 1979:      DBusPollFD *fdp = &fds[i];
        -: 1980:
        -: 1981:      if (fdp->events & _DBUS_POLLIN)
        -: 1982:	FD_SET (fdp->fd, &read_set);
        -: 1983:
        -: 1984:      if (fdp->events & _DBUS_POLLOUT)
        -: 1985:	FD_SET (fdp->fd, &write_set);
        -: 1986:
        -: 1987:      FD_SET (fdp->fd, &err_set);
        -: 1988:
        -: 1989:      max_fd = MAX (max_fd, fdp->fd);
        -: 1990:    }
        -: 1991:    
        -: 1992:  tv.tv_sec = timeout_milliseconds / 1000;
        -: 1993:  tv.tv_usec = (timeout_milliseconds % 1000) * 1000;
        -: 1994:
        -: 1995:  ready = select (max_fd + 1, &read_set, &write_set, &err_set,
        -: 1996:                  timeout_milliseconds < 0 ? NULL : &tv);
        -: 1997:
        -: 1998:  if (ready > 0)
        -: 1999:    {
        -: 2000:      for (i = 0; i < n_fds; i++)
        -: 2001:	{
        -: 2002:	  DBusPollFD *fdp = &fds[i];
        -: 2003:
        -: 2004:	  fdp->revents = 0;
        -: 2005:
        -: 2006:	  if (FD_ISSET (fdp->fd, &read_set))
        -: 2007:	    fdp->revents |= _DBUS_POLLIN;
        -: 2008:
        -: 2009:	  if (FD_ISSET (fdp->fd, &write_set))
        -: 2010:	    fdp->revents |= _DBUS_POLLOUT;
        -: 2011:
        -: 2012:	  if (FD_ISSET (fdp->fd, &err_set))
        -: 2013:	    fdp->revents |= _DBUS_POLLERR;
        -: 2014:	}
        -: 2015:    }
        -: 2016:
        -: 2017:  return ready;
        -: 2018:#endif
        -: 2019:}
        -: 2020:
        -: 2021:/** nanoseconds in a second */
        -: 2022:#define NANOSECONDS_PER_SECOND       1000000000
        -: 2023:/** microseconds in a second */
        -: 2024:#define MICROSECONDS_PER_SECOND      1000000
        -: 2025:/** milliseconds in a second */
        -: 2026:#define MILLISECONDS_PER_SECOND      1000
        -: 2027:/** nanoseconds in a millisecond */
        -: 2028:#define NANOSECONDS_PER_MILLISECOND  1000000
        -: 2029:/** microseconds in a millisecond */
        -: 2030:#define MICROSECONDS_PER_MILLISECOND 1000
        -: 2031:
        -: 2032:/**
        -: 2033: * Sleeps the given number of milliseconds.
        -: 2034: * @param milliseconds number of milliseconds
        -: 2035: */
        -: 2036:void
        -: 2037:_dbus_sleep_milliseconds (int milliseconds)
function _dbus_sleep_milliseconds called 2557 returned 100% blocks executed 57%
     2557: 2038:{
        -: 2039:#ifdef HAVE_NANOSLEEP
        -: 2040:  struct timespec req;
        -: 2041:  struct timespec rem;
        -: 2042:
     2557: 2043:  req.tv_sec = milliseconds / MILLISECONDS_PER_SECOND;
     2557: 2044:  req.tv_nsec = (milliseconds % MILLISECONDS_PER_SECOND) * NANOSECONDS_PER_MILLISECOND;
     2557: 2045:  rem.tv_sec = 0;
     2557: 2046:  rem.tv_nsec = 0;
        -: 2047:
     5114: 2048:  while (nanosleep (&req, &rem) < 0 && errno == EINTR)
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
call    3 never executed
branch  4 never executed
branch  5 never executed
    #####: 2049:    req = rem;
        -: 2050:#elif defined (HAVE_USLEEP)
        -: 2051:  usleep (milliseconds * MICROSECONDS_PER_MILLISECOND);
        -: 2052:#else /* ! HAVE_USLEEP */
        -: 2053:  sleep (MAX (milliseconds / 1000, 1));
        -: 2054:#endif
     2557: 2055:}
        -: 2056:
        -: 2057:/**
        -: 2058: * Get current time, as in gettimeofday().
        -: 2059: *
        -: 2060: * @param tv_sec return location for number of seconds
        -: 2061: * @param tv_usec return location for number of microseconds (thousandths)
        -: 2062: */
        -: 2063:void
        -: 2064:_dbus_get_current_time (long *tv_sec,
        -: 2065:                        long *tv_usec)
function _dbus_get_current_time called 1679751 returned 100% blocks executed 100%
  1679751: 2066:{
        -: 2067:  struct timeval t;
        -: 2068:
  1679751: 2069:  gettimeofday (&t, NULL);
call    0 returned 100%
        -: 2070:
  1679751: 2071:  if (tv_sec)
branch  0 taken 99% (fallthrough)
branch  1 taken 1%
  1679749: 2072:    *tv_sec = t.tv_sec;
  1679751: 2073:  if (tv_usec)
branch  0 taken 99% (fallthrough)
branch  1 taken 1%
  1672328: 2074:    *tv_usec = t.tv_usec;
  1679751: 2075:}
        -: 2076:
        -: 2077:/**
        -: 2078: * Appends the contents of the given file to the string,
        -: 2079: * returning error code. At the moment, won't open a file
        -: 2080: * more than a megabyte in size.
        -: 2081: *
        -: 2082: * @param str the string to append to
        -: 2083: * @param filename filename to load
        -: 2084: * @param error place to set an error
        -: 2085: * @returns #FALSE if error was set
        -: 2086: */
        -: 2087:dbus_bool_t
        -: 2088:_dbus_file_get_contents (DBusString       *str,
        -: 2089:                         const DBusString *filename,
        -: 2090:                         DBusError        *error)
function _dbus_file_get_contents called 7183 returned 100% blocks executed 65%
     7183: 2091:{
        -: 2092:  int fd;
        -: 2093:  struct stat sb;
        -: 2094:  int orig_len;
        -: 2095:  int total;
        -: 2096:  const char *filename_c;
        -: 2097:
     7183: 2098:  _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%
        -: 2099:  
     7183: 2100:  filename_c = _dbus_string_get_const_data (filename);
call    0 returned 100%
        -: 2101:  
        -: 2102:  /* O_BINARY useful on Cygwin */
     7183: 2103:  fd = open (filename_c, O_RDONLY | O_BINARY);
call    0 returned 100%
     7183: 2104:  if (fd < 0)
branch  0 taken 1% (fallthrough)
branch  1 taken 99%
        -: 2105:    {
       12: 2106:      dbus_set_error (error, _dbus_error_from_errno (errno),
call    0 returned 100%
call    1 returned 100%
call    2 returned 100%
call    3 returned 100%
call    4 returned 100%
        -: 2107:                      "Failed to open \"%s\": %s",
        -: 2108:                      filename_c,
        -: 2109:                      _dbus_strerror (errno));
       12: 2110:      return FALSE;
        -: 2111:    }
        -: 2112:
     7171: 2113:  if (fstat (fd, &sb) < 0)
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -: 2114:    {
    #####: 2115:      dbus_set_error (error, _dbus_error_from_errno (errno),
call    0 never executed
call    1 never executed
call    2 never executed
call    3 never executed
call    4 never executed
        -: 2116:                      "Failed to stat \"%s\": %s",
        -: 2117:                      filename_c,
        -: 2118:                      _dbus_strerror (errno));
        -: 2119:
    #####: 2120:      _dbus_verbose ("fstat() failed: %s",
call    0 never executed
call    1 never executed
call    2 never executed
        -: 2121:                     _dbus_strerror (errno));
        -: 2122:      
    #####: 2123:      close (fd);
call    0 never executed
        -: 2124:      
    #####: 2125:      return FALSE;
        -: 2126:    }
        -: 2127:
     7171: 2128:  if (sb.st_size > _DBUS_ONE_MEGABYTE)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -: 2129:    {
    #####: 2130:      dbus_set_error (error, DBUS_ERROR_FAILED,
call    0 never executed
        -: 2131:                      "File size %lu of \"%s\" is too large.",
        -: 2132:                      (unsigned long) sb.st_size, filename_c);
    #####: 2133:      close (fd);
call    0 never executed
    #####: 2134:      return FALSE;
        -: 2135:    }
        -: 2136:  
     7171: 2137:  total = 0;
     7171: 2138:  orig_len = _dbus_string_get_length (str);
call    0 returned 100%
     7171: 2139:  if (sb.st_size > 0 && S_ISREG (sb.st_mode))
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
        -: 2140:    {
        -: 2141:      int bytes_read;
        -: 2142:
    21508: 2143:      while (total < (int) sb.st_size)
branch  0 taken 50%
branch  1 taken 50% (fallthrough)
        -: 2144:        {
     7171: 2145:          bytes_read = _dbus_read (fd, str,
call    0 returned 100%
        -: 2146:                                   sb.st_size - total);
     7171: 2147:          if (bytes_read <= 0)
branch  0 taken 1% (fallthrough)
branch  1 taken 99%
        -: 2148:            {
        5: 2149:              dbus_set_error (error, _dbus_error_from_errno (errno),
call    0 returned 100%
call    1 returned 100%
call    2 returned 100%
call    3 returned 100%
call    4 returned 100%
        -: 2150:                              "Error reading \"%s\": %s",
        -: 2151:                              filename_c,
        -: 2152:                              _dbus_strerror (errno));
        -: 2153:
        5: 2154:              _dbus_verbose ("read() failed: %s",
call    0 returned 100%
call    1 returned 100%
call    2 returned 100%
        -: 2155:                             _dbus_strerror (errno));
        -: 2156:              
        5: 2157:              close (fd);
call    0 returned 100%
        5: 2158:              _dbus_string_set_length (str, orig_len);
call    0 returned 100%
        5: 2159:              return FALSE;
        -: 2160:            }
        -: 2161:          else
     7166: 2162:            total += bytes_read;
        -: 2163:        }
        -: 2164:
     7166: 2165:      close (fd);
call    0 returned 100%
     7166: 2166:      return TRUE;
        -: 2167:    }
    #####: 2168:  else if (sb.st_size != 0)
branch  0 never executed
branch  1 never executed
        -: 2169:    {
    #####: 2170:      _dbus_verbose ("Can only open regular files at the moment.\n");
call    0 never executed
    #####: 2171:      dbus_set_error (error, DBUS_ERROR_FAILED,
call    0 never executed
        -: 2172:                      "\"%s\" is not a regular file",
        -: 2173:                      filename_c);
    #####: 2174:      close (fd);
call    0 never executed
    #####: 2175:      return FALSE;
        -: 2176:    }
        -: 2177:  else
        -: 2178:    {
    #####: 2179:      close (fd);
call    0 never executed
    #####: 2180:      return TRUE;
        -: 2181:    }
        -: 2182:}
        -: 2183:
        -: 2184:/**
        -: 2185: * Writes a string out to a file. If the file exists,
        -: 2186: * it will be atomically overwritten by the new data.
        -: 2187: *
        -: 2188: * @param str the string to write out
        -: 2189: * @param filename the file to save string to
        -: 2190: * @param error error to be filled in on failure
        -: 2191: * @returns #FALSE on failure
        -: 2192: */
        -: 2193:dbus_bool_t
        -: 2194:_dbus_string_save_to_file (const DBusString *str,
        -: 2195:                           const DBusString *filename,
        -: 2196:                           DBusError        *error)
function _dbus_string_save_to_file called 310 returned 100% blocks executed 41%
      310: 2197:{
        -: 2198:  int fd;
        -: 2199:  int bytes_to_write;
        -: 2200:  const char *filename_c;
        -: 2201:  DBusString tmp_filename;
        -: 2202:  const char *tmp_filename_c;
        -: 2203:  int total;
        -: 2204:  dbus_bool_t need_unlink;
        -: 2205:  dbus_bool_t retval;
        -: 2206:
      310: 2207:  _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%
        -: 2208:  
      310: 2209:  fd = -1;
      310: 2210:  retval = FALSE;
      310: 2211:  need_unlink = FALSE;
        -: 2212:  
      310: 2213:  if (!_dbus_string_init (&tmp_filename))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -: 2214:    {
    #####: 2215:      dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
call    0 never executed
    #####: 2216:      return FALSE;
        -: 2217:    }
        -: 2218:
      310: 2219:  if (!_dbus_string_copy (filename, 0, &tmp_filename, 0))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -: 2220:    {
    #####: 2221:      dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
call    0 never executed
    #####: 2222:      _dbus_string_free (&tmp_filename);
call    0 never executed
    #####: 2223:      return FALSE;
        -: 2224:    }
        -: 2225:  
      310: 2226:  if (!_dbus_string_append (&tmp_filename, "."))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -: 2227:    {
    #####: 2228:      dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
call    0 never executed
    #####: 2229:      _dbus_string_free (&tmp_filename);
call    0 never executed
    #####: 2230:      return FALSE;
        -: 2231:    }
        -: 2232:
        -: 2233:#define N_TMP_FILENAME_RANDOM_BYTES 8
      310: 2234:  if (!_dbus_generate_random_ascii (&tmp_filename, N_TMP_FILENAME_RANDOM_BYTES))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -: 2235:    {
    #####: 2236:      dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
call    0 never executed
    #####: 2237:      _dbus_string_free (&tmp_filename);
call    0 never executed
    #####: 2238:      return FALSE;
        -: 2239:    }
        -: 2240:    
      310: 2241:  filename_c = _dbus_string_get_const_data (filename);
call    0 returned 100%
      310: 2242:  tmp_filename_c = _dbus_string_get_const_data (&tmp_filename);
call    0 returned 100%
        -: 2243:
      310: 2244:  fd = open (tmp_filename_c, O_WRONLY | O_BINARY | O_EXCL | O_CREAT,
call    0 returned 100%
        -: 2245:             0600);
      310: 2246:  if (fd < 0)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -: 2247:    {
    #####: 2248:      dbus_set_error (error, _dbus_error_from_errno (errno),
call    0 never executed
call    1 never executed
call    2 never executed
call    3 never executed
call    4 never executed
        -: 2249:                      "Could not create %s: %s", tmp_filename_c,
        -: 2250:                      _dbus_strerror (errno));
    #####: 2251:      goto out;
        -: 2252:    }
        -: 2253:
      310: 2254:  need_unlink = TRUE;
        -: 2255:  
      310: 2256:  total = 0;
      310: 2257:  bytes_to_write = _dbus_string_get_length (str);
call    0 returned 100%
        -: 2258:
      930: 2259:  while (total < bytes_to_write)
branch  0 taken 50%
branch  1 taken 50% (fallthrough)
        -: 2260:    {
        -: 2261:      int bytes_written;
        -: 2262:
      310: 2263:      bytes_written = _dbus_write (fd, str, total,
call    0 returned 100%
        -: 2264:                                   bytes_to_write - total);
        -: 2265:
      310: 2266:      if (bytes_written <= 0)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -: 2267:        {
    #####: 2268:          dbus_set_error (error, _dbus_error_from_errno (errno),
call    0 never executed
call    1 never executed
call    2 never executed
call    3 never executed
call    4 never executed
        -: 2269:                          "Could not write to %s: %s", tmp_filename_c,
        -: 2270:                          _dbus_strerror (errno));
        -: 2271:          
    #####: 2272:          goto out;
        -: 2273:        }
        -: 2274:
      310: 2275:      total += bytes_written;
        -: 2276:    }
        -: 2277:
      310: 2278:  if (close (fd) < 0)
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -: 2279:    {
    #####: 2280:      dbus_set_error (error, _dbus_error_from_errno (errno),
call    0 never executed
call    1 never executed
call    2 never executed
call    3 never executed
call    4 never executed
        -: 2281:                      "Could not close file %s: %s",
        -: 2282:                      tmp_filename_c, _dbus_strerror (errno));
        -: 2283:
    #####: 2284:      goto out;
        -: 2285:    }
        -: 2286:
      310: 2287:  fd = -1;
        -: 2288:  
      310: 2289:  if (rename (tmp_filename_c, filename_c) < 0)
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -: 2290:    {
    #####: 2291:      dbus_set_error (error, _dbus_error_from_errno (errno),
call    0 never executed
call    1 never executed
call    2 never executed
call    3 never executed
call    4 never executed
        -: 2292:                      "Could not rename %s to %s: %s",
        -: 2293:                      tmp_filename_c, filename_c,
        -: 2294:                      _dbus_strerror (errno));
        -: 2295:
    #####: 2296:      goto out;
        -: 2297:    }
        -: 2298:
      310: 2299:  need_unlink = FALSE;
        -: 2300:  
      310: 2301:  retval = TRUE;
        -: 2302:  
      310: 2303: out:
        -: 2304:  /* close first, then unlink, to prevent ".nfs34234235" garbage
        -: 2305:   * files
        -: 2306:   */
        -: 2307:
      310: 2308:  if (fd >= 0)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####: 2309:    close (fd);
call    0 never executed
        -: 2310:        
      310: 2311:  if (need_unlink && unlink (tmp_filename_c) < 0)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
call    2 never executed
branch  3 never executed
branch  4 never executed
    #####: 2312:    _dbus_verbose ("Failed to unlink temp file %s: %s\n",
call    0 never executed
call    1 never executed
call    2 never executed
        -: 2313:                   tmp_filename_c, _dbus_strerror (errno));
        -: 2314:
      310: 2315:  _dbus_string_free (&tmp_filename);
call    0 returned 100%
        -: 2316:
      310: 2317:  if (!retval)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####: 2318:    _DBUS_ASSERT_ERROR_IS_SET (error);
branch  0 never executed
branch  1 never executed
call    2 never executed
branch  3 never executed
branch  4 never executed
call    5 never executed
        -: 2319:  
      310: 2320:  return retval;
        -: 2321:}
        -: 2322:
        -: 2323:/** Creates the given file, failing if the file already exists.
        -: 2324: *
        -: 2325: * @param filename the filename
        -: 2326: * @param error error location
        -: 2327: * @returns #TRUE if we created the file and it didn't exist
        -: 2328: */
        -: 2329:dbus_bool_t
        -: 2330:_dbus_create_file_exclusively (const DBusString *filename,
        -: 2331:                               DBusError        *error)
function _dbus_create_file_exclusively called 310 returned 100% blocks executed 57%
      310: 2332:{
        -: 2333:  int fd;
        -: 2334:  const char *filename_c;
        -: 2335:
      310: 2336:  _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%
        -: 2337:  
      310: 2338:  filename_c = _dbus_string_get_const_data (filename);
call    0 returned 100%
        -: 2339:  
      310: 2340:  fd = open (filename_c, O_WRONLY | O_BINARY | O_EXCL | O_CREAT,
call    0 returned 100%
        -: 2341:             0600);
      310: 2342:  if (fd < 0)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -: 2343:    {
    #####: 2344:      dbus_set_error (error,
call    0 never executed
call    1 never executed
call    2 never executed
        -: 2345:                      DBUS_ERROR_FAILED,
        -: 2346:                      "Could not create file %s: %s\n",
        -: 2347:                      filename_c,
        -: 2348:                      _dbus_strerror (errno));
    #####: 2349:      return FALSE;
        -: 2350:    }
        -: 2351:
      310: 2352:  if (close (fd) < 0)
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -: 2353:    {
    #####: 2354:      dbus_set_error (error,
call    0 never executed
call    1 never executed
call    2 never executed
        -: 2355:                      DBUS_ERROR_FAILED,
        -: 2356:                      "Could not close file %s: %s\n",
        -: 2357:                      filename_c,
        -: 2358:                      _dbus_strerror (errno));
    #####: 2359:      return FALSE;
        -: 2360:    }
        -: 2361:  
      310: 2362:  return TRUE;
        -: 2363:}
        -: 2364:
        -: 2365:/**
        -: 2366: * Deletes the given file.
        -: 2367: *
        -: 2368: * @param filename the filename
        -: 2369: * @param error error location
        -: 2370: * 
        -: 2371: * @returns #TRUE if unlink() succeeded
        -: 2372: */
        -: 2373:dbus_bool_t
        -: 2374:_dbus_delete_file (const DBusString *filename,
        -: 2375:                   DBusError        *error)
function _dbus_delete_file called 319 returned 100% blocks executed 93%
      319: 2376:{
        -: 2377:  const char *filename_c;
        -: 2378:
      319: 2379:  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
branch  0 taken 97% (fallthrough)
branch  1 taken 3%
call    2 returned 100%
branch  3 taken 100% (fallthrough)
branch  4 taken 0%
call    5 returned 100%
        -: 2380:  
      319: 2381:  filename_c = _dbus_string_get_const_data (filename);
call    0 returned 100%
        -: 2382:
      319: 2383:  if (unlink (filename_c) < 0)
call    0 returned 100%
branch  1 taken 1% (fallthrough)
branch  2 taken 99%
        -: 2384:    {
        3: 2385:      dbus_set_error (error, DBUS_ERROR_FAILED,
call    0 returned 100%
call    1 returned 100%
call    2 returned 100%
        -: 2386:                      "Failed to delete file %s: %s\n",
        -: 2387:                      filename_c, _dbus_strerror (errno));
        3: 2388:      return FALSE;
        -: 2389:    }
        -: 2390:  else
      316: 2391:    return TRUE;
        -: 2392:}
        -: 2393:
        -: 2394:/**
        -: 2395: * Creates a directory; succeeds if the directory
        -: 2396: * is created or already existed.
        -: 2397: *
        -: 2398: * @param filename directory filename
        -: 2399: * @param error initialized error object
        -: 2400: * @returns #TRUE on success
        -: 2401: */
        -: 2402:dbus_bool_t
        -: 2403:_dbus_create_directory (const DBusString *filename,
        -: 2404:                        DBusError        *error)
function _dbus_create_directory called 6804 returned 100% blocks executed 72%
     6804: 2405:{
        -: 2406:  const char *filename_c;
        -: 2407:
     6804: 2408:  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
branch  0 taken 99% (fallthrough)
branch  1 taken 1%
call    2 returned 100%
branch  3 taken 100% (fallthrough)
branch  4 taken 0%
call    5 returned 100%
        -: 2409:  
     6804: 2410:  filename_c = _dbus_string_get_const_data (filename);
call    0 returned 100%
        -: 2411:
     6804: 2412:  if (mkdir (filename_c, 0700) < 0)
call    0 returned 100%
branch  1 taken 99% (fallthrough)
branch  2 taken 1%
        -: 2413:    {
     6801: 2414:      if (errno == EEXIST)
call    0 returned 100%
branch  1 taken 100% (fallthrough)
branch  2 taken 0%
     6801: 2415:        return TRUE;
        -: 2416:      
    #####: 2417:      dbus_set_error (error, DBUS_ERROR_FAILED,
call    0 never executed
call    1 never executed
call    2 never executed
        -: 2418:                      "Failed to create directory %s: %s\n",
        -: 2419:                      filename_c, _dbus_strerror (errno));
    #####: 2420:      return FALSE;
        -: 2421:    }
        -: 2422:  else
        3: 2423:    return TRUE;
        -: 2424:}
        -: 2425:
        -: 2426:/**
        -: 2427: * Appends the given filename to the given directory.
        -: 2428: *
        -: 2429: * @todo it might be cute to collapse multiple '/' such as "foo//"
        -: 2430: * concat "//bar"
        -: 2431: *
        -: 2432: * @param dir the directory name
        -: 2433: * @param next_component the filename
        -: 2434: * @returns #TRUE on success
        -: 2435: */
        -: 2436:dbus_bool_t
        -: 2437:_dbus_concat_dir_and_file (DBusString       *dir,
        -: 2438:                           const DBusString *next_component)
function _dbus_concat_dir_and_file called 21819 returned 100% blocks executed 81%
    21819: 2439:{
        -: 2440:  dbus_bool_t dir_ends_in_slash;
        -: 2441:  dbus_bool_t file_starts_with_slash;
        -: 2442:
    21819: 2443:  if (_dbus_string_get_length (dir) == 0 ||
call    0 returned 100%
branch  1 taken 100% (fallthrough)
branch  2 taken 0%
call    3 returned 100%
branch  4 taken 0% (fallthrough)
branch  5 taken 100%
        -: 2444:      _dbus_string_get_length (next_component) == 0)
    #####: 2445:    return TRUE;
        -: 2446:  
    21819: 2447:  dir_ends_in_slash = '/' == _dbus_string_get_byte (dir,
call    0 returned 100%
call    1 returned 100%
        -: 2448:                                                    _dbus_string_get_length (dir) - 1);
        -: 2449:
    21819: 2450:  file_starts_with_slash = '/' == _dbus_string_get_byte (next_component, 0);
call    0 returned 100%
        -: 2451:
    21819: 2452:  if (dir_ends_in_slash && file_starts_with_slash)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
branch  2 never executed
branch  3 never executed
        -: 2453:    {
    #####: 2454:      _dbus_string_shorten (dir, 1);
call    0 never executed
        -: 2455:    }
    21819: 2456:  else if (!(dir_ends_in_slash || file_starts_with_slash))
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
        -: 2457:    {
    21819: 2458:      if (!_dbus_string_append_byte (dir, '/'))
call    0 returned 100%
branch  1 taken 1% (fallthrough)
branch  2 taken 99%
       78: 2459:        return FALSE;
        -: 2460:    }
        -: 2461:
    21741: 2462:  return _dbus_string_copy (next_component, 0, dir,
call    0 returned 100%
call    1 returned 100%
        -: 2463:                            _dbus_string_get_length (dir));
        -: 2464:}
        -: 2465:
        -: 2466:static void
        -: 2467:pseudorandom_generate_random_bytes_buffer (char *buffer,
        -: 2468:                                           int   n_bytes)
function pseudorandom_generate_random_bytes_buffer called 2 returned 100% blocks executed 100%
        2: 2469:{
        -: 2470:  unsigned long tv_usec;
        -: 2471:  int i;
        -: 2472:  
        -: 2473:  /* fall back to pseudorandom */
        2: 2474:  _dbus_verbose ("Falling back to pseudorandom for %d bytes\n",
call    0 returned 100%
        -: 2475:                 n_bytes);
        -: 2476:  
        2: 2477:  _dbus_get_current_time (NULL, &tv_usec);
call    0 returned 100%
        2: 2478:  srand (tv_usec);
call    0 returned 100%
        -: 2479:  
        2: 2480:  i = 0;
       36: 2481:  while (i < n_bytes)
branch  0 taken 94%
branch  1 taken 6% (fallthrough)
        -: 2482:    {
        -: 2483:      double r;
        -: 2484:      unsigned int b;
        -: 2485:          
       32: 2486:      r = rand ();
call    0 returned 100%
       32: 2487:      b = (r / (double) RAND_MAX) * 255.0;
        -: 2488:
       32: 2489:      buffer[i] = b;
        -: 2490:
       32: 2491:      ++i;
        -: 2492:    }
        2: 2493:}
        -: 2494:
        -: 2495:static dbus_bool_t
        -: 2496:pseudorandom_generate_random_bytes (DBusString *str,
        -: 2497:                                    int         n_bytes)
function pseudorandom_generate_random_bytes called 7 returned 100% blocks executed 100%
        7: 2498:{
        -: 2499:  int old_len;
        -: 2500:  char *p;
        -: 2501:  
        7: 2502:  old_len = _dbus_string_get_length (str);
call    0 returned 100%
        -: 2503:
        7: 2504:  if (!_dbus_string_lengthen (str, n_bytes))
call    0 returned 100%
branch  1 taken 71% (fallthrough)
branch  2 taken 29%
        5: 2505:    return FALSE;
        -: 2506:
        2: 2507:  p = _dbus_string_get_data_len (str, old_len, n_bytes);
call    0 returned 100%
        -: 2508:
        2: 2509:  pseudorandom_generate_random_bytes_buffer (p, n_bytes);
call    0 returned 100%
        -: 2510:
        2: 2511:  return TRUE;
        -: 2512:}
        -: 2513:
        -: 2514:/**
        -: 2515: * Fills n_bytes of the given buffer with random bytes.
        -: 2516: *
        -: 2517: * @param buffer an allocated buffer
        -: 2518: * @param n_bytes the number of bytes in buffer to write to
        -: 2519: */
        -: 2520:void
        -: 2521:_dbus_generate_random_bytes_buffer (char *buffer,
        -: 2522:                                    int   n_bytes)
function _dbus_generate_random_bytes_buffer called 15 returned 100% blocks executed 58%
       15: 2523:{
        -: 2524:  DBusString str;
        -: 2525:
       15: 2526:  if (!_dbus_string_init (&str))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -: 2527:    {
    #####: 2528:      pseudorandom_generate_random_bytes_buffer (buffer, n_bytes);
call    0 never executed
    #####: 2529:      return;
        -: 2530:    }
        -: 2531:
       15: 2532:  if (!_dbus_generate_random_bytes (&str, n_bytes))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -: 2533:    {
    #####: 2534:      _dbus_string_free (&str);
call    0 never executed
    #####: 2535:      pseudorandom_generate_random_bytes_buffer (buffer, n_bytes);
call    0 never executed
    #####: 2536:      return;
        -: 2537:    }
        -: 2538:
       15: 2539:  _dbus_string_copy_to_buffer (&str, buffer, n_bytes);
call    0 returned 100%
        -: 2540:
       15: 2541:  _dbus_string_free (&str);
call    0 returned 100%
        -: 2542:}
        -: 2543:
        -: 2544:/**
        -: 2545: * Generates the given number of random bytes,
        -: 2546: * using the best mechanism we can come up with.
        -: 2547: *
        -: 2548: * @param str the string
        -: 2549: * @param n_bytes the number of random bytes to append to string
        -: 2550: * @returns #TRUE on success, #FALSE if no memory
        -: 2551: */
        -: 2552:dbus_bool_t
        -: 2553:_dbus_generate_random_bytes (DBusString *str,
        -: 2554:                             int         n_bytes)
function _dbus_generate_random_bytes called 8325 returned 100% blocks executed 87%
     8325: 2555:{
        -: 2556:  int old_len;
        -: 2557:  int fd;
        -: 2558:
        -: 2559:  /* FALSE return means "no memory", if it could
        -: 2560:   * mean something else then we'd need to return
        -: 2561:   * a DBusError. So we always fall back to pseudorandom
        -: 2562:   * if the I/O fails.
        -: 2563:   */
        -: 2564:  
     8325: 2565:  old_len = _dbus_string_get_length (str);
call    0 returned 100%
     8325: 2566:  fd = -1;
        -: 2567:
        -: 2568:  /* note, urandom on linux will fall back to pseudorandom */
     8325: 2569:  fd = open ("/dev/urandom", O_RDONLY);
call    0 returned 100%
     8325: 2570:  if (fd < 0)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####: 2571:    return pseudorandom_generate_random_bytes (str, n_bytes);
call    0 never executed
        -: 2572:
     8325: 2573:  if (_dbus_read (fd, str, n_bytes) != n_bytes)
call    0 returned 100%
branch  1 taken 1% (fallthrough)
branch  2 taken 99%
        -: 2574:    {
        7: 2575:      close (fd);
call    0 returned 100%
        7: 2576:      _dbus_string_set_length (str, old_len);
call    0 returned 100%
        7: 2577:      return pseudorandom_generate_random_bytes (str, n_bytes);
call    0 returned 100%
        -: 2578:    }
        -: 2579:
     8318: 2580:  _dbus_verbose ("Read %d bytes from /dev/urandom\n",
call    0 returned 100%
        -: 2581:                 n_bytes);
        -: 2582:  
     8318: 2583:  close (fd);
call    0 returned 100%
        -: 2584:  
     8318: 2585:  return TRUE;
        -: 2586:}
        -: 2587:
        -: 2588:/**
        -: 2589: * Generates the given number of random bytes, where the bytes are
        -: 2590: * chosen from the alphanumeric ASCII subset.
        -: 2591: *
        -: 2592: * @param str the string
        -: 2593: * @param n_bytes the number of random ASCII bytes to append to string
        -: 2594: * @returns #TRUE on success, #FALSE if no memory or other failure
        -: 2595: */
        -: 2596:dbus_bool_t
        -: 2597:_dbus_generate_random_ascii (DBusString *str,
        -: 2598:                             int         n_bytes)
function _dbus_generate_random_ascii called 314 returned 100% blocks executed 92%
      314: 2599:{
        -: 2600:  static const char letters[] =
        -: 2601:    "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
        -: 2602:  int i;
        -: 2603:  int len;
        -: 2604:  
      314: 2605:  if (!_dbus_generate_random_bytes (str, n_bytes))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####: 2606:    return FALSE;
        -: 2607:  
      314: 2608:  len = _dbus_string_get_length (str);
call    0 returned 100%
      314: 2609:  i = len - n_bytes;
     3144: 2610:  while (i < len)
branch  0 taken 89%
branch  1 taken 11% (fallthrough)
        -: 2611:    {
     2516: 2612:      _dbus_string_set_byte (str, i,
call    0 returned 100%
call    1 returned 100%
        -: 2613:                             letters[_dbus_string_get_byte (str, i) %
        -: 2614:                                     (sizeof (letters) - 1)]);
        -: 2615:
     2516: 2616:      ++i;
        -: 2617:    }
        -: 2618:
      314: 2619:  _dbus_assert (_dbus_string_validate_ascii (str, len - n_bytes,
call    0 returned 100%
call    1 returned 100%
        -: 2620:                                             n_bytes));
        -: 2621:
      314: 2622:  return TRUE;
        -: 2623:}
        -: 2624:
        -: 2625:/**
        -: 2626: * A wrapper around strerror() because some platforms
        -: 2627: * may be lame and not have strerror().
        -: 2628: *
        -: 2629: * @param error_number errno.
        -: 2630: * @returns error description.
        -: 2631: */
        -: 2632:const char*
        -: 2633:_dbus_strerror (int error_number)
function _dbus_strerror called 194 returned 100% blocks executed 75%
      194: 2634:{
        -: 2635:  const char *msg;
        -: 2636:  
      194: 2637:  msg = strerror (error_number);
call    0 returned 100%
      194: 2638:  if (msg == NULL)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####: 2639:    msg = "unknown";
        -: 2640:
      194: 2641:  return msg;
        -: 2642:}
        -: 2643:
        -: 2644:/**
        -: 2645: * signal (SIGPIPE, SIG_IGN);
        -: 2646: */
        -: 2647:void
        -: 2648:_dbus_disable_sigpipe (void)
function _dbus_disable_sigpipe called 14278 returned 100% blocks executed 100%
    14278: 2649:{
    14278: 2650:  signal (SIGPIPE, SIG_IGN);
call    0 returned 100%
    14278: 2651:}
        -: 2652:
        -: 2653:/**
        -: 2654: * Sets the file descriptor to be close
        -: 2655: * on exec. Should be called for all file
        -: 2656: * descriptors in D-BUS code.
        -: 2657: *
        -: 2658: * @param fd the file descriptor
        -: 2659: */
        -: 2660:void
        -: 2661:_dbus_fd_set_close_on_exec (int fd)
function _dbus_fd_set_close_on_exec called 24832 returned 100% blocks executed 80%
    24832: 2662:{
        -: 2663:  int val;
        -: 2664:  
    24832: 2665:  val = fcntl (fd, F_GETFD, 0);
call    0 returned 100%
        -: 2666:  
    24832: 2667:  if (val < 0)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####: 2668:    return;
        -: 2669:
    24832: 2670:  val |= FD_CLOEXEC;
        -: 2671:  
    24832: 2672:  fcntl (fd, F_SETFD, val);
call    0 returned 100%
        -: 2673:}
        -: 2674:
        -: 2675:/**
        -: 2676: * Converts a UNIX errno into a #DBusError name.
        -: 2677: *
        -: 2678: * @todo should cover more errnos, specifically those
        -: 2679: * from open().
        -: 2680: * 
        -: 2681: * @param error_number the errno.
        -: 2682: * @returns an error name
        -: 2683: */
        -: 2684:const char*
        -: 2685:_dbus_error_from_errno (int error_number)
function _dbus_error_from_errno called 138 returned 100% blocks executed 22%
      138: 2686:{
      138: 2687:  switch (error_number)
branch  0 taken 0%
branch  1 taken 0%
branch  2 taken 0%
branch  3 taken 0%
branch  4 taken 0%
branch  5 taken 0%
branch  6 taken 0%
branch  7 taken 0%
branch  8 taken 4%
branch  9 taken 0%
branch 10 taken 0%
branch 11 taken 0%
branch 12 taken 0%
branch 13 taken 0%
branch 14 taken 0%
branch 15 taken 0%
branch 16 taken 0%
branch 17 taken 0%
branch 18 taken 0%
branch 19 taken 17%
branch 20 taken 79%
        -: 2688:    {
        -: 2689:    case 0:
    #####: 2690:      return DBUS_ERROR_FAILED;
        -: 2691:      
        -: 2692:#ifdef EPROTONOSUPPORT
        -: 2693:    case EPROTONOSUPPORT:
    #####: 2694:      return DBUS_ERROR_NOT_SUPPORTED;
        -: 2695:#endif
        -: 2696:#ifdef EAFNOSUPPORT
        -: 2697:    case EAFNOSUPPORT:
    #####: 2698:      return DBUS_ERROR_NOT_SUPPORTED;
        -: 2699:#endif
        -: 2700:#ifdef ENFILE
        -: 2701:    case ENFILE:
    #####: 2702:      return DBUS_ERROR_LIMITS_EXCEEDED; /* kernel out of memory */
        -: 2703:#endif
        -: 2704:#ifdef EMFILE
        -: 2705:    case EMFILE:
    #####: 2706:      return DBUS_ERROR_LIMITS_EXCEEDED;
        -: 2707:#endif
        -: 2708:#ifdef EACCES
        -: 2709:    case EACCES:
    #####: 2710:      return DBUS_ERROR_ACCESS_DENIED;
        -: 2711:#endif
        -: 2712:#ifdef EPERM
        -: 2713:    case EPERM:
    #####: 2714:      return DBUS_ERROR_ACCESS_DENIED;
        -: 2715:#endif
        -: 2716:#ifdef ENOBUFS
        -: 2717:    case ENOBUFS:
    #####: 2718:      return DBUS_ERROR_NO_MEMORY;
        -: 2719:#endif
        -: 2720:#ifdef ENOMEM
        -: 2721:    case ENOMEM:
        5: 2722:      return DBUS_ERROR_NO_MEMORY;
        -: 2723:#endif
        -: 2724:#ifdef EINVAL
        -: 2725:    case EINVAL:
    #####: 2726:      return DBUS_ERROR_FAILED;
        -: 2727:#endif
        -: 2728:#ifdef EBADF
        -: 2729:    case EBADF:
    #####: 2730:      return DBUS_ERROR_FAILED;
        -: 2731:#endif
        -: 2732:#ifdef EFAULT
        -: 2733:    case EFAULT:
    #####: 2734:      return DBUS_ERROR_FAILED;
        -: 2735:#endif
        -: 2736:#ifdef ENOTSOCK
        -: 2737:    case ENOTSOCK:
    #####: 2738:      return DBUS_ERROR_FAILED;
        -: 2739:#endif
        -: 2740:#ifdef EISCONN
        -: 2741:    case EISCONN:
    #####: 2742:      return DBUS_ERROR_FAILED;
        -: 2743:#endif
        -: 2744:#ifdef ECONNREFUSED
        -: 2745:    case ECONNREFUSED:
    #####: 2746:      return DBUS_ERROR_NO_SERVER;
        -: 2747:#endif
        -: 2748:#ifdef ETIMEDOUT
        -: 2749:    case ETIMEDOUT:
    #####: 2750:      return DBUS_ERROR_TIMEOUT;
        -: 2751:#endif
        -: 2752:#ifdef ENETUNREACH
        -: 2753:    case ENETUNREACH:
    #####: 2754:      return DBUS_ERROR_NO_NETWORK;
        -: 2755:#endif
        -: 2756:#ifdef EADDRINUSE
        -: 2757:    case EADDRINUSE:
    #####: 2758:      return DBUS_ERROR_ADDRESS_IN_USE;
        -: 2759:#endif
        -: 2760:#ifdef EEXIST
        -: 2761:    case EEXIST:
    #####: 2762:      return DBUS_ERROR_FILE_NOT_FOUND;
        -: 2763:#endif
        -: 2764:#ifdef ENOENT
        -: 2765:    case ENOENT:
       24: 2766:      return DBUS_ERROR_FILE_NOT_FOUND;
        -: 2767:#endif
        -: 2768:    }
        -: 2769:
      109: 2770:  return DBUS_ERROR_FAILED;
        -: 2771:}
        -: 2772:
        -: 2773:/**
        -: 2774: * Exit the process, returning the given value.
        -: 2775: *
        -: 2776: * @param code the exit code
        -: 2777: */
        -: 2778:void
        -: 2779:_dbus_exit (int code)
function _dbus_exit called 0 returned 0% blocks executed 0%
    #####: 2780:{
    #####: 2781:  _exit (code);
call    0 never executed
        -: 2782:}
        -: 2783:
        -: 2784:/**
        -: 2785: * Closes a file descriptor.
        -: 2786: *
        -: 2787: * @param fd the file descriptor
        -: 2788: * @param error error object
        -: 2789: * @returns #FALSE if error set
        -: 2790: */
        -: 2791:dbus_bool_t
        -: 2792:_dbus_close (int        fd,
        -: 2793:             DBusError *error)
function _dbus_close called 14731 returned 100% blocks executed 41%
    14731: 2794:{
    14731: 2795:  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
call    2 never executed
branch  3 never executed
branch  4 never executed
call    5 returned 100%
        -: 2796:  
    14731: 2797: again:
    14731: 2798:  if (close (fd) < 0)
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -: 2799:    {
    #####: 2800:      if (errno == EINTR)
call    0 never executed
branch  1 never executed
branch  2 never executed
    #####: 2801:        goto again;
        -: 2802:
    #####: 2803:      dbus_set_error (error, _dbus_error_from_errno (errno),
call    0 never executed
call    1 never executed
call    2 never executed
        -: 2804:                      "Could not close fd %d", fd);
    #####: 2805:      return FALSE;
        -: 2806:    }
        -: 2807:
    14731: 2808:  return TRUE;
        -: 2809:}
        -: 2810:
        -: 2811:/**
        -: 2812: * Sets a file descriptor to be nonblocking.
        -: 2813: *
        -: 2814: * @param fd the file descriptor.
        -: 2815: * @param error address of error location.
        -: 2816: * @returns #TRUE on success.
        -: 2817: */
        -: 2818:dbus_bool_t
        -: 2819:_dbus_set_fd_nonblocking (int             fd,
        -: 2820:                          DBusError      *error)
function _dbus_set_fd_nonblocking called 15211 returned 100% blocks executed 37%
    15211: 2821:{
        -: 2822:  int val;
        -: 2823:
    15211: 2824:  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
branch  0 taken 6% (fallthrough)
branch  1 taken 94%
call    2 returned 100%
branch  3 taken 100% (fallthrough)
branch  4 taken 0%
call    5 returned 100%
        -: 2825:  
    15211: 2826:  val = fcntl (fd, F_GETFL, 0);
call    0 returned 100%
    15211: 2827:  if (val < 0)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -: 2828:    {
    #####: 2829:      dbus_set_error (error, _dbus_error_from_errno (errno),
call    0 never executed
call    1 never executed
call    2 never executed
call    3 never executed
call    4 never executed
        -: 2830:                      "Failed to get flags from file descriptor %d: %s",
        -: 2831:                      fd, _dbus_strerror (errno));
    #####: 2832:      _dbus_verbose ("Failed to get flags for fd %d: %s\n", fd,
call    0 never executed
call    1 never executed
call    2 never executed
        -: 2833:                     _dbus_strerror (errno));
    #####: 2834:      return FALSE;
        -: 2835:    }
        -: 2836:
    15211: 2837:  if (fcntl (fd, F_SETFL, val | O_NONBLOCK) < 0)
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -: 2838:    {
    #####: 2839:      dbus_set_error (error, _dbus_error_from_errno (errno),
call    0 never executed
call    1 never executed
call    2 never executed
call    3 never executed
call    4 never executed
        -: 2840:                      "Failed to set nonblocking flag of file descriptor %d: %s",
        -: 2841:                      fd, _dbus_strerror (errno));
    #####: 2842:      _dbus_verbose ("Failed to set fd %d nonblocking: %s\n",
call    0 never executed
call    1 never executed
call    2 never executed
        -: 2843:                     fd, _dbus_strerror (errno));
        -: 2844:
    #####: 2845:      return FALSE;
        -: 2846:    }
        -: 2847:
    15211: 2848:  return TRUE;
        -: 2849:}
        -: 2850:
        -: 2851:#if !defined (DBUS_DISABLE_ASSERT) || defined(DBUS_BUILD_TESTS)
        -: 2852:/**
        -: 2853: * On GNU libc systems, print a crude backtrace to the verbose log.
        -: 2854: * On other systems, print "no backtrace support"
        -: 2855: *
        -: 2856: */
        -: 2857:void
        -: 2858:_dbus_print_backtrace (void)
function _dbus_print_backtrace called 0 returned 0% blocks executed 0%
    #####: 2859:{
        -: 2860:#if defined (HAVE_BACKTRACE) && defined (DBUS_ENABLE_VERBOSE_MODE)
        -: 2861:  void *bt[500];
        -: 2862:  int bt_size;
        -: 2863:  int i;
        -: 2864:  char **syms;
        -: 2865:  
    #####: 2866:  bt_size = backtrace (bt, 500);
call    0 never executed
        -: 2867:
    #####: 2868:  syms = backtrace_symbols (bt, bt_size);
call    0 never executed
        -: 2869:  
    #####: 2870:  i = 0;
    #####: 2871:  while (i < bt_size)
branch  0 never executed
branch  1 never executed
        -: 2872:    {
    #####: 2873:      _dbus_verbose ("  %s\n", syms[i]);
call    0 never executed
    #####: 2874:      ++i;
        -: 2875:    }
        -: 2876:
    #####: 2877:  free (syms);
call    0 never executed
        -: 2878:#else
        -: 2879:  _dbus_verbose ("  D-BUS not compiled with backtrace support\n");
        -: 2880:#endif
    #####: 2881:}
        -: 2882:#endif /* asserts or tests enabled */
        -: 2883:
        -: 2884:
        -: 2885:/**
        -: 2886: * Gets a UID from a UID string.
        -: 2887: *
        -: 2888: * @param uid_str the UID in string form
        -: 2889: * @param uid UID to fill in
        -: 2890: * @returns #TRUE if successfully filled in UID
        -: 2891: */
        -: 2892:dbus_bool_t
        -: 2893:_dbus_parse_uid (const DBusString      *uid_str,
        -: 2894:                 dbus_uid_t            *uid)
function _dbus_parse_uid called 3841 returned 100% blocks executed 57%
     3841: 2895:{
        -: 2896:  int end;
        -: 2897:  long val;
        -: 2898:  
     3841: 2899:  if (_dbus_string_get_length (uid_str) == 0)
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -: 2900:    {
    #####: 2901:      _dbus_verbose ("UID string was zero length\n");
call    0 never executed
    #####: 2902:      return FALSE;
        -: 2903:    }
        -: 2904:
     3841: 2905:  val = -1;
     3841: 2906:  end = 0;
     3841: 2907:  if (!_dbus_string_parse_int (uid_str, 0, &val,
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -: 2908:                               &end))
        -: 2909:    {
    #####: 2910:      _dbus_verbose ("could not parse string as a UID\n");
call    0 never executed
    #####: 2911:      return FALSE;
        -: 2912:    }
        -: 2913:  
     3841: 2914:  if (end != _dbus_string_get_length (uid_str))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -: 2915:    {
    #####: 2916:      _dbus_verbose ("string contained trailing stuff after UID\n");
call    0 never executed
    #####: 2917:      return FALSE;
        -: 2918:    }
        -: 2919:
     3841: 2920:  *uid = val;
        -: 2921:
     3841: 2922:  return TRUE;
        -: 2923:}
        -: 2924:
        -: 2925:/**
        -: 2926: * Creates a full-duplex pipe (as in socketpair()).
        -: 2927: * Sets both ends of the pipe nonblocking.
        -: 2928: *
        -: 2929: * @todo libdbus only uses this for the debug-pipe server, so in
        -: 2930: * principle it could be in dbus-sysdeps-util.c, except that
        -: 2931: * dbus-sysdeps-util.c isn't in libdbus when tests are enabled and the
        -: 2932: * debug-pipe server is used.
        -: 2933: * 
        -: 2934: * @param fd1 return location for one end
        -: 2935: * @param fd2 return location for the other end
        -: 2936: * @param blocking #TRUE if pipe should be blocking
        -: 2937: * @param error error return
        -: 2938: * @returns #FALSE on failure (if error is set)
        -: 2939: */
        -: 2940:dbus_bool_t
        -: 2941:_dbus_full_duplex_pipe (int        *fd1,
        -: 2942:                        int        *fd2,
        -: 2943:                        dbus_bool_t blocking,
        -: 2944:                        DBusError  *error)
function _dbus_full_duplex_pipe called 9109 returned 100% blocks executed 58%
     9109: 2945:{
        -: 2946:#ifdef HAVE_SOCKETPAIR
        -: 2947:  int fds[2];
        -: 2948:
     9109: 2949:  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
branch  0 taken 35% (fallthrough)
branch  1 taken 65%
call    2 returned 100%
branch  3 taken 100% (fallthrough)
branch  4 taken 0%
call    5 returned 100%
        -: 2950:  
     9109: 2951:  if (socketpair (AF_UNIX, SOCK_STREAM, 0, fds) < 0)
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -: 2952:    {
    #####: 2953:      dbus_set_error (error, _dbus_error_from_errno (errno),
call    0 never executed
call    1 never executed
call    2 never executed
        -: 2954:                      "Could not create full-duplex pipe");
    #####: 2955:      return FALSE;
        -: 2956:    }
        -: 2957:
     9109: 2958:  if (!blocking &&
branch  0 taken 65% (fallthrough)
branch  1 taken 35%
call    2 returned 100%
branch  3 taken 100% (fallthrough)
branch  4 taken 0%
call    5 returned 100%
branch  6 taken 0% (fallthrough)
branch  7 taken 100%
        -: 2959:      (!_dbus_set_fd_nonblocking (fds[0], NULL) ||
        -: 2960:       !_dbus_set_fd_nonblocking (fds[1], NULL)))
        -: 2961:    {
    #####: 2962:      dbus_set_error (error, _dbus_error_from_errno (errno),
call    0 never executed
call    1 never executed
call    2 never executed
        -: 2963:                      "Could not set full-duplex pipe nonblocking");
        -: 2964:      
    #####: 2965:      close (fds[0]);
call    0 never executed
    #####: 2966:      close (fds[1]);
call    0 never executed
        -: 2967:      
    #####: 2968:      return FALSE;
        -: 2969:    }
        -: 2970:  
     9109: 2971:  *fd1 = fds[0];
     9109: 2972:  *fd2 = fds[1];
        -: 2973:
     9109: 2974:  _dbus_verbose ("full-duplex pipe %d <-> %d\n",
call    0 returned 100%
        -: 2975:                 *fd1, *fd2);
        -: 2976:  
     9109: 2977:  return TRUE;  
        -: 2978:#else
        -: 2979:  _dbus_warn ("_dbus_full_duplex_pipe() not implemented on this OS\n");
        -: 2980:  dbus_set_error (error, DBUS_ERROR_FAILED,
        -: 2981:                  "_dbus_full_duplex_pipe() not implemented on this OS");
        -: 2982:  return FALSE;
        -: 2983:#endif
        -: 2984:}
        -: 2985:
        -: 2986:/** @} end of sysdeps */
        -: 2987:
        -: 2988:/* tests in dbus-sysdeps-util.c */