Current File : //usr/share/doc/dbus/api/dbus-sysdeps-unix_8c_source.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>D-Bus: dbus-sysdeps-unix.c Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">D-Bus
   &#160;<span id="projectnumber">1.8.20</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">dbus-sysdeps-unix.c</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* -*- mode: C; c-file-style: &quot;gnu&quot;; indent-tabs-mode: nil; -*- */</span>
<a name="l00002"></a>00002 <span class="comment">/* dbus-sysdeps-unix.c Wrappers around UNIX system/libc features (internal to D-Bus implementation)</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002, 2003, 2006  Red Hat, Inc.</span>
<a name="l00005"></a>00005 <span class="comment"> * Copyright (C) 2003 CodeFactory AB</span>
<a name="l00006"></a>00006 <span class="comment"> *</span>
<a name="l00007"></a>00007 <span class="comment"> * Licensed under the Academic Free License version 2.1</span>
<a name="l00008"></a>00008 <span class="comment"> *</span>
<a name="l00009"></a>00009 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
<a name="l00010"></a>00010 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
<a name="l00011"></a>00011 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
<a name="l00012"></a>00012 <span class="comment"> * (at your option) any later version.</span>
<a name="l00013"></a>00013 <span class="comment"> *</span>
<a name="l00014"></a>00014 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
<a name="l00015"></a>00015 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00016"></a>00016 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<a name="l00017"></a>00017 <span class="comment"> * GNU General Public License for more details.</span>
<a name="l00018"></a>00018 <span class="comment"> *</span>
<a name="l00019"></a>00019 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
<a name="l00020"></a>00020 <span class="comment"> * along with this program; if not, write to the Free Software</span>
<a name="l00021"></a>00021 <span class="comment"> * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA</span>
<a name="l00022"></a>00022 <span class="comment"> *</span>
<a name="l00023"></a>00023 <span class="comment"> */</span>
<a name="l00024"></a>00024 
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;config.h&gt;</span>
<a name="l00026"></a>00026 
<a name="l00027"></a>00027 <span class="preprocessor">#include &quot;dbus-internals.h&quot;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &quot;dbus-sysdeps.h&quot;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include &quot;dbus-sysdeps-unix.h&quot;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &quot;dbus-threads.h&quot;</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &quot;dbus-protocol.h&quot;</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include &quot;dbus-transport.h&quot;</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include &quot;dbus-string.h&quot;</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include &quot;dbus-userdb.h&quot;</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include &quot;dbus-list.h&quot;</span>
<a name="l00036"></a>00036 <span class="preprocessor">#include &quot;dbus-credentials.h&quot;</span>
<a name="l00037"></a>00037 <span class="preprocessor">#include &quot;dbus-nonce.h&quot;</span>
<a name="l00038"></a>00038 
<a name="l00039"></a>00039 <span class="preprocessor">#include &lt;sys/types.h&gt;</span>
<a name="l00040"></a>00040 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00041"></a>00041 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00042"></a>00042 <span class="preprocessor">#include &lt;signal.h&gt;</span>
<a name="l00043"></a>00043 <span class="preprocessor">#include &lt;unistd.h&gt;</span>
<a name="l00044"></a>00044 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00045"></a>00045 <span class="preprocessor">#include &lt;fcntl.h&gt;</span>
<a name="l00046"></a>00046 <span class="preprocessor">#include &lt;sys/socket.h&gt;</span>
<a name="l00047"></a>00047 <span class="preprocessor">#include &lt;dirent.h&gt;</span>
<a name="l00048"></a>00048 <span class="preprocessor">#include &lt;sys/un.h&gt;</span>
<a name="l00049"></a>00049 <span class="preprocessor">#include &lt;pwd.h&gt;</span>
<a name="l00050"></a>00050 <span class="preprocessor">#include &lt;time.h&gt;</span>
<a name="l00051"></a>00051 <span class="preprocessor">#include &lt;locale.h&gt;</span>
<a name="l00052"></a>00052 <span class="preprocessor">#include &lt;sys/time.h&gt;</span>
<a name="l00053"></a>00053 <span class="preprocessor">#include &lt;sys/stat.h&gt;</span>
<a name="l00054"></a>00054 <span class="preprocessor">#include &lt;sys/wait.h&gt;</span>
<a name="l00055"></a>00055 <span class="preprocessor">#include &lt;netinet/in.h&gt;</span>
<a name="l00056"></a>00056 <span class="preprocessor">#include &lt;netdb.h&gt;</span>
<a name="l00057"></a>00057 <span class="preprocessor">#include &lt;grp.h&gt;</span>
<a name="l00058"></a>00058 <span class="preprocessor">#include &lt;arpa/inet.h&gt;</span>
<a name="l00059"></a>00059 <span class="preprocessor">#include &lt;alloca.h&gt;</span>
<a name="l00060"></a>00060 
<a name="l00061"></a>00061 <span class="preprocessor">#ifdef HAVE_ERRNO_H</span>
<a name="l00062"></a>00062 <span class="preprocessor"></span><span class="preprocessor">#include &lt;errno.h&gt;</span>
<a name="l00063"></a>00063 <span class="preprocessor">#endif</span>
<a name="l00064"></a>00064 <span class="preprocessor"></span><span class="preprocessor">#ifdef HAVE_WRITEV</span>
<a name="l00065"></a>00065 <span class="preprocessor"></span><span class="preprocessor">#include &lt;sys/uio.h&gt;</span>
<a name="l00066"></a>00066 <span class="preprocessor">#endif</span>
<a name="l00067"></a>00067 <span class="preprocessor"></span><span class="preprocessor">#ifdef HAVE_POLL</span>
<a name="l00068"></a>00068 <span class="preprocessor"></span><span class="preprocessor">#include &lt;sys/poll.h&gt;</span>
<a name="l00069"></a>00069 <span class="preprocessor">#endif</span>
<a name="l00070"></a>00070 <span class="preprocessor"></span><span class="preprocessor">#ifdef HAVE_BACKTRACE</span>
<a name="l00071"></a>00071 <span class="preprocessor"></span><span class="preprocessor">#include &lt;execinfo.h&gt;</span>
<a name="l00072"></a>00072 <span class="preprocessor">#endif</span>
<a name="l00073"></a>00073 <span class="preprocessor"></span><span class="preprocessor">#ifdef HAVE_GETPEERUCRED</span>
<a name="l00074"></a>00074 <span class="preprocessor"></span><span class="preprocessor">#include &lt;ucred.h&gt;</span>
<a name="l00075"></a>00075 <span class="preprocessor">#endif</span>
<a name="l00076"></a>00076 <span class="preprocessor"></span><span class="preprocessor">#ifdef HAVE_ALLOCA_H</span>
<a name="l00077"></a>00077 <span class="preprocessor"></span><span class="preprocessor">#include &lt;alloca.h&gt;</span>
<a name="l00078"></a>00078 <span class="preprocessor">#endif</span>
<a name="l00079"></a>00079 <span class="preprocessor"></span>
<a name="l00080"></a>00080 <span class="preprocessor">#ifdef HAVE_ADT</span>
<a name="l00081"></a>00081 <span class="preprocessor"></span><span class="preprocessor">#include &lt;bsm/adt.h&gt;</span>
<a name="l00082"></a>00082 <span class="preprocessor">#endif</span>
<a name="l00083"></a>00083 <span class="preprocessor"></span>
<a name="l00084"></a>00084 <span class="preprocessor">#include &quot;sd-daemon.h&quot;</span>
<a name="l00085"></a>00085 
<a name="l00086"></a>00086 <span class="preprocessor">#if !DBUS_USE_SYNC</span>
<a name="l00087"></a>00087 <span class="preprocessor"></span><span class="preprocessor">#include &lt;pthread.h&gt;</span>
<a name="l00088"></a>00088 <span class="preprocessor">#endif</span>
<a name="l00089"></a>00089 <span class="preprocessor"></span>
<a name="l00090"></a>00090 <span class="preprocessor">#ifndef O_BINARY</span>
<a name="l00091"></a>00091 <span class="preprocessor"></span><span class="preprocessor">#define O_BINARY 0</span>
<a name="l00092"></a>00092 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00093"></a>00093 <span class="preprocessor"></span>
<a name="l00094"></a>00094 <span class="preprocessor">#ifndef AI_ADDRCONFIG</span>
<a name="l00095"></a>00095 <span class="preprocessor"></span><span class="preprocessor">#define AI_ADDRCONFIG 0</span>
<a name="l00096"></a>00096 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00097"></a>00097 <span class="preprocessor"></span>
<a name="l00098"></a>00098 <span class="preprocessor">#ifndef HAVE_SOCKLEN_T</span>
<a name="l00099"></a>00099 <span class="preprocessor"></span><span class="preprocessor">#define socklen_t int</span>
<a name="l00100"></a>00100 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00101"></a>00101 <span class="preprocessor"></span>
<a name="l00102"></a>00102 <span class="preprocessor">#if defined (__sun) || defined (__sun__)</span>
<a name="l00103"></a>00103 <span class="preprocessor"></span><span class="comment">/*</span>
<a name="l00104"></a>00104 <span class="comment"> * CMS_SPACE etc. definitions for Solaris &lt; 10, based on</span>
<a name="l00105"></a>00105 <span class="comment"> *   http://mailman.videolan.org/pipermail/vlc-devel/2006-May/024402.html</span>
<a name="l00106"></a>00106 <span class="comment"> * via</span>
<a name="l00107"></a>00107 <span class="comment"> *   http://wiki.opencsw.org/porting-faq#toc10</span>
<a name="l00108"></a>00108 <span class="comment"> *</span>
<a name="l00109"></a>00109 <span class="comment"> * These are only redefined for Solaris, for now: if your OS needs these too,</span>
<a name="l00110"></a>00110 <span class="comment"> * please file a bug. (Or preferably, improve your OS so they&#39;re not needed.)</span>
<a name="l00111"></a>00111 <span class="comment"> */</span>
<a name="l00112"></a>00112 
<a name="l00113"></a>00113 <span class="preprocessor"># ifndef CMSG_ALIGN</span>
<a name="l00114"></a>00114 <span class="preprocessor"></span><span class="preprocessor">#   ifdef __sun__</span>
<a name="l00115"></a>00115 <span class="preprocessor"></span><span class="preprocessor">#     define CMSG_ALIGN(len) _CMSG_DATA_ALIGN (len)</span>
<a name="l00116"></a>00116 <span class="preprocessor"></span><span class="preprocessor">#   else</span>
<a name="l00117"></a>00117 <span class="preprocessor"></span>      <span class="comment">/* aligning to sizeof (long) is assumed to be portable (fd.o#40235) */</span>
<a name="l00118"></a>00118 <span class="preprocessor">#     define CMSG_ALIGN(len) (((len) + sizeof (long) - 1) &amp; \</span>
<a name="l00119"></a>00119 <span class="preprocessor">                              ~(sizeof (long) - 1))</span>
<a name="l00120"></a>00120 <span class="preprocessor"></span><span class="preprocessor">#   endif</span>
<a name="l00121"></a>00121 <span class="preprocessor"></span><span class="preprocessor"># endif</span>
<a name="l00122"></a>00122 <span class="preprocessor"></span>
<a name="l00123"></a>00123 <span class="preprocessor"># ifndef CMSG_SPACE</span>
<a name="l00124"></a>00124 <span class="preprocessor"></span><span class="preprocessor">#   define CMSG_SPACE(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + \</span>
<a name="l00125"></a>00125 <span class="preprocessor">                            CMSG_ALIGN (len))</span>
<a name="l00126"></a>00126 <span class="preprocessor"></span><span class="preprocessor"># endif</span>
<a name="l00127"></a>00127 <span class="preprocessor"></span>
<a name="l00128"></a>00128 <span class="preprocessor"># ifndef CMSG_LEN</span>
<a name="l00129"></a>00129 <span class="preprocessor"></span><span class="preprocessor">#   define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len))</span>
<a name="l00130"></a>00130 <span class="preprocessor"></span><span class="preprocessor"># endif</span>
<a name="l00131"></a>00131 <span class="preprocessor"></span>
<a name="l00132"></a>00132 <span class="preprocessor">#endif </span><span class="comment">/* Solaris */</span>
<a name="l00133"></a>00133 
<a name="l00134"></a>00134 <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l00135"></a>00135 _dbus_open_socket (<span class="keywordtype">int</span>              *fd_p,
<a name="l00136"></a>00136                    <span class="keywordtype">int</span>               domain,
<a name="l00137"></a>00137                    <span class="keywordtype">int</span>               type,
<a name="l00138"></a>00138                    <span class="keywordtype">int</span>               protocol,
<a name="l00139"></a>00139                    <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>        *error)
<a name="l00140"></a>00140 {
<a name="l00141"></a>00141 <span class="preprocessor">#ifdef SOCK_CLOEXEC</span>
<a name="l00142"></a>00142 <span class="preprocessor"></span>  <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> cloexec_done;
<a name="l00143"></a>00143 
<a name="l00144"></a>00144   *fd_p = socket (domain, type | SOCK_CLOEXEC, protocol);
<a name="l00145"></a>00145   cloexec_done = *fd_p &gt;= 0;
<a name="l00146"></a>00146 
<a name="l00147"></a>00147   <span class="comment">/* Check if kernel seems to be too old to know SOCK_CLOEXEC */</span>
<a name="l00148"></a>00148   <span class="keywordflow">if</span> (*fd_p &lt; 0 &amp;&amp; (errno == EINVAL || errno == EPROTOTYPE))
<a name="l00149"></a>00149 <span class="preprocessor">#endif</span>
<a name="l00150"></a>00150 <span class="preprocessor"></span>    {
<a name="l00151"></a>00151       *fd_p = socket (domain, type, protocol);
<a name="l00152"></a>00152     }
<a name="l00153"></a>00153 
<a name="l00154"></a>00154   <span class="keywordflow">if</span> (*fd_p &gt;= 0)
<a name="l00155"></a>00155     {
<a name="l00156"></a>00156 <span class="preprocessor">#ifdef SOCK_CLOEXEC</span>
<a name="l00157"></a>00157 <span class="preprocessor"></span>      <span class="keywordflow">if</span> (!cloexec_done)
<a name="l00158"></a>00158 <span class="preprocessor">#endif</span>
<a name="l00159"></a>00159 <span class="preprocessor"></span>        {
<a name="l00160"></a>00160           <a class="code" href="group__DBusSysdeps.html#ga21ef96952f98f23e590ebbf060fd5ca6" title="Sets the file descriptor to be close on exec.">_dbus_fd_set_close_on_exec</a>(*fd_p);
<a name="l00161"></a>00161         }
<a name="l00162"></a>00162 
<a name="l00163"></a>00163       _dbus_verbose (<span class="stringliteral">&quot;socket fd %d opened\n&quot;</span>, *fd_p);
<a name="l00164"></a>00164       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l00165"></a>00165     }
<a name="l00166"></a>00166   <span class="keywordflow">else</span>
<a name="l00167"></a>00167     {
<a name="l00168"></a>00168       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a>(error,
<a name="l00169"></a>00169                      <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l00170"></a>00170                      <span class="stringliteral">&quot;Failed to open socket: %s&quot;</span>,
<a name="l00171"></a>00171                      _dbus_strerror (errno));
<a name="l00172"></a>00172       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l00173"></a>00173     }
<a name="l00174"></a>00174 }
<a name="l00175"></a>00175 
<a name="l00186"></a>00186 <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l00187"></a>00187 _dbus_open_unix_socket (<span class="keywordtype">int</span>              *fd,
<a name="l00188"></a>00188                         <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>        *error)
<a name="l00189"></a>00189 {
<a name="l00190"></a>00190   <span class="keywordflow">return</span> _dbus_open_socket(fd, PF_UNIX, SOCK_STREAM, 0, error);
<a name="l00191"></a>00191 }
<a name="l00192"></a>00192 
<a name="l00201"></a>00201 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l00202"></a><a class="code" href="group__DBusSysdeps.html#ga701f9b3087c196404f66ff95b4ace0b8">00202</a> <a class="code" href="group__DBusSysdeps.html#ga701f9b3087c196404f66ff95b4ace0b8" title="Closes a socket.">_dbus_close_socket</a> (<span class="keywordtype">int</span>               fd,
<a name="l00203"></a>00203                     <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>        *error)
<a name="l00204"></a>00204 {
<a name="l00205"></a>00205   <span class="keywordflow">return</span> <a class="code" href="group__DBusSysdepsUnix.html#gac448479a1674e3b86cee9a4bdc7eba03" title="Closes a file descriptor.">_dbus_close</a> (fd, error);
<a name="l00206"></a>00206 }
<a name="l00207"></a>00207 
<a name="l00217"></a>00217 <span class="keywordtype">int</span>
<a name="l00218"></a><a class="code" href="group__DBusSysdeps.html#ga6fe72fa1c0484ac5594b08145ea19530">00218</a> <a class="code" href="group__DBusSysdeps.html#ga6fe72fa1c0484ac5594b08145ea19530" title="Like _dbus_read(), but only works on sockets so is available on Windows.">_dbus_read_socket</a> (<span class="keywordtype">int</span>               fd,
<a name="l00219"></a>00219                    <a class="code" href="structDBusString.html">DBusString</a>       *buffer,
<a name="l00220"></a>00220                    <span class="keywordtype">int</span>               count)
<a name="l00221"></a>00221 {
<a name="l00222"></a>00222   <span class="keywordflow">return</span> <a class="code" href="group__DBusSysdepsUnix.html#gaf52cb1d5b9fc5611808ce32eff898c28" title="Thin wrapper around the read() system call that appends the data it reads to the DBusString buffer...">_dbus_read</a> (fd, buffer, count);
<a name="l00223"></a>00223 }
<a name="l00224"></a>00224 
<a name="l00235"></a>00235 <span class="keywordtype">int</span>
<a name="l00236"></a><a class="code" href="group__DBusSysdeps.html#ga346cadd9b0f7d0ae1cd19007b2e4c2de">00236</a> <a class="code" href="group__DBusSysdeps.html#ga346cadd9b0f7d0ae1cd19007b2e4c2de" title="Like _dbus_write(), but only supports sockets and is thus available on Windows.">_dbus_write_socket</a> (<span class="keywordtype">int</span>               fd,
<a name="l00237"></a>00237                     <span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *buffer,
<a name="l00238"></a>00238                     <span class="keywordtype">int</span>               start,
<a name="l00239"></a>00239                     <span class="keywordtype">int</span>               len)
<a name="l00240"></a>00240 {
<a name="l00241"></a>00241 <span class="preprocessor">#if HAVE_DECL_MSG_NOSIGNAL</span>
<a name="l00242"></a>00242 <span class="preprocessor"></span>  <span class="keyword">const</span> <span class="keywordtype">char</span> *data;
<a name="l00243"></a>00243   <span class="keywordtype">int</span> bytes_written;
<a name="l00244"></a>00244 
<a name="l00245"></a>00245   data = <a class="code" href="group__DBusString.html#ga8c202a65e938f9bdb859fc6705a4f1bb" title="const version of _dbus_string_get_data_len().">_dbus_string_get_const_data_len</a> (buffer, start, len);
<a name="l00246"></a>00246 
<a name="l00247"></a>00247  again:
<a name="l00248"></a>00248 
<a name="l00249"></a>00249   bytes_written = send (fd, data, len, MSG_NOSIGNAL);
<a name="l00250"></a>00250 
<a name="l00251"></a>00251   <span class="keywordflow">if</span> (bytes_written &lt; 0 &amp;&amp; errno == EINTR)
<a name="l00252"></a>00252     <span class="keywordflow">goto</span> again;
<a name="l00253"></a>00253 
<a name="l00254"></a>00254   <span class="keywordflow">return</span> bytes_written;
<a name="l00255"></a>00255 
<a name="l00256"></a>00256 <span class="preprocessor">#else</span>
<a name="l00257"></a>00257 <span class="preprocessor"></span>  <span class="keywordflow">return</span> <a class="code" href="group__DBusSysdepsUnix.html#ga3a789bcdfd3d468c2bf917fa5081b27f" title="Thin wrapper around the write() system call that writes a part of a DBusString and handles EINTR for ...">_dbus_write</a> (fd, buffer, start, len);
<a name="l00258"></a>00258 <span class="preprocessor">#endif</span>
<a name="l00259"></a>00259 <span class="preprocessor"></span>}
<a name="l00260"></a>00260 
<a name="l00273"></a>00273 <span class="keywordtype">int</span>
<a name="l00274"></a><a class="code" href="group__DBusSysdeps.html#ga14aa692ac7e9aab777b9f565c4b8933b">00274</a> <a class="code" href="group__DBusSysdeps.html#ga14aa692ac7e9aab777b9f565c4b8933b" title="Like _dbus_read_socket() but also tries to read unix fds from the socket.">_dbus_read_socket_with_unix_fds</a> (<span class="keywordtype">int</span>               fd,
<a name="l00275"></a>00275                                  <a class="code" href="structDBusString.html">DBusString</a>       *buffer,
<a name="l00276"></a>00276                                  <span class="keywordtype">int</span>               count,
<a name="l00277"></a>00277                                  <span class="keywordtype">int</span>              *fds,
<a name="l00278"></a>00278                                  <span class="keywordtype">int</span>              *n_fds) {
<a name="l00279"></a>00279 <span class="preprocessor">#ifndef HAVE_UNIX_FD_PASSING</span>
<a name="l00280"></a>00280 <span class="preprocessor"></span>  <span class="keywordtype">int</span> r;
<a name="l00281"></a>00281 
<a name="l00282"></a>00282   <span class="keywordflow">if</span> ((r = <a class="code" href="group__DBusSysdeps.html#ga6fe72fa1c0484ac5594b08145ea19530" title="Like _dbus_read(), but only works on sockets so is available on Windows.">_dbus_read_socket</a>(fd, buffer, count)) &lt; 0)
<a name="l00283"></a>00283     <span class="keywordflow">return</span> r;
<a name="l00284"></a>00284 
<a name="l00285"></a>00285   *n_fds = 0;
<a name="l00286"></a>00286   <span class="keywordflow">return</span> r;
<a name="l00287"></a>00287 
<a name="l00288"></a>00288 <span class="preprocessor">#else</span>
<a name="l00289"></a>00289 <span class="preprocessor"></span>  <span class="keywordtype">int</span> bytes_read;
<a name="l00290"></a>00290   <span class="keywordtype">int</span> start;
<a name="l00291"></a>00291   <span class="keyword">struct </span>msghdr m;
<a name="l00292"></a>00292   <span class="keyword">struct </span>iovec iov;
<a name="l00293"></a>00293 
<a name="l00294"></a>00294   _dbus_assert (count &gt;= 0);
<a name="l00295"></a>00295   _dbus_assert (*n_fds &gt;= 0);
<a name="l00296"></a>00296 
<a name="l00297"></a>00297   start = <a class="code" href="group__DBusString.html#gaa5136e6fd2c5188f4b88de7863369c6d" title="Gets the length of a string (not including nul termination).">_dbus_string_get_length</a> (buffer);
<a name="l00298"></a>00298 
<a name="l00299"></a>00299   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga8f13997d90ceed2f437706e6b7804d9b" title="Makes a string longer by the given number of bytes.">_dbus_string_lengthen</a> (buffer, count))
<a name="l00300"></a>00300     {
<a name="l00301"></a>00301       errno = ENOMEM;
<a name="l00302"></a>00302       <span class="keywordflow">return</span> -1;
<a name="l00303"></a>00303     }
<a name="l00304"></a>00304 
<a name="l00305"></a>00305   _DBUS_ZERO(iov);
<a name="l00306"></a>00306   iov.iov_base = <a class="code" href="group__DBusString.html#ga7a73fb373398606e6e1d0a86c4587a3c" title="Gets a sub-portion of the raw character buffer from the string.">_dbus_string_get_data_len</a> (buffer, start, count);
<a name="l00307"></a>00307   iov.iov_len = count;
<a name="l00308"></a>00308 
<a name="l00309"></a>00309   _DBUS_ZERO(m);
<a name="l00310"></a>00310   m.msg_iov = &amp;iov;
<a name="l00311"></a>00311   m.msg_iovlen = 1;
<a name="l00312"></a>00312 
<a name="l00313"></a>00313   <span class="comment">/* Hmm, we have no clue how long the control data will actually be</span>
<a name="l00314"></a>00314 <span class="comment">     that is queued for us. The least we can do is assume that the</span>
<a name="l00315"></a>00315 <span class="comment">     caller knows. Hence let&#39;s make space for the number of fds that</span>
<a name="l00316"></a>00316 <span class="comment">     we shall read at max plus the cmsg header. */</span>
<a name="l00317"></a>00317   m.msg_controllen = CMSG_SPACE(*n_fds * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
<a name="l00318"></a>00318 
<a name="l00319"></a>00319   <span class="comment">/* It&#39;s probably safe to assume that systems with SCM_RIGHTS also</span>
<a name="l00320"></a>00320 <span class="comment">     know alloca() */</span>
<a name="l00321"></a>00321   m.msg_control = alloca(m.msg_controllen);
<a name="l00322"></a>00322   memset(m.msg_control, 0, m.msg_controllen);
<a name="l00323"></a>00323 
<a name="l00324"></a>00324   <span class="comment">/* Do not include the padding at the end when we tell the kernel</span>
<a name="l00325"></a>00325 <span class="comment">   * how much we&#39;re willing to receive. This avoids getting</span>
<a name="l00326"></a>00326 <span class="comment">   * the padding filled with additional fds that we weren&#39;t expecting,</span>
<a name="l00327"></a>00327 <span class="comment">   * if a (potentially malicious) sender included them. (fd.o #83622) */</span>
<a name="l00328"></a>00328   m.msg_controllen = CMSG_LEN (*n_fds * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
<a name="l00329"></a>00329 
<a name="l00330"></a>00330  again:
<a name="l00331"></a>00331 
<a name="l00332"></a>00332   bytes_read = recvmsg(fd, &amp;m, 0
<a name="l00333"></a>00333 #ifdef MSG_CMSG_CLOEXEC
<a name="l00334"></a>00334                        |MSG_CMSG_CLOEXEC
<a name="l00335"></a>00335 #endif
<a name="l00336"></a>00336                        );
<a name="l00337"></a>00337 
<a name="l00338"></a>00338   <span class="keywordflow">if</span> (bytes_read &lt; 0)
<a name="l00339"></a>00339     {
<a name="l00340"></a>00340       <span class="keywordflow">if</span> (errno == EINTR)
<a name="l00341"></a>00341         <span class="keywordflow">goto</span> again;
<a name="l00342"></a>00342       <span class="keywordflow">else</span>
<a name="l00343"></a>00343         {
<a name="l00344"></a>00344           <span class="comment">/* put length back (note that this doesn&#39;t actually realloc anything) */</span>
<a name="l00345"></a>00345           <a class="code" href="group__DBusString.html#ga08c423b93c28dd746dcb93e0461ab95c" title="Sets the length of a string.">_dbus_string_set_length</a> (buffer, start);
<a name="l00346"></a>00346           <span class="keywordflow">return</span> -1;
<a name="l00347"></a>00347         }
<a name="l00348"></a>00348     }
<a name="l00349"></a>00349   <span class="keywordflow">else</span>
<a name="l00350"></a>00350     {
<a name="l00351"></a>00351       <span class="keyword">struct </span>cmsghdr *cm;
<a name="l00352"></a>00352       <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> found = <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l00353"></a>00353 
<a name="l00354"></a>00354       <span class="keywordflow">if</span> (m.msg_flags &amp; MSG_CTRUNC)
<a name="l00355"></a>00355         {
<a name="l00356"></a>00356           <span class="comment">/* Hmm, apparently the control data was truncated. The bad</span>
<a name="l00357"></a>00357 <span class="comment">             thing is that we might have completely lost a couple of fds</span>
<a name="l00358"></a>00358 <span class="comment">             without chance to recover them. Hence let&#39;s treat this as a</span>
<a name="l00359"></a>00359 <span class="comment">             serious error. */</span>
<a name="l00360"></a>00360 
<a name="l00361"></a>00361           errno = ENOSPC;
<a name="l00362"></a>00362           <a class="code" href="group__DBusString.html#ga08c423b93c28dd746dcb93e0461ab95c" title="Sets the length of a string.">_dbus_string_set_length</a> (buffer, start);
<a name="l00363"></a>00363           <span class="keywordflow">return</span> -1;
<a name="l00364"></a>00364         }
<a name="l00365"></a>00365 
<a name="l00366"></a>00366       <span class="keywordflow">for</span> (cm = CMSG_FIRSTHDR(&amp;m); cm; cm = CMSG_NXTHDR(&amp;m, cm))
<a name="l00367"></a>00367         <span class="keywordflow">if</span> (cm-&gt;cmsg_level == SOL_SOCKET &amp;&amp; cm-&gt;cmsg_type == SCM_RIGHTS)
<a name="l00368"></a>00368           {
<a name="l00369"></a>00369             <span class="keywordtype">size_t</span> i;
<a name="l00370"></a>00370             <span class="keywordtype">int</span> *payload = (<span class="keywordtype">int</span> *) CMSG_DATA (cm);
<a name="l00371"></a>00371             <span class="keywordtype">size_t</span> payload_len_bytes = (cm-&gt;cmsg_len - CMSG_LEN (0));
<a name="l00372"></a>00372             <span class="keywordtype">size_t</span> payload_len_fds = payload_len_bytes / <span class="keyword">sizeof</span> (int);
<a name="l00373"></a>00373             <span class="keywordtype">size_t</span> fds_to_use;
<a name="l00374"></a>00374 
<a name="l00375"></a>00375             <span class="comment">/* Every non-negative int fits in a size_t without truncation,</span>
<a name="l00376"></a>00376 <span class="comment">             * and we already know that *n_fds is non-negative, so</span>
<a name="l00377"></a>00377 <span class="comment">             * casting (size_t) *n_fds is OK */</span>
<a name="l00378"></a>00378             _DBUS_STATIC_ASSERT (<span class="keyword">sizeof</span> (<span class="keywordtype">size_t</span>) &gt;= <span class="keyword">sizeof</span> (<span class="keywordtype">int</span>));
<a name="l00379"></a>00379 
<a name="l00380"></a>00380             <span class="keywordflow">if</span> (_DBUS_LIKELY (payload_len_fds &lt;= (<span class="keywordtype">size_t</span>) *n_fds))
<a name="l00381"></a>00381               {
<a name="l00382"></a>00382                 <span class="comment">/* The fds in the payload will fit in our buffer */</span>
<a name="l00383"></a>00383                 fds_to_use = payload_len_fds;
<a name="l00384"></a>00384               }
<a name="l00385"></a>00385             <span class="keywordflow">else</span>
<a name="l00386"></a>00386               {
<a name="l00387"></a>00387                 <span class="comment">/* Too many fds in the payload. This shouldn&#39;t happen</span>
<a name="l00388"></a>00388 <span class="comment">                 * any more because we&#39;re setting m.msg_controllen to</span>
<a name="l00389"></a>00389 <span class="comment">                 * the exact number we can accept, but be safe and</span>
<a name="l00390"></a>00390 <span class="comment">                 * truncate. */</span>
<a name="l00391"></a>00391                 fds_to_use = (size_t) *n_fds;
<a name="l00392"></a>00392 
<a name="l00393"></a>00393                 <span class="comment">/* Close the excess fds to avoid DoS: if they stayed open,</span>
<a name="l00394"></a>00394 <span class="comment">                 * someone could send us an extra fd per message</span>
<a name="l00395"></a>00395 <span class="comment">                 * and we&#39;d eventually run out. */</span>
<a name="l00396"></a>00396                 <span class="keywordflow">for</span> (i = fds_to_use; i &lt; payload_len_fds; i++)
<a name="l00397"></a>00397                   {
<a name="l00398"></a>00398                     close (payload[i]);
<a name="l00399"></a>00399                   }
<a name="l00400"></a>00400               }
<a name="l00401"></a>00401 
<a name="l00402"></a>00402             memcpy (fds, payload, fds_to_use * <span class="keyword">sizeof</span> (<span class="keywordtype">int</span>));
<a name="l00403"></a>00403             found = <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l00404"></a>00404             <span class="comment">/* This cannot overflow because we have chosen fds_to_use</span>
<a name="l00405"></a>00405 <span class="comment">             * to be &lt;= *n_fds */</span>
<a name="l00406"></a>00406             *n_fds = (int) fds_to_use;
<a name="l00407"></a>00407 
<a name="l00408"></a>00408             <span class="comment">/* Linux doesn&#39;t tell us whether MSG_CMSG_CLOEXEC actually</span>
<a name="l00409"></a>00409 <span class="comment">               worked, hence we need to go through this list and set</span>
<a name="l00410"></a>00410 <span class="comment">               CLOEXEC everywhere in any case */</span>
<a name="l00411"></a>00411             <span class="keywordflow">for</span> (i = 0; i &lt; fds_to_use; i++)
<a name="l00412"></a>00412               <a class="code" href="group__DBusSysdeps.html#ga21ef96952f98f23e590ebbf060fd5ca6" title="Sets the file descriptor to be close on exec.">_dbus_fd_set_close_on_exec</a>(fds[i]);
<a name="l00413"></a>00413 
<a name="l00414"></a>00414             <span class="keywordflow">break</span>;
<a name="l00415"></a>00415           }
<a name="l00416"></a>00416 
<a name="l00417"></a>00417       <span class="keywordflow">if</span> (!found)
<a name="l00418"></a>00418         *n_fds = 0;
<a name="l00419"></a>00419 
<a name="l00420"></a>00420       <span class="comment">/* put length back (doesn&#39;t actually realloc) */</span>
<a name="l00421"></a>00421       <a class="code" href="group__DBusString.html#ga08c423b93c28dd746dcb93e0461ab95c" title="Sets the length of a string.">_dbus_string_set_length</a> (buffer, start + bytes_read);
<a name="l00422"></a>00422 
<a name="l00423"></a>00423 <span class="preprocessor">#if 0</span>
<a name="l00424"></a>00424 <span class="preprocessor"></span>      <span class="keywordflow">if</span> (bytes_read &gt; 0)
<a name="l00425"></a>00425         <a class="code" href="group__DBusMarshal.html#ga3926bb35edf78d114cf0c341fe3258e0" title="Dump the given part of the string to verbose log.">_dbus_verbose_bytes_of_string</a> (buffer, start, bytes_read);
<a name="l00426"></a>00426 <span class="preprocessor">#endif</span>
<a name="l00427"></a>00427 <span class="preprocessor"></span>
<a name="l00428"></a>00428       <span class="keywordflow">return</span> bytes_read;
<a name="l00429"></a>00429     }
<a name="l00430"></a>00430 <span class="preprocessor">#endif</span>
<a name="l00431"></a>00431 <span class="preprocessor"></span>}
<a name="l00432"></a>00432 
<a name="l00433"></a>00433 <span class="keywordtype">int</span>
<a name="l00434"></a>00434 _dbus_write_socket_with_unix_fds(<span class="keywordtype">int</span>               fd,
<a name="l00435"></a>00435                                  <span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *buffer,
<a name="l00436"></a>00436                                  <span class="keywordtype">int</span>               start,
<a name="l00437"></a>00437                                  <span class="keywordtype">int</span>               len,
<a name="l00438"></a>00438                                  <span class="keyword">const</span> <span class="keywordtype">int</span>        *fds,
<a name="l00439"></a>00439                                  <span class="keywordtype">int</span>               n_fds) {
<a name="l00440"></a>00440 
<a name="l00441"></a>00441 <span class="preprocessor">#ifndef HAVE_UNIX_FD_PASSING</span>
<a name="l00442"></a>00442 <span class="preprocessor"></span>
<a name="l00443"></a>00443   <span class="keywordflow">if</span> (n_fds &gt; 0) {
<a name="l00444"></a>00444     errno = ENOTSUP;
<a name="l00445"></a>00445     <span class="keywordflow">return</span> -1;
<a name="l00446"></a>00446   }
<a name="l00447"></a>00447 
<a name="l00448"></a>00448   <span class="keywordflow">return</span> <a class="code" href="group__DBusSysdeps.html#ga346cadd9b0f7d0ae1cd19007b2e4c2de" title="Like _dbus_write(), but only supports sockets and is thus available on Windows.">_dbus_write_socket</a>(fd, buffer, start, len);
<a name="l00449"></a>00449 <span class="preprocessor">#else</span>
<a name="l00450"></a>00450 <span class="preprocessor"></span>  <span class="keywordflow">return</span> _dbus_write_socket_with_unix_fds_two(fd, buffer, start, len, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, 0, 0, fds, n_fds);
<a name="l00451"></a>00451 <span class="preprocessor">#endif</span>
<a name="l00452"></a>00452 <span class="preprocessor"></span>}
<a name="l00453"></a>00453 
<a name="l00454"></a>00454 <span class="keywordtype">int</span>
<a name="l00455"></a>00455 _dbus_write_socket_with_unix_fds_two(<span class="keywordtype">int</span>               fd,
<a name="l00456"></a>00456                                      <span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *buffer1,
<a name="l00457"></a>00457                                      <span class="keywordtype">int</span>               start1,
<a name="l00458"></a>00458                                      <span class="keywordtype">int</span>               len1,
<a name="l00459"></a>00459                                      <span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *buffer2,
<a name="l00460"></a>00460                                      <span class="keywordtype">int</span>               start2,
<a name="l00461"></a>00461                                      <span class="keywordtype">int</span>               len2,
<a name="l00462"></a>00462                                      <span class="keyword">const</span> <span class="keywordtype">int</span>        *fds,
<a name="l00463"></a>00463                                      <span class="keywordtype">int</span>               n_fds) {
<a name="l00464"></a>00464 
<a name="l00465"></a>00465 <span class="preprocessor">#ifndef HAVE_UNIX_FD_PASSING</span>
<a name="l00466"></a>00466 <span class="preprocessor"></span>
<a name="l00467"></a>00467   <span class="keywordflow">if</span> (n_fds &gt; 0) {
<a name="l00468"></a>00468     errno = ENOTSUP;
<a name="l00469"></a>00469     <span class="keywordflow">return</span> -1;
<a name="l00470"></a>00470   }
<a name="l00471"></a>00471 
<a name="l00472"></a>00472   <span class="keywordflow">return</span> <a class="code" href="group__DBusSysdeps.html#ga02da720105c2a2397b7c687c5ca81174" title="Like _dbus_write_two() but only works on sockets and is thus available on Windows.">_dbus_write_socket_two</a>(fd,
<a name="l00473"></a>00473                                 buffer1, start1, len1,
<a name="l00474"></a>00474                                 buffer2, start2, len2);
<a name="l00475"></a>00475 <span class="preprocessor">#else</span>
<a name="l00476"></a>00476 <span class="preprocessor"></span>
<a name="l00477"></a>00477   <span class="keyword">struct </span>msghdr m;
<a name="l00478"></a>00478   <span class="keyword">struct </span>cmsghdr *cm;
<a name="l00479"></a>00479   <span class="keyword">struct </span>iovec iov[2];
<a name="l00480"></a>00480   <span class="keywordtype">int</span> bytes_written;
<a name="l00481"></a>00481 
<a name="l00482"></a>00482   _dbus_assert (len1 &gt;= 0);
<a name="l00483"></a>00483   _dbus_assert (len2 &gt;= 0);
<a name="l00484"></a>00484   _dbus_assert (n_fds &gt;= 0);
<a name="l00485"></a>00485 
<a name="l00486"></a>00486   _DBUS_ZERO(iov);
<a name="l00487"></a>00487   iov[0].iov_base = (<span class="keywordtype">char</span>*) <a class="code" href="group__DBusString.html#ga8c202a65e938f9bdb859fc6705a4f1bb" title="const version of _dbus_string_get_data_len().">_dbus_string_get_const_data_len</a> (buffer1, start1, len1);
<a name="l00488"></a>00488   iov[0].iov_len = len1;
<a name="l00489"></a>00489 
<a name="l00490"></a>00490   <span class="keywordflow">if</span> (buffer2)
<a name="l00491"></a>00491     {
<a name="l00492"></a>00492       iov[1].iov_base = (<span class="keywordtype">char</span>*) <a class="code" href="group__DBusString.html#ga8c202a65e938f9bdb859fc6705a4f1bb" title="const version of _dbus_string_get_data_len().">_dbus_string_get_const_data_len</a> (buffer2, start2, len2);
<a name="l00493"></a>00493       iov[1].iov_len = len2;
<a name="l00494"></a>00494     }
<a name="l00495"></a>00495 
<a name="l00496"></a>00496   _DBUS_ZERO(m);
<a name="l00497"></a>00497   m.msg_iov = iov;
<a name="l00498"></a>00498   m.msg_iovlen = buffer2 ? 2 : 1;
<a name="l00499"></a>00499 
<a name="l00500"></a>00500   <span class="keywordflow">if</span> (n_fds &gt; 0)
<a name="l00501"></a>00501     {
<a name="l00502"></a>00502       m.msg_controllen = CMSG_SPACE(n_fds * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
<a name="l00503"></a>00503       m.msg_control = alloca(m.msg_controllen);
<a name="l00504"></a>00504       memset(m.msg_control, 0, m.msg_controllen);
<a name="l00505"></a>00505 
<a name="l00506"></a>00506       cm = CMSG_FIRSTHDR(&amp;m);
<a name="l00507"></a>00507       cm-&gt;cmsg_level = SOL_SOCKET;
<a name="l00508"></a>00508       cm-&gt;cmsg_type = SCM_RIGHTS;
<a name="l00509"></a>00509       cm-&gt;cmsg_len = CMSG_LEN(n_fds * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
<a name="l00510"></a>00510       memcpy(CMSG_DATA(cm), fds, n_fds * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>));
<a name="l00511"></a>00511     }
<a name="l00512"></a>00512 
<a name="l00513"></a>00513  again:
<a name="l00514"></a>00514 
<a name="l00515"></a>00515   bytes_written = sendmsg (fd, &amp;m, 0
<a name="l00516"></a>00516 #<span class="keywordflow">if</span> HAVE_DECL_MSG_NOSIGNAL
<a name="l00517"></a>00517                            |MSG_NOSIGNAL
<a name="l00518"></a>00518 #endif
<a name="l00519"></a>00519                            );
<a name="l00520"></a>00520 
<a name="l00521"></a>00521   <span class="keywordflow">if</span> (bytes_written &lt; 0 &amp;&amp; errno == EINTR)
<a name="l00522"></a>00522     <span class="keywordflow">goto</span> again;
<a name="l00523"></a>00523 
<a name="l00524"></a>00524 <span class="preprocessor">#if 0</span>
<a name="l00525"></a>00525 <span class="preprocessor"></span>  <span class="keywordflow">if</span> (bytes_written &gt; 0)
<a name="l00526"></a>00526     <a class="code" href="group__DBusMarshal.html#ga3926bb35edf78d114cf0c341fe3258e0" title="Dump the given part of the string to verbose log.">_dbus_verbose_bytes_of_string</a> (buffer, start, bytes_written);
<a name="l00527"></a>00527 <span class="preprocessor">#endif</span>
<a name="l00528"></a>00528 <span class="preprocessor"></span>
<a name="l00529"></a>00529   <span class="keywordflow">return</span> bytes_written;
<a name="l00530"></a>00530 <span class="preprocessor">#endif</span>
<a name="l00531"></a>00531 <span class="preprocessor"></span>}
<a name="l00532"></a>00532 
<a name="l00546"></a>00546 <span class="keywordtype">int</span>
<a name="l00547"></a><a class="code" href="group__DBusSysdeps.html#ga02da720105c2a2397b7c687c5ca81174">00547</a> <a class="code" href="group__DBusSysdeps.html#ga02da720105c2a2397b7c687c5ca81174" title="Like _dbus_write_two() but only works on sockets and is thus available on Windows.">_dbus_write_socket_two</a> (<span class="keywordtype">int</span>               fd,
<a name="l00548"></a>00548                         <span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *buffer1,
<a name="l00549"></a>00549                         <span class="keywordtype">int</span>               start1,
<a name="l00550"></a>00550                         <span class="keywordtype">int</span>               len1,
<a name="l00551"></a>00551                         <span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *buffer2,
<a name="l00552"></a>00552                         <span class="keywordtype">int</span>               start2,
<a name="l00553"></a>00553                         <span class="keywordtype">int</span>               len2)
<a name="l00554"></a>00554 {
<a name="l00555"></a>00555 <span class="preprocessor">#if HAVE_DECL_MSG_NOSIGNAL</span>
<a name="l00556"></a>00556 <span class="preprocessor"></span>  <span class="keyword">struct </span>iovec vectors[2];
<a name="l00557"></a>00557   <span class="keyword">const</span> <span class="keywordtype">char</span> *data1;
<a name="l00558"></a>00558   <span class="keyword">const</span> <span class="keywordtype">char</span> *data2;
<a name="l00559"></a>00559   <span class="keywordtype">int</span> bytes_written;
<a name="l00560"></a>00560   <span class="keyword">struct </span>msghdr m;
<a name="l00561"></a>00561 
<a name="l00562"></a>00562   _dbus_assert (buffer1 != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l00563"></a>00563   _dbus_assert (start1 &gt;= 0);
<a name="l00564"></a>00564   _dbus_assert (start2 &gt;= 0);
<a name="l00565"></a>00565   _dbus_assert (len1 &gt;= 0);
<a name="l00566"></a>00566   _dbus_assert (len2 &gt;= 0);
<a name="l00567"></a>00567 
<a name="l00568"></a>00568   data1 = <a class="code" href="group__DBusString.html#ga8c202a65e938f9bdb859fc6705a4f1bb" title="const version of _dbus_string_get_data_len().">_dbus_string_get_const_data_len</a> (buffer1, start1, len1);
<a name="l00569"></a>00569 
<a name="l00570"></a>00570   <span class="keywordflow">if</span> (buffer2 != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l00571"></a>00571     data2 = <a class="code" href="group__DBusString.html#ga8c202a65e938f9bdb859fc6705a4f1bb" title="const version of _dbus_string_get_data_len().">_dbus_string_get_const_data_len</a> (buffer2, start2, len2);
<a name="l00572"></a>00572   <span class="keywordflow">else</span>
<a name="l00573"></a>00573     {
<a name="l00574"></a>00574       data2 = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00575"></a>00575       start2 = 0;
<a name="l00576"></a>00576       len2 = 0;
<a name="l00577"></a>00577     }
<a name="l00578"></a>00578 
<a name="l00579"></a>00579   vectors[0].iov_base = (<span class="keywordtype">char</span>*) data1;
<a name="l00580"></a>00580   vectors[0].iov_len = len1;
<a name="l00581"></a>00581   vectors[1].iov_base = (<span class="keywordtype">char</span>*) data2;
<a name="l00582"></a>00582   vectors[1].iov_len = len2;
<a name="l00583"></a>00583 
<a name="l00584"></a>00584   _DBUS_ZERO(m);
<a name="l00585"></a>00585   m.msg_iov = vectors;
<a name="l00586"></a>00586   m.msg_iovlen = data2 ? 2 : 1;
<a name="l00587"></a>00587 
<a name="l00588"></a>00588  again:
<a name="l00589"></a>00589 
<a name="l00590"></a>00590   bytes_written = sendmsg (fd, &amp;m, MSG_NOSIGNAL);
<a name="l00591"></a>00591 
<a name="l00592"></a>00592   <span class="keywordflow">if</span> (bytes_written &lt; 0 &amp;&amp; errno == EINTR)
<a name="l00593"></a>00593     <span class="keywordflow">goto</span> again;
<a name="l00594"></a>00594 
<a name="l00595"></a>00595   <span class="keywordflow">return</span> bytes_written;
<a name="l00596"></a>00596 
<a name="l00597"></a>00597 <span class="preprocessor">#else</span>
<a name="l00598"></a>00598 <span class="preprocessor"></span>  <span class="keywordflow">return</span> <a class="code" href="group__DBusSysdepsUnix.html#ga506a183b1f6970d1bfca165ab3de4736" title="Like _dbus_write() but will use writev() if possible to write both buffers in sequence.">_dbus_write_two</a> (fd, buffer1, start1, len1,
<a name="l00599"></a>00599                           buffer2, start2, len2);
<a name="l00600"></a>00600 <span class="preprocessor">#endif</span>
<a name="l00601"></a>00601 <span class="preprocessor"></span>}
<a name="l00602"></a>00602 
<a name="l00603"></a>00603 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l00604"></a>00604 _dbus_socket_is_invalid (<span class="keywordtype">int</span> fd)
<a name="l00605"></a>00605 {
<a name="l00606"></a>00606     <span class="keywordflow">return</span> fd &lt; 0 ? <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a> : <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l00607"></a>00607 }
<a name="l00608"></a>00608 
<a name="l00625"></a>00625 <span class="keywordtype">int</span>
<a name="l00626"></a><a class="code" href="group__DBusSysdepsUnix.html#gaf52cb1d5b9fc5611808ce32eff898c28">00626</a> <a class="code" href="group__DBusSysdepsUnix.html#gaf52cb1d5b9fc5611808ce32eff898c28" title="Thin wrapper around the read() system call that appends the data it reads to the DBusString buffer...">_dbus_read</a> (<span class="keywordtype">int</span>               fd,
<a name="l00627"></a>00627             <a class="code" href="structDBusString.html">DBusString</a>       *buffer,
<a name="l00628"></a>00628             <span class="keywordtype">int</span>               count)
<a name="l00629"></a>00629 {
<a name="l00630"></a>00630   <span class="keywordtype">int</span> bytes_read;
<a name="l00631"></a>00631   <span class="keywordtype">int</span> start;
<a name="l00632"></a>00632   <span class="keywordtype">char</span> *data;
<a name="l00633"></a>00633 
<a name="l00634"></a>00634   _dbus_assert (count &gt;= 0);
<a name="l00635"></a>00635 
<a name="l00636"></a>00636   start = <a class="code" href="group__DBusString.html#gaa5136e6fd2c5188f4b88de7863369c6d" title="Gets the length of a string (not including nul termination).">_dbus_string_get_length</a> (buffer);
<a name="l00637"></a>00637 
<a name="l00638"></a>00638   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga8f13997d90ceed2f437706e6b7804d9b" title="Makes a string longer by the given number of bytes.">_dbus_string_lengthen</a> (buffer, count))
<a name="l00639"></a>00639     {
<a name="l00640"></a>00640       errno = ENOMEM;
<a name="l00641"></a>00641       <span class="keywordflow">return</span> -1;
<a name="l00642"></a>00642     }
<a name="l00643"></a>00643 
<a name="l00644"></a>00644   data = <a class="code" href="group__DBusString.html#ga7a73fb373398606e6e1d0a86c4587a3c" title="Gets a sub-portion of the raw character buffer from the string.">_dbus_string_get_data_len</a> (buffer, start, count);
<a name="l00645"></a>00645 
<a name="l00646"></a>00646  again:
<a name="l00647"></a>00647 
<a name="l00648"></a>00648   bytes_read = read (fd, data, count);
<a name="l00649"></a>00649 
<a name="l00650"></a>00650   <span class="keywordflow">if</span> (bytes_read &lt; 0)
<a name="l00651"></a>00651     {
<a name="l00652"></a>00652       <span class="keywordflow">if</span> (errno == EINTR)
<a name="l00653"></a>00653         <span class="keywordflow">goto</span> again;
<a name="l00654"></a>00654       <span class="keywordflow">else</span>
<a name="l00655"></a>00655         {
<a name="l00656"></a>00656           <span class="comment">/* put length back (note that this doesn&#39;t actually realloc anything) */</span>
<a name="l00657"></a>00657           <a class="code" href="group__DBusString.html#ga08c423b93c28dd746dcb93e0461ab95c" title="Sets the length of a string.">_dbus_string_set_length</a> (buffer, start);
<a name="l00658"></a>00658           <span class="keywordflow">return</span> -1;
<a name="l00659"></a>00659         }
<a name="l00660"></a>00660     }
<a name="l00661"></a>00661   <span class="keywordflow">else</span>
<a name="l00662"></a>00662     {
<a name="l00663"></a>00663       <span class="comment">/* put length back (doesn&#39;t actually realloc) */</span>
<a name="l00664"></a>00664       <a class="code" href="group__DBusString.html#ga08c423b93c28dd746dcb93e0461ab95c" title="Sets the length of a string.">_dbus_string_set_length</a> (buffer, start + bytes_read);
<a name="l00665"></a>00665 
<a name="l00666"></a>00666 <span class="preprocessor">#if 0</span>
<a name="l00667"></a>00667 <span class="preprocessor"></span>      <span class="keywordflow">if</span> (bytes_read &gt; 0)
<a name="l00668"></a>00668         <a class="code" href="group__DBusMarshal.html#ga3926bb35edf78d114cf0c341fe3258e0" title="Dump the given part of the string to verbose log.">_dbus_verbose_bytes_of_string</a> (buffer, start, bytes_read);
<a name="l00669"></a>00669 <span class="preprocessor">#endif</span>
<a name="l00670"></a>00670 <span class="preprocessor"></span>
<a name="l00671"></a>00671       <span class="keywordflow">return</span> bytes_read;
<a name="l00672"></a>00672     }
<a name="l00673"></a>00673 }
<a name="l00674"></a>00674 
<a name="l00685"></a>00685 <span class="keywordtype">int</span>
<a name="l00686"></a><a class="code" href="group__DBusSysdepsUnix.html#ga3a789bcdfd3d468c2bf917fa5081b27f">00686</a> <a class="code" href="group__DBusSysdepsUnix.html#ga3a789bcdfd3d468c2bf917fa5081b27f" title="Thin wrapper around the write() system call that writes a part of a DBusString and handles EINTR for ...">_dbus_write</a> (<span class="keywordtype">int</span>               fd,
<a name="l00687"></a>00687              <span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *buffer,
<a name="l00688"></a>00688              <span class="keywordtype">int</span>               start,
<a name="l00689"></a>00689              <span class="keywordtype">int</span>               len)
<a name="l00690"></a>00690 {
<a name="l00691"></a>00691   <span class="keyword">const</span> <span class="keywordtype">char</span> *data;
<a name="l00692"></a>00692   <span class="keywordtype">int</span> bytes_written;
<a name="l00693"></a>00693 
<a name="l00694"></a>00694   data = <a class="code" href="group__DBusString.html#ga8c202a65e938f9bdb859fc6705a4f1bb" title="const version of _dbus_string_get_data_len().">_dbus_string_get_const_data_len</a> (buffer, start, len);
<a name="l00695"></a>00695 
<a name="l00696"></a>00696  again:
<a name="l00697"></a>00697 
<a name="l00698"></a>00698   bytes_written = write (fd, data, len);
<a name="l00699"></a>00699 
<a name="l00700"></a>00700   <span class="keywordflow">if</span> (bytes_written &lt; 0 &amp;&amp; errno == EINTR)
<a name="l00701"></a>00701     <span class="keywordflow">goto</span> again;
<a name="l00702"></a>00702 
<a name="l00703"></a>00703 <span class="preprocessor">#if 0</span>
<a name="l00704"></a>00704 <span class="preprocessor"></span>  <span class="keywordflow">if</span> (bytes_written &gt; 0)
<a name="l00705"></a>00705     <a class="code" href="group__DBusMarshal.html#ga3926bb35edf78d114cf0c341fe3258e0" title="Dump the given part of the string to verbose log.">_dbus_verbose_bytes_of_string</a> (buffer, start, bytes_written);
<a name="l00706"></a>00706 <span class="preprocessor">#endif</span>
<a name="l00707"></a>00707 <span class="preprocessor"></span>
<a name="l00708"></a>00708   <span class="keywordflow">return</span> bytes_written;
<a name="l00709"></a>00709 }
<a name="l00710"></a>00710 
<a name="l00731"></a>00731 <span class="keywordtype">int</span>
<a name="l00732"></a><a class="code" href="group__DBusSysdepsUnix.html#ga506a183b1f6970d1bfca165ab3de4736">00732</a> <a class="code" href="group__DBusSysdepsUnix.html#ga506a183b1f6970d1bfca165ab3de4736" title="Like _dbus_write() but will use writev() if possible to write both buffers in sequence.">_dbus_write_two</a> (<span class="keywordtype">int</span>               fd,
<a name="l00733"></a>00733                  <span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *buffer1,
<a name="l00734"></a>00734                  <span class="keywordtype">int</span>               start1,
<a name="l00735"></a>00735                  <span class="keywordtype">int</span>               len1,
<a name="l00736"></a>00736                  <span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *buffer2,
<a name="l00737"></a>00737                  <span class="keywordtype">int</span>               start2,
<a name="l00738"></a>00738                  <span class="keywordtype">int</span>               len2)
<a name="l00739"></a>00739 {
<a name="l00740"></a>00740   _dbus_assert (buffer1 != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l00741"></a>00741   _dbus_assert (start1 &gt;= 0);
<a name="l00742"></a>00742   _dbus_assert (start2 &gt;= 0);
<a name="l00743"></a>00743   _dbus_assert (len1 &gt;= 0);
<a name="l00744"></a>00744   _dbus_assert (len2 &gt;= 0);
<a name="l00745"></a>00745 
<a name="l00746"></a>00746 <span class="preprocessor">#ifdef HAVE_WRITEV</span>
<a name="l00747"></a>00747 <span class="preprocessor"></span>  {
<a name="l00748"></a>00748     <span class="keyword">struct </span>iovec vectors[2];
<a name="l00749"></a>00749     <span class="keyword">const</span> <span class="keywordtype">char</span> *data1;
<a name="l00750"></a>00750     <span class="keyword">const</span> <span class="keywordtype">char</span> *data2;
<a name="l00751"></a>00751     <span class="keywordtype">int</span> bytes_written;
<a name="l00752"></a>00752 
<a name="l00753"></a>00753     data1 = <a class="code" href="group__DBusString.html#ga8c202a65e938f9bdb859fc6705a4f1bb" title="const version of _dbus_string_get_data_len().">_dbus_string_get_const_data_len</a> (buffer1, start1, len1);
<a name="l00754"></a>00754 
<a name="l00755"></a>00755     <span class="keywordflow">if</span> (buffer2 != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l00756"></a>00756       data2 = <a class="code" href="group__DBusString.html#ga8c202a65e938f9bdb859fc6705a4f1bb" title="const version of _dbus_string_get_data_len().">_dbus_string_get_const_data_len</a> (buffer2, start2, len2);
<a name="l00757"></a>00757     <span class="keywordflow">else</span>
<a name="l00758"></a>00758       {
<a name="l00759"></a>00759         data2 = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00760"></a>00760         start2 = 0;
<a name="l00761"></a>00761         len2 = 0;
<a name="l00762"></a>00762       }
<a name="l00763"></a>00763 
<a name="l00764"></a>00764     vectors[0].iov_base = (<span class="keywordtype">char</span>*) data1;
<a name="l00765"></a>00765     vectors[0].iov_len = len1;
<a name="l00766"></a>00766     vectors[1].iov_base = (<span class="keywordtype">char</span>*) data2;
<a name="l00767"></a>00767     vectors[1].iov_len = len2;
<a name="l00768"></a>00768 
<a name="l00769"></a>00769   again:
<a name="l00770"></a>00770 
<a name="l00771"></a>00771     bytes_written = writev (fd,
<a name="l00772"></a>00772                             vectors,
<a name="l00773"></a>00773                             data2 ? 2 : 1);
<a name="l00774"></a>00774 
<a name="l00775"></a>00775     <span class="keywordflow">if</span> (bytes_written &lt; 0 &amp;&amp; errno == EINTR)
<a name="l00776"></a>00776       <span class="keywordflow">goto</span> again;
<a name="l00777"></a>00777 
<a name="l00778"></a>00778     <span class="keywordflow">return</span> bytes_written;
<a name="l00779"></a>00779   }
<a name="l00780"></a>00780 <span class="preprocessor">#else </span><span class="comment">/* HAVE_WRITEV */</span>
<a name="l00781"></a>00781   {
<a name="l00782"></a>00782     <span class="keywordtype">int</span> ret1, ret2;
<a name="l00783"></a>00783 
<a name="l00784"></a>00784     ret1 = <a class="code" href="group__DBusSysdepsUnix.html#ga3a789bcdfd3d468c2bf917fa5081b27f" title="Thin wrapper around the write() system call that writes a part of a DBusString and handles EINTR for ...">_dbus_write</a> (fd, buffer1, start1, len1);
<a name="l00785"></a>00785     <span class="keywordflow">if</span> (ret1 == len1 &amp;&amp; buffer2 != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l00786"></a>00786       {
<a name="l00787"></a>00787         ret2 = <a class="code" href="group__DBusSysdepsUnix.html#ga3a789bcdfd3d468c2bf917fa5081b27f" title="Thin wrapper around the write() system call that writes a part of a DBusString and handles EINTR for ...">_dbus_write</a> (fd, buffer2, start2, len2);
<a name="l00788"></a>00788         <span class="keywordflow">if</span> (ret2 &lt; 0)
<a name="l00789"></a>00789           ret2 = 0; <span class="comment">/* we can&#39;t report an error as the first write was OK */</span>
<a name="l00790"></a>00790 
<a name="l00791"></a>00791         <span class="keywordflow">return</span> ret1 + ret2;
<a name="l00792"></a>00792       }
<a name="l00793"></a>00793     <span class="keywordflow">else</span>
<a name="l00794"></a>00794       <span class="keywordflow">return</span> ret1;
<a name="l00795"></a>00795   }
<a name="l00796"></a>00796 <span class="preprocessor">#endif </span><span class="comment">/* !HAVE_WRITEV */</span>
<a name="l00797"></a>00797 }
<a name="l00798"></a>00798 
<a name="l00799"></a>00799 <span class="preprocessor">#define _DBUS_MAX_SUN_PATH_LENGTH 99</span>
<a name="l00800"></a>00800 <span class="preprocessor"></span>
<a name="l00830"></a>00830 <span class="keywordtype">int</span>
<a name="l00831"></a><a class="code" href="group__DBusSysdepsUnix.html#ga0228009923a105d50a0849b24acbc31e">00831</a> <a class="code" href="group__DBusSysdepsUnix.html#ga0228009923a105d50a0849b24acbc31e" title="Creates a socket and connects it to the UNIX domain socket at the given path.">_dbus_connect_unix_socket</a> (<span class="keyword">const</span> <span class="keywordtype">char</span>     *path,
<a name="l00832"></a>00832                            <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>     <span class="keyword">abstract</span>,
<a name="l00833"></a>00833                            <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>      *error)
<a name="l00834"></a>00834 {
<a name="l00835"></a>00835   <span class="keywordtype">int</span> fd;
<a name="l00836"></a>00836   <span class="keywordtype">size_t</span> path_len;
<a name="l00837"></a>00837   <span class="keyword">struct </span>sockaddr_un addr;
<a name="l00838"></a>00838 
<a name="l00839"></a>00839   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l00840"></a>00840 
<a name="l00841"></a>00841   _dbus_verbose (<span class="stringliteral">&quot;connecting to unix socket %s abstract=%d\n&quot;</span>,
<a name="l00842"></a>00842                  path, <span class="keyword">abstract</span>);
<a name="l00843"></a>00843 
<a name="l00844"></a>00844 
<a name="l00845"></a>00845   <span class="keywordflow">if</span> (!_dbus_open_unix_socket (&amp;fd, error))
<a name="l00846"></a>00846     {
<a name="l00847"></a>00847       _DBUS_ASSERT_ERROR_IS_SET(error);
<a name="l00848"></a>00848       <span class="keywordflow">return</span> -1;
<a name="l00849"></a>00849     }
<a name="l00850"></a>00850   _DBUS_ASSERT_ERROR_IS_CLEAR(error);
<a name="l00851"></a>00851 
<a name="l00852"></a>00852   _DBUS_ZERO (addr);
<a name="l00853"></a>00853   addr.sun_family = AF_UNIX;
<a name="l00854"></a>00854   path_len = strlen (path);
<a name="l00855"></a>00855 
<a name="l00856"></a>00856   <span class="keywordflow">if</span> (<span class="keyword">abstract</span>)
<a name="l00857"></a>00857     {
<a name="l00858"></a>00858 <span class="preprocessor">#ifdef HAVE_ABSTRACT_SOCKETS</span>
<a name="l00859"></a>00859 <span class="preprocessor"></span>      addr.sun_path[0] = <span class="charliteral">&#39;\0&#39;</span>; <span class="comment">/* this is what says &quot;use abstract&quot; */</span>
<a name="l00860"></a>00860       path_len++; <span class="comment">/* Account for the extra nul byte added to the start of sun_path */</span>
<a name="l00861"></a>00861 
<a name="l00862"></a>00862       <span class="keywordflow">if</span> (path_len &gt; _DBUS_MAX_SUN_PATH_LENGTH)
<a name="l00863"></a>00863         {
<a name="l00864"></a>00864           <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#ga3fa04eb600edda4afc2dd9fe2e0f8b02" title="A D-Bus bus address was malformed.">DBUS_ERROR_BAD_ADDRESS</a>,
<a name="l00865"></a>00865                       <span class="stringliteral">&quot;Abstract socket name too long\n&quot;</span>);
<a name="l00866"></a>00866           <a class="code" href="group__DBusSysdepsUnix.html#gac448479a1674e3b86cee9a4bdc7eba03" title="Closes a file descriptor.">_dbus_close</a> (fd, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l00867"></a>00867           <span class="keywordflow">return</span> -1;
<a name="l00868"></a>00868         }
<a name="l00869"></a>00869 
<a name="l00870"></a>00870       strncpy (&amp;addr.sun_path[1], path, path_len);
<a name="l00871"></a>00871       <span class="comment">/* _dbus_verbose_bytes (addr.sun_path, sizeof (addr.sun_path)); */</span>
<a name="l00872"></a>00872 <span class="preprocessor">#else </span><span class="comment">/* HAVE_ABSTRACT_SOCKETS */</span>
<a name="l00873"></a>00873       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#ga33122bcaf8f5896ec222c755b6effb40" title="Requested operation isn&#39;t supported (like ENOSYS on UNIX).">DBUS_ERROR_NOT_SUPPORTED</a>,
<a name="l00874"></a>00874                       <span class="stringliteral">&quot;Operating system does not support abstract socket namespace\n&quot;</span>);
<a name="l00875"></a>00875       <a class="code" href="group__DBusSysdepsUnix.html#gac448479a1674e3b86cee9a4bdc7eba03" title="Closes a file descriptor.">_dbus_close</a> (fd, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l00876"></a>00876       <span class="keywordflow">return</span> -1;
<a name="l00877"></a>00877 <span class="preprocessor">#endif </span><span class="comment">/* ! HAVE_ABSTRACT_SOCKETS */</span>
<a name="l00878"></a>00878     }
<a name="l00879"></a>00879   <span class="keywordflow">else</span>
<a name="l00880"></a>00880     {
<a name="l00881"></a>00881       <span class="keywordflow">if</span> (path_len &gt; _DBUS_MAX_SUN_PATH_LENGTH)
<a name="l00882"></a>00882         {
<a name="l00883"></a>00883           <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#ga3fa04eb600edda4afc2dd9fe2e0f8b02" title="A D-Bus bus address was malformed.">DBUS_ERROR_BAD_ADDRESS</a>,
<a name="l00884"></a>00884                       <span class="stringliteral">&quot;Socket name too long\n&quot;</span>);
<a name="l00885"></a>00885           <a class="code" href="group__DBusSysdepsUnix.html#gac448479a1674e3b86cee9a4bdc7eba03" title="Closes a file descriptor.">_dbus_close</a> (fd, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l00886"></a>00886           <span class="keywordflow">return</span> -1;
<a name="l00887"></a>00887         }
<a name="l00888"></a>00888 
<a name="l00889"></a>00889       strncpy (addr.sun_path, path, path_len);
<a name="l00890"></a>00890     }
<a name="l00891"></a>00891 
<a name="l00892"></a>00892   <span class="keywordflow">if</span> (connect (fd, (<span class="keyword">struct</span> sockaddr*) &amp;addr, _DBUS_STRUCT_OFFSET (<span class="keyword">struct</span> sockaddr_un, sun_path) + path_len) &lt; 0)
<a name="l00893"></a>00893     {
<a name="l00894"></a>00894       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error,
<a name="l00895"></a>00895                       <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l00896"></a>00896                       <span class="stringliteral">&quot;Failed to connect to socket %s: %s&quot;</span>,
<a name="l00897"></a>00897                       path, _dbus_strerror (errno));
<a name="l00898"></a>00898 
<a name="l00899"></a>00899       <a class="code" href="group__DBusSysdepsUnix.html#gac448479a1674e3b86cee9a4bdc7eba03" title="Closes a file descriptor.">_dbus_close</a> (fd, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l00900"></a>00900       <span class="keywordflow">return</span> -1;
<a name="l00901"></a>00901     }
<a name="l00902"></a>00902 
<a name="l00903"></a>00903   <span class="keywordflow">if</span> (!_dbus_set_fd_nonblocking (fd, error))
<a name="l00904"></a>00904     {
<a name="l00905"></a>00905       _DBUS_ASSERT_ERROR_IS_SET (error);
<a name="l00906"></a>00906 
<a name="l00907"></a>00907       <a class="code" href="group__DBusSysdepsUnix.html#gac448479a1674e3b86cee9a4bdc7eba03" title="Closes a file descriptor.">_dbus_close</a> (fd, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l00908"></a>00908       <span class="keywordflow">return</span> -1;
<a name="l00909"></a>00909     }
<a name="l00910"></a>00910 
<a name="l00911"></a>00911   <span class="keywordflow">return</span> fd;
<a name="l00912"></a>00912 }
<a name="l00913"></a>00913 
<a name="l00926"></a>00926 <span class="keywordtype">int</span>
<a name="l00927"></a><a class="code" href="group__DBusSysdepsUnix.html#gab9a5fd9662ae1ee18598d1736def70ea">00927</a> <a class="code" href="group__DBusSysdepsUnix.html#gab9a5fd9662ae1ee18598d1736def70ea" title="Creates a UNIX domain socket and connects it to the specified process to execute.">_dbus_connect_exec</a> (<span class="keyword">const</span> <span class="keywordtype">char</span>     *path,
<a name="l00928"></a>00928                     <span class="keywordtype">char</span> *<span class="keyword">const</span>    argv[],
<a name="l00929"></a>00929                     <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>      *error)
<a name="l00930"></a>00930 {
<a name="l00931"></a>00931   <span class="keywordtype">int</span> fds[2];
<a name="l00932"></a>00932   pid_t pid;
<a name="l00933"></a>00933   <span class="keywordtype">int</span> retval;
<a name="l00934"></a>00934   <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> cloexec_done = 0;
<a name="l00935"></a>00935 
<a name="l00936"></a>00936   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l00937"></a>00937 
<a name="l00938"></a>00938   _dbus_verbose (<span class="stringliteral">&quot;connecting to process %s\n&quot;</span>, path);
<a name="l00939"></a>00939 
<a name="l00940"></a>00940 <span class="preprocessor">#ifdef SOCK_CLOEXEC</span>
<a name="l00941"></a>00941 <span class="preprocessor"></span>  retval = socketpair (AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0, fds);
<a name="l00942"></a>00942   cloexec_done = (retval &gt;= 0);
<a name="l00943"></a>00943 
<a name="l00944"></a>00944   <span class="keywordflow">if</span> (retval &lt; 0 &amp;&amp; (errno == EINVAL || errno == EPROTOTYPE))
<a name="l00945"></a>00945 #endif
<a name="l00946"></a>00946     {
<a name="l00947"></a>00947       retval = socketpair (AF_UNIX, SOCK_STREAM, 0, fds);
<a name="l00948"></a>00948     }
<a name="l00949"></a>00949 
<a name="l00950"></a>00950   <span class="keywordflow">if</span> (retval &lt; 0)
<a name="l00951"></a>00951     {
<a name="l00952"></a>00952       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error,
<a name="l00953"></a>00953                       <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l00954"></a>00954                       <span class="stringliteral">&quot;Failed to create socket pair: %s&quot;</span>,
<a name="l00955"></a>00955                       _dbus_strerror (errno));
<a name="l00956"></a>00956       <span class="keywordflow">return</span> -1;
<a name="l00957"></a>00957     }
<a name="l00958"></a>00958 
<a name="l00959"></a>00959   <span class="keywordflow">if</span> (!cloexec_done)
<a name="l00960"></a>00960     {
<a name="l00961"></a>00961       <a class="code" href="group__DBusSysdeps.html#ga21ef96952f98f23e590ebbf060fd5ca6" title="Sets the file descriptor to be close on exec.">_dbus_fd_set_close_on_exec</a> (fds[0]);
<a name="l00962"></a>00962       <a class="code" href="group__DBusSysdeps.html#ga21ef96952f98f23e590ebbf060fd5ca6" title="Sets the file descriptor to be close on exec.">_dbus_fd_set_close_on_exec</a> (fds[1]);
<a name="l00963"></a>00963     }
<a name="l00964"></a>00964 
<a name="l00965"></a>00965   pid = fork ();
<a name="l00966"></a>00966   <span class="keywordflow">if</span> (pid &lt; 0)
<a name="l00967"></a>00967     {
<a name="l00968"></a>00968       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error,
<a name="l00969"></a>00969                       <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l00970"></a>00970                       <span class="stringliteral">&quot;Failed to fork() to call %s: %s&quot;</span>,
<a name="l00971"></a>00971                       path, _dbus_strerror (errno));
<a name="l00972"></a>00972       close (fds[0]);
<a name="l00973"></a>00973       close (fds[1]);
<a name="l00974"></a>00974       <span class="keywordflow">return</span> -1;
<a name="l00975"></a>00975     }
<a name="l00976"></a>00976 
<a name="l00977"></a>00977   <span class="keywordflow">if</span> (pid == 0)
<a name="l00978"></a>00978     {
<a name="l00979"></a>00979       <span class="comment">/* child */</span>
<a name="l00980"></a>00980       close (fds[0]);
<a name="l00981"></a>00981 
<a name="l00982"></a>00982       dup2 (fds[1], STDIN_FILENO);
<a name="l00983"></a>00983       dup2 (fds[1], STDOUT_FILENO);
<a name="l00984"></a>00984 
<a name="l00985"></a>00985       <span class="keywordflow">if</span> (fds[1] != STDIN_FILENO &amp;&amp;
<a name="l00986"></a>00986           fds[1] != STDOUT_FILENO)
<a name="l00987"></a>00987         close (fds[1]);
<a name="l00988"></a>00988 
<a name="l00989"></a>00989       <span class="comment">/* Inherit STDERR and the controlling terminal from the</span>
<a name="l00990"></a>00990 <span class="comment">         parent */</span>
<a name="l00991"></a>00991 
<a name="l00992"></a>00992       <a class="code" href="group__DBusSysdepsUnix.html#gae63f6bdc70a1dd5c9ba0a6a1be57e320" title="Closes all file descriptors except the first three (i.e.">_dbus_close_all</a> ();
<a name="l00993"></a>00993 
<a name="l00994"></a>00994       execvp (path, argv);
<a name="l00995"></a>00995 
<a name="l00996"></a>00996       fprintf (stderr, <span class="stringliteral">&quot;Failed to execute process %s: %s\n&quot;</span>, path, _dbus_strerror (errno));
<a name="l00997"></a>00997 
<a name="l00998"></a>00998       _exit(1);
<a name="l00999"></a>00999     }
<a name="l01000"></a>01000 
<a name="l01001"></a>01001   <span class="comment">/* parent */</span>
<a name="l01002"></a>01002   close (fds[1]);
<a name="l01003"></a>01003 
<a name="l01004"></a>01004   <span class="keywordflow">if</span> (!_dbus_set_fd_nonblocking (fds[0], error))
<a name="l01005"></a>01005     {
<a name="l01006"></a>01006       _DBUS_ASSERT_ERROR_IS_SET (error);
<a name="l01007"></a>01007 
<a name="l01008"></a>01008       close (fds[0]);
<a name="l01009"></a>01009       <span class="keywordflow">return</span> -1;
<a name="l01010"></a>01010     }
<a name="l01011"></a>01011 
<a name="l01012"></a>01012   <span class="keywordflow">return</span> fds[0];
<a name="l01013"></a>01013 }
<a name="l01014"></a>01014 
<a name="l01032"></a>01032 <span class="keywordtype">int</span>
<a name="l01033"></a><a class="code" href="group__DBusSysdepsUnix.html#ga2cd48fe3d7aa14d0d3c7813cdddb3f74">01033</a> <a class="code" href="group__DBusSysdepsUnix.html#ga2cd48fe3d7aa14d0d3c7813cdddb3f74" title="Creates a socket and binds it to the given path, then listens on the socket.">_dbus_listen_unix_socket</a> (<span class="keyword">const</span> <span class="keywordtype">char</span>     *path,
<a name="l01034"></a>01034                           <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>     <span class="keyword">abstract</span>,
<a name="l01035"></a>01035                           <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>      *error)
<a name="l01036"></a>01036 {
<a name="l01037"></a>01037   <span class="keywordtype">int</span> listen_fd;
<a name="l01038"></a>01038   <span class="keyword">struct </span>sockaddr_un addr;
<a name="l01039"></a>01039   <span class="keywordtype">size_t</span> path_len;
<a name="l01040"></a>01040 
<a name="l01041"></a>01041   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l01042"></a>01042 
<a name="l01043"></a>01043   _dbus_verbose (<span class="stringliteral">&quot;listening on unix socket %s abstract=%d\n&quot;</span>,
<a name="l01044"></a>01044                  path, <span class="keyword">abstract</span>);
<a name="l01045"></a>01045 
<a name="l01046"></a>01046   <span class="keywordflow">if</span> (!_dbus_open_unix_socket (&amp;listen_fd, error))
<a name="l01047"></a>01047     {
<a name="l01048"></a>01048       _DBUS_ASSERT_ERROR_IS_SET(error);
<a name="l01049"></a>01049       <span class="keywordflow">return</span> -1;
<a name="l01050"></a>01050     }
<a name="l01051"></a>01051   _DBUS_ASSERT_ERROR_IS_CLEAR(error);
<a name="l01052"></a>01052 
<a name="l01053"></a>01053   _DBUS_ZERO (addr);
<a name="l01054"></a>01054   addr.sun_family = AF_UNIX;
<a name="l01055"></a>01055   path_len = strlen (path);
<a name="l01056"></a>01056 
<a name="l01057"></a>01057   <span class="keywordflow">if</span> (<span class="keyword">abstract</span>)
<a name="l01058"></a>01058     {
<a name="l01059"></a>01059 <span class="preprocessor">#ifdef HAVE_ABSTRACT_SOCKETS</span>
<a name="l01060"></a>01060 <span class="preprocessor"></span>      <span class="comment">/* remember that abstract names aren&#39;t nul-terminated so we rely</span>
<a name="l01061"></a>01061 <span class="comment">       * on sun_path being filled in with zeroes above.</span>
<a name="l01062"></a>01062 <span class="comment">       */</span>
<a name="l01063"></a>01063       addr.sun_path[0] = <span class="charliteral">&#39;\0&#39;</span>; <span class="comment">/* this is what says &quot;use abstract&quot; */</span>
<a name="l01064"></a>01064       path_len++; <span class="comment">/* Account for the extra nul byte added to the start of sun_path */</span>
<a name="l01065"></a>01065 
<a name="l01066"></a>01066       <span class="keywordflow">if</span> (path_len &gt; _DBUS_MAX_SUN_PATH_LENGTH)
<a name="l01067"></a>01067         {
<a name="l01068"></a>01068           <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#ga3fa04eb600edda4afc2dd9fe2e0f8b02" title="A D-Bus bus address was malformed.">DBUS_ERROR_BAD_ADDRESS</a>,
<a name="l01069"></a>01069                       <span class="stringliteral">&quot;Abstract socket name too long\n&quot;</span>);
<a name="l01070"></a>01070           <a class="code" href="group__DBusSysdepsUnix.html#gac448479a1674e3b86cee9a4bdc7eba03" title="Closes a file descriptor.">_dbus_close</a> (listen_fd, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l01071"></a>01071           <span class="keywordflow">return</span> -1;
<a name="l01072"></a>01072         }
<a name="l01073"></a>01073 
<a name="l01074"></a>01074       strncpy (&amp;addr.sun_path[1], path, path_len);
<a name="l01075"></a>01075       <span class="comment">/* _dbus_verbose_bytes (addr.sun_path, sizeof (addr.sun_path)); */</span>
<a name="l01076"></a>01076 <span class="preprocessor">#else </span><span class="comment">/* HAVE_ABSTRACT_SOCKETS */</span>
<a name="l01077"></a>01077       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#ga33122bcaf8f5896ec222c755b6effb40" title="Requested operation isn&#39;t supported (like ENOSYS on UNIX).">DBUS_ERROR_NOT_SUPPORTED</a>,
<a name="l01078"></a>01078                       <span class="stringliteral">&quot;Operating system does not support abstract socket namespace\n&quot;</span>);
<a name="l01079"></a>01079       <a class="code" href="group__DBusSysdepsUnix.html#gac448479a1674e3b86cee9a4bdc7eba03" title="Closes a file descriptor.">_dbus_close</a> (listen_fd, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l01080"></a>01080       <span class="keywordflow">return</span> -1;
<a name="l01081"></a>01081 <span class="preprocessor">#endif </span><span class="comment">/* ! HAVE_ABSTRACT_SOCKETS */</span>
<a name="l01082"></a>01082     }
<a name="l01083"></a>01083   <span class="keywordflow">else</span>
<a name="l01084"></a>01084     {
<a name="l01085"></a>01085       <span class="comment">/* Discussed security implications of this with Nalin,</span>
<a name="l01086"></a>01086 <span class="comment">       * and we couldn&#39;t think of where it would kick our ass, but</span>
<a name="l01087"></a>01087 <span class="comment">       * it still seems a bit sucky. It also has non-security suckage;</span>
<a name="l01088"></a>01088 <span class="comment">       * really we&#39;d prefer to exit if the socket is already in use.</span>
<a name="l01089"></a>01089 <span class="comment">       * But there doesn&#39;t seem to be a good way to do this.</span>
<a name="l01090"></a>01090 <span class="comment">       *</span>
<a name="l01091"></a>01091 <span class="comment">       * Just to be extra careful, I threw in the stat() - clearly</span>
<a name="l01092"></a>01092 <span class="comment">       * the stat() can&#39;t *fix* any security issue, but it at least</span>
<a name="l01093"></a>01093 <span class="comment">       * avoids inadvertent/accidental data loss.</span>
<a name="l01094"></a>01094 <span class="comment">       */</span>
<a name="l01095"></a>01095       {
<a name="l01096"></a>01096         <span class="keyword">struct </span>stat sb;
<a name="l01097"></a>01097 
<a name="l01098"></a>01098         <span class="keywordflow">if</span> (stat (path, &amp;sb) == 0 &amp;&amp;
<a name="l01099"></a>01099             S_ISSOCK (sb.st_mode))
<a name="l01100"></a>01100           unlink (path);
<a name="l01101"></a>01101       }
<a name="l01102"></a>01102 
<a name="l01103"></a>01103       <span class="keywordflow">if</span> (path_len &gt; _DBUS_MAX_SUN_PATH_LENGTH)
<a name="l01104"></a>01104         {
<a name="l01105"></a>01105           <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#ga3fa04eb600edda4afc2dd9fe2e0f8b02" title="A D-Bus bus address was malformed.">DBUS_ERROR_BAD_ADDRESS</a>,
<a name="l01106"></a>01106                       <span class="stringliteral">&quot;Abstract socket name too long\n&quot;</span>);
<a name="l01107"></a>01107           <a class="code" href="group__DBusSysdepsUnix.html#gac448479a1674e3b86cee9a4bdc7eba03" title="Closes a file descriptor.">_dbus_close</a> (listen_fd, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l01108"></a>01108           <span class="keywordflow">return</span> -1;
<a name="l01109"></a>01109         }
<a name="l01110"></a>01110 
<a name="l01111"></a>01111       strncpy (addr.sun_path, path, path_len);
<a name="l01112"></a>01112     }
<a name="l01113"></a>01113 
<a name="l01114"></a>01114   <span class="keywordflow">if</span> (bind (listen_fd, (<span class="keyword">struct</span> sockaddr*) &amp;addr, _DBUS_STRUCT_OFFSET (<span class="keyword">struct</span> sockaddr_un, sun_path) + path_len) &lt; 0)
<a name="l01115"></a>01115     {
<a name="l01116"></a>01116       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l01117"></a>01117                       <span class="stringliteral">&quot;Failed to bind socket \&quot;%s\&quot;: %s&quot;</span>,
<a name="l01118"></a>01118                       path, _dbus_strerror (errno));
<a name="l01119"></a>01119       <a class="code" href="group__DBusSysdepsUnix.html#gac448479a1674e3b86cee9a4bdc7eba03" title="Closes a file descriptor.">_dbus_close</a> (listen_fd, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l01120"></a>01120       <span class="keywordflow">return</span> -1;
<a name="l01121"></a>01121     }
<a name="l01122"></a>01122 
<a name="l01123"></a>01123   <span class="keywordflow">if</span> (listen (listen_fd, 30 <span class="comment">/* backlog */</span>) &lt; 0)
<a name="l01124"></a>01124     {
<a name="l01125"></a>01125       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l01126"></a>01126                       <span class="stringliteral">&quot;Failed to listen on socket \&quot;%s\&quot;: %s&quot;</span>,
<a name="l01127"></a>01127                       path, _dbus_strerror (errno));
<a name="l01128"></a>01128       <a class="code" href="group__DBusSysdepsUnix.html#gac448479a1674e3b86cee9a4bdc7eba03" title="Closes a file descriptor.">_dbus_close</a> (listen_fd, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l01129"></a>01129       <span class="keywordflow">return</span> -1;
<a name="l01130"></a>01130     }
<a name="l01131"></a>01131 
<a name="l01132"></a>01132   <span class="keywordflow">if</span> (!_dbus_set_fd_nonblocking (listen_fd, error))
<a name="l01133"></a>01133     {
<a name="l01134"></a>01134       _DBUS_ASSERT_ERROR_IS_SET (error);
<a name="l01135"></a>01135       <a class="code" href="group__DBusSysdepsUnix.html#gac448479a1674e3b86cee9a4bdc7eba03" title="Closes a file descriptor.">_dbus_close</a> (listen_fd, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l01136"></a>01136       <span class="keywordflow">return</span> -1;
<a name="l01137"></a>01137     }
<a name="l01138"></a>01138 
<a name="l01139"></a>01139   <span class="comment">/* Try opening up the permissions, but if we can&#39;t, just go ahead</span>
<a name="l01140"></a>01140 <span class="comment">   * and continue, maybe it will be good enough.</span>
<a name="l01141"></a>01141 <span class="comment">   */</span>
<a name="l01142"></a>01142   <span class="keywordflow">if</span> (!<span class="keyword">abstract</span> &amp;&amp; chmod (path, 0777) &lt; 0)
<a name="l01143"></a>01143     <a class="code" href="group__DBusInternalsUtils.html#gabea2c16d6d3fe7c4eb5b9496fc877f84" title="Prints a warning message to stderr.">_dbus_warn</a> (<span class="stringliteral">&quot;Could not set mode 0777 on socket %s\n&quot;</span>,
<a name="l01144"></a>01144                 path);
<a name="l01145"></a>01145 
<a name="l01146"></a>01146   <span class="keywordflow">return</span> listen_fd;
<a name="l01147"></a>01147 }
<a name="l01148"></a>01148 
<a name="l01159"></a>01159 <span class="keywordtype">int</span>
<a name="l01160"></a><a class="code" href="group__DBusSysdepsUnix.html#ga71aa508a7790c6d1c9c0159defcdd4a6">01160</a> <a class="code" href="group__DBusSysdepsUnix.html#ga71aa508a7790c6d1c9c0159defcdd4a6" title="Acquires one or more sockets passed in from systemd.">_dbus_listen_systemd_sockets</a> (<span class="keywordtype">int</span>       **fds,
<a name="l01161"></a>01161                               <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a> *error)
<a name="l01162"></a>01162 {
<a name="l01163"></a>01163   <span class="keywordtype">int</span> r, n;
<a name="l01164"></a>01164   <span class="keywordtype">unsigned</span> fd;
<a name="l01165"></a>01165   <span class="keywordtype">int</span> *new_fds;
<a name="l01166"></a>01166 
<a name="l01167"></a>01167   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l01168"></a>01168 
<a name="l01169"></a>01169   n = sd_listen_fds (<a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>);
<a name="l01170"></a>01170   <span class="keywordflow">if</span> (n &lt; 0)
<a name="l01171"></a>01171     {
<a name="l01172"></a>01172       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (-n),
<a name="l01173"></a>01173                       <span class="stringliteral">&quot;Failed to acquire systemd socket: %s&quot;</span>,
<a name="l01174"></a>01174                       _dbus_strerror (-n));
<a name="l01175"></a>01175       <span class="keywordflow">return</span> -1;
<a name="l01176"></a>01176     }
<a name="l01177"></a>01177 
<a name="l01178"></a>01178   <span class="keywordflow">if</span> (n &lt;= 0)
<a name="l01179"></a>01179     {
<a name="l01180"></a>01180       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#ga3fa04eb600edda4afc2dd9fe2e0f8b02" title="A D-Bus bus address was malformed.">DBUS_ERROR_BAD_ADDRESS</a>,
<a name="l01181"></a>01181                       <span class="stringliteral">&quot;No socket received.&quot;</span>);
<a name="l01182"></a>01182       <span class="keywordflow">return</span> -1;
<a name="l01183"></a>01183     }
<a name="l01184"></a>01184 
<a name="l01185"></a>01185   <span class="keywordflow">for</span> (fd = SD_LISTEN_FDS_START; fd &lt; SD_LISTEN_FDS_START + n; fd ++)
<a name="l01186"></a>01186     {
<a name="l01187"></a>01187       r = sd_is_socket (fd, AF_UNSPEC, SOCK_STREAM, 1);
<a name="l01188"></a>01188       <span class="keywordflow">if</span> (r &lt; 0)
<a name="l01189"></a>01189         {
<a name="l01190"></a>01190           <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (-r),
<a name="l01191"></a>01191                           <span class="stringliteral">&quot;Failed to verify systemd socket type: %s&quot;</span>,
<a name="l01192"></a>01192                           _dbus_strerror (-r));
<a name="l01193"></a>01193           <span class="keywordflow">return</span> -1;
<a name="l01194"></a>01194         }
<a name="l01195"></a>01195 
<a name="l01196"></a>01196       <span class="keywordflow">if</span> (!r)
<a name="l01197"></a>01197         {
<a name="l01198"></a>01198           <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#ga3fa04eb600edda4afc2dd9fe2e0f8b02" title="A D-Bus bus address was malformed.">DBUS_ERROR_BAD_ADDRESS</a>,
<a name="l01199"></a>01199                           <span class="stringliteral">&quot;Passed socket has wrong type.&quot;</span>);
<a name="l01200"></a>01200           <span class="keywordflow">return</span> -1;
<a name="l01201"></a>01201         }
<a name="l01202"></a>01202     }
<a name="l01203"></a>01203 
<a name="l01204"></a>01204   <span class="comment">/* OK, the file descriptors are all good, so let&#39;s take posession of</span>
<a name="l01205"></a>01205 <span class="comment">     them then. */</span>
<a name="l01206"></a>01206 
<a name="l01207"></a>01207   new_fds = <a class="code" href="group__DBusMemory.html#ga54ccb556e7964112a825a7f46c156ca0" title="Safe macro for using dbus_malloc().">dbus_new</a> (<span class="keywordtype">int</span>, n);
<a name="l01208"></a>01208   <span class="keywordflow">if</span> (!new_fds)
<a name="l01209"></a>01209     {
<a name="l01210"></a>01210       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gac32eaf0b92f798307853cd4fe0cf11c2" title="There was not enough memory to complete an operation.">DBUS_ERROR_NO_MEMORY</a>,
<a name="l01211"></a>01211                       <span class="stringliteral">&quot;Failed to allocate file handle array.&quot;</span>);
<a name="l01212"></a>01212       <span class="keywordflow">goto</span> fail;
<a name="l01213"></a>01213     }
<a name="l01214"></a>01214 
<a name="l01215"></a>01215   <span class="keywordflow">for</span> (fd = SD_LISTEN_FDS_START; fd &lt; SD_LISTEN_FDS_START + n; fd ++)
<a name="l01216"></a>01216     {
<a name="l01217"></a>01217       <span class="keywordflow">if</span> (!_dbus_set_fd_nonblocking (fd, error))
<a name="l01218"></a>01218         {
<a name="l01219"></a>01219           _DBUS_ASSERT_ERROR_IS_SET (error);
<a name="l01220"></a>01220           <span class="keywordflow">goto</span> fail;
<a name="l01221"></a>01221         }
<a name="l01222"></a>01222 
<a name="l01223"></a>01223       new_fds[fd - SD_LISTEN_FDS_START] = fd;
<a name="l01224"></a>01224     }
<a name="l01225"></a>01225 
<a name="l01226"></a>01226   *fds = new_fds;
<a name="l01227"></a>01227   <span class="keywordflow">return</span> n;
<a name="l01228"></a>01228 
<a name="l01229"></a>01229  fail:
<a name="l01230"></a>01230 
<a name="l01231"></a>01231   <span class="keywordflow">for</span> (fd = SD_LISTEN_FDS_START; fd &lt; SD_LISTEN_FDS_START + n; fd ++)
<a name="l01232"></a>01232     {
<a name="l01233"></a>01233       <a class="code" href="group__DBusSysdepsUnix.html#gac448479a1674e3b86cee9a4bdc7eba03" title="Closes a file descriptor.">_dbus_close</a> (fd, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l01234"></a>01234     }
<a name="l01235"></a>01235 
<a name="l01236"></a>01236   <a class="code" href="group__DBusMemory.html#ga34e666b19b015035a9a31e53da84b39a" title="Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().">dbus_free</a> (new_fds);
<a name="l01237"></a>01237   <span class="keywordflow">return</span> -1;
<a name="l01238"></a>01238 }
<a name="l01239"></a>01239 
<a name="l01253"></a>01253 <span class="keywordtype">int</span>
<a name="l01254"></a><a class="code" href="group__DBusSysdeps.html#gaa3adf90f6e47d30eeacf0a27d1a09ee5">01254</a> <a class="code" href="group__DBusSysdeps.html#gaa3adf90f6e47d30eeacf0a27d1a09ee5" title="Creates a socket and connects to a socket at the given host and port.">_dbus_connect_tcp_socket</a> (<span class="keyword">const</span> <span class="keywordtype">char</span>     *host,
<a name="l01255"></a>01255                           <span class="keyword">const</span> <span class="keywordtype">char</span>     *port,
<a name="l01256"></a>01256                           <span class="keyword">const</span> <span class="keywordtype">char</span>     *family,
<a name="l01257"></a>01257                           <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>      *error)
<a name="l01258"></a>01258 {
<a name="l01259"></a>01259     <span class="keywordflow">return</span> _dbus_connect_tcp_socket_with_nonce (host, port, family, (<span class="keyword">const</span> <span class="keywordtype">char</span>*)<a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, error);
<a name="l01260"></a>01260 }
<a name="l01261"></a>01261 
<a name="l01262"></a>01262 <span class="keywordtype">int</span>
<a name="l01263"></a>01263 _dbus_connect_tcp_socket_with_nonce (<span class="keyword">const</span> <span class="keywordtype">char</span>     *host,
<a name="l01264"></a>01264                                      <span class="keyword">const</span> <span class="keywordtype">char</span>     *port,
<a name="l01265"></a>01265                                      <span class="keyword">const</span> <span class="keywordtype">char</span>     *family,
<a name="l01266"></a>01266                                      <span class="keyword">const</span> <span class="keywordtype">char</span>     *noncefile,
<a name="l01267"></a>01267                                      <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>      *error)
<a name="l01268"></a>01268 {
<a name="l01269"></a>01269   <span class="keywordtype">int</span> saved_errno = 0;
<a name="l01270"></a>01270   <span class="keywordtype">int</span> fd = -1, res;
<a name="l01271"></a>01271   <span class="keyword">struct </span>addrinfo hints;
<a name="l01272"></a>01272   <span class="keyword">struct </span>addrinfo *ai, *tmp;
<a name="l01273"></a>01273 
<a name="l01274"></a>01274   _DBUS_ASSERT_ERROR_IS_CLEAR(error);
<a name="l01275"></a>01275 
<a name="l01276"></a>01276   _DBUS_ZERO (hints);
<a name="l01277"></a>01277 
<a name="l01278"></a>01278   <span class="keywordflow">if</span> (!family)
<a name="l01279"></a>01279     hints.ai_family = AF_UNSPEC;
<a name="l01280"></a>01280   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(family, <span class="stringliteral">&quot;ipv4&quot;</span>))
<a name="l01281"></a>01281     hints.ai_family = AF_INET;
<a name="l01282"></a>01282   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(family, <span class="stringliteral">&quot;ipv6&quot;</span>))
<a name="l01283"></a>01283     hints.ai_family = AF_INET6;
<a name="l01284"></a>01284   <span class="keywordflow">else</span>
<a name="l01285"></a>01285     {
<a name="l01286"></a>01286       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error,
<a name="l01287"></a>01287                       <a class="code" href="group__DBusProtocol.html#ga3fa04eb600edda4afc2dd9fe2e0f8b02" title="A D-Bus bus address was malformed.">DBUS_ERROR_BAD_ADDRESS</a>,
<a name="l01288"></a>01288                       <span class="stringliteral">&quot;Unknown address family %s&quot;</span>, family);
<a name="l01289"></a>01289       <span class="keywordflow">return</span> -1;
<a name="l01290"></a>01290     }
<a name="l01291"></a>01291   hints.ai_protocol = IPPROTO_TCP;
<a name="l01292"></a>01292   hints.ai_socktype = SOCK_STREAM;
<a name="l01293"></a>01293   hints.ai_flags = AI_ADDRCONFIG;
<a name="l01294"></a>01294 
<a name="l01295"></a>01295   <span class="keywordflow">if</span> ((res = getaddrinfo(host, port, &amp;hints, &amp;ai)) != 0)
<a name="l01296"></a>01296     {
<a name="l01297"></a>01297       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error,
<a name="l01298"></a>01298                       <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l01299"></a>01299                       <span class="stringliteral">&quot;Failed to lookup host/port: \&quot;%s:%s\&quot;: %s (%d)&quot;</span>,
<a name="l01300"></a>01300                       host, port, gai_strerror(res), res);
<a name="l01301"></a>01301       <span class="keywordflow">return</span> -1;
<a name="l01302"></a>01302     }
<a name="l01303"></a>01303 
<a name="l01304"></a>01304   tmp = ai;
<a name="l01305"></a>01305   <span class="keywordflow">while</span> (tmp)
<a name="l01306"></a>01306     {
<a name="l01307"></a>01307       <span class="keywordflow">if</span> (!_dbus_open_socket (&amp;fd, tmp-&gt;ai_family, SOCK_STREAM, 0, error))
<a name="l01308"></a>01308         {
<a name="l01309"></a>01309           freeaddrinfo(ai);
<a name="l01310"></a>01310           _DBUS_ASSERT_ERROR_IS_SET(error);
<a name="l01311"></a>01311           <span class="keywordflow">return</span> -1;
<a name="l01312"></a>01312         }
<a name="l01313"></a>01313       _DBUS_ASSERT_ERROR_IS_CLEAR(error);
<a name="l01314"></a>01314 
<a name="l01315"></a>01315       <span class="keywordflow">if</span> (connect (fd, (<span class="keyword">struct</span> sockaddr*) tmp-&gt;ai_addr, tmp-&gt;ai_addrlen) &lt; 0)
<a name="l01316"></a>01316         {
<a name="l01317"></a>01317           saved_errno = errno;
<a name="l01318"></a>01318           <a class="code" href="group__DBusSysdepsUnix.html#gac448479a1674e3b86cee9a4bdc7eba03" title="Closes a file descriptor.">_dbus_close</a>(fd, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l01319"></a>01319           fd = -1;
<a name="l01320"></a>01320           tmp = tmp-&gt;ai_next;
<a name="l01321"></a>01321           <span class="keywordflow">continue</span>;
<a name="l01322"></a>01322         }
<a name="l01323"></a>01323 
<a name="l01324"></a>01324       <span class="keywordflow">break</span>;
<a name="l01325"></a>01325     }
<a name="l01326"></a>01326   freeaddrinfo(ai);
<a name="l01327"></a>01327 
<a name="l01328"></a>01328   <span class="keywordflow">if</span> (fd == -1)
<a name="l01329"></a>01329     {
<a name="l01330"></a>01330       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error,
<a name="l01331"></a>01331                       <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (saved_errno),
<a name="l01332"></a>01332                       <span class="stringliteral">&quot;Failed to connect to socket \&quot;%s:%s\&quot; %s&quot;</span>,
<a name="l01333"></a>01333                       host, port, _dbus_strerror(saved_errno));
<a name="l01334"></a>01334       <span class="keywordflow">return</span> -1;
<a name="l01335"></a>01335     }
<a name="l01336"></a>01336 
<a name="l01337"></a>01337   <span class="keywordflow">if</span> (noncefile != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l01338"></a>01338     {
<a name="l01339"></a>01339       <a class="code" href="structDBusString.html">DBusString</a> noncefileStr;
<a name="l01340"></a>01340       <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> ret;
<a name="l01341"></a>01341       <a class="code" href="group__DBusString.html#ga374640ddfa2f0b27a8356e2379ba8043" title="Initializes a constant string.">_dbus_string_init_const</a> (&amp;noncefileStr, noncefile);
<a name="l01342"></a>01342       ret = _dbus_send_nonce (fd, &amp;noncefileStr, error);
<a name="l01343"></a>01343       <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a> (&amp;noncefileStr);
<a name="l01344"></a>01344 
<a name="l01345"></a>01345       <span class="keywordflow">if</span> (!ret)
<a name="l01346"></a>01346     {
<a name="l01347"></a>01347       <a class="code" href="group__DBusSysdepsUnix.html#gac448479a1674e3b86cee9a4bdc7eba03" title="Closes a file descriptor.">_dbus_close</a> (fd, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l01348"></a>01348           <span class="keywordflow">return</span> -1;
<a name="l01349"></a>01349         }
<a name="l01350"></a>01350     }
<a name="l01351"></a>01351 
<a name="l01352"></a>01352   <span class="keywordflow">if</span> (!_dbus_set_fd_nonblocking (fd, error))
<a name="l01353"></a>01353     {
<a name="l01354"></a>01354       <a class="code" href="group__DBusSysdepsUnix.html#gac448479a1674e3b86cee9a4bdc7eba03" title="Closes a file descriptor.">_dbus_close</a> (fd, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l01355"></a>01355       <span class="keywordflow">return</span> -1;
<a name="l01356"></a>01356     }
<a name="l01357"></a>01357 
<a name="l01358"></a>01358   <span class="keywordflow">return</span> fd;
<a name="l01359"></a>01359 }
<a name="l01360"></a>01360 
<a name="l01377"></a>01377 <span class="keywordtype">int</span>
<a name="l01378"></a><a class="code" href="group__DBusSysdeps.html#gafdae31b3b61299dbaaccfcb1205a6f30">01378</a> <a class="code" href="group__DBusSysdeps.html#gafdae31b3b61299dbaaccfcb1205a6f30" title="Creates a socket and binds it to the given path, then listens on the socket.">_dbus_listen_tcp_socket</a> (<span class="keyword">const</span> <span class="keywordtype">char</span>     *host,
<a name="l01379"></a>01379                          <span class="keyword">const</span> <span class="keywordtype">char</span>     *port,
<a name="l01380"></a>01380                          <span class="keyword">const</span> <span class="keywordtype">char</span>     *family,
<a name="l01381"></a>01381                          <a class="code" href="structDBusString.html">DBusString</a>     *retport,
<a name="l01382"></a>01382                          <span class="keywordtype">int</span>           **fds_p,
<a name="l01383"></a>01383                          <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>      *error)
<a name="l01384"></a>01384 {
<a name="l01385"></a>01385   <span class="keywordtype">int</span> saved_errno;
<a name="l01386"></a>01386   <span class="keywordtype">int</span> nlisten_fd = 0, *listen_fd = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, res, i;
<a name="l01387"></a>01387   <span class="keyword">struct </span>addrinfo hints;
<a name="l01388"></a>01388   <span class="keyword">struct </span>addrinfo *ai, *tmp;
<a name="l01389"></a>01389   <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> reuseaddr;
<a name="l01390"></a>01390 
<a name="l01391"></a>01391   *fds_p = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l01392"></a>01392   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l01393"></a>01393 
<a name="l01394"></a>01394   _DBUS_ZERO (hints);
<a name="l01395"></a>01395 
<a name="l01396"></a>01396   <span class="keywordflow">if</span> (!family)
<a name="l01397"></a>01397     hints.ai_family = AF_UNSPEC;
<a name="l01398"></a>01398   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(family, <span class="stringliteral">&quot;ipv4&quot;</span>))
<a name="l01399"></a>01399     hints.ai_family = AF_INET;
<a name="l01400"></a>01400   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(family, <span class="stringliteral">&quot;ipv6&quot;</span>))
<a name="l01401"></a>01401     hints.ai_family = AF_INET6;
<a name="l01402"></a>01402   <span class="keywordflow">else</span>
<a name="l01403"></a>01403     {
<a name="l01404"></a>01404       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error,
<a name="l01405"></a>01405                       <a class="code" href="group__DBusProtocol.html#ga3fa04eb600edda4afc2dd9fe2e0f8b02" title="A D-Bus bus address was malformed.">DBUS_ERROR_BAD_ADDRESS</a>,
<a name="l01406"></a>01406                       <span class="stringliteral">&quot;Unknown address family %s&quot;</span>, family);
<a name="l01407"></a>01407       <span class="keywordflow">return</span> -1;
<a name="l01408"></a>01408     }
<a name="l01409"></a>01409 
<a name="l01410"></a>01410   hints.ai_protocol = IPPROTO_TCP;
<a name="l01411"></a>01411   hints.ai_socktype = SOCK_STREAM;
<a name="l01412"></a>01412   hints.ai_flags = AI_ADDRCONFIG | AI_PASSIVE;
<a name="l01413"></a>01413 
<a name="l01414"></a>01414  redo_lookup_with_port:
<a name="l01415"></a>01415   ai = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l01416"></a>01416   <span class="keywordflow">if</span> ((res = getaddrinfo(host, port, &amp;hints, &amp;ai)) != 0 || !ai)
<a name="l01417"></a>01417     {
<a name="l01418"></a>01418       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error,
<a name="l01419"></a>01419                       <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l01420"></a>01420                       <span class="stringliteral">&quot;Failed to lookup host/port: \&quot;%s:%s\&quot;: %s (%d)&quot;</span>,
<a name="l01421"></a>01421                       host ? host : <span class="stringliteral">&quot;*&quot;</span>, port, gai_strerror(res), res);
<a name="l01422"></a>01422       <span class="keywordflow">goto</span> failed;
<a name="l01423"></a>01423     }
<a name="l01424"></a>01424 
<a name="l01425"></a>01425   tmp = ai;
<a name="l01426"></a>01426   <span class="keywordflow">while</span> (tmp)
<a name="l01427"></a>01427     {
<a name="l01428"></a>01428       <span class="keywordtype">int</span> fd = -1, *newlisten_fd;
<a name="l01429"></a>01429       <span class="keywordflow">if</span> (!_dbus_open_socket (&amp;fd, tmp-&gt;ai_family, SOCK_STREAM, 0, error))
<a name="l01430"></a>01430         {
<a name="l01431"></a>01431           _DBUS_ASSERT_ERROR_IS_SET(error);
<a name="l01432"></a>01432           <span class="keywordflow">goto</span> failed;
<a name="l01433"></a>01433         }
<a name="l01434"></a>01434       _DBUS_ASSERT_ERROR_IS_CLEAR(error);
<a name="l01435"></a>01435 
<a name="l01436"></a>01436       reuseaddr = 1;
<a name="l01437"></a>01437       <span class="keywordflow">if</span> (setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &amp;reuseaddr, <span class="keyword">sizeof</span>(reuseaddr))==-1)
<a name="l01438"></a>01438         {
<a name="l01439"></a>01439           <a class="code" href="group__DBusInternalsUtils.html#gabea2c16d6d3fe7c4eb5b9496fc877f84" title="Prints a warning message to stderr.">_dbus_warn</a> (<span class="stringliteral">&quot;Failed to set socket option \&quot;%s:%s\&quot;: %s&quot;</span>,
<a name="l01440"></a>01440                       host ? host : <span class="stringliteral">&quot;*&quot;</span>, port, _dbus_strerror (errno));
<a name="l01441"></a>01441         }
<a name="l01442"></a>01442 
<a name="l01443"></a>01443       <span class="keywordflow">if</span> (bind (fd, (<span class="keyword">struct</span> sockaddr*) tmp-&gt;ai_addr, tmp-&gt;ai_addrlen) &lt; 0)
<a name="l01444"></a>01444         {
<a name="l01445"></a>01445           saved_errno = errno;
<a name="l01446"></a>01446           <a class="code" href="group__DBusSysdepsUnix.html#gac448479a1674e3b86cee9a4bdc7eba03" title="Closes a file descriptor.">_dbus_close</a>(fd, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l01447"></a>01447           <span class="keywordflow">if</span> (saved_errno == EADDRINUSE)
<a name="l01448"></a>01448             {
<a name="l01449"></a>01449               <span class="comment">/* Depending on kernel policy, it may or may not</span>
<a name="l01450"></a>01450 <span class="comment">                 be neccessary to bind to both IPv4 &amp; 6 addresses</span>
<a name="l01451"></a>01451 <span class="comment">                 so ignore EADDRINUSE here */</span>
<a name="l01452"></a>01452               tmp = tmp-&gt;ai_next;
<a name="l01453"></a>01453               <span class="keywordflow">continue</span>;
<a name="l01454"></a>01454             }
<a name="l01455"></a>01455           <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (saved_errno),
<a name="l01456"></a>01456                           <span class="stringliteral">&quot;Failed to bind socket \&quot;%s:%s\&quot;: %s&quot;</span>,
<a name="l01457"></a>01457                           host ? host : <span class="stringliteral">&quot;*&quot;</span>, port, _dbus_strerror (saved_errno));
<a name="l01458"></a>01458           <span class="keywordflow">goto</span> failed;
<a name="l01459"></a>01459         }
<a name="l01460"></a>01460 
<a name="l01461"></a>01461       <span class="keywordflow">if</span> (listen (fd, 30 <span class="comment">/* backlog */</span>) &lt; 0)
<a name="l01462"></a>01462         {
<a name="l01463"></a>01463           saved_errno = errno;
<a name="l01464"></a>01464           <a class="code" href="group__DBusSysdepsUnix.html#gac448479a1674e3b86cee9a4bdc7eba03" title="Closes a file descriptor.">_dbus_close</a> (fd, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l01465"></a>01465           <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (saved_errno),
<a name="l01466"></a>01466                           <span class="stringliteral">&quot;Failed to listen on socket \&quot;%s:%s\&quot;: %s&quot;</span>,
<a name="l01467"></a>01467                           host ? host : <span class="stringliteral">&quot;*&quot;</span>, port, _dbus_strerror (saved_errno));
<a name="l01468"></a>01468           <span class="keywordflow">goto</span> failed;
<a name="l01469"></a>01469         }
<a name="l01470"></a>01470 
<a name="l01471"></a>01471       newlisten_fd = <a class="code" href="group__DBusMemory.html#ga2d505f2960ccf343042d363170b27f9c" title="Resizes a block of memory previously allocated by dbus_malloc() or dbus_malloc0().">dbus_realloc</a>(listen_fd, <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)*(nlisten_fd+1));
<a name="l01472"></a>01472       <span class="keywordflow">if</span> (!newlisten_fd)
<a name="l01473"></a>01473         {
<a name="l01474"></a>01474           saved_errno = errno;
<a name="l01475"></a>01475           <a class="code" href="group__DBusSysdepsUnix.html#gac448479a1674e3b86cee9a4bdc7eba03" title="Closes a file descriptor.">_dbus_close</a> (fd, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l01476"></a>01476           <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (saved_errno),
<a name="l01477"></a>01477                           <span class="stringliteral">&quot;Failed to allocate file handle array: %s&quot;</span>,
<a name="l01478"></a>01478                           _dbus_strerror (saved_errno));
<a name="l01479"></a>01479           <span class="keywordflow">goto</span> failed;
<a name="l01480"></a>01480         }
<a name="l01481"></a>01481       listen_fd = newlisten_fd;
<a name="l01482"></a>01482       listen_fd[nlisten_fd] = fd;
<a name="l01483"></a>01483       nlisten_fd++;
<a name="l01484"></a>01484 
<a name="l01485"></a>01485       <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#gaa5136e6fd2c5188f4b88de7863369c6d" title="Gets the length of a string (not including nul termination).">_dbus_string_get_length</a>(retport))
<a name="l01486"></a>01486         {
<a name="l01487"></a>01487           <span class="comment">/* If the user didn&#39;t specify a port, or used 0, then</span>
<a name="l01488"></a>01488 <span class="comment">             the kernel chooses a port. After the first address</span>
<a name="l01489"></a>01489 <span class="comment">             is bound to, we need to force all remaining addresses</span>
<a name="l01490"></a>01490 <span class="comment">             to use the same port */</span>
<a name="l01491"></a>01491           <span class="keywordflow">if</span> (!port || !strcmp(port, <span class="stringliteral">&quot;0&quot;</span>))
<a name="l01492"></a>01492             {
<a name="l01493"></a>01493               <span class="keywordtype">int</span> result;
<a name="l01494"></a>01494               <span class="keyword">struct </span>sockaddr_storage addr;
<a name="l01495"></a>01495               socklen_t addrlen;
<a name="l01496"></a>01496               <span class="keywordtype">char</span> portbuf[50];
<a name="l01497"></a>01497 
<a name="l01498"></a>01498               addrlen = <span class="keyword">sizeof</span>(addr);
<a name="l01499"></a>01499               result = getsockname(fd, (<span class="keyword">struct</span> sockaddr*) &amp;addr, &amp;addrlen);
<a name="l01500"></a>01500 
<a name="l01501"></a>01501               <span class="keywordflow">if</span> (result == -1 ||
<a name="l01502"></a>01502                   (res = getnameinfo ((<span class="keyword">struct</span> sockaddr*)&amp;addr, addrlen, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, 0,
<a name="l01503"></a>01503                                       portbuf, <span class="keyword">sizeof</span>(portbuf),
<a name="l01504"></a>01504                                       NI_NUMERICHOST)) != 0)
<a name="l01505"></a>01505                 {
<a name="l01506"></a>01506                   <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l01507"></a>01507                                   <span class="stringliteral">&quot;Failed to resolve port \&quot;%s:%s\&quot;: %s (%s)&quot;</span>,
<a name="l01508"></a>01508                                   host ? host : <span class="stringliteral">&quot;*&quot;</span>, port, gai_strerror(res), res);
<a name="l01509"></a>01509                   <span class="keywordflow">goto</span> failed;
<a name="l01510"></a>01510                 }
<a name="l01511"></a>01511               <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga100c5ce0696822c5a4cfbdfaba674d96" title="Appends a nul-terminated C-style string to a DBusString.">_dbus_string_append</a>(retport, portbuf))
<a name="l01512"></a>01512                 {
<a name="l01513"></a>01513                   <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gac32eaf0b92f798307853cd4fe0cf11c2" title="There was not enough memory to complete an operation.">DBUS_ERROR_NO_MEMORY</a>, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l01514"></a>01514                   <span class="keywordflow">goto</span> failed;
<a name="l01515"></a>01515                 }
<a name="l01516"></a>01516 
<a name="l01517"></a>01517               <span class="comment">/* Release current address list &amp; redo lookup */</span>
<a name="l01518"></a>01518               port = <a class="code" href="group__DBusString.html#ga33e20241ae7d784624f97d89b1a0539e" title="Gets the raw character buffer from a const string.">_dbus_string_get_const_data</a>(retport);
<a name="l01519"></a>01519               freeaddrinfo(ai);
<a name="l01520"></a>01520               <span class="keywordflow">goto</span> redo_lookup_with_port;
<a name="l01521"></a>01521             }
<a name="l01522"></a>01522           <span class="keywordflow">else</span>
<a name="l01523"></a>01523             {
<a name="l01524"></a>01524               <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga100c5ce0696822c5a4cfbdfaba674d96" title="Appends a nul-terminated C-style string to a DBusString.">_dbus_string_append</a>(retport, port))
<a name="l01525"></a>01525                 {
<a name="l01526"></a>01526                     <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gac32eaf0b92f798307853cd4fe0cf11c2" title="There was not enough memory to complete an operation.">DBUS_ERROR_NO_MEMORY</a>, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l01527"></a>01527                     <span class="keywordflow">goto</span> failed;
<a name="l01528"></a>01528                 }
<a name="l01529"></a>01529             }
<a name="l01530"></a>01530         }
<a name="l01531"></a>01531 
<a name="l01532"></a>01532       tmp = tmp-&gt;ai_next;
<a name="l01533"></a>01533     }
<a name="l01534"></a>01534   freeaddrinfo(ai);
<a name="l01535"></a>01535   ai = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l01536"></a>01536 
<a name="l01537"></a>01537   <span class="keywordflow">if</span> (!nlisten_fd)
<a name="l01538"></a>01538     {
<a name="l01539"></a>01539       errno = EADDRINUSE;
<a name="l01540"></a>01540       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l01541"></a>01541                       <span class="stringliteral">&quot;Failed to bind socket \&quot;%s:%s\&quot;: %s&quot;</span>,
<a name="l01542"></a>01542                       host ? host : <span class="stringliteral">&quot;*&quot;</span>, port, _dbus_strerror (errno));
<a name="l01543"></a>01543       <span class="keywordflow">goto</span> failed;
<a name="l01544"></a>01544     }
<a name="l01545"></a>01545 
<a name="l01546"></a>01546   <span class="keywordflow">for</span> (i = 0 ; i &lt; nlisten_fd ; i++)
<a name="l01547"></a>01547     {
<a name="l01548"></a>01548       <span class="keywordflow">if</span> (!_dbus_set_fd_nonblocking (listen_fd[i], error))
<a name="l01549"></a>01549         {
<a name="l01550"></a>01550           <span class="keywordflow">goto</span> failed;
<a name="l01551"></a>01551         }
<a name="l01552"></a>01552     }
<a name="l01553"></a>01553 
<a name="l01554"></a>01554   *fds_p = listen_fd;
<a name="l01555"></a>01555 
<a name="l01556"></a>01556   <span class="keywordflow">return</span> nlisten_fd;
<a name="l01557"></a>01557 
<a name="l01558"></a>01558  failed:
<a name="l01559"></a>01559   <span class="keywordflow">if</span> (ai)
<a name="l01560"></a>01560     freeaddrinfo(ai);
<a name="l01561"></a>01561   <span class="keywordflow">for</span> (i = 0 ; i &lt; nlisten_fd ; i++)
<a name="l01562"></a>01562     <a class="code" href="group__DBusSysdepsUnix.html#gac448479a1674e3b86cee9a4bdc7eba03" title="Closes a file descriptor.">_dbus_close</a>(listen_fd[i], <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l01563"></a>01563   <a class="code" href="group__DBusMemory.html#ga34e666b19b015035a9a31e53da84b39a" title="Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().">dbus_free</a>(listen_fd);
<a name="l01564"></a>01564   <span class="keywordflow">return</span> -1;
<a name="l01565"></a>01565 }
<a name="l01566"></a>01566 
<a name="l01567"></a>01567 <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l01568"></a>01568 write_credentials_byte (<span class="keywordtype">int</span>             server_fd,
<a name="l01569"></a>01569                         <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>      *error)
<a name="l01570"></a>01570 {
<a name="l01571"></a>01571   <span class="keywordtype">int</span> bytes_written;
<a name="l01572"></a>01572   <span class="keywordtype">char</span> buf[1] = { <span class="charliteral">&#39;\0&#39;</span> };
<a name="l01573"></a>01573 <span class="preprocessor">#if defined(HAVE_CMSGCRED)</span>
<a name="l01574"></a>01574 <span class="preprocessor"></span>  <span class="keyword">union </span>{
<a name="l01575"></a>01575           <span class="keyword">struct </span>cmsghdr hdr;
<a name="l01576"></a>01576           <span class="keywordtype">char</span> cred[CMSG_SPACE (<span class="keyword">sizeof</span> (<span class="keyword">struct</span> cmsgcred))];
<a name="l01577"></a>01577   } cmsg;
<a name="l01578"></a>01578   <span class="keyword">struct </span>iovec iov;
<a name="l01579"></a>01579   <span class="keyword">struct </span>msghdr msg;
<a name="l01580"></a>01580   iov.iov_base = buf;
<a name="l01581"></a>01581   iov.iov_len = 1;
<a name="l01582"></a>01582 
<a name="l01583"></a>01583   _DBUS_ZERO(msg);
<a name="l01584"></a>01584   msg.msg_iov = &amp;iov;
<a name="l01585"></a>01585   msg.msg_iovlen = 1;
<a name="l01586"></a>01586 
<a name="l01587"></a>01587   msg.msg_control = (caddr_t) &amp;cmsg;
<a name="l01588"></a>01588   msg.msg_controllen = CMSG_SPACE (<span class="keyword">sizeof</span> (<span class="keyword">struct</span> cmsgcred));
<a name="l01589"></a>01589   _DBUS_ZERO(cmsg);
<a name="l01590"></a>01590   cmsg.hdr.cmsg_len = CMSG_LEN (<span class="keyword">sizeof</span> (<span class="keyword">struct</span> cmsgcred));
<a name="l01591"></a>01591   cmsg.hdr.cmsg_level = SOL_SOCKET;
<a name="l01592"></a>01592   cmsg.hdr.cmsg_type = SCM_CREDS;
<a name="l01593"></a>01593 <span class="preprocessor">#endif</span>
<a name="l01594"></a>01594 <span class="preprocessor"></span>
<a name="l01595"></a>01595   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l01596"></a>01596 
<a name="l01597"></a>01597  again:
<a name="l01598"></a>01598 
<a name="l01599"></a>01599 <span class="preprocessor">#if defined(HAVE_CMSGCRED)</span>
<a name="l01600"></a>01600 <span class="preprocessor"></span>  bytes_written = sendmsg (server_fd, &amp;msg, 0
<a name="l01601"></a>01601 #<span class="keywordflow">if</span> HAVE_DECL_MSG_NOSIGNAL
<a name="l01602"></a>01602                            |MSG_NOSIGNAL
<a name="l01603"></a>01603 #endif
<a name="l01604"></a>01604                            );
<a name="l01605"></a>01605 
<a name="l01606"></a>01606   <span class="comment">/* If we HAVE_CMSGCRED, the OS still might not let us sendmsg()</span>
<a name="l01607"></a>01607 <span class="comment">   * with a SOL_SOCKET/SCM_CREDS message - for instance, FreeBSD</span>
<a name="l01608"></a>01608 <span class="comment">   * only allows that on AF_UNIX. Try just doing a send() instead. */</span>
<a name="l01609"></a>01609   <span class="keywordflow">if</span> (bytes_written &lt; 0 &amp;&amp; errno == EINVAL)
<a name="l01610"></a>01610 <span class="preprocessor">#endif</span>
<a name="l01611"></a>01611 <span class="preprocessor"></span>    {
<a name="l01612"></a>01612       bytes_written = send (server_fd, buf, 1, 0
<a name="l01613"></a>01613 #<span class="keywordflow">if</span> HAVE_DECL_MSG_NOSIGNAL
<a name="l01614"></a>01614                             |MSG_NOSIGNAL
<a name="l01615"></a>01615 #endif
<a name="l01616"></a>01616                             );
<a name="l01617"></a>01617     }
<a name="l01618"></a>01618 
<a name="l01619"></a>01619   <span class="keywordflow">if</span> (bytes_written &lt; 0 &amp;&amp; errno == EINTR)
<a name="l01620"></a>01620     <span class="keywordflow">goto</span> again;
<a name="l01621"></a>01621 
<a name="l01622"></a>01622   <span class="keywordflow">if</span> (bytes_written &lt; 0)
<a name="l01623"></a>01623     {
<a name="l01624"></a>01624       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l01625"></a>01625                       <span class="stringliteral">&quot;Failed to write credentials byte: %s&quot;</span>,
<a name="l01626"></a>01626                      _dbus_strerror (errno));
<a name="l01627"></a>01627       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l01628"></a>01628     }
<a name="l01629"></a>01629   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (bytes_written == 0)
<a name="l01630"></a>01630     {
<a name="l01631"></a>01631       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#ga445d7ad73da94c796ef441df2dcc3cc8" title="Something went wrong reading or writing to a socket, for example.">DBUS_ERROR_IO_ERROR</a>,
<a name="l01632"></a>01632                       <span class="stringliteral">&quot;wrote zero bytes writing credentials byte&quot;</span>);
<a name="l01633"></a>01633       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l01634"></a>01634     }
<a name="l01635"></a>01635   <span class="keywordflow">else</span>
<a name="l01636"></a>01636     {
<a name="l01637"></a>01637       _dbus_assert (bytes_written == 1);
<a name="l01638"></a>01638       _dbus_verbose (<span class="stringliteral">&quot;wrote credentials byte\n&quot;</span>);
<a name="l01639"></a>01639       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l01640"></a>01640     }
<a name="l01641"></a>01641 }
<a name="l01642"></a>01642 
<a name="l01664"></a>01664 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l01665"></a><a class="code" href="group__DBusSysdeps.html#ga9906c86bebb51358f0d8df6a42af30f6">01665</a> <a class="code" href="group__DBusSysdeps.html#ga9906c86bebb51358f0d8df6a42af30f6" title="Reads a single byte which must be nul (an error occurs otherwise), and reads unix credentials if avai...">_dbus_read_credentials_socket</a>  (<span class="keywordtype">int</span>              client_fd,
<a name="l01666"></a>01666                                 <a class="code" href="structDBusCredentials.html">DBusCredentials</a> *credentials,
<a name="l01667"></a>01667                                 <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>       *error)
<a name="l01668"></a>01668 {
<a name="l01669"></a>01669   <span class="keyword">struct </span>msghdr msg;
<a name="l01670"></a>01670   <span class="keyword">struct </span>iovec iov;
<a name="l01671"></a>01671   <span class="keywordtype">char</span> buf;
<a name="l01672"></a>01672   <a class="code" href="group__DBusSysdeps.html#ga186e987b700f9ddc6cea8aa0db82b151" title="A user ID.">dbus_uid_t</a> uid_read;
<a name="l01673"></a>01673   <a class="code" href="group__DBusSysdeps.html#ga1eff6303266888ec466cddba6c03aa40" title="A process ID.">dbus_pid_t</a> pid_read;
<a name="l01674"></a>01674   <span class="keywordtype">int</span> bytes_read;
<a name="l01675"></a>01675 
<a name="l01676"></a>01676 <span class="preprocessor">#ifdef HAVE_CMSGCRED</span>
<a name="l01677"></a>01677 <span class="preprocessor"></span>  <span class="keyword">union </span>{
<a name="l01678"></a>01678     <span class="keyword">struct </span>cmsghdr hdr;
<a name="l01679"></a>01679     <span class="keywordtype">char</span> cred[CMSG_SPACE (<span class="keyword">sizeof</span> (<span class="keyword">struct</span> cmsgcred))];
<a name="l01680"></a>01680   } cmsg;
<a name="l01681"></a>01681 <span class="preprocessor">#endif</span>
<a name="l01682"></a>01682 <span class="preprocessor"></span>
<a name="l01683"></a>01683   uid_read = <a class="code" href="group__DBusSysdeps.html#ga3d2f3fb32bb759cabe362ca2de383f7d" title="an invalid UID used to represent an uninitialized dbus_uid_t field">DBUS_UID_UNSET</a>;
<a name="l01684"></a>01684   pid_read = <a class="code" href="group__DBusSysdeps.html#ga4eb5f05dd6ad89caa4b0340e1cf0b8d9" title="an invalid PID used to represent an uninitialized dbus_pid_t field">DBUS_PID_UNSET</a>;
<a name="l01685"></a>01685 
<a name="l01686"></a>01686   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l01687"></a>01687 
<a name="l01688"></a>01688   <span class="comment">/* The POSIX spec certainly doesn&#39;t promise this, but</span>
<a name="l01689"></a>01689 <span class="comment">   * we need these assertions to fail as soon as we&#39;re wrong about</span>
<a name="l01690"></a>01690 <span class="comment">   * it so we can do the porting fixups</span>
<a name="l01691"></a>01691 <span class="comment">   */</span>
<a name="l01692"></a>01692   _dbus_assert (<span class="keyword">sizeof</span> (pid_t) &lt;= <span class="keyword">sizeof</span> (<a class="code" href="group__DBusSysdeps.html#ga1eff6303266888ec466cddba6c03aa40" title="A process ID.">dbus_pid_t</a>));
<a name="l01693"></a>01693   _dbus_assert (<span class="keyword">sizeof</span> (uid_t) &lt;= <span class="keyword">sizeof</span> (<a class="code" href="group__DBusSysdeps.html#ga186e987b700f9ddc6cea8aa0db82b151" title="A user ID.">dbus_uid_t</a>));
<a name="l01694"></a>01694   _dbus_assert (<span class="keyword">sizeof</span> (gid_t) &lt;= <span class="keyword">sizeof</span> (<a class="code" href="group__DBusSysdeps.html#ga2f5c2e418b81ec2a86594f56ec6d7627" title="A group ID.">dbus_gid_t</a>));
<a name="l01695"></a>01695 
<a name="l01696"></a>01696   <a class="code" href="group__DBusCredentials.html#ga40a5c7e37b10419e233a473dc7173f3c" title="Clear all credentials in the object.">_dbus_credentials_clear</a> (credentials);
<a name="l01697"></a>01697 
<a name="l01698"></a>01698   iov.iov_base = &amp;buf;
<a name="l01699"></a>01699   iov.iov_len = 1;
<a name="l01700"></a>01700 
<a name="l01701"></a>01701   _DBUS_ZERO(msg);
<a name="l01702"></a>01702   msg.msg_iov = &amp;iov;
<a name="l01703"></a>01703   msg.msg_iovlen = 1;
<a name="l01704"></a>01704 
<a name="l01705"></a>01705 <span class="preprocessor">#if defined(HAVE_CMSGCRED)</span>
<a name="l01706"></a>01706 <span class="preprocessor"></span>  _DBUS_ZERO(cmsg);
<a name="l01707"></a>01707   msg.msg_control = (caddr_t) &amp;cmsg;
<a name="l01708"></a>01708   msg.msg_controllen = CMSG_SPACE (<span class="keyword">sizeof</span> (<span class="keyword">struct</span> cmsgcred));
<a name="l01709"></a>01709 <span class="preprocessor">#endif</span>
<a name="l01710"></a>01710 <span class="preprocessor"></span>
<a name="l01711"></a>01711  again:
<a name="l01712"></a>01712   bytes_read = recvmsg (client_fd, &amp;msg, 0);
<a name="l01713"></a>01713 
<a name="l01714"></a>01714   <span class="keywordflow">if</span> (bytes_read &lt; 0)
<a name="l01715"></a>01715     {
<a name="l01716"></a>01716       <span class="keywordflow">if</span> (errno == EINTR)
<a name="l01717"></a>01717         <span class="keywordflow">goto</span> again;
<a name="l01718"></a>01718 
<a name="l01719"></a>01719       <span class="comment">/* EAGAIN or EWOULDBLOCK would be unexpected here since we would</span>
<a name="l01720"></a>01720 <span class="comment">       * normally only call read_credentials if the socket was ready</span>
<a name="l01721"></a>01721 <span class="comment">       * for reading</span>
<a name="l01722"></a>01722 <span class="comment">       */</span>
<a name="l01723"></a>01723 
<a name="l01724"></a>01724       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l01725"></a>01725                       <span class="stringliteral">&quot;Failed to read credentials byte: %s&quot;</span>,
<a name="l01726"></a>01726                       _dbus_strerror (errno));
<a name="l01727"></a>01727       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l01728"></a>01728     }
<a name="l01729"></a>01729   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (bytes_read == 0)
<a name="l01730"></a>01730     {
<a name="l01731"></a>01731       <span class="comment">/* this should not happen unless we are using recvmsg wrong,</span>
<a name="l01732"></a>01732 <span class="comment">       * so is essentially here for paranoia</span>
<a name="l01733"></a>01733 <span class="comment">       */</span>
<a name="l01734"></a>01734       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gabb62fd6340d0787fbd56ff8dd2f326c7" title="A generic error; &quot;something went wrong&quot; - see the error message for more.">DBUS_ERROR_FAILED</a>,
<a name="l01735"></a>01735                       <span class="stringliteral">&quot;Failed to read credentials byte (zero-length read)&quot;</span>);
<a name="l01736"></a>01736       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l01737"></a>01737     }
<a name="l01738"></a>01738   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (buf != <span class="charliteral">&#39;\0&#39;</span>)
<a name="l01739"></a>01739     {
<a name="l01740"></a>01740       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gabb62fd6340d0787fbd56ff8dd2f326c7" title="A generic error; &quot;something went wrong&quot; - see the error message for more.">DBUS_ERROR_FAILED</a>,
<a name="l01741"></a>01741                       <span class="stringliteral">&quot;Credentials byte was not nul&quot;</span>);
<a name="l01742"></a>01742       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l01743"></a>01743     }
<a name="l01744"></a>01744 
<a name="l01745"></a>01745   _dbus_verbose (<span class="stringliteral">&quot;read credentials byte\n&quot;</span>);
<a name="l01746"></a>01746 
<a name="l01747"></a>01747   {
<a name="l01748"></a>01748 <span class="preprocessor">#ifdef SO_PEERCRED</span>
<a name="l01749"></a>01749 <span class="preprocessor"></span>    <span class="comment">/* Supported by at least Linux and OpenBSD, with minor differences.</span>
<a name="l01750"></a>01750 <span class="comment">     *</span>
<a name="l01751"></a>01751 <span class="comment">     * This mechanism passes the process ID through and does not require</span>
<a name="l01752"></a>01752 <span class="comment">     * the peer&#39;s cooperation, so we prefer it over all others. Notably,</span>
<a name="l01753"></a>01753 <span class="comment">     * Linux also supports SCM_CREDENTIALS, which is similar to FreeBSD</span>
<a name="l01754"></a>01754 <span class="comment">     * SCM_CREDS; it&#39;s implemented in GIO, but we don&#39;t use it in dbus at all,</span>
<a name="l01755"></a>01755 <span class="comment">     * because this is much less fragile.</span>
<a name="l01756"></a>01756 <span class="comment">     */</span>
<a name="l01757"></a>01757 <span class="preprocessor">#ifdef __OpenBSD__</span>
<a name="l01758"></a>01758 <span class="preprocessor"></span>    <span class="keyword">struct </span>sockpeercred cr;
<a name="l01759"></a>01759 <span class="preprocessor">#else</span>
<a name="l01760"></a>01760 <span class="preprocessor"></span>    <span class="keyword">struct </span>ucred cr;
<a name="l01761"></a>01761 <span class="preprocessor">#endif</span>
<a name="l01762"></a>01762 <span class="preprocessor"></span>    <span class="keywordtype">int</span> cr_len = <span class="keyword">sizeof</span> (cr);
<a name="l01763"></a>01763 
<a name="l01764"></a>01764     <span class="keywordflow">if</span> (getsockopt (client_fd, SOL_SOCKET, SO_PEERCRED, &amp;cr, &amp;cr_len) == 0 &amp;&amp;
<a name="l01765"></a>01765         cr_len == <span class="keyword">sizeof</span> (cr))
<a name="l01766"></a>01766       {
<a name="l01767"></a>01767         pid_read = cr.pid;
<a name="l01768"></a>01768         uid_read = cr.uid;
<a name="l01769"></a>01769       }
<a name="l01770"></a>01770     <span class="keywordflow">else</span>
<a name="l01771"></a>01771       {
<a name="l01772"></a>01772         _dbus_verbose (<span class="stringliteral">&quot;Failed to getsockopt() credentials, returned len %d/%d: %s\n&quot;</span>,
<a name="l01773"></a>01773                        cr_len, (<span class="keywordtype">int</span>) <span class="keyword">sizeof</span> (cr), _dbus_strerror (errno));
<a name="l01774"></a>01774       }
<a name="l01775"></a>01775 <span class="preprocessor">#elif defined(HAVE_CMSGCRED)</span>
<a name="l01776"></a>01776 <span class="preprocessor"></span>    <span class="comment">/* We only check for HAVE_CMSGCRED, but we&#39;re really assuming that the</span>
<a name="l01777"></a>01777 <span class="comment">     * presence of that struct implies SCM_CREDS. Supported by at least</span>
<a name="l01778"></a>01778 <span class="comment">     * FreeBSD and DragonflyBSD.</span>
<a name="l01779"></a>01779 <span class="comment">     *</span>
<a name="l01780"></a>01780 <span class="comment">     * This mechanism requires the peer to help us (it has to send us a</span>
<a name="l01781"></a>01781 <span class="comment">     * SCM_CREDS message) but it does pass the process ID through,</span>
<a name="l01782"></a>01782 <span class="comment">     * which makes it better than getpeereid().</span>
<a name="l01783"></a>01783 <span class="comment">     */</span>
<a name="l01784"></a>01784     <span class="keyword">struct </span>cmsgcred *cred;
<a name="l01785"></a>01785     <span class="keyword">struct </span>cmsghdr *cmsgp;
<a name="l01786"></a>01786 
<a name="l01787"></a>01787     <span class="keywordflow">for</span> (cmsgp = CMSG_FIRSTHDR (&amp;msg);
<a name="l01788"></a>01788          cmsgp != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l01789"></a>01789          cmsgp = CMSG_NXTHDR (&amp;msg, cmsgp))
<a name="l01790"></a>01790       {
<a name="l01791"></a>01791         <span class="keywordflow">if</span> (cmsgp-&gt;cmsg_type == SCM_CREDS &amp;&amp;
<a name="l01792"></a>01792             cmsgp-&gt;cmsg_level == SOL_SOCKET &amp;&amp;
<a name="l01793"></a>01793             cmsgp-&gt;cmsg_len &gt;= CMSG_LEN (<span class="keyword">sizeof</span> (<span class="keyword">struct</span> cmsgcred)))
<a name="l01794"></a>01794           {
<a name="l01795"></a>01795             cred = (<span class="keyword">struct </span>cmsgcred *) CMSG_DATA (cmsgp);
<a name="l01796"></a>01796             pid_read = cred-&gt;cmcred_pid;
<a name="l01797"></a>01797             uid_read = cred-&gt;cmcred_euid;
<a name="l01798"></a>01798             <span class="keywordflow">break</span>;
<a name="l01799"></a>01799           }
<a name="l01800"></a>01800       }
<a name="l01801"></a>01801 
<a name="l01802"></a>01802 <span class="preprocessor">#elif defined(HAVE_GETPEERUCRED)</span>
<a name="l01803"></a>01803 <span class="preprocessor"></span>    <span class="comment">/* Supported in at least Solaris &gt;= 10. It should probably be higher</span>
<a name="l01804"></a>01804 <span class="comment">     * up this list, because it carries the pid and we use this code path</span>
<a name="l01805"></a>01805 <span class="comment">     * for audit data. */</span>
<a name="l01806"></a>01806     ucred_t * ucred = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l01807"></a>01807     <span class="keywordflow">if</span> (getpeerucred (client_fd, &amp;ucred) == 0)
<a name="l01808"></a>01808       {
<a name="l01809"></a>01809         pid_read = ucred_getpid (ucred);
<a name="l01810"></a>01810         uid_read = ucred_geteuid (ucred);
<a name="l01811"></a>01811 <span class="preprocessor">#ifdef HAVE_ADT</span>
<a name="l01812"></a>01812 <span class="preprocessor"></span>        <span class="comment">/* generate audit session data based on socket ucred */</span>
<a name="l01813"></a>01813         adt_session_data_t *adth = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l01814"></a>01814         adt_export_data_t *data = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l01815"></a>01815         <span class="keywordtype">size_t</span> size = 0;
<a name="l01816"></a>01816         <span class="keywordflow">if</span> (adt_start_session (&amp;adth, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, 0) || (adth == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>))
<a name="l01817"></a>01817           {
<a name="l01818"></a>01818             _dbus_verbose (<span class="stringliteral">&quot;Failed to adt_start_session(): %s\n&quot;</span>, _dbus_strerror (errno));
<a name="l01819"></a>01819           }
<a name="l01820"></a>01820         <span class="keywordflow">else</span>
<a name="l01821"></a>01821           {
<a name="l01822"></a>01822             <span class="keywordflow">if</span> (adt_set_from_ucred (adth, ucred, ADT_NEW))
<a name="l01823"></a>01823               {
<a name="l01824"></a>01824                 _dbus_verbose (<span class="stringliteral">&quot;Failed to adt_set_from_ucred(): %s\n&quot;</span>, _dbus_strerror (errno));
<a name="l01825"></a>01825               }
<a name="l01826"></a>01826             <span class="keywordflow">else</span>
<a name="l01827"></a>01827               {
<a name="l01828"></a>01828                 size = adt_export_session_data (adth, &amp;data);
<a name="l01829"></a>01829                 <span class="keywordflow">if</span> (size &lt;= 0)
<a name="l01830"></a>01830                   {
<a name="l01831"></a>01831                     _dbus_verbose (<span class="stringliteral">&quot;Failed to adt_export_session_data(): %s\n&quot;</span>, _dbus_strerror (errno));
<a name="l01832"></a>01832                   }
<a name="l01833"></a>01833                 <span class="keywordflow">else</span>
<a name="l01834"></a>01834                   {
<a name="l01835"></a>01835                     <a class="code" href="group__DBusCredentials.html#gab26eb5cb8d05139806cf06e99c4ec5b0" title="Add ADT audit data to the credentials.">_dbus_credentials_add_adt_audit_data</a> (credentials, data, size);
<a name="l01836"></a>01836                     free (data);
<a name="l01837"></a>01837                   }
<a name="l01838"></a>01838               }
<a name="l01839"></a>01839             (void) adt_end_session (adth);
<a name="l01840"></a>01840           }
<a name="l01841"></a>01841 <span class="preprocessor">#endif </span><span class="comment">/* HAVE_ADT */</span>
<a name="l01842"></a>01842       }
<a name="l01843"></a>01843     <span class="keywordflow">else</span>
<a name="l01844"></a>01844       {
<a name="l01845"></a>01845         _dbus_verbose (<span class="stringliteral">&quot;Failed to getpeerucred() credentials: %s\n&quot;</span>, _dbus_strerror (errno));
<a name="l01846"></a>01846       }
<a name="l01847"></a>01847     <span class="keywordflow">if</span> (ucred != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l01848"></a>01848       ucred_free (ucred);
<a name="l01849"></a>01849 
<a name="l01850"></a>01850     <span class="comment">/* ----------------------------------------------------------------</span>
<a name="l01851"></a>01851 <span class="comment">     * When adding new mechanisms, please add them above this point</span>
<a name="l01852"></a>01852 <span class="comment">     * if they support passing the process ID through, or below if not.</span>
<a name="l01853"></a>01853 <span class="comment">     * ---------------------------------------------------------------- */</span>
<a name="l01854"></a>01854 
<a name="l01855"></a>01855 <span class="preprocessor">#elif defined(HAVE_GETPEEREID)</span>
<a name="l01856"></a>01856 <span class="preprocessor"></span>    <span class="comment">/* getpeereid() originates from D.J. Bernstein and is fairly</span>
<a name="l01857"></a>01857 <span class="comment">     * widely-supported. According to a web search, it might be present in</span>
<a name="l01858"></a>01858 <span class="comment">     * any/all of:</span>
<a name="l01859"></a>01859 <span class="comment">     *</span>
<a name="l01860"></a>01860 <span class="comment">     * - AIX?</span>
<a name="l01861"></a>01861 <span class="comment">     * - Blackberry?</span>
<a name="l01862"></a>01862 <span class="comment">     * - Cygwin</span>
<a name="l01863"></a>01863 <span class="comment">     * - FreeBSD 4.6+ (but we prefer SCM_CREDS: it carries the pid)</span>
<a name="l01864"></a>01864 <span class="comment">     * - Mac OS X</span>
<a name="l01865"></a>01865 <span class="comment">     * - Minix 3.1.8+</span>
<a name="l01866"></a>01866 <span class="comment">     * - MirBSD?</span>
<a name="l01867"></a>01867 <span class="comment">     * - NetBSD 5.0+ (but LOCAL_PEEREID would be better: it carries the pid)</span>
<a name="l01868"></a>01868 <span class="comment">     * - OpenBSD 3.0+ (but we prefer SO_PEERCRED: it carries the pid)</span>
<a name="l01869"></a>01869 <span class="comment">     * - QNX?</span>
<a name="l01870"></a>01870 <span class="comment">     */</span>
<a name="l01871"></a>01871     uid_t euid;
<a name="l01872"></a>01872     gid_t egid;
<a name="l01873"></a>01873     <span class="keywordflow">if</span> (getpeereid (client_fd, &amp;euid, &amp;egid) == 0)
<a name="l01874"></a>01874       {
<a name="l01875"></a>01875         uid_read = euid;
<a name="l01876"></a>01876       }
<a name="l01877"></a>01877     <span class="keywordflow">else</span>
<a name="l01878"></a>01878       {
<a name="l01879"></a>01879         _dbus_verbose (<span class="stringliteral">&quot;Failed to getpeereid() credentials: %s\n&quot;</span>, _dbus_strerror (errno));
<a name="l01880"></a>01880       }
<a name="l01881"></a>01881 <span class="preprocessor">#else </span><span class="comment">/* no supported mechanism */</span>
<a name="l01882"></a>01882 
<a name="l01883"></a>01883 <span class="preprocessor">#warning Socket credentials not supported on this Unix OS</span>
<a name="l01884"></a>01884 <span class="preprocessor"></span><span class="preprocessor">#warning Please tell https://bugs.freedesktop.org/enter_bug.cgi?product=DBus</span>
<a name="l01885"></a>01885 <span class="preprocessor"></span>
<a name="l01886"></a>01886     <span class="comment">/* Please add other operating systems known to support at least one of</span>
<a name="l01887"></a>01887 <span class="comment">     * the mechanisms above to this list, keeping alphabetical order.</span>
<a name="l01888"></a>01888 <span class="comment">     * Everything not in this list  is best-effort.</span>
<a name="l01889"></a>01889 <span class="comment">     */</span>
<a name="l01890"></a>01890 <span class="preprocessor">#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \</span>
<a name="l01891"></a>01891 <span class="preprocessor">    defined(__linux__) || \</span>
<a name="l01892"></a>01892 <span class="preprocessor">    defined(__OpenBSD__) || \</span>
<a name="l01893"></a>01893 <span class="preprocessor">    defined(__NetBSD__)</span>
<a name="l01894"></a>01894 <span class="preprocessor"></span><span class="preprocessor"># error Credentials passing not working on this OS is a regression!</span>
<a name="l01895"></a>01895 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l01896"></a>01896 <span class="preprocessor"></span>
<a name="l01897"></a>01897     _dbus_verbose (<span class="stringliteral">&quot;Socket credentials not supported on this OS\n&quot;</span>);
<a name="l01898"></a>01898 <span class="preprocessor">#endif</span>
<a name="l01899"></a>01899 <span class="preprocessor"></span>  }
<a name="l01900"></a>01900 
<a name="l01901"></a>01901   _dbus_verbose (<span class="stringliteral">&quot;Credentials:&quot;</span>
<a name="l01902"></a>01902                  <span class="stringliteral">&quot;  pid &quot;</span><a class="code" href="group__DBusSysdeps.html#gaf4553a43e3b8c0e43d9148a00dcc3fa4" title="an appropriate printf format for dbus_pid_t">DBUS_PID_FORMAT</a>
<a name="l01903"></a>01903                  <span class="stringliteral">&quot;  uid &quot;</span><a class="code" href="group__DBusSysdeps.html#gab657f0434f01b463891942f373f7b4a1" title="an appropriate printf format for dbus_uid_t">DBUS_UID_FORMAT</a>
<a name="l01904"></a>01904                  <span class="stringliteral">&quot;\n&quot;</span>,
<a name="l01905"></a>01905                  pid_read,
<a name="l01906"></a>01906                  uid_read);
<a name="l01907"></a>01907 
<a name="l01908"></a>01908   <span class="keywordflow">if</span> (pid_read != <a class="code" href="group__DBusSysdeps.html#ga4eb5f05dd6ad89caa4b0340e1cf0b8d9" title="an invalid PID used to represent an uninitialized dbus_pid_t field">DBUS_PID_UNSET</a>)
<a name="l01909"></a>01909     {
<a name="l01910"></a>01910       <span class="keywordflow">if</span> (!<a class="code" href="group__DBusCredentials.html#gaad133a8d06af2a447307266a8425a9f8" title="Add a UNIX process ID to the credentials.">_dbus_credentials_add_pid</a> (credentials, pid_read))
<a name="l01911"></a>01911         {
<a name="l01912"></a>01912           _DBUS_SET_OOM (error);
<a name="l01913"></a>01913           <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l01914"></a>01914         }
<a name="l01915"></a>01915     }
<a name="l01916"></a>01916 
<a name="l01917"></a>01917   <span class="keywordflow">if</span> (uid_read != <a class="code" href="group__DBusSysdeps.html#ga3d2f3fb32bb759cabe362ca2de383f7d" title="an invalid UID used to represent an uninitialized dbus_uid_t field">DBUS_UID_UNSET</a>)
<a name="l01918"></a>01918     {
<a name="l01919"></a>01919       <span class="keywordflow">if</span> (!<a class="code" href="group__DBusCredentials.html#ga9cec6da43e4be233d44f5bd60b071624" title="Add a UNIX user ID to the credentials.">_dbus_credentials_add_unix_uid</a> (credentials, uid_read))
<a name="l01920"></a>01920         {
<a name="l01921"></a>01921           _DBUS_SET_OOM (error);
<a name="l01922"></a>01922           <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l01923"></a>01923         }
<a name="l01924"></a>01924     }
<a name="l01925"></a>01925 
<a name="l01926"></a>01926   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l01927"></a>01927 }
<a name="l01928"></a>01928 
<a name="l01946"></a>01946 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l01947"></a><a class="code" href="group__DBusSysdeps.html#ga6cc9916aa1dde4d44072ee85b5691b5b">01947</a> <a class="code" href="group__DBusSysdeps.html#ga6cc9916aa1dde4d44072ee85b5691b5b" title="Sends a single nul byte with our UNIX credentials as ancillary data.">_dbus_send_credentials_socket</a>  (<span class="keywordtype">int</span>              server_fd,
<a name="l01948"></a>01948                                 <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>       *error)
<a name="l01949"></a>01949 {
<a name="l01950"></a>01950   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l01951"></a>01951 
<a name="l01952"></a>01952   <span class="keywordflow">if</span> (write_credentials_byte (server_fd, error))
<a name="l01953"></a>01953     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l01954"></a>01954   <span class="keywordflow">else</span>
<a name="l01955"></a>01955     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l01956"></a>01956 }
<a name="l01957"></a>01957 
<a name="l01967"></a>01967 <span class="keywordtype">int</span>
<a name="l01968"></a><a class="code" href="group__DBusSysdeps.html#ga687f4393a365474ec16f02e40c418cce">01968</a> <a class="code" href="group__DBusSysdeps.html#ga687f4393a365474ec16f02e40c418cce" title="Accepts a connection on a listening socket.">_dbus_accept</a>  (<span class="keywordtype">int</span> listen_fd)
<a name="l01969"></a>01969 {
<a name="l01970"></a>01970   <span class="keywordtype">int</span> client_fd;
<a name="l01971"></a>01971   <span class="keyword">struct </span>sockaddr addr;
<a name="l01972"></a>01972   socklen_t addrlen;
<a name="l01973"></a>01973 <span class="preprocessor">#ifdef HAVE_ACCEPT4</span>
<a name="l01974"></a>01974 <span class="preprocessor"></span>  <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> cloexec_done;
<a name="l01975"></a>01975 <span class="preprocessor">#endif</span>
<a name="l01976"></a>01976 <span class="preprocessor"></span>
<a name="l01977"></a>01977   addrlen = <span class="keyword">sizeof</span> (addr);
<a name="l01978"></a>01978 
<a name="l01979"></a>01979  retry:
<a name="l01980"></a>01980 
<a name="l01981"></a>01981 <span class="preprocessor">#ifdef HAVE_ACCEPT4</span>
<a name="l01982"></a>01982 <span class="preprocessor"></span>  <span class="comment">/*</span>
<a name="l01983"></a>01983 <span class="comment">   * At compile-time, we assume that if accept4() is available in</span>
<a name="l01984"></a>01984 <span class="comment">   * libc headers, SOCK_CLOEXEC is too. At runtime, it is still</span>
<a name="l01985"></a>01985 <span class="comment">   * not necessarily true that either is supported by the running kernel.</span>
<a name="l01986"></a>01986 <span class="comment">   */</span>
<a name="l01987"></a>01987   client_fd = accept4 (listen_fd, &amp;addr, &amp;addrlen, SOCK_CLOEXEC);
<a name="l01988"></a>01988   cloexec_done = client_fd &gt;= 0;
<a name="l01989"></a>01989 
<a name="l01990"></a>01990   <span class="keywordflow">if</span> (client_fd &lt; 0 &amp;&amp; (errno == ENOSYS || errno == EINVAL))
<a name="l01991"></a>01991 <span class="preprocessor">#endif</span>
<a name="l01992"></a>01992 <span class="preprocessor"></span>    {
<a name="l01993"></a>01993       client_fd = accept (listen_fd, &amp;addr, &amp;addrlen);
<a name="l01994"></a>01994     }
<a name="l01995"></a>01995 
<a name="l01996"></a>01996   <span class="keywordflow">if</span> (client_fd &lt; 0)
<a name="l01997"></a>01997     {
<a name="l01998"></a>01998       <span class="keywordflow">if</span> (errno == EINTR)
<a name="l01999"></a>01999         <span class="keywordflow">goto</span> retry;
<a name="l02000"></a>02000     }
<a name="l02001"></a>02001 
<a name="l02002"></a>02002   _dbus_verbose (<span class="stringliteral">&quot;client fd %d accepted\n&quot;</span>, client_fd);
<a name="l02003"></a>02003 
<a name="l02004"></a>02004 <span class="preprocessor">#ifdef HAVE_ACCEPT4</span>
<a name="l02005"></a>02005 <span class="preprocessor"></span>  <span class="keywordflow">if</span> (!cloexec_done)
<a name="l02006"></a>02006 <span class="preprocessor">#endif</span>
<a name="l02007"></a>02007 <span class="preprocessor"></span>    {
<a name="l02008"></a>02008       <a class="code" href="group__DBusSysdeps.html#ga21ef96952f98f23e590ebbf060fd5ca6" title="Sets the file descriptor to be close on exec.">_dbus_fd_set_close_on_exec</a>(client_fd);
<a name="l02009"></a>02009     }
<a name="l02010"></a>02010 
<a name="l02011"></a>02011   <span class="keywordflow">return</span> client_fd;
<a name="l02012"></a>02012 }
<a name="l02013"></a>02013 
<a name="l02022"></a>02022 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l02023"></a><a class="code" href="group__DBusSysdeps.html#ga8e16f75e361d9fed43223f69baf0e2a5">02023</a> <a class="code" href="group__DBusSysdeps.html#ga8e16f75e361d9fed43223f69baf0e2a5" title="Checks to make sure the given directory is private to the user.">_dbus_check_dir_is_private_to_user</a> (<a class="code" href="structDBusString.html">DBusString</a> *dir, <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a> *error)
<a name="l02024"></a>02024 {
<a name="l02025"></a>02025   <span class="keyword">const</span> <span class="keywordtype">char</span> *directory;
<a name="l02026"></a>02026   <span class="keyword">struct </span>stat sb;
<a name="l02027"></a>02027 
<a name="l02028"></a>02028   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l02029"></a>02029 
<a name="l02030"></a>02030   directory = <a class="code" href="group__DBusString.html#ga33e20241ae7d784624f97d89b1a0539e" title="Gets the raw character buffer from a const string.">_dbus_string_get_const_data</a> (dir);
<a name="l02031"></a>02031 
<a name="l02032"></a>02032   <span class="keywordflow">if</span> (stat (directory, &amp;sb) &lt; 0)
<a name="l02033"></a>02033     {
<a name="l02034"></a>02034       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l02035"></a>02035                       <span class="stringliteral">&quot;%s&quot;</span>, _dbus_strerror (errno));
<a name="l02036"></a>02036 
<a name="l02037"></a>02037       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02038"></a>02038     }
<a name="l02039"></a>02039 
<a name="l02040"></a>02040   <span class="keywordflow">if</span> (sb.st_uid != geteuid ())
<a name="l02041"></a>02041     {
<a name="l02042"></a>02042       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gabb62fd6340d0787fbd56ff8dd2f326c7" title="A generic error; &quot;something went wrong&quot; - see the error message for more.">DBUS_ERROR_FAILED</a>,
<a name="l02043"></a>02043                      <span class="stringliteral">&quot;%s directory is owned by user %lu, not %lu&quot;</span>,
<a name="l02044"></a>02044                      directory,
<a name="l02045"></a>02045                      (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>) sb.st_uid,
<a name="l02046"></a>02046                      (<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>) geteuid ());
<a name="l02047"></a>02047       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02048"></a>02048     }
<a name="l02049"></a>02049 
<a name="l02050"></a>02050   <span class="keywordflow">if</span> ((S_IROTH &amp; sb.st_mode) || (S_IWOTH &amp; sb.st_mode) ||
<a name="l02051"></a>02051       (S_IRGRP &amp; sb.st_mode) || (S_IWGRP &amp; sb.st_mode))
<a name="l02052"></a>02052     {
<a name="l02053"></a>02053       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gabb62fd6340d0787fbd56ff8dd2f326c7" title="A generic error; &quot;something went wrong&quot; - see the error message for more.">DBUS_ERROR_FAILED</a>,
<a name="l02054"></a>02054                      <span class="stringliteral">&quot;%s directory is not private to the user&quot;</span>, directory);
<a name="l02055"></a>02055       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02056"></a>02056     }
<a name="l02057"></a>02057 
<a name="l02058"></a>02058   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l02059"></a>02059 }
<a name="l02060"></a>02060 
<a name="l02061"></a>02061 <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l02062"></a>02062 fill_user_info_from_passwd (<span class="keyword">struct</span> passwd *p,
<a name="l02063"></a>02063                             <a class="code" href="structDBusUserInfo.html" title="Information about a UNIX user.">DBusUserInfo</a>  *info,
<a name="l02064"></a>02064                             <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>     *error)
<a name="l02065"></a>02065 {
<a name="l02066"></a>02066   _dbus_assert (p-&gt;pw_name != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l02067"></a>02067   _dbus_assert (p-&gt;pw_dir != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l02068"></a>02068 
<a name="l02069"></a>02069   info-&gt;<a class="code" href="structDBusUserInfo.html#a2d9c74d29f371e391a79b81162050b2e" title="UID.">uid</a> = p-&gt;pw_uid;
<a name="l02070"></a>02070   info-&gt;<a class="code" href="structDBusUserInfo.html#ac970de2fac9ea4ba91485e6c37c3bf93" title="GID.">primary_gid</a> = p-&gt;pw_gid;
<a name="l02071"></a>02071   info-&gt;<a class="code" href="structDBusUserInfo.html#ac6b57db1dc8315eee3f532f4e77912d1" title="Username.">username</a> = <a class="code" href="group__DBusInternalsUtils.html#ga9d00d77f6595b9d7ac1baf59d44bf58c" title="Duplicates a string.">_dbus_strdup</a> (p-&gt;pw_name);
<a name="l02072"></a>02072   info-&gt;<a class="code" href="structDBusUserInfo.html#a5235d4d021cd134e1130e1e8e912bc0c" title="Home directory.">homedir</a> = <a class="code" href="group__DBusInternalsUtils.html#ga9d00d77f6595b9d7ac1baf59d44bf58c" title="Duplicates a string.">_dbus_strdup</a> (p-&gt;pw_dir);
<a name="l02073"></a>02073 
<a name="l02074"></a>02074   <span class="keywordflow">if</span> (info-&gt;<a class="code" href="structDBusUserInfo.html#ac6b57db1dc8315eee3f532f4e77912d1" title="Username.">username</a> == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a> ||
<a name="l02075"></a>02075       info-&gt;<a class="code" href="structDBusUserInfo.html#a5235d4d021cd134e1130e1e8e912bc0c" title="Home directory.">homedir</a> == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l02076"></a>02076     {
<a name="l02077"></a>02077       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gac32eaf0b92f798307853cd4fe0cf11c2" title="There was not enough memory to complete an operation.">DBUS_ERROR_NO_MEMORY</a>, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l02078"></a>02078       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02079"></a>02079     }
<a name="l02080"></a>02080 
<a name="l02081"></a>02081   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l02082"></a>02082 }
<a name="l02083"></a>02083 
<a name="l02084"></a>02084 <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l02085"></a>02085 fill_user_info (<a class="code" href="structDBusUserInfo.html" title="Information about a UNIX user.">DBusUserInfo</a>       *info,
<a name="l02086"></a>02086                 <a class="code" href="group__DBusSysdeps.html#ga186e987b700f9ddc6cea8aa0db82b151" title="A user ID.">dbus_uid_t</a>          uid,
<a name="l02087"></a>02087                 <span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a>   *username,
<a name="l02088"></a>02088                 <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>          *error)
<a name="l02089"></a>02089 {
<a name="l02090"></a>02090   <span class="keyword">const</span> <span class="keywordtype">char</span> *username_c;
<a name="l02091"></a>02091 
<a name="l02092"></a>02092   <span class="comment">/* exactly one of username/uid provided */</span>
<a name="l02093"></a>02093   _dbus_assert (username != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a> || uid != <a class="code" href="group__DBusSysdeps.html#ga3d2f3fb32bb759cabe362ca2de383f7d" title="an invalid UID used to represent an uninitialized dbus_uid_t field">DBUS_UID_UNSET</a>);
<a name="l02094"></a>02094   _dbus_assert (username == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a> || uid == <a class="code" href="group__DBusSysdeps.html#ga3d2f3fb32bb759cabe362ca2de383f7d" title="an invalid UID used to represent an uninitialized dbus_uid_t field">DBUS_UID_UNSET</a>);
<a name="l02095"></a>02095 
<a name="l02096"></a>02096   info-&gt;<a class="code" href="structDBusUserInfo.html#a2d9c74d29f371e391a79b81162050b2e" title="UID.">uid</a> = <a class="code" href="group__DBusSysdeps.html#ga3d2f3fb32bb759cabe362ca2de383f7d" title="an invalid UID used to represent an uninitialized dbus_uid_t field">DBUS_UID_UNSET</a>;
<a name="l02097"></a>02097   info-&gt;<a class="code" href="structDBusUserInfo.html#ac970de2fac9ea4ba91485e6c37c3bf93" title="GID.">primary_gid</a> = <a class="code" href="group__DBusSysdeps.html#ga768a080926a119a6131083facc0bd42b" title="an invalid GID used to represent an uninitialized dbus_gid_t field">DBUS_GID_UNSET</a>;
<a name="l02098"></a>02098   info-&gt;<a class="code" href="structDBusUserInfo.html#a902af9e0fb7d37c14eefb7d2b016ab11" title="Groups IDs, *including* above primary group.">group_ids</a> = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l02099"></a>02099   info-&gt;<a class="code" href="structDBusUserInfo.html#a21c07867fbffb1854a97aed265d87c89" title="Size of group IDs array.">n_group_ids</a> = 0;
<a name="l02100"></a>02100   info-&gt;<a class="code" href="structDBusUserInfo.html#ac6b57db1dc8315eee3f532f4e77912d1" title="Username.">username</a> = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l02101"></a>02101   info-&gt;<a class="code" href="structDBusUserInfo.html#a5235d4d021cd134e1130e1e8e912bc0c" title="Home directory.">homedir</a> = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l02102"></a>02102 
<a name="l02103"></a>02103   <span class="keywordflow">if</span> (username != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l02104"></a>02104     username_c = <a class="code" href="group__DBusString.html#ga33e20241ae7d784624f97d89b1a0539e" title="Gets the raw character buffer from a const string.">_dbus_string_get_const_data</a> (username);
<a name="l02105"></a>02105   <span class="keywordflow">else</span>
<a name="l02106"></a>02106     username_c = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l02107"></a>02107 
<a name="l02108"></a>02108   <span class="comment">/* For now assuming that the getpwnam() and getpwuid() flavors</span>
<a name="l02109"></a>02109 <span class="comment">   * are always symmetrical, if not we have to add more configure</span>
<a name="l02110"></a>02110 <span class="comment">   * checks</span>
<a name="l02111"></a>02111 <span class="comment">   */</span>
<a name="l02112"></a>02112 
<a name="l02113"></a>02113 <span class="preprocessor">#if defined (HAVE_POSIX_GETPWNAM_R) || defined (HAVE_NONPOSIX_GETPWNAM_R)</span>
<a name="l02114"></a>02114 <span class="preprocessor"></span>  {
<a name="l02115"></a>02115     <span class="keyword">struct </span>passwd *p;
<a name="l02116"></a>02116     <span class="keywordtype">int</span> result;
<a name="l02117"></a>02117     <span class="keywordtype">size_t</span> buflen;
<a name="l02118"></a>02118     <span class="keywordtype">char</span> *buf;
<a name="l02119"></a>02119     <span class="keyword">struct </span>passwd p_str;
<a name="l02120"></a>02120 
<a name="l02121"></a>02121     <span class="comment">/* retrieve maximum needed size for buf */</span>
<a name="l02122"></a>02122     buflen = sysconf (_SC_GETPW_R_SIZE_MAX);
<a name="l02123"></a>02123 
<a name="l02124"></a>02124     <span class="comment">/* sysconf actually returns a long, but everything else expects size_t,</span>
<a name="l02125"></a>02125 <span class="comment">     * so just recast here.</span>
<a name="l02126"></a>02126 <span class="comment">     * https://bugs.freedesktop.org/show_bug.cgi?id=17061</span>
<a name="l02127"></a>02127 <span class="comment">     */</span>
<a name="l02128"></a>02128     <span class="keywordflow">if</span> ((<span class="keywordtype">long</span>) buflen &lt;= 0)
<a name="l02129"></a>02129       buflen = 1024;
<a name="l02130"></a>02130 
<a name="l02131"></a>02131     result = -1;
<a name="l02132"></a>02132     <span class="keywordflow">while</span> (1)
<a name="l02133"></a>02133       {
<a name="l02134"></a>02134         buf = <a class="code" href="group__DBusMemory.html#gaf6e588659067a854c3cca7ebe8ae5084" title="Allocates the given number of bytes, as with standard malloc().">dbus_malloc</a> (buflen);
<a name="l02135"></a>02135         <span class="keywordflow">if</span> (buf == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l02136"></a>02136           {
<a name="l02137"></a>02137             <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gac32eaf0b92f798307853cd4fe0cf11c2" title="There was not enough memory to complete an operation.">DBUS_ERROR_NO_MEMORY</a>, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l02138"></a>02138             <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02139"></a>02139           }
<a name="l02140"></a>02140 
<a name="l02141"></a>02141         p = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l02142"></a>02142 <span class="preprocessor">#ifdef HAVE_POSIX_GETPWNAM_R</span>
<a name="l02143"></a>02143 <span class="preprocessor"></span>        <span class="keywordflow">if</span> (uid != <a class="code" href="group__DBusSysdeps.html#ga3d2f3fb32bb759cabe362ca2de383f7d" title="an invalid UID used to represent an uninitialized dbus_uid_t field">DBUS_UID_UNSET</a>)
<a name="l02144"></a>02144           result = getpwuid_r (uid, &amp;p_str, buf, buflen,
<a name="l02145"></a>02145                                &amp;p);
<a name="l02146"></a>02146         <span class="keywordflow">else</span>
<a name="l02147"></a>02147           result = getpwnam_r (username_c, &amp;p_str, buf, buflen,
<a name="l02148"></a>02148                                &amp;p);
<a name="l02149"></a>02149 <span class="preprocessor">#else</span>
<a name="l02150"></a>02150 <span class="preprocessor"></span>        <span class="keywordflow">if</span> (uid != <a class="code" href="group__DBusSysdeps.html#ga3d2f3fb32bb759cabe362ca2de383f7d" title="an invalid UID used to represent an uninitialized dbus_uid_t field">DBUS_UID_UNSET</a>)
<a name="l02151"></a>02151           p = getpwuid_r (uid, &amp;p_str, buf, buflen);
<a name="l02152"></a>02152         <span class="keywordflow">else</span>
<a name="l02153"></a>02153           p = getpwnam_r (username_c, &amp;p_str, buf, buflen);
<a name="l02154"></a>02154         result = 0;
<a name="l02155"></a>02155 <span class="preprocessor">#endif </span><span class="comment">/* !HAVE_POSIX_GETPWNAM_R */</span>
<a name="l02156"></a>02156         <span class="comment">//Try a bigger buffer if ERANGE was returned</span>
<a name="l02157"></a>02157         <span class="keywordflow">if</span> (result == ERANGE &amp;&amp; buflen &lt; 512 * 1024)
<a name="l02158"></a>02158           {
<a name="l02159"></a>02159             <a class="code" href="group__DBusMemory.html#ga34e666b19b015035a9a31e53da84b39a" title="Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().">dbus_free</a> (buf);
<a name="l02160"></a>02160             buflen *= 2;
<a name="l02161"></a>02161           }
<a name="l02162"></a>02162         <span class="keywordflow">else</span>
<a name="l02163"></a>02163           {
<a name="l02164"></a>02164             <span class="keywordflow">break</span>;
<a name="l02165"></a>02165           }
<a name="l02166"></a>02166       }
<a name="l02167"></a>02167     <span class="keywordflow">if</span> (result == 0 &amp;&amp; p == &amp;p_str)
<a name="l02168"></a>02168       {
<a name="l02169"></a>02169         <span class="keywordflow">if</span> (!fill_user_info_from_passwd (p, info, error))
<a name="l02170"></a>02170           {
<a name="l02171"></a>02171             <a class="code" href="group__DBusMemory.html#ga34e666b19b015035a9a31e53da84b39a" title="Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().">dbus_free</a> (buf);
<a name="l02172"></a>02172             <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02173"></a>02173           }
<a name="l02174"></a>02174         <a class="code" href="group__DBusMemory.html#ga34e666b19b015035a9a31e53da84b39a" title="Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().">dbus_free</a> (buf);
<a name="l02175"></a>02175       }
<a name="l02176"></a>02176     <span class="keywordflow">else</span>
<a name="l02177"></a>02177       {
<a name="l02178"></a>02178         <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l02179"></a>02179                         <span class="stringliteral">&quot;User \&quot;%s\&quot; unknown or no memory to allocate password entry\n&quot;</span>,
<a name="l02180"></a>02180                         username_c ? username_c : <span class="stringliteral">&quot;???&quot;</span>);
<a name="l02181"></a>02181         _dbus_verbose (<span class="stringliteral">&quot;User %s unknown\n&quot;</span>, username_c ? username_c : <span class="stringliteral">&quot;???&quot;</span>);
<a name="l02182"></a>02182         <a class="code" href="group__DBusMemory.html#ga34e666b19b015035a9a31e53da84b39a" title="Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().">dbus_free</a> (buf);
<a name="l02183"></a>02183         <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02184"></a>02184       }
<a name="l02185"></a>02185   }
<a name="l02186"></a>02186 <span class="preprocessor">#else </span><span class="comment">/* ! HAVE_GETPWNAM_R */</span>
<a name="l02187"></a>02187   {
<a name="l02188"></a>02188     <span class="comment">/* I guess we&#39;re screwed on thread safety here */</span>
<a name="l02189"></a>02189     <span class="keyword">struct </span>passwd *p;
<a name="l02190"></a>02190 
<a name="l02191"></a>02191     <span class="keywordflow">if</span> (uid != <a class="code" href="group__DBusSysdeps.html#ga3d2f3fb32bb759cabe362ca2de383f7d" title="an invalid UID used to represent an uninitialized dbus_uid_t field">DBUS_UID_UNSET</a>)
<a name="l02192"></a>02192       p = getpwuid (uid);
<a name="l02193"></a>02193     <span class="keywordflow">else</span>
<a name="l02194"></a>02194       p = getpwnam (username_c);
<a name="l02195"></a>02195 
<a name="l02196"></a>02196     <span class="keywordflow">if</span> (p != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l02197"></a>02197       {
<a name="l02198"></a>02198         <span class="keywordflow">if</span> (!fill_user_info_from_passwd (p, info, error))
<a name="l02199"></a>02199           {
<a name="l02200"></a>02200             <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02201"></a>02201           }
<a name="l02202"></a>02202       }
<a name="l02203"></a>02203     <span class="keywordflow">else</span>
<a name="l02204"></a>02204       {
<a name="l02205"></a>02205         <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l02206"></a>02206                         <span class="stringliteral">&quot;User \&quot;%s\&quot; unknown or no memory to allocate password entry\n&quot;</span>,
<a name="l02207"></a>02207                         username_c ? username_c : <span class="stringliteral">&quot;???&quot;</span>);
<a name="l02208"></a>02208         _dbus_verbose (<span class="stringliteral">&quot;User %s unknown\n&quot;</span>, username_c ? username_c : <span class="stringliteral">&quot;???&quot;</span>);
<a name="l02209"></a>02209         <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02210"></a>02210       }
<a name="l02211"></a>02211   }
<a name="l02212"></a>02212 <span class="preprocessor">#endif  </span><span class="comment">/* ! HAVE_GETPWNAM_R */</span>
<a name="l02213"></a>02213 
<a name="l02214"></a>02214   <span class="comment">/* Fill this in so we can use it to get groups */</span>
<a name="l02215"></a>02215   username_c = info-&gt;<a class="code" href="structDBusUserInfo.html#ac6b57db1dc8315eee3f532f4e77912d1" title="Username.">username</a>;
<a name="l02216"></a>02216 
<a name="l02217"></a>02217 <span class="preprocessor">#ifdef HAVE_GETGROUPLIST</span>
<a name="l02218"></a>02218 <span class="preprocessor"></span>  {
<a name="l02219"></a>02219     gid_t *buf;
<a name="l02220"></a>02220     <span class="keywordtype">int</span> buf_count;
<a name="l02221"></a>02221     <span class="keywordtype">int</span> i;
<a name="l02222"></a>02222     <span class="keywordtype">int</span> initial_buf_count;
<a name="l02223"></a>02223 
<a name="l02224"></a>02224     initial_buf_count = 17;
<a name="l02225"></a>02225     buf_count = initial_buf_count;
<a name="l02226"></a>02226     buf = <a class="code" href="group__DBusMemory.html#ga54ccb556e7964112a825a7f46c156ca0" title="Safe macro for using dbus_malloc().">dbus_new</a> (gid_t, buf_count);
<a name="l02227"></a>02227     <span class="keywordflow">if</span> (buf == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l02228"></a>02228       {
<a name="l02229"></a>02229         <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gac32eaf0b92f798307853cd4fe0cf11c2" title="There was not enough memory to complete an operation.">DBUS_ERROR_NO_MEMORY</a>, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l02230"></a>02230         <span class="keywordflow">goto</span> failed;
<a name="l02231"></a>02231       }
<a name="l02232"></a>02232 
<a name="l02233"></a>02233     <span class="keywordflow">if</span> (getgrouplist (username_c,
<a name="l02234"></a>02234                       info-&gt;<a class="code" href="structDBusUserInfo.html#ac970de2fac9ea4ba91485e6c37c3bf93" title="GID.">primary_gid</a>,
<a name="l02235"></a>02235                       buf, &amp;buf_count) &lt; 0)
<a name="l02236"></a>02236       {
<a name="l02237"></a>02237         gid_t *<span class="keyword">new</span>;
<a name="l02238"></a>02238         <span class="comment">/* Presumed cause of negative return code: buf has insufficient</span>
<a name="l02239"></a>02239 <span class="comment">           entries to hold the entire group list. The Linux behavior in this</span>
<a name="l02240"></a>02240 <span class="comment">           case is to pass back the actual number of groups in buf_count, but</span>
<a name="l02241"></a>02241 <span class="comment">           on Mac OS X 10.5, buf_count is unhelpfully left alone.</span>
<a name="l02242"></a>02242 <span class="comment">           So as a hack, try to help out a bit by guessing a larger</span>
<a name="l02243"></a>02243 <span class="comment">           number of groups, within reason.. might still fail, of course,</span>
<a name="l02244"></a>02244 <span class="comment">           but we can at least print a more informative message.  I looked up</span>
<a name="l02245"></a>02245 <span class="comment">           the &quot;right way&quot; to do this by downloading Apple&#39;s own source code</span>
<a name="l02246"></a>02246 <span class="comment">           for the &quot;id&quot; command, and it turns out that they use an</span>
<a name="l02247"></a>02247 <span class="comment">           undocumented library function getgrouplist_2 (!) which is not</span>
<a name="l02248"></a>02248 <span class="comment">           declared in any header in /usr/include (!!). That did not seem</span>
<a name="l02249"></a>02249 <span class="comment">           like the way to go here.</span>
<a name="l02250"></a>02250 <span class="comment">        */</span>
<a name="l02251"></a>02251         <span class="keywordflow">if</span> (buf_count == initial_buf_count)
<a name="l02252"></a>02252           {
<a name="l02253"></a>02253             buf_count *= 16; <span class="comment">/* Retry with an arbitrarily scaled-up array */</span>
<a name="l02254"></a>02254           }
<a name="l02255"></a>02255         <span class="keyword">new</span> = <a class="code" href="group__DBusMemory.html#ga2d505f2960ccf343042d363170b27f9c" title="Resizes a block of memory previously allocated by dbus_malloc() or dbus_malloc0().">dbus_realloc</a> (buf, buf_count * <span class="keyword">sizeof</span> (buf[0]));
<a name="l02256"></a>02256         <span class="keywordflow">if</span> (<span class="keyword">new</span> == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l02257"></a>02257           {
<a name="l02258"></a>02258             <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gac32eaf0b92f798307853cd4fe0cf11c2" title="There was not enough memory to complete an operation.">DBUS_ERROR_NO_MEMORY</a>, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l02259"></a>02259             <a class="code" href="group__DBusMemory.html#ga34e666b19b015035a9a31e53da84b39a" title="Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().">dbus_free</a> (buf);
<a name="l02260"></a>02260             <span class="keywordflow">goto</span> failed;
<a name="l02261"></a>02261           }
<a name="l02262"></a>02262 
<a name="l02263"></a>02263         buf = <span class="keyword">new</span>;
<a name="l02264"></a>02264 
<a name="l02265"></a>02265         errno = 0;
<a name="l02266"></a>02266         <span class="keywordflow">if</span> (getgrouplist (username_c, info-&gt;<a class="code" href="structDBusUserInfo.html#ac970de2fac9ea4ba91485e6c37c3bf93" title="GID.">primary_gid</a>, buf, &amp;buf_count) &lt; 0)
<a name="l02267"></a>02267           {
<a name="l02268"></a>02268             <span class="keywordflow">if</span> (errno == 0)
<a name="l02269"></a>02269               {
<a name="l02270"></a>02270                 <a class="code" href="group__DBusInternalsUtils.html#gabea2c16d6d3fe7c4eb5b9496fc877f84" title="Prints a warning message to stderr.">_dbus_warn</a> (<span class="stringliteral">&quot;It appears that username \&quot;%s\&quot; is in more than %d groups.\nProceeding with just the first %d groups.&quot;</span>,
<a name="l02271"></a>02271                             username_c, buf_count, buf_count);
<a name="l02272"></a>02272               }
<a name="l02273"></a>02273             <span class="keywordflow">else</span>
<a name="l02274"></a>02274               {
<a name="l02275"></a>02275                 <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error,
<a name="l02276"></a>02276                                 <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l02277"></a>02277                                 <span class="stringliteral">&quot;Failed to get groups for username \&quot;%s\&quot; primary GID &quot;</span>
<a name="l02278"></a>02278                                 <a class="code" href="group__DBusSysdeps.html#gaaab5918b2ae57886d9783df09bd61c7e" title="an appropriate printf format for dbus_gid_t">DBUS_GID_FORMAT</a> <span class="stringliteral">&quot;: %s\n&quot;</span>,
<a name="l02279"></a>02279                                 username_c, info-&gt;<a class="code" href="structDBusUserInfo.html#ac970de2fac9ea4ba91485e6c37c3bf93" title="GID.">primary_gid</a>,
<a name="l02280"></a>02280                                 _dbus_strerror (errno));
<a name="l02281"></a>02281                 <a class="code" href="group__DBusMemory.html#ga34e666b19b015035a9a31e53da84b39a" title="Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().">dbus_free</a> (buf);
<a name="l02282"></a>02282                 <span class="keywordflow">goto</span> failed;
<a name="l02283"></a>02283               }
<a name="l02284"></a>02284           }
<a name="l02285"></a>02285       }
<a name="l02286"></a>02286 
<a name="l02287"></a>02287     info-&gt;<a class="code" href="structDBusUserInfo.html#a902af9e0fb7d37c14eefb7d2b016ab11" title="Groups IDs, *including* above primary group.">group_ids</a> = <a class="code" href="group__DBusMemory.html#ga54ccb556e7964112a825a7f46c156ca0" title="Safe macro for using dbus_malloc().">dbus_new</a> (<a class="code" href="group__DBusSysdeps.html#ga2f5c2e418b81ec2a86594f56ec6d7627" title="A group ID.">dbus_gid_t</a>, buf_count);
<a name="l02288"></a>02288     <span class="keywordflow">if</span> (info-&gt;<a class="code" href="structDBusUserInfo.html#a902af9e0fb7d37c14eefb7d2b016ab11" title="Groups IDs, *including* above primary group.">group_ids</a> == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l02289"></a>02289       {
<a name="l02290"></a>02290         <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gac32eaf0b92f798307853cd4fe0cf11c2" title="There was not enough memory to complete an operation.">DBUS_ERROR_NO_MEMORY</a>, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l02291"></a>02291         <a class="code" href="group__DBusMemory.html#ga34e666b19b015035a9a31e53da84b39a" title="Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().">dbus_free</a> (buf);
<a name="l02292"></a>02292         <span class="keywordflow">goto</span> failed;
<a name="l02293"></a>02293       }
<a name="l02294"></a>02294 
<a name="l02295"></a>02295     <span class="keywordflow">for</span> (i = 0; i &lt; buf_count; ++i)
<a name="l02296"></a>02296       info-&gt;<a class="code" href="structDBusUserInfo.html#a902af9e0fb7d37c14eefb7d2b016ab11" title="Groups IDs, *including* above primary group.">group_ids</a>[i] = buf[i];
<a name="l02297"></a>02297 
<a name="l02298"></a>02298     info-&gt;<a class="code" href="structDBusUserInfo.html#a21c07867fbffb1854a97aed265d87c89" title="Size of group IDs array.">n_group_ids</a> = buf_count;
<a name="l02299"></a>02299 
<a name="l02300"></a>02300     <a class="code" href="group__DBusMemory.html#ga34e666b19b015035a9a31e53da84b39a" title="Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().">dbus_free</a> (buf);
<a name="l02301"></a>02301   }
<a name="l02302"></a>02302 <span class="preprocessor">#else  </span><span class="comment">/* HAVE_GETGROUPLIST */</span>
<a name="l02303"></a>02303   {
<a name="l02304"></a>02304     <span class="comment">/* We just get the one group ID */</span>
<a name="l02305"></a>02305     info-&gt;<a class="code" href="structDBusUserInfo.html#a902af9e0fb7d37c14eefb7d2b016ab11" title="Groups IDs, *including* above primary group.">group_ids</a> = <a class="code" href="group__DBusMemory.html#ga54ccb556e7964112a825a7f46c156ca0" title="Safe macro for using dbus_malloc().">dbus_new</a> (<a class="code" href="group__DBusSysdeps.html#ga2f5c2e418b81ec2a86594f56ec6d7627" title="A group ID.">dbus_gid_t</a>, 1);
<a name="l02306"></a>02306     <span class="keywordflow">if</span> (info-&gt;<a class="code" href="structDBusUserInfo.html#a902af9e0fb7d37c14eefb7d2b016ab11" title="Groups IDs, *including* above primary group.">group_ids</a> == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l02307"></a>02307       {
<a name="l02308"></a>02308         <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gac32eaf0b92f798307853cd4fe0cf11c2" title="There was not enough memory to complete an operation.">DBUS_ERROR_NO_MEMORY</a>, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l02309"></a>02309         <span class="keywordflow">goto</span> failed;
<a name="l02310"></a>02310       }
<a name="l02311"></a>02311 
<a name="l02312"></a>02312     info-&gt;<a class="code" href="structDBusUserInfo.html#a21c07867fbffb1854a97aed265d87c89" title="Size of group IDs array.">n_group_ids</a> = 1;
<a name="l02313"></a>02313 
<a name="l02314"></a>02314     (info-&gt;<a class="code" href="structDBusUserInfo.html#a902af9e0fb7d37c14eefb7d2b016ab11" title="Groups IDs, *including* above primary group.">group_ids</a>)[0] = info-&gt;<a class="code" href="structDBusUserInfo.html#ac970de2fac9ea4ba91485e6c37c3bf93" title="GID.">primary_gid</a>;
<a name="l02315"></a>02315   }
<a name="l02316"></a>02316 <span class="preprocessor">#endif </span><span class="comment">/* HAVE_GETGROUPLIST */</span>
<a name="l02317"></a>02317 
<a name="l02318"></a>02318   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l02319"></a>02319 
<a name="l02320"></a>02320   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l02321"></a>02321 
<a name="l02322"></a>02322  failed:
<a name="l02323"></a>02323   _DBUS_ASSERT_ERROR_IS_SET (error);
<a name="l02324"></a>02324   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02325"></a>02325 }
<a name="l02326"></a>02326 
<a name="l02335"></a>02335 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l02336"></a><a class="code" href="group__DBusSysdepsUnix.html#ga95e9deb9dd2d76aa3a64fdac555d956d">02336</a> <a class="code" href="group__DBusSysdepsUnix.html#ga95e9deb9dd2d76aa3a64fdac555d956d" title="Gets user info for the given username.">_dbus_user_info_fill</a> (<a class="code" href="structDBusUserInfo.html" title="Information about a UNIX user.">DBusUserInfo</a>     *info,
<a name="l02337"></a>02337                       <span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *username,
<a name="l02338"></a>02338                       <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>        *error)
<a name="l02339"></a>02339 {
<a name="l02340"></a>02340   <span class="keywordflow">return</span> fill_user_info (info, <a class="code" href="group__DBusSysdeps.html#ga3d2f3fb32bb759cabe362ca2de383f7d" title="an invalid UID used to represent an uninitialized dbus_uid_t field">DBUS_UID_UNSET</a>,
<a name="l02341"></a>02341                          username, error);
<a name="l02342"></a>02342 }
<a name="l02343"></a>02343 
<a name="l02352"></a>02352 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l02353"></a><a class="code" href="group__DBusSysdepsUnix.html#gafcc2fbcde2c72f499f04fa43d97dfcec">02353</a> <a class="code" href="group__DBusSysdepsUnix.html#gafcc2fbcde2c72f499f04fa43d97dfcec" title="Gets user info for the given user ID.">_dbus_user_info_fill_uid</a> (<a class="code" href="structDBusUserInfo.html" title="Information about a UNIX user.">DBusUserInfo</a> *info,
<a name="l02354"></a>02354                           <a class="code" href="group__DBusSysdeps.html#ga186e987b700f9ddc6cea8aa0db82b151" title="A user ID.">dbus_uid_t</a>    uid,
<a name="l02355"></a>02355                           <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>    *error)
<a name="l02356"></a>02356 {
<a name="l02357"></a>02357   <span class="keywordflow">return</span> fill_user_info (info, uid,
<a name="l02358"></a>02358                          <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, error);
<a name="l02359"></a>02359 }
<a name="l02360"></a>02360 
<a name="l02368"></a>02368 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l02369"></a><a class="code" href="group__DBusSysdeps.html#ga9d5493f8bd1c5577060c8c6dce44d09f">02369</a> <a class="code" href="group__DBusSysdeps.html#ga9d5493f8bd1c5577060c8c6dce44d09f" title="Adds the credentials of the current process to the passed-in credentials object.">_dbus_credentials_add_from_current_process</a> (<a class="code" href="structDBusCredentials.html">DBusCredentials</a> *credentials)
<a name="l02370"></a>02370 {
<a name="l02371"></a>02371   <span class="comment">/* The POSIX spec certainly doesn&#39;t promise this, but</span>
<a name="l02372"></a>02372 <span class="comment">   * we need these assertions to fail as soon as we&#39;re wrong about</span>
<a name="l02373"></a>02373 <span class="comment">   * it so we can do the porting fixups</span>
<a name="l02374"></a>02374 <span class="comment">   */</span>
<a name="l02375"></a>02375   _dbus_assert (<span class="keyword">sizeof</span> (pid_t) &lt;= <span class="keyword">sizeof</span> (<a class="code" href="group__DBusSysdeps.html#ga1eff6303266888ec466cddba6c03aa40" title="A process ID.">dbus_pid_t</a>));
<a name="l02376"></a>02376   _dbus_assert (<span class="keyword">sizeof</span> (uid_t) &lt;= <span class="keyword">sizeof</span> (<a class="code" href="group__DBusSysdeps.html#ga186e987b700f9ddc6cea8aa0db82b151" title="A user ID.">dbus_uid_t</a>));
<a name="l02377"></a>02377   _dbus_assert (<span class="keyword">sizeof</span> (gid_t) &lt;= <span class="keyword">sizeof</span> (<a class="code" href="group__DBusSysdeps.html#ga2f5c2e418b81ec2a86594f56ec6d7627" title="A group ID.">dbus_gid_t</a>));
<a name="l02378"></a>02378 
<a name="l02379"></a>02379   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusCredentials.html#gaad133a8d06af2a447307266a8425a9f8" title="Add a UNIX process ID to the credentials.">_dbus_credentials_add_pid</a>(credentials, <a class="code" href="group__DBusSysdeps.html#ga870807b07f3b1c1a725eb9408edad147" title="Gets our process ID.">_dbus_getpid</a>()))
<a name="l02380"></a>02380     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02381"></a>02381   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusCredentials.html#ga9cec6da43e4be233d44f5bd60b071624" title="Add a UNIX user ID to the credentials.">_dbus_credentials_add_unix_uid</a>(credentials, <a class="code" href="group__DBusSysdepsUnix.html#ga50438942c6e9f4027ea555a09d758ca3" title="Gets our effective UID.">_dbus_geteuid</a>()))
<a name="l02382"></a>02382     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02383"></a>02383 
<a name="l02384"></a>02384   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l02385"></a>02385 }
<a name="l02386"></a>02386 
<a name="l02398"></a>02398 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l02399"></a><a class="code" href="group__DBusSysdeps.html#ga095c54de3974c6d04c29ef86c6e06e35">02399</a> <a class="code" href="group__DBusSysdeps.html#ga095c54de3974c6d04c29ef86c6e06e35" title="Append to the string the identity we would like to have when we authenticate, on UNIX this is the cur...">_dbus_append_user_from_current_process</a> (<a class="code" href="structDBusString.html">DBusString</a> *str)
<a name="l02400"></a>02400 {
<a name="l02401"></a>02401   <span class="keywordflow">return</span> <a class="code" href="group__DBusString.html#gaa63064881001085159c78204f70acde8" title="Appends an unsigned integer to a DBusString.">_dbus_string_append_uint</a> (str,
<a name="l02402"></a>02402                                    <a class="code" href="group__DBusSysdepsUnix.html#ga50438942c6e9f4027ea555a09d758ca3" title="Gets our effective UID.">_dbus_geteuid</a> ());
<a name="l02403"></a>02403 }
<a name="l02404"></a>02404 
<a name="l02409"></a>02409 <a class="code" href="group__DBusSysdeps.html#ga1eff6303266888ec466cddba6c03aa40" title="A process ID.">dbus_pid_t</a>
<a name="l02410"></a><a class="code" href="group__DBusSysdeps.html#ga870807b07f3b1c1a725eb9408edad147">02410</a> <a class="code" href="group__DBusSysdeps.html#ga870807b07f3b1c1a725eb9408edad147" title="Gets our process ID.">_dbus_getpid</a> (<span class="keywordtype">void</span>)
<a name="l02411"></a>02411 {
<a name="l02412"></a>02412   <span class="keywordflow">return</span> getpid ();
<a name="l02413"></a>02413 }
<a name="l02414"></a>02414 
<a name="l02418"></a>02418 <a class="code" href="group__DBusSysdeps.html#ga186e987b700f9ddc6cea8aa0db82b151" title="A user ID.">dbus_uid_t</a>
<a name="l02419"></a><a class="code" href="group__DBusSysdepsUnix.html#gae7701063932951bdd8a7df0dcacb3bab">02419</a> <a class="code" href="group__DBusSysdepsUnix.html#gae7701063932951bdd8a7df0dcacb3bab" title="Gets our UID.">_dbus_getuid</a> (<span class="keywordtype">void</span>)
<a name="l02420"></a>02420 {
<a name="l02421"></a>02421   <span class="keywordflow">return</span> getuid ();
<a name="l02422"></a>02422 }
<a name="l02423"></a>02423 
<a name="l02427"></a>02427 <a class="code" href="group__DBusSysdeps.html#ga186e987b700f9ddc6cea8aa0db82b151" title="A user ID.">dbus_uid_t</a>
<a name="l02428"></a><a class="code" href="group__DBusSysdepsUnix.html#ga50438942c6e9f4027ea555a09d758ca3">02428</a> <a class="code" href="group__DBusSysdepsUnix.html#ga50438942c6e9f4027ea555a09d758ca3" title="Gets our effective UID.">_dbus_geteuid</a> (<span class="keywordtype">void</span>)
<a name="l02429"></a>02429 {
<a name="l02430"></a>02430   <span class="keywordflow">return</span> geteuid ();
<a name="l02431"></a>02431 }
<a name="l02432"></a>02432 
<a name="l02439"></a>02439 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>
<a name="l02440"></a><a class="code" href="group__DBusSysdeps.html#ga1b30aa55e8758ed6e1b62e0f86866543">02440</a> <a class="code" href="group__DBusSysdeps.html#ga1b30aa55e8758ed6e1b62e0f86866543" title="The only reason this is separate from _dbus_getpid() is to allow it on Windows for logging but not fo...">_dbus_pid_for_log</a> (<span class="keywordtype">void</span>)
<a name="l02441"></a>02441 {
<a name="l02442"></a>02442   <span class="keywordflow">return</span> getpid ();
<a name="l02443"></a>02443 }
<a name="l02444"></a>02444 
<a name="l02452"></a>02452 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l02453"></a><a class="code" href="group__DBusSysdepsUnix.html#ga5a1854d99394d4593522ff5f2ca380d9">02453</a> <a class="code" href="group__DBusSysdepsUnix.html#ga5a1854d99394d4593522ff5f2ca380d9" title="Gets a UID from a UID string.">_dbus_parse_uid</a> (<span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a>      *uid_str,
<a name="l02454"></a>02454                  <a class="code" href="group__DBusSysdeps.html#ga186e987b700f9ddc6cea8aa0db82b151" title="A user ID.">dbus_uid_t</a>            *uid)
<a name="l02455"></a>02455 {
<a name="l02456"></a>02456   <span class="keywordtype">int</span> end;
<a name="l02457"></a>02457   <span class="keywordtype">long</span> val;
<a name="l02458"></a>02458 
<a name="l02459"></a>02459   <span class="keywordflow">if</span> (<a class="code" href="group__DBusString.html#gaa5136e6fd2c5188f4b88de7863369c6d" title="Gets the length of a string (not including nul termination).">_dbus_string_get_length</a> (uid_str) == 0)
<a name="l02460"></a>02460     {
<a name="l02461"></a>02461       _dbus_verbose (<span class="stringliteral">&quot;UID string was zero length\n&quot;</span>);
<a name="l02462"></a>02462       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02463"></a>02463     }
<a name="l02464"></a>02464 
<a name="l02465"></a>02465   val = -1;
<a name="l02466"></a>02466   end = 0;
<a name="l02467"></a>02467   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga93e22894a5e2e0d65c179c7d36a8b1c8" title="Parses an integer contained in a DBusString.">_dbus_string_parse_int</a> (uid_str, 0, &amp;val,
<a name="l02468"></a>02468                                &amp;end))
<a name="l02469"></a>02469     {
<a name="l02470"></a>02470       _dbus_verbose (<span class="stringliteral">&quot;could not parse string as a UID\n&quot;</span>);
<a name="l02471"></a>02471       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02472"></a>02472     }
<a name="l02473"></a>02473 
<a name="l02474"></a>02474   <span class="keywordflow">if</span> (end != <a class="code" href="group__DBusString.html#gaa5136e6fd2c5188f4b88de7863369c6d" title="Gets the length of a string (not including nul termination).">_dbus_string_get_length</a> (uid_str))
<a name="l02475"></a>02475     {
<a name="l02476"></a>02476       _dbus_verbose (<span class="stringliteral">&quot;string contained trailing stuff after UID\n&quot;</span>);
<a name="l02477"></a>02477       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02478"></a>02478     }
<a name="l02479"></a>02479 
<a name="l02480"></a>02480   *uid = val;
<a name="l02481"></a>02481 
<a name="l02482"></a>02482   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l02483"></a>02483 }
<a name="l02484"></a>02484 
<a name="l02485"></a>02485 <span class="preprocessor">#if !DBUS_USE_SYNC</span>
<a name="l02486"></a>02486 <span class="preprocessor"></span><span class="comment">/* To be thread-safe by default on platforms that don&#39;t necessarily have</span>
<a name="l02487"></a>02487 <span class="comment"> * atomic operations (notably Debian armel, which is armv4t), we must</span>
<a name="l02488"></a>02488 <span class="comment"> * use a mutex that can be initialized statically, like this.</span>
<a name="l02489"></a>02489 <span class="comment"> * GLib &gt;= 2.32 uses a similar system.</span>
<a name="l02490"></a>02490 <span class="comment"> */</span>
<a name="l02491"></a>02491 <span class="keyword">static</span> pthread_mutex_t atomic_mutex = PTHREAD_MUTEX_INITIALIZER;
<a name="l02492"></a>02492 <span class="preprocessor">#endif</span>
<a name="l02493"></a>02493 <span class="preprocessor"></span>
<a name="l02500"></a>02500 <a class="code" href="group__DBusTypes.html#gab18afa60e9b17b6e322735bda3d863d8" title="A 32-bit signed integer on all platforms.">dbus_int32_t</a>
<a name="l02501"></a><a class="code" href="group__DBusSysdeps.html#gae74c3fcf12acaeccdb152ef907de951c">02501</a> <a class="code" href="group__DBusSysdeps.html#gae74c3fcf12acaeccdb152ef907de951c" title="Atomically increments an integer.">_dbus_atomic_inc</a> (<a class="code" href="structDBusAtomic.html" title="An atomic integer safe to increment or decrement from multiple threads.">DBusAtomic</a> *atomic)
<a name="l02502"></a>02502 {
<a name="l02503"></a>02503 <span class="preprocessor">#if DBUS_USE_SYNC</span>
<a name="l02504"></a>02504 <span class="preprocessor"></span>  <span class="keywordflow">return</span> __sync_add_and_fetch(&amp;atomic-&gt;<a class="code" href="structDBusAtomic.html#aef100f17856a635a9d0f3cae7a7f6bf8" title="Value of the atomic integer.">value</a>, 1)-1;
<a name="l02505"></a>02505 <span class="preprocessor">#else</span>
<a name="l02506"></a>02506 <span class="preprocessor"></span>  <a class="code" href="group__DBusTypes.html#gab18afa60e9b17b6e322735bda3d863d8" title="A 32-bit signed integer on all platforms.">dbus_int32_t</a> res;
<a name="l02507"></a>02507 
<a name="l02508"></a>02508   pthread_mutex_lock (&amp;atomic_mutex);
<a name="l02509"></a>02509   res = atomic-&gt;<a class="code" href="structDBusAtomic.html#aef100f17856a635a9d0f3cae7a7f6bf8" title="Value of the atomic integer.">value</a>;
<a name="l02510"></a>02510   atomic-&gt;<a class="code" href="structDBusAtomic.html#aef100f17856a635a9d0f3cae7a7f6bf8" title="Value of the atomic integer.">value</a> += 1;
<a name="l02511"></a>02511   pthread_mutex_unlock (&amp;atomic_mutex);
<a name="l02512"></a>02512 
<a name="l02513"></a>02513   <span class="keywordflow">return</span> res;
<a name="l02514"></a>02514 <span class="preprocessor">#endif</span>
<a name="l02515"></a>02515 <span class="preprocessor"></span>}
<a name="l02516"></a>02516 
<a name="l02523"></a>02523 <a class="code" href="group__DBusTypes.html#gab18afa60e9b17b6e322735bda3d863d8" title="A 32-bit signed integer on all platforms.">dbus_int32_t</a>
<a name="l02524"></a><a class="code" href="group__DBusSysdeps.html#ga3c50a069f795dceeb9172fe2b517bbdc">02524</a> <a class="code" href="group__DBusSysdeps.html#ga3c50a069f795dceeb9172fe2b517bbdc" title="Atomically decrement an integer.">_dbus_atomic_dec</a> (<a class="code" href="structDBusAtomic.html" title="An atomic integer safe to increment or decrement from multiple threads.">DBusAtomic</a> *atomic)
<a name="l02525"></a>02525 {
<a name="l02526"></a>02526 <span class="preprocessor">#if DBUS_USE_SYNC</span>
<a name="l02527"></a>02527 <span class="preprocessor"></span>  <span class="keywordflow">return</span> __sync_sub_and_fetch(&amp;atomic-&gt;<a class="code" href="structDBusAtomic.html#aef100f17856a635a9d0f3cae7a7f6bf8" title="Value of the atomic integer.">value</a>, 1)+1;
<a name="l02528"></a>02528 <span class="preprocessor">#else</span>
<a name="l02529"></a>02529 <span class="preprocessor"></span>  <a class="code" href="group__DBusTypes.html#gab18afa60e9b17b6e322735bda3d863d8" title="A 32-bit signed integer on all platforms.">dbus_int32_t</a> res;
<a name="l02530"></a>02530 
<a name="l02531"></a>02531   pthread_mutex_lock (&amp;atomic_mutex);
<a name="l02532"></a>02532   res = atomic-&gt;<a class="code" href="structDBusAtomic.html#aef100f17856a635a9d0f3cae7a7f6bf8" title="Value of the atomic integer.">value</a>;
<a name="l02533"></a>02533   atomic-&gt;<a class="code" href="structDBusAtomic.html#aef100f17856a635a9d0f3cae7a7f6bf8" title="Value of the atomic integer.">value</a> -= 1;
<a name="l02534"></a>02534   pthread_mutex_unlock (&amp;atomic_mutex);
<a name="l02535"></a>02535 
<a name="l02536"></a>02536   <span class="keywordflow">return</span> res;
<a name="l02537"></a>02537 <span class="preprocessor">#endif</span>
<a name="l02538"></a>02538 <span class="preprocessor"></span>}
<a name="l02539"></a>02539 
<a name="l02547"></a>02547 <a class="code" href="group__DBusTypes.html#gab18afa60e9b17b6e322735bda3d863d8" title="A 32-bit signed integer on all platforms.">dbus_int32_t</a>
<a name="l02548"></a><a class="code" href="group__DBusSysdeps.html#ga626c810359ba0e362367ce2ec6691aca">02548</a> <a class="code" href="group__DBusSysdeps.html#ga626c810359ba0e362367ce2ec6691aca" title="Atomically get the value of an integer.">_dbus_atomic_get</a> (<a class="code" href="structDBusAtomic.html" title="An atomic integer safe to increment or decrement from multiple threads.">DBusAtomic</a> *atomic)
<a name="l02549"></a>02549 {
<a name="l02550"></a>02550 <span class="preprocessor">#if DBUS_USE_SYNC</span>
<a name="l02551"></a>02551 <span class="preprocessor"></span>  __sync_synchronize ();
<a name="l02552"></a>02552   <span class="keywordflow">return</span> atomic-&gt;<a class="code" href="structDBusAtomic.html#aef100f17856a635a9d0f3cae7a7f6bf8" title="Value of the atomic integer.">value</a>;
<a name="l02553"></a>02553 <span class="preprocessor">#else</span>
<a name="l02554"></a>02554 <span class="preprocessor"></span>  <a class="code" href="group__DBusTypes.html#gab18afa60e9b17b6e322735bda3d863d8" title="A 32-bit signed integer on all platforms.">dbus_int32_t</a> res;
<a name="l02555"></a>02555 
<a name="l02556"></a>02556   pthread_mutex_lock (&amp;atomic_mutex);
<a name="l02557"></a>02557   res = atomic-&gt;<a class="code" href="structDBusAtomic.html#aef100f17856a635a9d0f3cae7a7f6bf8" title="Value of the atomic integer.">value</a>;
<a name="l02558"></a>02558   pthread_mutex_unlock (&amp;atomic_mutex);
<a name="l02559"></a>02559 
<a name="l02560"></a>02560   <span class="keywordflow">return</span> res;
<a name="l02561"></a>02561 <span class="preprocessor">#endif</span>
<a name="l02562"></a>02562 <span class="preprocessor"></span>}
<a name="l02563"></a>02563 
<a name="l02572"></a>02572 <span class="keywordtype">int</span>
<a name="l02573"></a><a class="code" href="group__DBusSysdeps.html#gac1cdb5995dcef6dd54399ab610ae689a">02573</a> <a class="code" href="group__DBusSysdeps.html#gac1cdb5995dcef6dd54399ab610ae689a" title="Wrapper for poll().">_dbus_poll</a> (<a class="code" href="structDBusPollFD.html" title="A portable struct pollfd wrapper.">DBusPollFD</a> *fds,
<a name="l02574"></a>02574             <span class="keywordtype">int</span>         n_fds,
<a name="l02575"></a>02575             <span class="keywordtype">int</span>         timeout_milliseconds)
<a name="l02576"></a>02576 {
<a name="l02577"></a>02577 <span class="preprocessor">#if defined(HAVE_POLL) &amp;&amp; !defined(BROKEN_POLL)</span>
<a name="l02578"></a>02578 <span class="preprocessor"></span>  <span class="comment">/* This big thing is a constant expression and should get optimized</span>
<a name="l02579"></a>02579 <span class="comment">   * out of existence. So it&#39;s more robust than a configure check at</span>
<a name="l02580"></a>02580 <span class="comment">   * no cost.</span>
<a name="l02581"></a>02581 <span class="comment">   */</span>
<a name="l02582"></a>02582   <span class="keywordflow">if</span> (<a class="code" href="group__DBusSysdeps.html#ga96b5ba58b9939d789bfece0d9bb82f41" title="There is data to read.">_DBUS_POLLIN</a> == POLLIN &amp;&amp;
<a name="l02583"></a>02583       <a class="code" href="group__DBusSysdeps.html#ga1db7d09a41912c10978c6a4955d9a9d2" title="There is urgent data to read.">_DBUS_POLLPRI</a> == POLLPRI &amp;&amp;
<a name="l02584"></a>02584       <a class="code" href="group__DBusSysdeps.html#ga0cb1ace07be145e0b908687e99b5f161" title="Writing now will not block.">_DBUS_POLLOUT</a> == POLLOUT &amp;&amp;
<a name="l02585"></a>02585       <a class="code" href="group__DBusSysdeps.html#ga231164196ff407eccb732452a2d36468" title="Error condition.">_DBUS_POLLERR</a> == POLLERR &amp;&amp;
<a name="l02586"></a>02586       <a class="code" href="group__DBusSysdeps.html#ga6f08232c1f943313e3eefd7de8f3592f" title="Hung up.">_DBUS_POLLHUP</a> == POLLHUP &amp;&amp;
<a name="l02587"></a>02587       <a class="code" href="group__DBusSysdeps.html#ga83bf3d24f3a1a853dda794835c39fc6f" title="Invalid request: fd not open.">_DBUS_POLLNVAL</a> == POLLNVAL &amp;&amp;
<a name="l02588"></a>02588       <span class="keyword">sizeof</span> (<a class="code" href="structDBusPollFD.html" title="A portable struct pollfd wrapper.">DBusPollFD</a>) == <span class="keyword">sizeof</span> (<span class="keyword">struct</span> pollfd) &amp;&amp;
<a name="l02589"></a>02589       _DBUS_STRUCT_OFFSET (<a class="code" href="structDBusPollFD.html" title="A portable struct pollfd wrapper.">DBusPollFD</a>, fd) ==
<a name="l02590"></a>02590       _DBUS_STRUCT_OFFSET (<span class="keyword">struct</span> pollfd, fd) &amp;&amp;
<a name="l02591"></a>02591       _DBUS_STRUCT_OFFSET (<a class="code" href="structDBusPollFD.html" title="A portable struct pollfd wrapper.">DBusPollFD</a>, events) ==
<a name="l02592"></a>02592       _DBUS_STRUCT_OFFSET (<span class="keyword">struct</span> pollfd, events) &amp;&amp;
<a name="l02593"></a>02593       _DBUS_STRUCT_OFFSET (<a class="code" href="structDBusPollFD.html" title="A portable struct pollfd wrapper.">DBusPollFD</a>, revents) ==
<a name="l02594"></a>02594       _DBUS_STRUCT_OFFSET (<span class="keyword">struct</span> pollfd, revents))
<a name="l02595"></a>02595     {
<a name="l02596"></a>02596       <span class="keywordflow">return</span> poll ((<span class="keyword">struct</span> pollfd*) fds,
<a name="l02597"></a>02597                    n_fds,
<a name="l02598"></a>02598                    timeout_milliseconds);
<a name="l02599"></a>02599     }
<a name="l02600"></a>02600   <span class="keywordflow">else</span>
<a name="l02601"></a>02601     {
<a name="l02602"></a>02602       <span class="comment">/* We have to convert the DBusPollFD to an array of</span>
<a name="l02603"></a>02603 <span class="comment">       * struct pollfd, poll, and convert back.</span>
<a name="l02604"></a>02604 <span class="comment">       */</span>
<a name="l02605"></a>02605       <a class="code" href="group__DBusInternalsUtils.html#gabea2c16d6d3fe7c4eb5b9496fc877f84" title="Prints a warning message to stderr.">_dbus_warn</a> (<span class="stringliteral">&quot;didn&#39;t implement poll() properly for this system yet\n&quot;</span>);
<a name="l02606"></a>02606       <span class="keywordflow">return</span> -1;
<a name="l02607"></a>02607     }
<a name="l02608"></a>02608 <span class="preprocessor">#else </span><span class="comment">/* ! HAVE_POLL */</span>
<a name="l02609"></a>02609 
<a name="l02610"></a>02610   fd_set read_set, write_set, err_set;
<a name="l02611"></a>02611   <span class="keywordtype">int</span> max_fd = 0;
<a name="l02612"></a>02612   <span class="keywordtype">int</span> i;
<a name="l02613"></a>02613   <span class="keyword">struct </span>timeval tv;
<a name="l02614"></a>02614   <span class="keywordtype">int</span> ready;
<a name="l02615"></a>02615 
<a name="l02616"></a>02616   FD_ZERO (&amp;read_set);
<a name="l02617"></a>02617   FD_ZERO (&amp;write_set);
<a name="l02618"></a>02618   FD_ZERO (&amp;err_set);
<a name="l02619"></a>02619 
<a name="l02620"></a>02620   <span class="keywordflow">for</span> (i = 0; i &lt; n_fds; i++)
<a name="l02621"></a>02621     {
<a name="l02622"></a>02622       <a class="code" href="structDBusPollFD.html" title="A portable struct pollfd wrapper.">DBusPollFD</a> *fdp = &amp;fds[i];
<a name="l02623"></a>02623 
<a name="l02624"></a>02624       <span class="keywordflow">if</span> (fdp-&gt;<a class="code" href="structDBusPollFD.html#a10e65e6721451e92361497b2efaa758f" title="Events to poll for.">events</a> &amp; <a class="code" href="group__DBusSysdeps.html#ga96b5ba58b9939d789bfece0d9bb82f41" title="There is data to read.">_DBUS_POLLIN</a>)
<a name="l02625"></a>02625         FD_SET (fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>, &amp;read_set);
<a name="l02626"></a>02626 
<a name="l02627"></a>02627       <span class="keywordflow">if</span> (fdp-&gt;<a class="code" href="structDBusPollFD.html#a10e65e6721451e92361497b2efaa758f" title="Events to poll for.">events</a> &amp; <a class="code" href="group__DBusSysdeps.html#ga0cb1ace07be145e0b908687e99b5f161" title="Writing now will not block.">_DBUS_POLLOUT</a>)
<a name="l02628"></a>02628         FD_SET (fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>, &amp;write_set);
<a name="l02629"></a>02629 
<a name="l02630"></a>02630       FD_SET (fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>, &amp;err_set);
<a name="l02631"></a>02631 
<a name="l02632"></a>02632       max_fd = MAX (max_fd, fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>);
<a name="l02633"></a>02633     }
<a name="l02634"></a>02634 
<a name="l02635"></a>02635   tv.tv_sec = timeout_milliseconds / 1000;
<a name="l02636"></a>02636   tv.tv_usec = (timeout_milliseconds % 1000) * 1000;
<a name="l02637"></a>02637 
<a name="l02638"></a>02638   ready = select (max_fd + 1, &amp;read_set, &amp;write_set, &amp;err_set,
<a name="l02639"></a>02639                   timeout_milliseconds &lt; 0 ? <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a> : &amp;tv);
<a name="l02640"></a>02640 
<a name="l02641"></a>02641   <span class="keywordflow">if</span> (ready &gt; 0)
<a name="l02642"></a>02642     {
<a name="l02643"></a>02643       <span class="keywordflow">for</span> (i = 0; i &lt; n_fds; i++)
<a name="l02644"></a>02644         {
<a name="l02645"></a>02645           <a class="code" href="structDBusPollFD.html" title="A portable struct pollfd wrapper.">DBusPollFD</a> *fdp = &amp;fds[i];
<a name="l02646"></a>02646 
<a name="l02647"></a>02647           fdp-&gt;<a class="code" href="structDBusPollFD.html#a24bc29c766b8bbddc5da052e7a46bc9e" title="Events that occurred.">revents</a> = 0;
<a name="l02648"></a>02648 
<a name="l02649"></a>02649           <span class="keywordflow">if</span> (FD_ISSET (fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>, &amp;read_set))
<a name="l02650"></a>02650             fdp-&gt;<a class="code" href="structDBusPollFD.html#a24bc29c766b8bbddc5da052e7a46bc9e" title="Events that occurred.">revents</a> |= <a class="code" href="group__DBusSysdeps.html#ga96b5ba58b9939d789bfece0d9bb82f41" title="There is data to read.">_DBUS_POLLIN</a>;
<a name="l02651"></a>02651 
<a name="l02652"></a>02652           <span class="keywordflow">if</span> (FD_ISSET (fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>, &amp;write_set))
<a name="l02653"></a>02653             fdp-&gt;<a class="code" href="structDBusPollFD.html#a24bc29c766b8bbddc5da052e7a46bc9e" title="Events that occurred.">revents</a> |= <a class="code" href="group__DBusSysdeps.html#ga0cb1ace07be145e0b908687e99b5f161" title="Writing now will not block.">_DBUS_POLLOUT</a>;
<a name="l02654"></a>02654 
<a name="l02655"></a>02655           <span class="keywordflow">if</span> (FD_ISSET (fdp-&gt;<a class="code" href="structDBusPollFD.html#a10b23977d2f696abfd276b9077f8c97e" title="File descriptor.">fd</a>, &amp;err_set))
<a name="l02656"></a>02656             fdp-&gt;<a class="code" href="structDBusPollFD.html#a24bc29c766b8bbddc5da052e7a46bc9e" title="Events that occurred.">revents</a> |= <a class="code" href="group__DBusSysdeps.html#ga231164196ff407eccb732452a2d36468" title="Error condition.">_DBUS_POLLERR</a>;
<a name="l02657"></a>02657         }
<a name="l02658"></a>02658     }
<a name="l02659"></a>02659 
<a name="l02660"></a>02660   <span class="keywordflow">return</span> ready;
<a name="l02661"></a>02661 <span class="preprocessor">#endif</span>
<a name="l02662"></a>02662 <span class="preprocessor"></span>}
<a name="l02663"></a>02663 
<a name="l02671"></a>02671 <span class="keywordtype">void</span>
<a name="l02672"></a><a class="code" href="group__DBusSysdeps.html#gab9951a7fd8c33188bf86314e7fd56300">02672</a> <a class="code" href="group__DBusSysdeps.html#gab9951a7fd8c33188bf86314e7fd56300" title="Get current time, as in gettimeofday().">_dbus_get_monotonic_time</a> (<span class="keywordtype">long</span> *tv_sec,
<a name="l02673"></a>02673                           <span class="keywordtype">long</span> *tv_usec)
<a name="l02674"></a>02674 {
<a name="l02675"></a>02675 <span class="preprocessor">#ifdef HAVE_MONOTONIC_CLOCK</span>
<a name="l02676"></a>02676 <span class="preprocessor"></span>  <span class="keyword">struct </span>timespec ts;
<a name="l02677"></a>02677   clock_gettime (CLOCK_MONOTONIC, &amp;ts);
<a name="l02678"></a>02678 
<a name="l02679"></a>02679   <span class="keywordflow">if</span> (tv_sec)
<a name="l02680"></a>02680     *tv_sec = ts.tv_sec;
<a name="l02681"></a>02681   <span class="keywordflow">if</span> (tv_usec)
<a name="l02682"></a>02682     *tv_usec = ts.tv_nsec / 1000;
<a name="l02683"></a>02683 <span class="preprocessor">#else</span>
<a name="l02684"></a>02684 <span class="preprocessor"></span>  <span class="keyword">struct </span>timeval t;
<a name="l02685"></a>02685 
<a name="l02686"></a>02686   gettimeofday (&amp;t, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l02687"></a>02687 
<a name="l02688"></a>02688   <span class="keywordflow">if</span> (tv_sec)
<a name="l02689"></a>02689     *tv_sec = t.tv_sec;
<a name="l02690"></a>02690   <span class="keywordflow">if</span> (tv_usec)
<a name="l02691"></a>02691     *tv_usec = t.tv_usec;
<a name="l02692"></a>02692 <span class="preprocessor">#endif</span>
<a name="l02693"></a>02693 <span class="preprocessor"></span>}
<a name="l02694"></a>02694 
<a name="l02702"></a>02702 <span class="keywordtype">void</span>
<a name="l02703"></a><a class="code" href="group__DBusSysdeps.html#gae10ee21ab353beadbe2493728065f600">02703</a> <a class="code" href="group__DBusSysdeps.html#gae10ee21ab353beadbe2493728065f600" title="Get current time, as in gettimeofday().">_dbus_get_real_time</a> (<span class="keywordtype">long</span> *tv_sec,
<a name="l02704"></a>02704                      <span class="keywordtype">long</span> *tv_usec)
<a name="l02705"></a>02705 {
<a name="l02706"></a>02706   <span class="keyword">struct </span>timeval t;
<a name="l02707"></a>02707 
<a name="l02708"></a>02708   gettimeofday (&amp;t, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l02709"></a>02709 
<a name="l02710"></a>02710   <span class="keywordflow">if</span> (tv_sec)
<a name="l02711"></a>02711     *tv_sec = t.tv_sec;
<a name="l02712"></a>02712   <span class="keywordflow">if</span> (tv_usec)
<a name="l02713"></a>02713     *tv_usec = t.tv_usec;
<a name="l02714"></a>02714 }
<a name="l02715"></a>02715 
<a name="l02724"></a>02724 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l02725"></a><a class="code" href="group__DBusSysdeps.html#gaa47156dedbe573ee9b213d1fd3f7bb79">02725</a> <a class="code" href="group__DBusSysdeps.html#gaa47156dedbe573ee9b213d1fd3f7bb79" title="Creates a directory; succeeds if the directory is created or already existed.">_dbus_create_directory</a> (<span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *filename,
<a name="l02726"></a>02726                         <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>        *error)
<a name="l02727"></a>02727 {
<a name="l02728"></a>02728   <span class="keyword">const</span> <span class="keywordtype">char</span> *filename_c;
<a name="l02729"></a>02729 
<a name="l02730"></a>02730   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l02731"></a>02731 
<a name="l02732"></a>02732   filename_c = <a class="code" href="group__DBusString.html#ga33e20241ae7d784624f97d89b1a0539e" title="Gets the raw character buffer from a const string.">_dbus_string_get_const_data</a> (filename);
<a name="l02733"></a>02733 
<a name="l02734"></a>02734   <span class="keywordflow">if</span> (mkdir (filename_c, 0700) &lt; 0)
<a name="l02735"></a>02735     {
<a name="l02736"></a>02736       <span class="keywordflow">if</span> (errno == EEXIST)
<a name="l02737"></a>02737         <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l02738"></a>02738 
<a name="l02739"></a>02739       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gabb62fd6340d0787fbd56ff8dd2f326c7" title="A generic error; &quot;something went wrong&quot; - see the error message for more.">DBUS_ERROR_FAILED</a>,
<a name="l02740"></a>02740                       <span class="stringliteral">&quot;Failed to create directory %s: %s\n&quot;</span>,
<a name="l02741"></a>02741                       filename_c, _dbus_strerror (errno));
<a name="l02742"></a>02742       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02743"></a>02743     }
<a name="l02744"></a>02744   <span class="keywordflow">else</span>
<a name="l02745"></a>02745     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l02746"></a>02746 }
<a name="l02747"></a>02747 
<a name="l02758"></a>02758 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l02759"></a><a class="code" href="group__DBusSysdeps.html#gae3a3fdc0c6001e367584bb016aca495d">02759</a> <a class="code" href="group__DBusSysdeps.html#gae3a3fdc0c6001e367584bb016aca495d" title="Appends the given filename to the given directory.">_dbus_concat_dir_and_file</a> (<a class="code" href="structDBusString.html">DBusString</a>       *dir,
<a name="l02760"></a>02760                            <span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *next_component)
<a name="l02761"></a>02761 {
<a name="l02762"></a>02762   <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> dir_ends_in_slash;
<a name="l02763"></a>02763   <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> file_starts_with_slash;
<a name="l02764"></a>02764 
<a name="l02765"></a>02765   <span class="keywordflow">if</span> (<a class="code" href="group__DBusString.html#gaa5136e6fd2c5188f4b88de7863369c6d" title="Gets the length of a string (not including nul termination).">_dbus_string_get_length</a> (dir) == 0 ||
<a name="l02766"></a>02766       <a class="code" href="group__DBusString.html#gaa5136e6fd2c5188f4b88de7863369c6d" title="Gets the length of a string (not including nul termination).">_dbus_string_get_length</a> (next_component) == 0)
<a name="l02767"></a>02767     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l02768"></a>02768 
<a name="l02769"></a>02769   dir_ends_in_slash = <span class="charliteral">&#39;/&#39;</span> == <a class="code" href="group__DBusString.html#gac1cb7b207eac3c6527a5d42fbc5449b1" title="Gets the byte at the given position.">_dbus_string_get_byte</a> (dir,
<a name="l02770"></a>02770                                                     <a class="code" href="group__DBusString.html#gaa5136e6fd2c5188f4b88de7863369c6d" title="Gets the length of a string (not including nul termination).">_dbus_string_get_length</a> (dir) - 1);
<a name="l02771"></a>02771 
<a name="l02772"></a>02772   file_starts_with_slash = <span class="charliteral">&#39;/&#39;</span> == <a class="code" href="group__DBusString.html#gac1cb7b207eac3c6527a5d42fbc5449b1" title="Gets the byte at the given position.">_dbus_string_get_byte</a> (next_component, 0);
<a name="l02773"></a>02773 
<a name="l02774"></a>02774   <span class="keywordflow">if</span> (dir_ends_in_slash &amp;&amp; file_starts_with_slash)
<a name="l02775"></a>02775     {
<a name="l02776"></a>02776       <a class="code" href="group__DBusString.html#ga7af1cbfa905f26d972ab644d890548b8" title="Makes a string shorter by the given number of bytes.">_dbus_string_shorten</a> (dir, 1);
<a name="l02777"></a>02777     }
<a name="l02778"></a>02778   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!(dir_ends_in_slash || file_starts_with_slash))
<a name="l02779"></a>02779     {
<a name="l02780"></a>02780       <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#gaa6ecf36e70263659f921a4ef0335db12" title="Appends a single byte to the string, returning FALSE if not enough memory.">_dbus_string_append_byte</a> (dir, <span class="charliteral">&#39;/&#39;</span>))
<a name="l02781"></a>02781         <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02782"></a>02782     }
<a name="l02783"></a>02783 
<a name="l02784"></a>02784   <span class="keywordflow">return</span> <a class="code" href="group__DBusString.html#ga3c10f0d1bcaa3b450025b9c6a8b901d7" title="Like _dbus_string_move(), but does not delete the section of the source string that&#39;s copied to the d...">_dbus_string_copy</a> (next_component, 0, dir,
<a name="l02785"></a>02785                             <a class="code" href="group__DBusString.html#gaa5136e6fd2c5188f4b88de7863369c6d" title="Gets the length of a string (not including nul termination).">_dbus_string_get_length</a> (dir));
<a name="l02786"></a>02786 }
<a name="l02787"></a>02787 
<a name="l02789"></a>02789 <span class="preprocessor">#define NANOSECONDS_PER_SECOND       1000000000</span>
<a name="l02790"></a>02790 <span class="preprocessor"></span>
<a name="l02791"></a>02791 <span class="preprocessor">#define MICROSECONDS_PER_SECOND      1000000</span>
<a name="l02792"></a>02792 <span class="preprocessor"></span>
<a name="l02793"></a>02793 <span class="preprocessor">#define MILLISECONDS_PER_SECOND      1000</span>
<a name="l02794"></a>02794 <span class="preprocessor"></span>
<a name="l02795"></a>02795 <span class="preprocessor">#define NANOSECONDS_PER_MILLISECOND  1000000</span>
<a name="l02796"></a>02796 <span class="preprocessor"></span>
<a name="l02797"></a>02797 <span class="preprocessor">#define MICROSECONDS_PER_MILLISECOND 1000</span>
<a name="l02798"></a>02798 <span class="preprocessor"></span>
<a name="l02803"></a>02803 <span class="keywordtype">void</span>
<a name="l02804"></a><a class="code" href="group__DBusSysdeps.html#ga1153b4669819148af6b3f6f2b7c9183a">02804</a> <a class="code" href="group__DBusSysdeps.html#ga1153b4669819148af6b3f6f2b7c9183a" title="Sleeps the given number of milliseconds.">_dbus_sleep_milliseconds</a> (<span class="keywordtype">int</span> milliseconds)
<a name="l02805"></a>02805 {
<a name="l02806"></a>02806 <span class="preprocessor">#ifdef HAVE_NANOSLEEP</span>
<a name="l02807"></a>02807 <span class="preprocessor"></span>  <span class="keyword">struct </span>timespec req;
<a name="l02808"></a>02808   <span class="keyword">struct </span>timespec rem;
<a name="l02809"></a>02809 
<a name="l02810"></a>02810   req.tv_sec = milliseconds / MILLISECONDS_PER_SECOND;
<a name="l02811"></a>02811   req.tv_nsec = (milliseconds % MILLISECONDS_PER_SECOND) * NANOSECONDS_PER_MILLISECOND;
<a name="l02812"></a>02812   rem.tv_sec = 0;
<a name="l02813"></a>02813   rem.tv_nsec = 0;
<a name="l02814"></a>02814 
<a name="l02815"></a>02815   <span class="keywordflow">while</span> (nanosleep (&amp;req, &amp;rem) &lt; 0 &amp;&amp; errno == EINTR)
<a name="l02816"></a>02816     req = rem;
<a name="l02817"></a>02817 <span class="preprocessor">#elif defined (HAVE_USLEEP)</span>
<a name="l02818"></a>02818 <span class="preprocessor"></span>  usleep (milliseconds * MICROSECONDS_PER_MILLISECOND);
<a name="l02819"></a>02819 <span class="preprocessor">#else </span><span class="comment">/* ! HAVE_USLEEP */</span>
<a name="l02820"></a>02820   sleep (MAX (milliseconds / 1000, 1));
<a name="l02821"></a>02821 <span class="preprocessor">#endif</span>
<a name="l02822"></a>02822 <span class="preprocessor"></span>}
<a name="l02823"></a>02823 
<a name="l02824"></a>02824 <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l02825"></a>02825 _dbus_generate_pseudorandom_bytes (<a class="code" href="structDBusString.html">DBusString</a> *str,
<a name="l02826"></a>02826                                    <span class="keywordtype">int</span>         n_bytes)
<a name="l02827"></a>02827 {
<a name="l02828"></a>02828   <span class="keywordtype">int</span> old_len;
<a name="l02829"></a>02829   <span class="keywordtype">char</span> *p;
<a name="l02830"></a>02830 
<a name="l02831"></a>02831   old_len = <a class="code" href="group__DBusString.html#gaa5136e6fd2c5188f4b88de7863369c6d" title="Gets the length of a string (not including nul termination).">_dbus_string_get_length</a> (str);
<a name="l02832"></a>02832 
<a name="l02833"></a>02833   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga8f13997d90ceed2f437706e6b7804d9b" title="Makes a string longer by the given number of bytes.">_dbus_string_lengthen</a> (str, n_bytes))
<a name="l02834"></a>02834     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02835"></a>02835 
<a name="l02836"></a>02836   p = <a class="code" href="group__DBusString.html#ga7a73fb373398606e6e1d0a86c4587a3c" title="Gets a sub-portion of the raw character buffer from the string.">_dbus_string_get_data_len</a> (str, old_len, n_bytes);
<a name="l02837"></a>02837 
<a name="l02838"></a>02838   <a class="code" href="group__DBusInternalsUtils.html#gafb4454c18ee8e5bcc20dbccd93e1d9ba" title="Random numbers.">_dbus_generate_pseudorandom_bytes_buffer</a> (p, n_bytes);
<a name="l02839"></a>02839 
<a name="l02840"></a>02840   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l02841"></a>02841 }
<a name="l02842"></a>02842 
<a name="l02851"></a>02851 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l02852"></a><a class="code" href="group__DBusSysdeps.html#gac9fd08af5e54c0e9b3db108b48a65778">02852</a> <a class="code" href="group__DBusSysdeps.html#gac9fd08af5e54c0e9b3db108b48a65778" title="Generates the given number of random bytes, using the best mechanism we can come up with...">_dbus_generate_random_bytes</a> (<a class="code" href="structDBusString.html">DBusString</a> *str,
<a name="l02853"></a>02853                              <span class="keywordtype">int</span>         n_bytes)
<a name="l02854"></a>02854 {
<a name="l02855"></a>02855   <span class="keywordtype">int</span> old_len;
<a name="l02856"></a>02856   <span class="keywordtype">int</span> fd;
<a name="l02857"></a>02857 
<a name="l02858"></a>02858   <span class="comment">/* FALSE return means &quot;no memory&quot;, if it could</span>
<a name="l02859"></a>02859 <span class="comment">   * mean something else then we&#39;d need to return</span>
<a name="l02860"></a>02860 <span class="comment">   * a DBusError. So we always fall back to pseudorandom</span>
<a name="l02861"></a>02861 <span class="comment">   * if the I/O fails.</span>
<a name="l02862"></a>02862 <span class="comment">   */</span>
<a name="l02863"></a>02863 
<a name="l02864"></a>02864   old_len = <a class="code" href="group__DBusString.html#gaa5136e6fd2c5188f4b88de7863369c6d" title="Gets the length of a string (not including nul termination).">_dbus_string_get_length</a> (str);
<a name="l02865"></a>02865   fd = -1;
<a name="l02866"></a>02866 
<a name="l02867"></a>02867   <span class="comment">/* note, urandom on linux will fall back to pseudorandom */</span>
<a name="l02868"></a>02868   fd = open (<span class="stringliteral">&quot;/dev/urandom&quot;</span>, O_RDONLY);
<a name="l02869"></a>02869   <span class="keywordflow">if</span> (fd &lt; 0)
<a name="l02870"></a>02870     <span class="keywordflow">return</span> _dbus_generate_pseudorandom_bytes (str, n_bytes);
<a name="l02871"></a>02871 
<a name="l02872"></a>02872   _dbus_verbose (<span class="stringliteral">&quot;/dev/urandom fd %d opened\n&quot;</span>, fd);
<a name="l02873"></a>02873 
<a name="l02874"></a>02874   <span class="keywordflow">if</span> (<a class="code" href="group__DBusSysdepsUnix.html#gaf52cb1d5b9fc5611808ce32eff898c28" title="Thin wrapper around the read() system call that appends the data it reads to the DBusString buffer...">_dbus_read</a> (fd, str, n_bytes) != n_bytes)
<a name="l02875"></a>02875     {
<a name="l02876"></a>02876       <a class="code" href="group__DBusSysdepsUnix.html#gac448479a1674e3b86cee9a4bdc7eba03" title="Closes a file descriptor.">_dbus_close</a> (fd, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l02877"></a>02877       <a class="code" href="group__DBusString.html#ga08c423b93c28dd746dcb93e0461ab95c" title="Sets the length of a string.">_dbus_string_set_length</a> (str, old_len);
<a name="l02878"></a>02878       <span class="keywordflow">return</span> _dbus_generate_pseudorandom_bytes (str, n_bytes);
<a name="l02879"></a>02879     }
<a name="l02880"></a>02880 
<a name="l02881"></a>02881   _dbus_verbose (<span class="stringliteral">&quot;Read %d bytes from /dev/urandom\n&quot;</span>,
<a name="l02882"></a>02882                  n_bytes);
<a name="l02883"></a>02883 
<a name="l02884"></a>02884   <a class="code" href="group__DBusSysdepsUnix.html#gac448479a1674e3b86cee9a4bdc7eba03" title="Closes a file descriptor.">_dbus_close</a> (fd, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l02885"></a>02885 
<a name="l02886"></a>02886   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l02887"></a>02887 }
<a name="l02888"></a>02888 
<a name="l02894"></a>02894 <span class="keywordtype">void</span>
<a name="l02895"></a><a class="code" href="group__DBusSysdeps.html#ga203e3257b50597a8fe7757c920474a20">02895</a> <a class="code" href="group__DBusSysdeps.html#ga203e3257b50597a8fe7757c920474a20" title="Exit the process, returning the given value.">_dbus_exit</a> (<span class="keywordtype">int</span> code)
<a name="l02896"></a>02896 {
<a name="l02897"></a>02897   _exit (code);
<a name="l02898"></a>02898 }
<a name="l02899"></a>02899 
<a name="l02908"></a>02908 <span class="keyword">const</span> <span class="keywordtype">char</span>*
<a name="l02909"></a>02909 _dbus_strerror (<span class="keywordtype">int</span> error_number)
<a name="l02910"></a>02910 {
<a name="l02911"></a>02911   <span class="keyword">const</span> <span class="keywordtype">char</span> *msg;
<a name="l02912"></a>02912 
<a name="l02913"></a>02913   msg = strerror (error_number);
<a name="l02914"></a>02914   <span class="keywordflow">if</span> (msg == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l02915"></a>02915     msg = <span class="stringliteral">&quot;unknown&quot;</span>;
<a name="l02916"></a>02916 
<a name="l02917"></a>02917   <span class="keywordflow">return</span> msg;
<a name="l02918"></a>02918 }
<a name="l02919"></a>02919 
<a name="l02923"></a>02923 <span class="keywordtype">void</span>
<a name="l02924"></a><a class="code" href="group__DBusSysdeps.html#ga6890d4cde3afec0bf274ca2af8c9e204">02924</a> <a class="code" href="group__DBusSysdeps.html#ga6890d4cde3afec0bf274ca2af8c9e204" title="signal (SIGPIPE, SIG_IGN);">_dbus_disable_sigpipe</a> (<span class="keywordtype">void</span>)
<a name="l02925"></a>02925 {
<a name="l02926"></a>02926   signal (SIGPIPE, SIG_IGN);
<a name="l02927"></a>02927 }
<a name="l02928"></a>02928 
<a name="l02936"></a>02936 <span class="keywordtype">void</span>
<a name="l02937"></a><a class="code" href="group__DBusSysdeps.html#ga21ef96952f98f23e590ebbf060fd5ca6">02937</a> <a class="code" href="group__DBusSysdeps.html#ga21ef96952f98f23e590ebbf060fd5ca6" title="Sets the file descriptor to be close on exec.">_dbus_fd_set_close_on_exec</a> (intptr_t fd)
<a name="l02938"></a>02938 {
<a name="l02939"></a>02939   <span class="keywordtype">int</span> val;
<a name="l02940"></a>02940 
<a name="l02941"></a>02941   val = fcntl (fd, F_GETFD, 0);
<a name="l02942"></a>02942 
<a name="l02943"></a>02943   <span class="keywordflow">if</span> (val &lt; 0)
<a name="l02944"></a>02944     <span class="keywordflow">return</span>;
<a name="l02945"></a>02945 
<a name="l02946"></a>02946   val |= FD_CLOEXEC;
<a name="l02947"></a>02947 
<a name="l02948"></a>02948   fcntl (fd, F_SETFD, val);
<a name="l02949"></a>02949 }
<a name="l02950"></a>02950 
<a name="l02958"></a>02958 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l02959"></a><a class="code" href="group__DBusSysdepsUnix.html#gac448479a1674e3b86cee9a4bdc7eba03">02959</a> <a class="code" href="group__DBusSysdepsUnix.html#gac448479a1674e3b86cee9a4bdc7eba03" title="Closes a file descriptor.">_dbus_close</a> (<span class="keywordtype">int</span>        fd,
<a name="l02960"></a>02960              <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a> *error)
<a name="l02961"></a>02961 {
<a name="l02962"></a>02962   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l02963"></a>02963 
<a name="l02964"></a>02964  again:
<a name="l02965"></a>02965   <span class="keywordflow">if</span> (close (fd) &lt; 0)
<a name="l02966"></a>02966     {
<a name="l02967"></a>02967       <span class="keywordflow">if</span> (errno == EINTR)
<a name="l02968"></a>02968         <span class="keywordflow">goto</span> again;
<a name="l02969"></a>02969 
<a name="l02970"></a>02970       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l02971"></a>02971                       <span class="stringliteral">&quot;Could not close fd %d&quot;</span>, fd);
<a name="l02972"></a>02972       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l02973"></a>02973     }
<a name="l02974"></a>02974 
<a name="l02975"></a>02975   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l02976"></a>02976 }
<a name="l02977"></a>02977 
<a name="l02986"></a>02986 <span class="keywordtype">int</span>
<a name="l02987"></a><a class="code" href="group__DBusSysdepsUnix.html#gad79d20e59fb519233004208988851cf1">02987</a> <a class="code" href="group__DBusSysdepsUnix.html#gad79d20e59fb519233004208988851cf1" title="Duplicates a file descriptor.">_dbus_dup</a>(<span class="keywordtype">int</span>        fd,
<a name="l02988"></a>02988           <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a> *error)
<a name="l02989"></a>02989 {
<a name="l02990"></a>02990   <span class="keywordtype">int</span> new_fd;
<a name="l02991"></a>02991 
<a name="l02992"></a>02992 <span class="preprocessor">#ifdef F_DUPFD_CLOEXEC</span>
<a name="l02993"></a>02993 <span class="preprocessor"></span>  <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> cloexec_done;
<a name="l02994"></a>02994 
<a name="l02995"></a>02995   new_fd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
<a name="l02996"></a>02996   cloexec_done = new_fd &gt;= 0;
<a name="l02997"></a>02997 
<a name="l02998"></a>02998   <span class="keywordflow">if</span> (new_fd &lt; 0 &amp;&amp; errno == EINVAL)
<a name="l02999"></a>02999 <span class="preprocessor">#endif</span>
<a name="l03000"></a>03000 <span class="preprocessor"></span>    {
<a name="l03001"></a>03001       new_fd = fcntl(fd, F_DUPFD, 3);
<a name="l03002"></a>03002     }
<a name="l03003"></a>03003 
<a name="l03004"></a>03004   <span class="keywordflow">if</span> (new_fd &lt; 0) {
<a name="l03005"></a>03005 
<a name="l03006"></a>03006     <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l03007"></a>03007                     <span class="stringliteral">&quot;Could not duplicate fd %d&quot;</span>, fd);
<a name="l03008"></a>03008     <span class="keywordflow">return</span> -1;
<a name="l03009"></a>03009   }
<a name="l03010"></a>03010 
<a name="l03011"></a>03011 <span class="preprocessor">#ifdef F_DUPFD_CLOEXEC</span>
<a name="l03012"></a>03012 <span class="preprocessor"></span>  <span class="keywordflow">if</span> (!cloexec_done)
<a name="l03013"></a>03013 <span class="preprocessor">#endif</span>
<a name="l03014"></a>03014 <span class="preprocessor"></span>    {
<a name="l03015"></a>03015       <a class="code" href="group__DBusSysdeps.html#ga21ef96952f98f23e590ebbf060fd5ca6" title="Sets the file descriptor to be close on exec.">_dbus_fd_set_close_on_exec</a>(new_fd);
<a name="l03016"></a>03016     }
<a name="l03017"></a>03017 
<a name="l03018"></a>03018   <span class="keywordflow">return</span> new_fd;
<a name="l03019"></a>03019 }
<a name="l03020"></a>03020 
<a name="l03028"></a>03028 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l03029"></a>03029 _dbus_set_fd_nonblocking (<span class="keywordtype">int</span>             fd,
<a name="l03030"></a>03030                           <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>      *error)
<a name="l03031"></a>03031 {
<a name="l03032"></a>03032   <span class="keywordtype">int</span> val;
<a name="l03033"></a>03033 
<a name="l03034"></a>03034   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l03035"></a>03035 
<a name="l03036"></a>03036   val = fcntl (fd, F_GETFL, 0);
<a name="l03037"></a>03037   <span class="keywordflow">if</span> (val &lt; 0)
<a name="l03038"></a>03038     {
<a name="l03039"></a>03039       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l03040"></a>03040                       <span class="stringliteral">&quot;Failed to get flags from file descriptor %d: %s&quot;</span>,
<a name="l03041"></a>03041                       fd, _dbus_strerror (errno));
<a name="l03042"></a>03042       _dbus_verbose (<span class="stringliteral">&quot;Failed to get flags for fd %d: %s\n&quot;</span>, fd,
<a name="l03043"></a>03043                      _dbus_strerror (errno));
<a name="l03044"></a>03044       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03045"></a>03045     }
<a name="l03046"></a>03046 
<a name="l03047"></a>03047   <span class="keywordflow">if</span> (fcntl (fd, F_SETFL, val | O_NONBLOCK) &lt; 0)
<a name="l03048"></a>03048     {
<a name="l03049"></a>03049       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l03050"></a>03050                       <span class="stringliteral">&quot;Failed to set nonblocking flag of file descriptor %d: %s&quot;</span>,
<a name="l03051"></a>03051                       fd, _dbus_strerror (errno));
<a name="l03052"></a>03052       _dbus_verbose (<span class="stringliteral">&quot;Failed to set fd %d nonblocking: %s\n&quot;</span>,
<a name="l03053"></a>03053                      fd, _dbus_strerror (errno));
<a name="l03054"></a>03054 
<a name="l03055"></a>03055       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03056"></a>03056     }
<a name="l03057"></a>03057 
<a name="l03058"></a>03058   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l03059"></a>03059 }
<a name="l03060"></a>03060 
<a name="l03066"></a>03066 <span class="keywordtype">void</span>
<a name="l03067"></a><a class="code" href="group__DBusSysdeps.html#ga8646ab2ef727fcc862c7904113c88a8d">03067</a> <a class="code" href="group__DBusSysdeps.html#ga8646ab2ef727fcc862c7904113c88a8d" title="On GNU libc systems, print a crude backtrace to stderr.">_dbus_print_backtrace</a> (<span class="keywordtype">void</span>)
<a name="l03068"></a>03068 {
<a name="l03069"></a>03069 <span class="preprocessor">#if defined (HAVE_BACKTRACE) &amp;&amp; defined (DBUS_BUILT_R_DYNAMIC)</span>
<a name="l03070"></a>03070 <span class="preprocessor"></span>  <span class="keywordtype">void</span> *bt[500];
<a name="l03071"></a>03071   <span class="keywordtype">int</span> bt_size;
<a name="l03072"></a>03072   <span class="keywordtype">int</span> i;
<a name="l03073"></a>03073   <span class="keywordtype">char</span> **syms;
<a name="l03074"></a>03074 
<a name="l03075"></a>03075   bt_size = backtrace (bt, 500);
<a name="l03076"></a>03076 
<a name="l03077"></a>03077   syms = backtrace_symbols (bt, bt_size);
<a name="l03078"></a>03078 
<a name="l03079"></a>03079   i = 0;
<a name="l03080"></a>03080   <span class="keywordflow">while</span> (i &lt; bt_size)
<a name="l03081"></a>03081     {
<a name="l03082"></a>03082       <span class="comment">/* don&#39;t use dbus_warn since it can _dbus_abort() */</span>
<a name="l03083"></a>03083       fprintf (stderr, <span class="stringliteral">&quot;  %s\n&quot;</span>, syms[i]);
<a name="l03084"></a>03084       ++i;
<a name="l03085"></a>03085     }
<a name="l03086"></a>03086   fflush (stderr);
<a name="l03087"></a>03087 
<a name="l03088"></a>03088   free (syms);
<a name="l03089"></a>03089 <span class="preprocessor">#elif defined (HAVE_BACKTRACE) &amp;&amp; ! defined (DBUS_BUILT_R_DYNAMIC)</span>
<a name="l03090"></a>03090 <span class="preprocessor"></span>  fprintf (stderr, <span class="stringliteral">&quot;  D-Bus not built with -rdynamic so unable to print a backtrace\n&quot;</span>);
<a name="l03091"></a>03091 <span class="preprocessor">#else</span>
<a name="l03092"></a>03092 <span class="preprocessor"></span>  fprintf (stderr, <span class="stringliteral">&quot;  D-Bus not compiled with backtrace support so unable to print a backtrace\n&quot;</span>);
<a name="l03093"></a>03093 <span class="preprocessor">#endif</span>
<a name="l03094"></a>03094 <span class="preprocessor"></span>}
<a name="l03095"></a>03095 
<a name="l03108"></a>03108 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l03109"></a><a class="code" href="group__DBusSysdeps.html#gae96a3f400324b065f78a865a86454d09">03109</a> <a class="code" href="group__DBusSysdeps.html#gae96a3f400324b065f78a865a86454d09" title="Creates a full-duplex pipe (as in socketpair()).">_dbus_full_duplex_pipe</a> (<span class="keywordtype">int</span>        *fd1,
<a name="l03110"></a>03110                         <span class="keywordtype">int</span>        *fd2,
<a name="l03111"></a>03111                         <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> blocking,
<a name="l03112"></a>03112                         <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>  *error)
<a name="l03113"></a>03113 {
<a name="l03114"></a>03114 <span class="preprocessor">#ifdef HAVE_SOCKETPAIR</span>
<a name="l03115"></a>03115 <span class="preprocessor"></span>  <span class="keywordtype">int</span> fds[2];
<a name="l03116"></a>03116   <span class="keywordtype">int</span> retval;
<a name="l03117"></a>03117 
<a name="l03118"></a>03118 <span class="preprocessor">#ifdef SOCK_CLOEXEC</span>
<a name="l03119"></a>03119 <span class="preprocessor"></span>  <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> cloexec_done;
<a name="l03120"></a>03120 
<a name="l03121"></a>03121   retval = socketpair(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0, fds);
<a name="l03122"></a>03122   cloexec_done = retval &gt;= 0;
<a name="l03123"></a>03123 
<a name="l03124"></a>03124   <span class="keywordflow">if</span> (retval &lt; 0 &amp;&amp; (errno == EINVAL || errno == EPROTOTYPE))
<a name="l03125"></a>03125 <span class="preprocessor">#endif</span>
<a name="l03126"></a>03126 <span class="preprocessor"></span>    {
<a name="l03127"></a>03127       retval = socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
<a name="l03128"></a>03128     }
<a name="l03129"></a>03129 
<a name="l03130"></a>03130   <span class="keywordflow">if</span> (retval &lt; 0)
<a name="l03131"></a>03131     {
<a name="l03132"></a>03132       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l03133"></a>03133                       <span class="stringliteral">&quot;Could not create full-duplex pipe&quot;</span>);
<a name="l03134"></a>03134       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03135"></a>03135     }
<a name="l03136"></a>03136 
<a name="l03137"></a>03137   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l03138"></a>03138 
<a name="l03139"></a>03139 <span class="preprocessor">#ifdef SOCK_CLOEXEC</span>
<a name="l03140"></a>03140 <span class="preprocessor"></span>  <span class="keywordflow">if</span> (!cloexec_done)
<a name="l03141"></a>03141 <span class="preprocessor">#endif</span>
<a name="l03142"></a>03142 <span class="preprocessor"></span>    {
<a name="l03143"></a>03143       <a class="code" href="group__DBusSysdeps.html#ga21ef96952f98f23e590ebbf060fd5ca6" title="Sets the file descriptor to be close on exec.">_dbus_fd_set_close_on_exec</a> (fds[0]);
<a name="l03144"></a>03144       <a class="code" href="group__DBusSysdeps.html#ga21ef96952f98f23e590ebbf060fd5ca6" title="Sets the file descriptor to be close on exec.">_dbus_fd_set_close_on_exec</a> (fds[1]);
<a name="l03145"></a>03145     }
<a name="l03146"></a>03146 
<a name="l03147"></a>03147   <span class="keywordflow">if</span> (!blocking &amp;&amp;
<a name="l03148"></a>03148       (!_dbus_set_fd_nonblocking (fds[0], <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>) ||
<a name="l03149"></a>03149        !_dbus_set_fd_nonblocking (fds[1], <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)))
<a name="l03150"></a>03150     {
<a name="l03151"></a>03151       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l03152"></a>03152                       <span class="stringliteral">&quot;Could not set full-duplex pipe nonblocking&quot;</span>);
<a name="l03153"></a>03153 
<a name="l03154"></a>03154       <a class="code" href="group__DBusSysdepsUnix.html#gac448479a1674e3b86cee9a4bdc7eba03" title="Closes a file descriptor.">_dbus_close</a> (fds[0], <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l03155"></a>03155       <a class="code" href="group__DBusSysdepsUnix.html#gac448479a1674e3b86cee9a4bdc7eba03" title="Closes a file descriptor.">_dbus_close</a> (fds[1], <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l03156"></a>03156 
<a name="l03157"></a>03157       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03158"></a>03158     }
<a name="l03159"></a>03159 
<a name="l03160"></a>03160   *fd1 = fds[0];
<a name="l03161"></a>03161   *fd2 = fds[1];
<a name="l03162"></a>03162 
<a name="l03163"></a>03163   _dbus_verbose (<span class="stringliteral">&quot;full-duplex pipe %d &lt;-&gt; %d\n&quot;</span>,
<a name="l03164"></a>03164                  *fd1, *fd2);
<a name="l03165"></a>03165 
<a name="l03166"></a>03166   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l03167"></a>03167 <span class="preprocessor">#else</span>
<a name="l03168"></a>03168 <span class="preprocessor"></span>  <a class="code" href="group__DBusInternalsUtils.html#gabea2c16d6d3fe7c4eb5b9496fc877f84" title="Prints a warning message to stderr.">_dbus_warn</a> (<span class="stringliteral">&quot;_dbus_full_duplex_pipe() not implemented on this OS\n&quot;</span>);
<a name="l03169"></a>03169   <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gabb62fd6340d0787fbd56ff8dd2f326c7" title="A generic error; &quot;something went wrong&quot; - see the error message for more.">DBUS_ERROR_FAILED</a>,
<a name="l03170"></a>03170                   <span class="stringliteral">&quot;_dbus_full_duplex_pipe() not implemented on this OS&quot;</span>);
<a name="l03171"></a>03171   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03172"></a>03172 <span class="preprocessor">#endif</span>
<a name="l03173"></a>03173 <span class="preprocessor"></span>}
<a name="l03174"></a>03174 
<a name="l03183"></a>03183 <span class="keywordtype">int</span>
<a name="l03184"></a><a class="code" href="group__DBusSysdeps.html#gaffaf8b5bb832c20a8ccb10f012920776">03184</a> <a class="code" href="group__DBusSysdeps.html#gaffaf8b5bb832c20a8ccb10f012920776" title="Measure the length of the given format string and arguments, not including the terminating nul...">_dbus_printf_string_upper_bound</a> (<span class="keyword">const</span> <span class="keywordtype">char</span> *format,
<a name="l03185"></a>03185                                  va_list     args)
<a name="l03186"></a>03186 {
<a name="l03187"></a>03187   <span class="keywordtype">char</span> static_buf[1024];
<a name="l03188"></a>03188   <span class="keywordtype">int</span> bufsize = <span class="keyword">sizeof</span> (static_buf);
<a name="l03189"></a>03189   <span class="keywordtype">int</span> len;
<a name="l03190"></a>03190   va_list args_copy;
<a name="l03191"></a>03191 
<a name="l03192"></a>03192   DBUS_VA_COPY (args_copy, args);
<a name="l03193"></a>03193   len = vsnprintf (static_buf, bufsize, format, args_copy);
<a name="l03194"></a>03194   va_end (args_copy);
<a name="l03195"></a>03195 
<a name="l03196"></a>03196   <span class="comment">/* If vsnprintf() returned non-negative, then either the string fits in</span>
<a name="l03197"></a>03197 <span class="comment">   * static_buf, or this OS has the POSIX and C99 behaviour where vsnprintf</span>
<a name="l03198"></a>03198 <span class="comment">   * returns the number of characters that were needed, or this OS returns the</span>
<a name="l03199"></a>03199 <span class="comment">   * truncated length.</span>
<a name="l03200"></a>03200 <span class="comment">   *</span>
<a name="l03201"></a>03201 <span class="comment">   * We ignore the possibility that snprintf might just ignore the length and</span>
<a name="l03202"></a>03202 <span class="comment">   * overrun the buffer (64-bit Solaris 7), because that&#39;s pathological.</span>
<a name="l03203"></a>03203 <span class="comment">   * If your libc is really that bad, come back when you have a better one. */</span>
<a name="l03204"></a>03204   <span class="keywordflow">if</span> (len == bufsize)
<a name="l03205"></a>03205     {
<a name="l03206"></a>03206       <span class="comment">/* This could be the truncated length (Tru64 and IRIX have this bug),</span>
<a name="l03207"></a>03207 <span class="comment">       * or the real length could be coincidentally the same. Which is it?</span>
<a name="l03208"></a>03208 <span class="comment">       * If vsnprintf returns the truncated length, we&#39;ll go to the slow</span>
<a name="l03209"></a>03209 <span class="comment">       * path. */</span>
<a name="l03210"></a>03210       DBUS_VA_COPY (args_copy, args);
<a name="l03211"></a>03211 
<a name="l03212"></a>03212       <span class="keywordflow">if</span> (vsnprintf (static_buf, 1, format, args_copy) == 1)
<a name="l03213"></a>03213         len = -1;
<a name="l03214"></a>03214 
<a name="l03215"></a>03215       va_end (args_copy);
<a name="l03216"></a>03216     }
<a name="l03217"></a>03217 
<a name="l03218"></a>03218   <span class="comment">/* If vsnprintf() returned negative, we have to do more work.</span>
<a name="l03219"></a>03219 <span class="comment">   * HP-UX returns negative. */</span>
<a name="l03220"></a>03220   <span class="keywordflow">while</span> (len &lt; 0)
<a name="l03221"></a>03221     {
<a name="l03222"></a>03222       <span class="keywordtype">char</span> *buf;
<a name="l03223"></a>03223 
<a name="l03224"></a>03224       bufsize *= 2;
<a name="l03225"></a>03225 
<a name="l03226"></a>03226       buf = <a class="code" href="group__DBusMemory.html#gaf6e588659067a854c3cca7ebe8ae5084" title="Allocates the given number of bytes, as with standard malloc().">dbus_malloc</a> (bufsize);
<a name="l03227"></a>03227 
<a name="l03228"></a>03228       <span class="keywordflow">if</span> (buf == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l03229"></a>03229         <span class="keywordflow">return</span> -1;
<a name="l03230"></a>03230 
<a name="l03231"></a>03231       DBUS_VA_COPY (args_copy, args);
<a name="l03232"></a>03232       len = vsnprintf (buf, bufsize, format, args_copy);
<a name="l03233"></a>03233       va_end (args_copy);
<a name="l03234"></a>03234 
<a name="l03235"></a>03235       <a class="code" href="group__DBusMemory.html#ga34e666b19b015035a9a31e53da84b39a" title="Frees a block of memory previously allocated by dbus_malloc() or dbus_malloc0().">dbus_free</a> (buf);
<a name="l03236"></a>03236 
<a name="l03237"></a>03237       <span class="comment">/* If the reported length is exactly the buffer size, round up to the</span>
<a name="l03238"></a>03238 <span class="comment">       * next size, in case vsnprintf has been returning the truncated</span>
<a name="l03239"></a>03239 <span class="comment">       * length */</span>
<a name="l03240"></a>03240       <span class="keywordflow">if</span> (len == bufsize)
<a name="l03241"></a>03241         len = -1;
<a name="l03242"></a>03242     }
<a name="l03243"></a>03243 
<a name="l03244"></a>03244   <span class="keywordflow">return</span> len;
<a name="l03245"></a>03245 }
<a name="l03246"></a>03246 
<a name="l03253"></a>03253 <span class="keyword">const</span> <span class="keywordtype">char</span>*
<a name="l03254"></a><a class="code" href="group__DBusSysdeps.html#ga3ecdae905f2d9e95fd35891b20f06532">03254</a> <a class="code" href="group__DBusSysdeps.html#ga3ecdae905f2d9e95fd35891b20f06532" title="Gets the temporary files directory by inspecting the environment variables TMPDIR, TMP, and TEMP in that order.">_dbus_get_tmpdir</a>(<span class="keywordtype">void</span>)
<a name="l03255"></a>03255 {
<a name="l03256"></a>03256   <span class="comment">/* Protected by _DBUS_LOCK_sysdeps */</span>
<a name="l03257"></a>03257   <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* tmpdir = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l03258"></a>03258 
<a name="l03259"></a>03259   <span class="keywordflow">if</span> (!_DBUS_LOCK (sysdeps))
<a name="l03260"></a>03260     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l03261"></a>03261 
<a name="l03262"></a>03262   <span class="keywordflow">if</span> (tmpdir == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l03263"></a>03263     {
<a name="l03264"></a>03264       <span class="comment">/* TMPDIR is what glibc uses, then</span>
<a name="l03265"></a>03265 <span class="comment">       * glibc falls back to the P_tmpdir macro which</span>
<a name="l03266"></a>03266 <span class="comment">       * just expands to &quot;/tmp&quot;</span>
<a name="l03267"></a>03267 <span class="comment">       */</span>
<a name="l03268"></a>03268       <span class="keywordflow">if</span> (tmpdir == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l03269"></a>03269         tmpdir = getenv(<span class="stringliteral">&quot;TMPDIR&quot;</span>);
<a name="l03270"></a>03270 
<a name="l03271"></a>03271       <span class="comment">/* These two env variables are probably</span>
<a name="l03272"></a>03272 <span class="comment">       * broken, but maybe some OS uses them?</span>
<a name="l03273"></a>03273 <span class="comment">       */</span>
<a name="l03274"></a>03274       <span class="keywordflow">if</span> (tmpdir == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l03275"></a>03275         tmpdir = getenv(<span class="stringliteral">&quot;TMP&quot;</span>);
<a name="l03276"></a>03276       <span class="keywordflow">if</span> (tmpdir == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l03277"></a>03277         tmpdir = getenv(<span class="stringliteral">&quot;TEMP&quot;</span>);
<a name="l03278"></a>03278 
<a name="l03279"></a>03279       <span class="comment">/* And this is the sane fallback. */</span>
<a name="l03280"></a>03280       <span class="keywordflow">if</span> (tmpdir == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l03281"></a>03281         tmpdir = <span class="stringliteral">&quot;/tmp&quot;</span>;
<a name="l03282"></a>03282     }
<a name="l03283"></a>03283 
<a name="l03284"></a>03284   _DBUS_UNLOCK (sysdeps);
<a name="l03285"></a>03285 
<a name="l03286"></a>03286   _dbus_assert(tmpdir != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l03287"></a>03287 
<a name="l03288"></a>03288   <span class="keywordflow">return</span> tmpdir;
<a name="l03289"></a>03289 }
<a name="l03290"></a>03290 
<a name="l03291"></a>03291 <span class="preprocessor">#if defined(DBUS_ENABLE_X11_AUTOLAUNCH) || defined(DBUS_ENABLE_LAUNCHD)</span>
<a name="l03292"></a>03292 <span class="preprocessor"></span>
<a name="l03311"></a>03311 <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l03312"></a>03312 _read_subprocess_line_argv (<span class="keyword">const</span> <span class="keywordtype">char</span> *progpath,
<a name="l03313"></a>03313                             <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> path_fallback,
<a name="l03314"></a>03314                             <span class="keywordtype">char</span>       * <span class="keyword">const</span> *argv,
<a name="l03315"></a>03315                             <a class="code" href="structDBusString.html">DBusString</a> *result,
<a name="l03316"></a>03316                             <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>  *error)
<a name="l03317"></a>03317 {
<a name="l03318"></a>03318   <span class="keywordtype">int</span> result_pipe[2] = { -1, -1 };
<a name="l03319"></a>03319   <span class="keywordtype">int</span> errors_pipe[2] = { -1, -1 };
<a name="l03320"></a>03320   pid_t pid;
<a name="l03321"></a>03321   <span class="keywordtype">int</span> ret;
<a name="l03322"></a>03322   <span class="keywordtype">int</span> status;
<a name="l03323"></a>03323   <span class="keywordtype">int</span> orig_len;
<a name="l03324"></a>03324 
<a name="l03325"></a>03325   <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> retval;
<a name="l03326"></a>03326   sigset_t new_set, old_set;
<a name="l03327"></a>03327 
<a name="l03328"></a>03328   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l03329"></a>03329   retval = <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03330"></a>03330 
<a name="l03331"></a>03331   <span class="comment">/* We need to block any existing handlers for SIGCHLD temporarily; they</span>
<a name="l03332"></a>03332 <span class="comment">   * will cause waitpid() below to fail.</span>
<a name="l03333"></a>03333 <span class="comment">   * https://bugs.freedesktop.org/show_bug.cgi?id=21347</span>
<a name="l03334"></a>03334 <span class="comment">   */</span>
<a name="l03335"></a>03335   sigemptyset (&amp;new_set);
<a name="l03336"></a>03336   sigaddset (&amp;new_set, SIGCHLD);
<a name="l03337"></a>03337   sigprocmask (SIG_BLOCK, &amp;new_set, &amp;old_set);
<a name="l03338"></a>03338 
<a name="l03339"></a>03339   orig_len = <a class="code" href="group__DBusString.html#gaa5136e6fd2c5188f4b88de7863369c6d" title="Gets the length of a string (not including nul termination).">_dbus_string_get_length</a> (result);
<a name="l03340"></a>03340 
<a name="l03341"></a>03341 <span class="preprocessor">#define READ_END        0</span>
<a name="l03342"></a>03342 <span class="preprocessor"></span><span class="preprocessor">#define WRITE_END       1</span>
<a name="l03343"></a>03343 <span class="preprocessor"></span>  <span class="keywordflow">if</span> (pipe (result_pipe) &lt; 0)
<a name="l03344"></a>03344     {
<a name="l03345"></a>03345       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l03346"></a>03346                       <span class="stringliteral">&quot;Failed to create a pipe to call %s: %s&quot;</span>,
<a name="l03347"></a>03347                       progpath, _dbus_strerror (errno));
<a name="l03348"></a>03348       _dbus_verbose (<span class="stringliteral">&quot;Failed to create a pipe to call %s: %s\n&quot;</span>,
<a name="l03349"></a>03349                      progpath, _dbus_strerror (errno));
<a name="l03350"></a>03350       <span class="keywordflow">goto</span> out;
<a name="l03351"></a>03351     }
<a name="l03352"></a>03352   <span class="keywordflow">if</span> (pipe (errors_pipe) &lt; 0)
<a name="l03353"></a>03353     {
<a name="l03354"></a>03354       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l03355"></a>03355                       <span class="stringliteral">&quot;Failed to create a pipe to call %s: %s&quot;</span>,
<a name="l03356"></a>03356                       progpath, _dbus_strerror (errno));
<a name="l03357"></a>03357       _dbus_verbose (<span class="stringliteral">&quot;Failed to create a pipe to call %s: %s\n&quot;</span>,
<a name="l03358"></a>03358                      progpath, _dbus_strerror (errno));
<a name="l03359"></a>03359       <span class="keywordflow">goto</span> out;
<a name="l03360"></a>03360     }
<a name="l03361"></a>03361 
<a name="l03362"></a>03362   pid = fork ();
<a name="l03363"></a>03363   <span class="keywordflow">if</span> (pid &lt; 0)
<a name="l03364"></a>03364     {
<a name="l03365"></a>03365       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l03366"></a>03366                       <span class="stringliteral">&quot;Failed to fork() to call %s: %s&quot;</span>,
<a name="l03367"></a>03367                       progpath, _dbus_strerror (errno));
<a name="l03368"></a>03368       _dbus_verbose (<span class="stringliteral">&quot;Failed to fork() to call %s: %s\n&quot;</span>,
<a name="l03369"></a>03369                      progpath, _dbus_strerror (errno));
<a name="l03370"></a>03370       <span class="keywordflow">goto</span> out;
<a name="l03371"></a>03371     }
<a name="l03372"></a>03372 
<a name="l03373"></a>03373   <span class="keywordflow">if</span> (pid == 0)
<a name="l03374"></a>03374     {
<a name="l03375"></a>03375       <span class="comment">/* child process */</span>
<a name="l03376"></a>03376       <span class="keywordtype">int</span> fd;
<a name="l03377"></a>03377 
<a name="l03378"></a>03378       fd = open (<span class="stringliteral">&quot;/dev/null&quot;</span>, O_RDWR);
<a name="l03379"></a>03379       <span class="keywordflow">if</span> (fd == -1)
<a name="l03380"></a>03380         <span class="comment">/* huh?! can&#39;t open /dev/null? */</span>
<a name="l03381"></a>03381         _exit (1);
<a name="l03382"></a>03382 
<a name="l03383"></a>03383       _dbus_verbose (<span class="stringliteral">&quot;/dev/null fd %d opened\n&quot;</span>, fd);
<a name="l03384"></a>03384 
<a name="l03385"></a>03385       <span class="comment">/* set-up stdXXX */</span>
<a name="l03386"></a>03386       close (result_pipe[<a class="code" href="group__DBusInternalsUtils.html#ga2469c53816dc077f9deefb187ffcabf3" title="Helps remember which end of the pipe is which.">READ_END</a>]);
<a name="l03387"></a>03387       close (errors_pipe[<a class="code" href="group__DBusInternalsUtils.html#ga2469c53816dc077f9deefb187ffcabf3" title="Helps remember which end of the pipe is which.">READ_END</a>]);
<a name="l03388"></a>03388 
<a name="l03389"></a>03389       <span class="keywordflow">if</span> (dup2 (fd, 0) == -1) <span class="comment">/* setup stdin */</span>
<a name="l03390"></a>03390         _exit (1);
<a name="l03391"></a>03391       <span class="keywordflow">if</span> (dup2 (result_pipe[<a class="code" href="group__DBusInternalsUtils.html#ga2efd706d915e621e5e18b3f0803c4ed2" title="Helps remember which end of the pipe is which.">WRITE_END</a>], 1) == -1) <span class="comment">/* setup stdout */</span>
<a name="l03392"></a>03392         _exit (1);
<a name="l03393"></a>03393       <span class="keywordflow">if</span> (dup2 (errors_pipe[WRITE_END], 2) == -1) <span class="comment">/* setup stderr */</span>
<a name="l03394"></a>03394         _exit (1);
<a name="l03395"></a>03395 
<a name="l03396"></a>03396       <a class="code" href="group__DBusSysdepsUnix.html#gae63f6bdc70a1dd5c9ba0a6a1be57e320" title="Closes all file descriptors except the first three (i.e.">_dbus_close_all</a> ();
<a name="l03397"></a>03397 
<a name="l03398"></a>03398       sigprocmask (SIG_SETMASK, &amp;old_set, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l03399"></a>03399 
<a name="l03400"></a>03400       <span class="comment">/* If it looks fully-qualified, try execv first */</span>
<a name="l03401"></a>03401       <span class="keywordflow">if</span> (progpath[0] == <span class="charliteral">&#39;/&#39;</span>)
<a name="l03402"></a>03402         {
<a name="l03403"></a>03403           execv (progpath, argv);
<a name="l03404"></a>03404           <span class="comment">/* Ok, that failed.  Now if path_fallback is given, let&#39;s</span>
<a name="l03405"></a>03405 <span class="comment">           * try unqualified.  This is mostly a hack to work</span>
<a name="l03406"></a>03406 <span class="comment">           * around systems which ship dbus-launch in /usr/bin</span>
<a name="l03407"></a>03407 <span class="comment">           * but everything else in /bin (because dbus-launch</span>
<a name="l03408"></a>03408 <span class="comment">           * depends on X11).</span>
<a name="l03409"></a>03409 <span class="comment">           */</span>
<a name="l03410"></a>03410           <span class="keywordflow">if</span> (path_fallback)
<a name="l03411"></a>03411             <span class="comment">/* We must have a slash, because we checked above */</span>
<a name="l03412"></a>03412             execvp (strrchr (progpath, <span class="charliteral">&#39;/&#39;</span>)+1, argv);
<a name="l03413"></a>03413         }
<a name="l03414"></a>03414       <span class="keywordflow">else</span>
<a name="l03415"></a>03415         execvp (progpath, argv);
<a name="l03416"></a>03416 
<a name="l03417"></a>03417       <span class="comment">/* still nothing, we failed */</span>
<a name="l03418"></a>03418       _exit (1);
<a name="l03419"></a>03419     }
<a name="l03420"></a>03420 
<a name="l03421"></a>03421   <span class="comment">/* parent process */</span>
<a name="l03422"></a>03422   close (result_pipe[WRITE_END]);
<a name="l03423"></a>03423   close (errors_pipe[WRITE_END]);
<a name="l03424"></a>03424   result_pipe[<a class="code" href="group__DBusInternalsUtils.html#ga2efd706d915e621e5e18b3f0803c4ed2" title="Helps remember which end of the pipe is which.">WRITE_END</a>] = -1;
<a name="l03425"></a>03425   errors_pipe[<a class="code" href="group__DBusInternalsUtils.html#ga2efd706d915e621e5e18b3f0803c4ed2" title="Helps remember which end of the pipe is which.">WRITE_END</a>] = -1;
<a name="l03426"></a>03426 
<a name="l03427"></a>03427   ret = 0;
<a name="l03428"></a>03428   <span class="keywordflow">do</span>
<a name="l03429"></a>03429     {
<a name="l03430"></a>03430       ret = <a class="code" href="group__DBusSysdepsUnix.html#gaf52cb1d5b9fc5611808ce32eff898c28" title="Thin wrapper around the read() system call that appends the data it reads to the DBusString buffer...">_dbus_read</a> (result_pipe[<a class="code" href="group__DBusInternalsUtils.html#ga2469c53816dc077f9deefb187ffcabf3" title="Helps remember which end of the pipe is which.">READ_END</a>], result, 1024);
<a name="l03431"></a>03431     }
<a name="l03432"></a>03432   <span class="keywordflow">while</span> (ret &gt; 0);
<a name="l03433"></a>03433 
<a name="l03434"></a>03434   <span class="comment">/* reap the child process to avoid it lingering as zombie */</span>
<a name="l03435"></a>03435   <span class="keywordflow">do</span>
<a name="l03436"></a>03436     {
<a name="l03437"></a>03437       ret = waitpid (pid, &amp;status, 0);
<a name="l03438"></a>03438     }
<a name="l03439"></a>03439   <span class="keywordflow">while</span> (ret == -1 &amp;&amp; errno == EINTR);
<a name="l03440"></a>03440 
<a name="l03441"></a>03441   <span class="comment">/* We succeeded if the process exited with status 0 and</span>
<a name="l03442"></a>03442 <span class="comment">     anything was read */</span>
<a name="l03443"></a>03443   <span class="keywordflow">if</span> (!WIFEXITED (status) || WEXITSTATUS (status) != 0 )
<a name="l03444"></a>03444     {
<a name="l03445"></a>03445       <span class="comment">/* The process ended with error */</span>
<a name="l03446"></a>03446       <a class="code" href="structDBusString.html">DBusString</a> error_message;
<a name="l03447"></a>03447       <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga348252317f7bb8ac43529972945830ae" title="Initializes a string.">_dbus_string_init</a> (&amp;error_message))
<a name="l03448"></a>03448         {
<a name="l03449"></a>03449           _DBUS_SET_OOM (error);
<a name="l03450"></a>03450           <span class="keywordflow">goto</span> out;
<a name="l03451"></a>03451         }
<a name="l03452"></a>03452 
<a name="l03453"></a>03453       ret = 0;
<a name="l03454"></a>03454       <span class="keywordflow">do</span>
<a name="l03455"></a>03455         {
<a name="l03456"></a>03456           ret = <a class="code" href="group__DBusSysdepsUnix.html#gaf52cb1d5b9fc5611808ce32eff898c28" title="Thin wrapper around the read() system call that appends the data it reads to the DBusString buffer...">_dbus_read</a> (errors_pipe[<a class="code" href="group__DBusInternalsUtils.html#ga2469c53816dc077f9deefb187ffcabf3" title="Helps remember which end of the pipe is which.">READ_END</a>], &amp;error_message, 1024);
<a name="l03457"></a>03457         }
<a name="l03458"></a>03458       <span class="keywordflow">while</span> (ret &gt; 0);
<a name="l03459"></a>03459 
<a name="l03460"></a>03460       <a class="code" href="group__DBusString.html#ga08c423b93c28dd746dcb93e0461ab95c" title="Sets the length of a string.">_dbus_string_set_length</a> (result, orig_len);
<a name="l03461"></a>03461       <span class="keywordflow">if</span> (<a class="code" href="group__DBusString.html#gaa5136e6fd2c5188f4b88de7863369c6d" title="Gets the length of a string (not including nul termination).">_dbus_string_get_length</a> (&amp;error_message) &gt; 0)
<a name="l03462"></a>03462         <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gac04bc3bebee1674e93ef96aaa2b34b40" title="While starting a new process, the exec() call failed.">DBUS_ERROR_SPAWN_EXEC_FAILED</a>,
<a name="l03463"></a>03463                         <span class="stringliteral">&quot;%s terminated abnormally with the following error: %s&quot;</span>,
<a name="l03464"></a>03464                         progpath, <a class="code" href="group__DBusString.html#gaa9b5aa08d313048df72aa12bb4dc0cda" title="Gets the raw character buffer from the string.">_dbus_string_get_data</a> (&amp;error_message));
<a name="l03465"></a>03465       <span class="keywordflow">else</span>
<a name="l03466"></a>03466         <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gac04bc3bebee1674e93ef96aaa2b34b40" title="While starting a new process, the exec() call failed.">DBUS_ERROR_SPAWN_EXEC_FAILED</a>,
<a name="l03467"></a>03467                         <span class="stringliteral">&quot;%s terminated abnormally without any error message&quot;</span>,
<a name="l03468"></a>03468                         progpath);
<a name="l03469"></a>03469       <span class="keywordflow">goto</span> out;
<a name="l03470"></a>03470     }
<a name="l03471"></a>03471 
<a name="l03472"></a>03472   retval = <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l03473"></a>03473 
<a name="l03474"></a>03474  out:
<a name="l03475"></a>03475   sigprocmask (SIG_SETMASK, &amp;old_set, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l03476"></a>03476 
<a name="l03477"></a>03477   <span class="keywordflow">if</span> (retval)
<a name="l03478"></a>03478     _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l03479"></a>03479   <span class="keywordflow">else</span>
<a name="l03480"></a>03480     _DBUS_ASSERT_ERROR_IS_SET (error);
<a name="l03481"></a>03481 
<a name="l03482"></a>03482   <span class="keywordflow">if</span> (result_pipe[0] != -1)
<a name="l03483"></a>03483     close (result_pipe[0]);
<a name="l03484"></a>03484   <span class="keywordflow">if</span> (result_pipe[1] != -1)
<a name="l03485"></a>03485     close (result_pipe[1]);
<a name="l03486"></a>03486   <span class="keywordflow">if</span> (errors_pipe[0] != -1)
<a name="l03487"></a>03487     close (errors_pipe[0]);
<a name="l03488"></a>03488   <span class="keywordflow">if</span> (errors_pipe[1] != -1)
<a name="l03489"></a>03489     close (errors_pipe[1]);
<a name="l03490"></a>03490 
<a name="l03491"></a>03491   <span class="keywordflow">return</span> retval;
<a name="l03492"></a>03492 }
<a name="l03493"></a>03493 <span class="preprocessor">#endif</span>
<a name="l03494"></a>03494 <span class="preprocessor"></span>
<a name="l03507"></a>03507 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l03508"></a><a class="code" href="group__DBusSysdeps.html#gabc4712c0db91f11854cdd933027355af">03508</a> <a class="code" href="group__DBusSysdeps.html#gabc4712c0db91f11854cdd933027355af" title="Returns the address of a new session bus.">_dbus_get_autolaunch_address</a> (<span class="keyword">const</span> <span class="keywordtype">char</span> *scope,
<a name="l03509"></a>03509                               <a class="code" href="structDBusString.html">DBusString</a> *address,
<a name="l03510"></a>03510                               <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>  *error)
<a name="l03511"></a>03511 {
<a name="l03512"></a>03512 <span class="preprocessor">#ifdef DBUS_ENABLE_X11_AUTOLAUNCH</span>
<a name="l03513"></a>03513 <span class="preprocessor"></span>  <span class="comment">/* Perform X11-based autolaunch. (We also support launchd-based autolaunch,</span>
<a name="l03514"></a>03514 <span class="comment">   * but that&#39;s done elsewhere, and if it worked, this function wouldn&#39;t</span>
<a name="l03515"></a>03515 <span class="comment">   * be called.) */</span>
<a name="l03516"></a>03516   <span class="keyword">const</span> <span class="keywordtype">char</span> *display;
<a name="l03517"></a>03517   <span class="keywordtype">char</span> *argv[6];
<a name="l03518"></a>03518   <span class="keywordtype">int</span> i;
<a name="l03519"></a>03519   <a class="code" href="structDBusString.html">DBusString</a> uuid;
<a name="l03520"></a>03520   <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> retval;
<a name="l03521"></a>03521 
<a name="l03522"></a>03522   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l03523"></a>03523   retval = <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03524"></a>03524 
<a name="l03525"></a>03525   <span class="comment">/* fd.o #19997: if $DISPLAY isn&#39;t set to something useful, then</span>
<a name="l03526"></a>03526 <span class="comment">   * dbus-launch-x11 is just going to fail. Rather than trying to</span>
<a name="l03527"></a>03527 <span class="comment">   * run it, we might as well bail out early with a nice error. */</span>
<a name="l03528"></a>03528   display = <a class="code" href="group__DBusSysdeps.html#gab846071a4de54cb7e518654f9375313a" title="Wrapper for getenv().">_dbus_getenv</a> (<span class="stringliteral">&quot;DISPLAY&quot;</span>);
<a name="l03529"></a>03529 
<a name="l03530"></a>03530   <span class="keywordflow">if</span> (display == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a> || display[0] == <span class="charliteral">&#39;\0&#39;</span>)
<a name="l03531"></a>03531     {
<a name="l03532"></a>03532       <a class="code" href="group__DBusErrors.html#ga3cc15cc37bcd3aaca87aa4d791c124f5" title="Assigns an error name and message to a DBusError.">dbus_set_error_const</a> (error, <a class="code" href="group__DBusProtocol.html#ga33122bcaf8f5896ec222c755b6effb40" title="Requested operation isn&#39;t supported (like ENOSYS on UNIX).">DBUS_ERROR_NOT_SUPPORTED</a>,
<a name="l03533"></a>03533           <span class="stringliteral">&quot;Unable to autolaunch a dbus-daemon without a $DISPLAY for X11&quot;</span>);
<a name="l03534"></a>03534       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03535"></a>03535     }
<a name="l03536"></a>03536 
<a name="l03537"></a>03537   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga348252317f7bb8ac43529972945830ae" title="Initializes a string.">_dbus_string_init</a> (&amp;uuid))
<a name="l03538"></a>03538     {
<a name="l03539"></a>03539       _DBUS_SET_OOM (error);
<a name="l03540"></a>03540       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03541"></a>03541     }
<a name="l03542"></a>03542 
<a name="l03543"></a>03543   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusInternalsUtils.html#ga49ba67405d677af6cde9329ed87ea91f" title="Gets the hex-encoded UUID of the machine this function is executed on.">_dbus_get_local_machine_uuid_encoded</a> (&amp;uuid))
<a name="l03544"></a>03544     {
<a name="l03545"></a>03545       _DBUS_SET_OOM (error);
<a name="l03546"></a>03546       <span class="keywordflow">goto</span> out;
<a name="l03547"></a>03547     }
<a name="l03548"></a>03548 
<a name="l03549"></a>03549   i = 0;
<a name="l03550"></a>03550 <span class="preprocessor">#ifdef DBUS_ENABLE_EMBEDDED_TESTS</span>
<a name="l03551"></a>03551 <span class="preprocessor"></span>  <span class="keywordflow">if</span> (<a class="code" href="group__DBusSysdeps.html#gab846071a4de54cb7e518654f9375313a" title="Wrapper for getenv().">_dbus_getenv</a> (<span class="stringliteral">&quot;DBUS_USE_TEST_BINARY&quot;</span>) != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l03552"></a>03552     argv[i] = TEST_BUS_LAUNCH_BINARY;
<a name="l03553"></a>03553   <span class="keywordflow">else</span>
<a name="l03554"></a>03554 <span class="preprocessor">#endif</span>
<a name="l03555"></a>03555 <span class="preprocessor"></span>    argv[i] = DBUS_BINDIR <span class="stringliteral">&quot;/dbus-launch&quot;</span>;
<a name="l03556"></a>03556   ++i;
<a name="l03557"></a>03557   argv[i] = <span class="stringliteral">&quot;--autolaunch&quot;</span>;
<a name="l03558"></a>03558   ++i;
<a name="l03559"></a>03559   argv[i] = <a class="code" href="group__DBusString.html#gaa9b5aa08d313048df72aa12bb4dc0cda" title="Gets the raw character buffer from the string.">_dbus_string_get_data</a> (&amp;uuid);
<a name="l03560"></a>03560   ++i;
<a name="l03561"></a>03561   argv[i] = <span class="stringliteral">&quot;--binary-syntax&quot;</span>;
<a name="l03562"></a>03562   ++i;
<a name="l03563"></a>03563   argv[i] = <span class="stringliteral">&quot;--close-stderr&quot;</span>;
<a name="l03564"></a>03564   ++i;
<a name="l03565"></a>03565   argv[i] = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l03566"></a>03566   ++i;
<a name="l03567"></a>03567 
<a name="l03568"></a>03568   _dbus_assert (i == _DBUS_N_ELEMENTS (argv));
<a name="l03569"></a>03569 
<a name="l03570"></a>03570   retval = _read_subprocess_line_argv (argv[0],
<a name="l03571"></a>03571                                        <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>,
<a name="l03572"></a>03572                                        argv, address, error);
<a name="l03573"></a>03573 
<a name="l03574"></a>03574  out:
<a name="l03575"></a>03575   <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a> (&amp;uuid);
<a name="l03576"></a>03576   <span class="keywordflow">return</span> retval;
<a name="l03577"></a>03577 <span class="preprocessor">#else</span>
<a name="l03578"></a>03578 <span class="preprocessor"></span>  <a class="code" href="group__DBusErrors.html#ga3cc15cc37bcd3aaca87aa4d791c124f5" title="Assigns an error name and message to a DBusError.">dbus_set_error_const</a> (error, <a class="code" href="group__DBusProtocol.html#ga33122bcaf8f5896ec222c755b6effb40" title="Requested operation isn&#39;t supported (like ENOSYS on UNIX).">DBUS_ERROR_NOT_SUPPORTED</a>,
<a name="l03579"></a>03579       <span class="stringliteral">&quot;Using X11 for dbus-daemon autolaunch was disabled at compile time, &quot;</span>
<a name="l03580"></a>03580       <span class="stringliteral">&quot;set your DBUS_SESSION_BUS_ADDRESS instead&quot;</span>);
<a name="l03581"></a>03581   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03582"></a>03582 <span class="preprocessor">#endif</span>
<a name="l03583"></a>03583 <span class="preprocessor"></span>}
<a name="l03584"></a>03584 
<a name="l03603"></a>03603 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l03604"></a><a class="code" href="group__DBusSysdeps.html#ga3f073afc8ef8397471531baf513e1bb5">03604</a> <a class="code" href="group__DBusSysdeps.html#ga3f073afc8ef8397471531baf513e1bb5" title="Reads the uuid of the machine we&#39;re running on from the dbus configuration.">_dbus_read_local_machine_uuid</a> (<a class="code" href="group__DBusSysdeps.html#ga24015a2f75b94c1307360755ce97f869" title="Type representing a universally unique ID.">DBusGUID</a>   *machine_id,
<a name="l03605"></a>03605                                <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> create_if_not_found,
<a name="l03606"></a>03606                                <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>  *error)
<a name="l03607"></a>03607 {
<a name="l03608"></a>03608   <a class="code" href="structDBusString.html">DBusString</a> filename;
<a name="l03609"></a>03609   <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> b;
<a name="l03610"></a>03610 
<a name="l03611"></a>03611   <a class="code" href="group__DBusString.html#ga374640ddfa2f0b27a8356e2379ba8043" title="Initializes a constant string.">_dbus_string_init_const</a> (&amp;filename, DBUS_MACHINE_UUID_FILE);
<a name="l03612"></a>03612 
<a name="l03613"></a>03613   b = <a class="code" href="group__DBusInternalsUtils.html#ga709fd30e6b940a5952af38efaf24ad51" title="Reads (and optionally writes) a uuid to a file.">_dbus_read_uuid_file</a> (&amp;filename, machine_id, <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>, error);
<a name="l03614"></a>03614   <span class="keywordflow">if</span> (b)
<a name="l03615"></a>03615     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l03616"></a>03616 
<a name="l03617"></a>03617   <a class="code" href="group__DBusErrors.html#gaac6c14ead14829ee4e090f39de6a7568" title="Frees an error that&#39;s been set (or just initialized), then reinitializes the error as in dbus_error_i...">dbus_error_free</a> (error);
<a name="l03618"></a>03618 
<a name="l03619"></a>03619   <span class="comment">/* Fallback to the system machine ID */</span>
<a name="l03620"></a>03620   <a class="code" href="group__DBusString.html#ga374640ddfa2f0b27a8356e2379ba8043" title="Initializes a constant string.">_dbus_string_init_const</a> (&amp;filename, <span class="stringliteral">&quot;/etc/machine-id&quot;</span>);
<a name="l03621"></a>03621   b = <a class="code" href="group__DBusInternalsUtils.html#ga709fd30e6b940a5952af38efaf24ad51" title="Reads (and optionally writes) a uuid to a file.">_dbus_read_uuid_file</a> (&amp;filename, machine_id, <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>, error);
<a name="l03622"></a>03622 
<a name="l03623"></a>03623   <span class="keywordflow">if</span> (b)
<a name="l03624"></a>03624     {
<a name="l03625"></a>03625       <span class="comment">/* try to copy it to the DBUS_MACHINE_UUID_FILE, but do not</span>
<a name="l03626"></a>03626 <span class="comment">       * complain if that isn&#39;t possible for whatever reason */</span>
<a name="l03627"></a>03627       <a class="code" href="group__DBusString.html#ga374640ddfa2f0b27a8356e2379ba8043" title="Initializes a constant string.">_dbus_string_init_const</a> (&amp;filename, DBUS_MACHINE_UUID_FILE);
<a name="l03628"></a>03628       <a class="code" href="group__DBusInternalsUtils.html#gaa16de06b33c56323fa33dd96eaab3829" title="Write the give UUID to a file.">_dbus_write_uuid_file</a> (&amp;filename, machine_id, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l03629"></a>03629 
<a name="l03630"></a>03630       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l03631"></a>03631     }
<a name="l03632"></a>03632 
<a name="l03633"></a>03633   <span class="keywordflow">if</span> (!create_if_not_found)
<a name="l03634"></a>03634     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03635"></a>03635 
<a name="l03636"></a>03636   <span class="comment">/* if none found, try to make a new one */</span>
<a name="l03637"></a>03637   <a class="code" href="group__DBusErrors.html#gaac6c14ead14829ee4e090f39de6a7568" title="Frees an error that&#39;s been set (or just initialized), then reinitializes the error as in dbus_error_i...">dbus_error_free</a> (error);
<a name="l03638"></a>03638   <a class="code" href="group__DBusString.html#ga374640ddfa2f0b27a8356e2379ba8043" title="Initializes a constant string.">_dbus_string_init_const</a> (&amp;filename, DBUS_MACHINE_UUID_FILE);
<a name="l03639"></a>03639   <a class="code" href="group__DBusInternalsUtils.html#ga08c2922335845e5c857e88399436b9ba" title="Generates a new UUID.">_dbus_generate_uuid</a> (machine_id);
<a name="l03640"></a>03640   <span class="keywordflow">return</span> <a class="code" href="group__DBusInternalsUtils.html#gaa16de06b33c56323fa33dd96eaab3829" title="Write the give UUID to a file.">_dbus_write_uuid_file</a> (&amp;filename, machine_id, error);
<a name="l03641"></a>03641 }
<a name="l03642"></a>03642 
<a name="l03650"></a>03650 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l03651"></a><a class="code" href="group__DBusSysdepsUnix.html#ga6425e8cf4a38c71a48309b436322d4db">03651</a> <a class="code" href="group__DBusSysdepsUnix.html#ga6425e8cf4a38c71a48309b436322d4db" title="quries launchd for a specific env var which holds the socket path.">_dbus_lookup_launchd_socket</a> (<a class="code" href="structDBusString.html">DBusString</a> *socket_path,
<a name="l03652"></a>03652                              <span class="keyword">const</span> <span class="keywordtype">char</span> *launchd_env_var,
<a name="l03653"></a>03653                              <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>  *error)
<a name="l03654"></a>03654 {
<a name="l03655"></a>03655 <span class="preprocessor">#ifdef DBUS_ENABLE_LAUNCHD</span>
<a name="l03656"></a>03656 <span class="preprocessor"></span>  <span class="keywordtype">char</span> *argv[4];
<a name="l03657"></a>03657   <span class="keywordtype">int</span> i;
<a name="l03658"></a>03658 
<a name="l03659"></a>03659   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l03660"></a>03660 
<a name="l03661"></a>03661   i = 0;
<a name="l03662"></a>03662   argv[i] = <span class="stringliteral">&quot;launchctl&quot;</span>;
<a name="l03663"></a>03663   ++i;
<a name="l03664"></a>03664   argv[i] = <span class="stringliteral">&quot;getenv&quot;</span>;
<a name="l03665"></a>03665   ++i;
<a name="l03666"></a>03666   argv[i] = (<span class="keywordtype">char</span>*)launchd_env_var;
<a name="l03667"></a>03667   ++i;
<a name="l03668"></a>03668   argv[i] = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l03669"></a>03669   ++i;
<a name="l03670"></a>03670 
<a name="l03671"></a>03671   _dbus_assert (i == _DBUS_N_ELEMENTS (argv));
<a name="l03672"></a>03672 
<a name="l03673"></a>03673   <span class="keywordflow">if</span> (!_read_subprocess_line_argv(argv[0], <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>, argv, socket_path, error))
<a name="l03674"></a>03674     {
<a name="l03675"></a>03675       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03676"></a>03676     }
<a name="l03677"></a>03677 
<a name="l03678"></a>03678   <span class="comment">/* no error, but no result either */</span>
<a name="l03679"></a>03679   <span class="keywordflow">if</span> (<a class="code" href="group__DBusString.html#gaa5136e6fd2c5188f4b88de7863369c6d" title="Gets the length of a string (not including nul termination).">_dbus_string_get_length</a>(socket_path) == 0)
<a name="l03680"></a>03680     {
<a name="l03681"></a>03681       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03682"></a>03682     }
<a name="l03683"></a>03683 
<a name="l03684"></a>03684   <span class="comment">/* strip the carriage-return */</span>
<a name="l03685"></a>03685   <a class="code" href="group__DBusString.html#ga7af1cbfa905f26d972ab644d890548b8" title="Makes a string shorter by the given number of bytes.">_dbus_string_shorten</a>(socket_path, 1);
<a name="l03686"></a>03686   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l03687"></a>03687 <span class="preprocessor">#else </span><span class="comment">/* DBUS_ENABLE_LAUNCHD */</span>
<a name="l03688"></a>03688   <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a>(error, <a class="code" href="group__DBusProtocol.html#ga33122bcaf8f5896ec222c755b6effb40" title="Requested operation isn&#39;t supported (like ENOSYS on UNIX).">DBUS_ERROR_NOT_SUPPORTED</a>,
<a name="l03689"></a>03689                 <span class="stringliteral">&quot;can&#39;t lookup socket from launchd; launchd support not compiled in&quot;</span>);
<a name="l03690"></a>03690   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03691"></a>03691 <span class="preprocessor">#endif</span>
<a name="l03692"></a>03692 <span class="preprocessor"></span>}
<a name="l03693"></a>03693 
<a name="l03694"></a>03694 <span class="preprocessor">#ifdef DBUS_ENABLE_LAUNCHD</span>
<a name="l03695"></a>03695 <span class="preprocessor"></span><span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l03696"></a>03696 _dbus_lookup_session_address_launchd (<a class="code" href="structDBusString.html">DBusString</a> *address, <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>  *error)
<a name="l03697"></a>03697 {
<a name="l03698"></a>03698   <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> valid_socket;
<a name="l03699"></a>03699   <a class="code" href="structDBusString.html">DBusString</a> socket_path;
<a name="l03700"></a>03700 
<a name="l03701"></a>03701   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga348252317f7bb8ac43529972945830ae" title="Initializes a string.">_dbus_string_init</a> (&amp;socket_path))
<a name="l03702"></a>03702     {
<a name="l03703"></a>03703       _DBUS_SET_OOM (error);
<a name="l03704"></a>03704       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03705"></a>03705     }
<a name="l03706"></a>03706 
<a name="l03707"></a>03707   valid_socket = <a class="code" href="group__DBusSysdepsUnix.html#ga6425e8cf4a38c71a48309b436322d4db" title="quries launchd for a specific env var which holds the socket path.">_dbus_lookup_launchd_socket</a> (&amp;socket_path, <span class="stringliteral">&quot;DBUS_LAUNCHD_SESSION_BUS_SOCKET&quot;</span>, error);
<a name="l03708"></a>03708 
<a name="l03709"></a>03709   <span class="keywordflow">if</span> (<a class="code" href="group__DBusErrors.html#gab0ed62e9fc2685897eb2d41467c89405" title="Checks whether an error occurred (the error is set).">dbus_error_is_set</a>(error))
<a name="l03710"></a>03710     {
<a name="l03711"></a>03711       <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a>(&amp;socket_path);
<a name="l03712"></a>03712       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03713"></a>03713     }
<a name="l03714"></a>03714 
<a name="l03715"></a>03715   <span class="keywordflow">if</span> (!valid_socket)
<a name="l03716"></a>03716     {
<a name="l03717"></a>03717       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a>(error, <span class="stringliteral">&quot;no socket path&quot;</span>,
<a name="l03718"></a>03718                 <span class="stringliteral">&quot;launchd did not provide a socket path, &quot;</span>
<a name="l03719"></a>03719                 <span class="stringliteral">&quot;verify that org.freedesktop.dbus-session.plist is loaded!&quot;</span>);
<a name="l03720"></a>03720       <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a>(&amp;socket_path);
<a name="l03721"></a>03721       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03722"></a>03722     }
<a name="l03723"></a>03723   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga100c5ce0696822c5a4cfbdfaba674d96" title="Appends a nul-terminated C-style string to a DBusString.">_dbus_string_append</a> (address, <span class="stringliteral">&quot;unix:path=&quot;</span>))
<a name="l03724"></a>03724     {
<a name="l03725"></a>03725       _DBUS_SET_OOM (error);
<a name="l03726"></a>03726       <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a>(&amp;socket_path);
<a name="l03727"></a>03727       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03728"></a>03728     }
<a name="l03729"></a>03729   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga3c10f0d1bcaa3b450025b9c6a8b901d7" title="Like _dbus_string_move(), but does not delete the section of the source string that&#39;s copied to the d...">_dbus_string_copy</a> (&amp;socket_path, 0, address,
<a name="l03730"></a>03730                           <a class="code" href="group__DBusString.html#gaa5136e6fd2c5188f4b88de7863369c6d" title="Gets the length of a string (not including nul termination).">_dbus_string_get_length</a> (address)))
<a name="l03731"></a>03731     {
<a name="l03732"></a>03732       _DBUS_SET_OOM (error);
<a name="l03733"></a>03733       <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a>(&amp;socket_path);
<a name="l03734"></a>03734       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03735"></a>03735     }
<a name="l03736"></a>03736 
<a name="l03737"></a>03737   <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a>(&amp;socket_path);
<a name="l03738"></a>03738   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l03739"></a>03739 }
<a name="l03740"></a>03740 <span class="preprocessor">#endif</span>
<a name="l03741"></a>03741 <span class="preprocessor"></span>
<a name="l03761"></a>03761 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l03762"></a><a class="code" href="group__DBusSysdeps.html#gade479f90c1083346d74bc21af178d856">03762</a> <a class="code" href="group__DBusSysdeps.html#gade479f90c1083346d74bc21af178d856" title="Determines the address of the session bus by querying a platform-specific method.">_dbus_lookup_session_address</a> (<a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> *supported,
<a name="l03763"></a>03763                               <a class="code" href="structDBusString.html">DBusString</a>  *address,
<a name="l03764"></a>03764                               <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>   *error)
<a name="l03765"></a>03765 {
<a name="l03766"></a>03766 <span class="preprocessor">#ifdef DBUS_ENABLE_LAUNCHD</span>
<a name="l03767"></a>03767 <span class="preprocessor"></span>  *supported = <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l03768"></a>03768   <span class="keywordflow">return</span> _dbus_lookup_session_address_launchd (address, error);
<a name="l03769"></a>03769 <span class="preprocessor">#else</span>
<a name="l03770"></a>03770 <span class="preprocessor"></span>  <span class="comment">/* On non-Mac Unix platforms, if the session address isn&#39;t already</span>
<a name="l03771"></a>03771 <span class="comment">   * set in DBUS_SESSION_BUS_ADDRESS environment variable, we punt and</span>
<a name="l03772"></a>03772 <span class="comment">   * fall back to the autolaunch: global default; see</span>
<a name="l03773"></a>03773 <span class="comment">   * init_session_address in dbus/dbus-bus.c. */</span>
<a name="l03774"></a>03774   *supported = <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03775"></a>03775   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l03776"></a>03776 <span class="preprocessor">#endif</span>
<a name="l03777"></a>03777 <span class="preprocessor"></span>}
<a name="l03778"></a>03778 
<a name="l03786"></a>03786 <span class="keywordtype">void</span>
<a name="l03787"></a><a class="code" href="group__DBusSysdeps.html#ga184b42c4b42b91ef73e9ee50a1fa12c2">03787</a> <a class="code" href="group__DBusSysdeps.html#ga184b42c4b42b91ef73e9ee50a1fa12c2" title="Called when the bus daemon is signaled to reload its configuration; any caches should be nuked...">_dbus_flush_caches</a> (<span class="keywordtype">void</span>)
<a name="l03788"></a>03788 {
<a name="l03789"></a>03789   <a class="code" href="group__DBusInternalsUtils.html#ga788ce7775d7f812d28d931e8b87ddfde" title="Flushes the system global user database;.">_dbus_user_database_flush_system</a> ();
<a name="l03790"></a>03790 }
<a name="l03791"></a>03791 
<a name="l03805"></a>03805 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l03806"></a><a class="code" href="group__DBusSysdeps.html#ga3cc5a5734416858fa58f3166ed181a64">03806</a> <a class="code" href="group__DBusSysdeps.html#ga3cc5a5734416858fa58f3166ed181a64" title="Appends the directory in which a keyring for the given credentials should be stored.">_dbus_append_keyring_directory_for_credentials</a> (<a class="code" href="structDBusString.html">DBusString</a>      *directory,
<a name="l03807"></a>03807                                                 <a class="code" href="structDBusCredentials.html">DBusCredentials</a> *credentials)
<a name="l03808"></a>03808 {
<a name="l03809"></a>03809   <a class="code" href="structDBusString.html">DBusString</a> homedir;
<a name="l03810"></a>03810   <a class="code" href="structDBusString.html">DBusString</a> dotdir;
<a name="l03811"></a>03811   <a class="code" href="group__DBusSysdeps.html#ga186e987b700f9ddc6cea8aa0db82b151" title="A user ID.">dbus_uid_t</a> uid;
<a name="l03812"></a>03812 
<a name="l03813"></a>03813   _dbus_assert (credentials != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l03814"></a>03814   _dbus_assert (!<a class="code" href="group__DBusCredentials.html#gabfd7a1f681a91b45ba2f4e7461131827" title="Checks whether a credentials object contains a user identity.">_dbus_credentials_are_anonymous</a> (credentials));
<a name="l03815"></a>03815 
<a name="l03816"></a>03816   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga348252317f7bb8ac43529972945830ae" title="Initializes a string.">_dbus_string_init</a> (&amp;homedir))
<a name="l03817"></a>03817     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03818"></a>03818 
<a name="l03819"></a>03819   uid = <a class="code" href="group__DBusCredentials.html#ga462892f995f2932bf0eb3b843407e6d5" title="Gets the UNIX user ID in the credentials, or DBUS_UID_UNSET if the credentials object doesn&#39;t contain...">_dbus_credentials_get_unix_uid</a> (credentials);
<a name="l03820"></a>03820   _dbus_assert (uid != <a class="code" href="group__DBusSysdeps.html#ga3d2f3fb32bb759cabe362ca2de383f7d" title="an invalid UID used to represent an uninitialized dbus_uid_t field">DBUS_UID_UNSET</a>);
<a name="l03821"></a>03821 
<a name="l03822"></a>03822   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusInternalsUtils.html#gabdd1dc47f44e3d6702c86c68da9a0173" title="Gets the home directory for the given user.">_dbus_homedir_from_uid</a> (uid, &amp;homedir))
<a name="l03823"></a>03823     <span class="keywordflow">goto</span> failed;
<a name="l03824"></a>03824 
<a name="l03825"></a>03825 <span class="preprocessor">#ifdef DBUS_ENABLE_EMBEDDED_TESTS</span>
<a name="l03826"></a>03826 <span class="preprocessor"></span>  {
<a name="l03827"></a>03827     <span class="keyword">const</span> <span class="keywordtype">char</span> *<span class="keyword">override</span>;
<a name="l03828"></a>03828 
<a name="l03829"></a>03829     <span class="keyword">override</span> = <a class="code" href="group__DBusSysdeps.html#gab846071a4de54cb7e518654f9375313a" title="Wrapper for getenv().">_dbus_getenv</a> (<span class="stringliteral">&quot;DBUS_TEST_HOMEDIR&quot;</span>);
<a name="l03830"></a>03830     <span class="keywordflow">if</span> (<span class="keyword">override</span> != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a> &amp;&amp; *<span class="keyword">override</span> != <span class="charliteral">&#39;\0&#39;</span>)
<a name="l03831"></a>03831       {
<a name="l03832"></a>03832         <a class="code" href="group__DBusString.html#ga08c423b93c28dd746dcb93e0461ab95c" title="Sets the length of a string.">_dbus_string_set_length</a> (&amp;homedir, 0);
<a name="l03833"></a>03833         <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga100c5ce0696822c5a4cfbdfaba674d96" title="Appends a nul-terminated C-style string to a DBusString.">_dbus_string_append</a> (&amp;homedir, <span class="keyword">override</span>))
<a name="l03834"></a>03834           <span class="keywordflow">goto</span> failed;
<a name="l03835"></a>03835 
<a name="l03836"></a>03836         _dbus_verbose (<span class="stringliteral">&quot;Using fake homedir for testing: %s\n&quot;</span>,
<a name="l03837"></a>03837                        <a class="code" href="group__DBusString.html#ga33e20241ae7d784624f97d89b1a0539e" title="Gets the raw character buffer from a const string.">_dbus_string_get_const_data</a> (&amp;homedir));
<a name="l03838"></a>03838       }
<a name="l03839"></a>03839     <span class="keywordflow">else</span>
<a name="l03840"></a>03840       {
<a name="l03841"></a>03841         <span class="comment">/* Not strictly thread-safe, but if we fail at thread-safety here,</span>
<a name="l03842"></a>03842 <span class="comment">         * the worst that will happen is some extra warnings. */</span>
<a name="l03843"></a>03843         <span class="keyword">static</span> <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a> already_warned = <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03844"></a>03844         <span class="keywordflow">if</span> (!already_warned)
<a name="l03845"></a>03845           {
<a name="l03846"></a>03846             <a class="code" href="group__DBusInternalsUtils.html#gabea2c16d6d3fe7c4eb5b9496fc877f84" title="Prints a warning message to stderr.">_dbus_warn</a> (<span class="stringliteral">&quot;Using your real home directory for testing, set DBUS_TEST_HOMEDIR to avoid\n&quot;</span>);
<a name="l03847"></a>03847             already_warned = <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l03848"></a>03848           }
<a name="l03849"></a>03849       }
<a name="l03850"></a>03850   }
<a name="l03851"></a>03851 <span class="preprocessor">#endif</span>
<a name="l03852"></a>03852 <span class="preprocessor"></span>
<a name="l03853"></a>03853   <a class="code" href="group__DBusString.html#ga374640ddfa2f0b27a8356e2379ba8043" title="Initializes a constant string.">_dbus_string_init_const</a> (&amp;dotdir, <span class="stringliteral">&quot;.dbus-keyrings&quot;</span>);
<a name="l03854"></a>03854   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusSysdeps.html#gae3a3fdc0c6001e367584bb016aca495d" title="Appends the given filename to the given directory.">_dbus_concat_dir_and_file</a> (&amp;homedir,
<a name="l03855"></a>03855                                   &amp;dotdir))
<a name="l03856"></a>03856     <span class="keywordflow">goto</span> failed;
<a name="l03857"></a>03857 
<a name="l03858"></a>03858   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga3c10f0d1bcaa3b450025b9c6a8b901d7" title="Like _dbus_string_move(), but does not delete the section of the source string that&#39;s copied to the d...">_dbus_string_copy</a> (&amp;homedir, 0,
<a name="l03859"></a>03859                           directory, <a class="code" href="group__DBusString.html#gaa5136e6fd2c5188f4b88de7863369c6d" title="Gets the length of a string (not including nul termination).">_dbus_string_get_length</a> (directory))) {
<a name="l03860"></a>03860     <span class="keywordflow">goto</span> failed;
<a name="l03861"></a>03861   }
<a name="l03862"></a>03862 
<a name="l03863"></a>03863   <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a> (&amp;homedir);
<a name="l03864"></a>03864   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l03865"></a>03865 
<a name="l03866"></a>03866  failed:
<a name="l03867"></a>03867   <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a> (&amp;homedir);
<a name="l03868"></a>03868   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03869"></a>03869 }
<a name="l03870"></a>03870 
<a name="l03871"></a>03871 <span class="comment">//PENDING(kdab) docs</span>
<a name="l03872"></a>03872 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l03873"></a>03873 _dbus_daemon_publish_session_bus_address (<span class="keyword">const</span> <span class="keywordtype">char</span>* addr,
<a name="l03874"></a>03874                                           <span class="keyword">const</span> <span class="keywordtype">char</span> *scope)
<a name="l03875"></a>03875 {
<a name="l03876"></a>03876   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l03877"></a>03877 }
<a name="l03878"></a>03878 
<a name="l03879"></a>03879 <span class="comment">//PENDING(kdab) docs</span>
<a name="l03880"></a>03880 <span class="keywordtype">void</span>
<a name="l03881"></a>03881 _dbus_daemon_unpublish_session_bus_address (<span class="keywordtype">void</span>)
<a name="l03882"></a>03882 {
<a name="l03883"></a>03883 
<a name="l03884"></a>03884 }
<a name="l03885"></a>03885 
<a name="l03892"></a>03892 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l03893"></a><a class="code" href="group__DBusSysdeps.html#gaa03e5d4d95ef46a70d25fe315e674e24">03893</a> <a class="code" href="group__DBusSysdeps.html#gaa03e5d4d95ef46a70d25fe315e674e24" title="See if errno is EAGAIN or EWOULDBLOCK (this has to be done differently for Winsock so is abstracted)...">_dbus_get_is_errno_eagain_or_ewouldblock</a> (<span class="keywordtype">void</span>)
<a name="l03894"></a>03894 {
<a name="l03895"></a>03895   <span class="keywordflow">return</span> errno == EAGAIN || errno == EWOULDBLOCK;
<a name="l03896"></a>03896 }
<a name="l03897"></a>03897 
<a name="l03905"></a>03905 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l03906"></a><a class="code" href="group__DBusSysdeps.html#ga3bc1512aef42cea17a2aaacc7d8e7211">03906</a> <a class="code" href="group__DBusSysdeps.html#ga3bc1512aef42cea17a2aaacc7d8e7211" title="Removes a directory; Directory must be empty.">_dbus_delete_directory</a> (<span class="keyword">const</span> <a class="code" href="structDBusString.html">DBusString</a> *filename,
<a name="l03907"></a>03907                         <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>        *error)
<a name="l03908"></a>03908 {
<a name="l03909"></a>03909   <span class="keyword">const</span> <span class="keywordtype">char</span> *filename_c;
<a name="l03910"></a>03910 
<a name="l03911"></a>03911   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l03912"></a>03912 
<a name="l03913"></a>03913   filename_c = <a class="code" href="group__DBusString.html#ga33e20241ae7d784624f97d89b1a0539e" title="Gets the raw character buffer from a const string.">_dbus_string_get_const_data</a> (filename);
<a name="l03914"></a>03914 
<a name="l03915"></a>03915   <span class="keywordflow">if</span> (rmdir (filename_c) != 0)
<a name="l03916"></a>03916     {
<a name="l03917"></a>03917       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error, <a class="code" href="group__DBusProtocol.html#gabb62fd6340d0787fbd56ff8dd2f326c7" title="A generic error; &quot;something went wrong&quot; - see the error message for more.">DBUS_ERROR_FAILED</a>,
<a name="l03918"></a>03918                       <span class="stringliteral">&quot;Failed to remove directory %s: %s\n&quot;</span>,
<a name="l03919"></a>03919                       filename_c, _dbus_strerror (errno));
<a name="l03920"></a>03920       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03921"></a>03921     }
<a name="l03922"></a>03922 
<a name="l03923"></a>03923   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l03924"></a>03924 }
<a name="l03925"></a>03925 
<a name="l03933"></a>03933 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l03934"></a><a class="code" href="group__DBusSysdeps.html#ga06183453a52a6919619e85dc1812c9b7">03934</a> <a class="code" href="group__DBusSysdeps.html#ga06183453a52a6919619e85dc1812c9b7" title="Checks whether file descriptors may be passed via the socket.">_dbus_socket_can_pass_unix_fd</a>(<span class="keywordtype">int</span> fd) {
<a name="l03935"></a>03935 
<a name="l03936"></a>03936 <span class="preprocessor">#ifdef SCM_RIGHTS</span>
<a name="l03937"></a>03937 <span class="preprocessor"></span>  <span class="keyword">union </span>{
<a name="l03938"></a>03938     <span class="keyword">struct </span>sockaddr sa;
<a name="l03939"></a>03939     <span class="keyword">struct </span>sockaddr_storage storage;
<a name="l03940"></a>03940     <span class="keyword">struct </span>sockaddr_un un;
<a name="l03941"></a>03941   } sa_buf;
<a name="l03942"></a>03942 
<a name="l03943"></a>03943   socklen_t sa_len = <span class="keyword">sizeof</span>(sa_buf);
<a name="l03944"></a>03944 
<a name="l03945"></a>03945   _DBUS_ZERO(sa_buf);
<a name="l03946"></a>03946 
<a name="l03947"></a>03947   <span class="keywordflow">if</span> (getsockname(fd, &amp;sa_buf.sa, &amp;sa_len) &lt; 0)
<a name="l03948"></a>03948     <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03949"></a>03949 
<a name="l03950"></a>03950   <span class="keywordflow">return</span> sa_buf.sa.sa_family == AF_UNIX;
<a name="l03951"></a>03951 
<a name="l03952"></a>03952 <span class="preprocessor">#else</span>
<a name="l03953"></a>03953 <span class="preprocessor"></span>  <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l03954"></a>03954 
<a name="l03955"></a>03955 <span class="preprocessor">#endif</span>
<a name="l03956"></a>03956 <span class="preprocessor"></span>}
<a name="l03957"></a>03957 
<a name="l03962"></a>03962 <span class="keywordtype">void</span>
<a name="l03963"></a><a class="code" href="group__DBusSysdepsUnix.html#gae63f6bdc70a1dd5c9ba0a6a1be57e320">03963</a> <a class="code" href="group__DBusSysdepsUnix.html#gae63f6bdc70a1dd5c9ba0a6a1be57e320" title="Closes all file descriptors except the first three (i.e.">_dbus_close_all</a> (<span class="keywordtype">void</span>)
<a name="l03964"></a>03964 {
<a name="l03965"></a>03965   <span class="keywordtype">int</span> maxfds, i;
<a name="l03966"></a>03966 
<a name="l03967"></a>03967 <span class="preprocessor">#if HAVE_CLOSEFROM</span>
<a name="l03968"></a>03968 <span class="preprocessor"></span>      closefrom(3);
<a name="l03969"></a>03969 <span class="preprocessor">#endif</span>
<a name="l03970"></a>03970 <span class="preprocessor"></span>
<a name="l03971"></a>03971 <span class="preprocessor">#ifdef __linux__</span>
<a name="l03972"></a>03972 <span class="preprocessor"></span>  <a class="code" href="structDIR.html">DIR</a> *d;
<a name="l03973"></a>03973 
<a name="l03974"></a>03974   <span class="comment">/* On Linux we can optimize this a bit if /proc is available. If it</span>
<a name="l03975"></a>03975 <span class="comment">     isn&#39;t available, fall back to the brute force way. */</span>
<a name="l03976"></a>03976 
<a name="l03977"></a>03977   d = opendir (<span class="stringliteral">&quot;/proc/self/fd&quot;</span>);
<a name="l03978"></a>03978   <span class="keywordflow">if</span> (d)
<a name="l03979"></a>03979     {
<a name="l03980"></a>03980       <span class="keywordflow">for</span> (;;)
<a name="l03981"></a>03981         {
<a name="l03982"></a>03982           <span class="keyword">struct </span><a class="code" href="structdirent.html">dirent</a> buf, *de;
<a name="l03983"></a>03983           <span class="keywordtype">int</span> k, fd;
<a name="l03984"></a>03984           <span class="keywordtype">long</span> l;
<a name="l03985"></a>03985           <span class="keywordtype">char</span> *e = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l03986"></a>03986 
<a name="l03987"></a>03987           k = readdir_r (d, &amp;buf, &amp;de);
<a name="l03988"></a>03988           <span class="keywordflow">if</span> (k != 0 || !de)
<a name="l03989"></a>03989             <span class="keywordflow">break</span>;
<a name="l03990"></a>03990 
<a name="l03991"></a>03991           <span class="keywordflow">if</span> (de-&gt;d_name[0] == <span class="charliteral">&#39;.&#39;</span>)
<a name="l03992"></a>03992             <span class="keywordflow">continue</span>;
<a name="l03993"></a>03993 
<a name="l03994"></a>03994           errno = 0;
<a name="l03995"></a>03995           l = strtol (de-&gt;d_name, &amp;e, 10);
<a name="l03996"></a>03996           <span class="keywordflow">if</span> (errno != 0 || e == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a> || *e != <span class="charliteral">&#39;\0&#39;</span>)
<a name="l03997"></a>03997             <span class="keywordflow">continue</span>;
<a name="l03998"></a>03998 
<a name="l03999"></a>03999           fd = (int) l;
<a name="l04000"></a>04000           <span class="keywordflow">if</span> (fd &lt; 3)
<a name="l04001"></a>04001             <span class="keywordflow">continue</span>;
<a name="l04002"></a>04002 
<a name="l04003"></a>04003           <span class="keywordflow">if</span> (fd == dirfd (d))
<a name="l04004"></a>04004             <span class="keywordflow">continue</span>;
<a name="l04005"></a>04005 
<a name="l04006"></a>04006           close (fd);
<a name="l04007"></a>04007         }
<a name="l04008"></a>04008 
<a name="l04009"></a>04009       closedir (d);
<a name="l04010"></a>04010       <span class="keywordflow">return</span>;
<a name="l04011"></a>04011     }
<a name="l04012"></a>04012 <span class="preprocessor">#endif</span>
<a name="l04013"></a>04013 <span class="preprocessor"></span>
<a name="l04014"></a>04014   maxfds = sysconf (_SC_OPEN_MAX);
<a name="l04015"></a>04015 
<a name="l04016"></a>04016   <span class="comment">/* Pick something reasonable if for some reason sysconf says</span>
<a name="l04017"></a>04017 <span class="comment">   * unlimited.</span>
<a name="l04018"></a>04018 <span class="comment">   */</span>
<a name="l04019"></a>04019   <span class="keywordflow">if</span> (maxfds &lt; 0)
<a name="l04020"></a>04020     maxfds = 1024;
<a name="l04021"></a>04021 
<a name="l04022"></a>04022   <span class="comment">/* close all inherited fds */</span>
<a name="l04023"></a>04023   <span class="keywordflow">for</span> (i = 3; i &lt; maxfds; i++)
<a name="l04024"></a>04024     close (i);
<a name="l04025"></a>04025 }
<a name="l04026"></a>04026 
<a name="l04034"></a>04034 <a class="code" href="group__DBusTypes.html#ga39c9cb0f3a2a8ad6f55cc4855d035349" title="A boolean, valid values are TRUE and FALSE.">dbus_bool_t</a>
<a name="l04035"></a><a class="code" href="group__DBusSysdepsUnix.html#ga974b137fa165ce2e0ace041b20883fe6">04035</a> <a class="code" href="group__DBusSysdepsUnix.html#ga974b137fa165ce2e0ace041b20883fe6" title="Read the address from the socket and append it to the string.">_dbus_append_address_from_socket</a> (<span class="keywordtype">int</span>         fd,
<a name="l04036"></a>04036                                   <a class="code" href="structDBusString.html">DBusString</a> *address,
<a name="l04037"></a>04037                                   <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>  *error)
<a name="l04038"></a>04038 {
<a name="l04039"></a>04039   <span class="keyword">union </span>{
<a name="l04040"></a>04040       <span class="keyword">struct </span>sockaddr sa;
<a name="l04041"></a>04041       <span class="keyword">struct </span>sockaddr_storage storage;
<a name="l04042"></a>04042       <span class="keyword">struct </span>sockaddr_un un;
<a name="l04043"></a>04043       <span class="keyword">struct </span>sockaddr_in ipv4;
<a name="l04044"></a>04044       <span class="keyword">struct </span>sockaddr_in6 ipv6;
<a name="l04045"></a>04045   } socket;
<a name="l04046"></a>04046   <span class="keywordtype">char</span> hostip[INET6_ADDRSTRLEN];
<a name="l04047"></a>04047   <span class="keywordtype">int</span> size = <span class="keyword">sizeof</span> (socket);
<a name="l04048"></a>04048   <a class="code" href="structDBusString.html">DBusString</a> path_str;
<a name="l04049"></a>04049 
<a name="l04050"></a>04050   <span class="keywordflow">if</span> (getsockname (fd, &amp;socket.sa, &amp;size))
<a name="l04051"></a>04051     <span class="keywordflow">goto</span> err;
<a name="l04052"></a>04052 
<a name="l04053"></a>04053   <span class="keywordflow">switch</span> (socket.sa.sa_family)
<a name="l04054"></a>04054     {
<a name="l04055"></a>04055     <span class="keywordflow">case</span> AF_UNIX:
<a name="l04056"></a>04056       <span class="keywordflow">if</span> (socket.un.sun_path[0]==<span class="charliteral">&#39;\0&#39;</span>)
<a name="l04057"></a>04057         {
<a name="l04058"></a>04058           <a class="code" href="group__DBusString.html#ga374640ddfa2f0b27a8356e2379ba8043" title="Initializes a constant string.">_dbus_string_init_const</a> (&amp;path_str, &amp;(socket.un.sun_path[1]));
<a name="l04059"></a>04059           <span class="keywordflow">if</span> (<a class="code" href="group__DBusString.html#ga100c5ce0696822c5a4cfbdfaba674d96" title="Appends a nul-terminated C-style string to a DBusString.">_dbus_string_append</a> (address, <span class="stringliteral">&quot;unix:abstract=&quot;</span>) &amp;&amp;
<a name="l04060"></a>04060               <a class="code" href="group__DBusAddressInternals.html#ga1ecc2f460303cd70c34e7667e8b12b37" title="Appends an escaped version of one string to another string, using the D-Bus address escaping mechanis...">_dbus_address_append_escaped</a> (address, &amp;path_str))
<a name="l04061"></a>04061             <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l04062"></a>04062         }
<a name="l04063"></a>04063       <span class="keywordflow">else</span>
<a name="l04064"></a>04064         {
<a name="l04065"></a>04065           <a class="code" href="group__DBusString.html#ga374640ddfa2f0b27a8356e2379ba8043" title="Initializes a constant string.">_dbus_string_init_const</a> (&amp;path_str, socket.un.sun_path);
<a name="l04066"></a>04066           <span class="keywordflow">if</span> (<a class="code" href="group__DBusString.html#ga100c5ce0696822c5a4cfbdfaba674d96" title="Appends a nul-terminated C-style string to a DBusString.">_dbus_string_append</a> (address, <span class="stringliteral">&quot;unix:path=&quot;</span>) &amp;&amp;
<a name="l04067"></a>04067               <a class="code" href="group__DBusAddressInternals.html#ga1ecc2f460303cd70c34e7667e8b12b37" title="Appends an escaped version of one string to another string, using the D-Bus address escaping mechanis...">_dbus_address_append_escaped</a> (address, &amp;path_str))
<a name="l04068"></a>04068             <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l04069"></a>04069         }
<a name="l04070"></a>04070       <span class="keywordflow">break</span>;
<a name="l04071"></a>04071     <span class="keywordflow">case</span> AF_INET:
<a name="l04072"></a>04072       <span class="keywordflow">if</span> (inet_ntop (AF_INET, &amp;socket.ipv4.sin_addr, hostip, sizeof (hostip)))
<a name="l04073"></a>04073         <span class="keywordflow">if</span> (<a class="code" href="group__DBusString.html#gab0078cf7e0e5bd784ec6d6e0cc3923a2" title="Appends a printf-style formatted string to the DBusString.">_dbus_string_append_printf</a> (address, <span class="stringliteral">&quot;tcp:family=ipv4,host=%s,port=%u&quot;</span>,
<a name="l04074"></a>04074                                         hostip, ntohs (socket.ipv4.sin_port)))
<a name="l04075"></a>04075           <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l04076"></a>04076       <span class="keywordflow">break</span>;
<a name="l04077"></a>04077 <span class="preprocessor">#ifdef AF_INET6</span>
<a name="l04078"></a>04078 <span class="preprocessor"></span>    <span class="keywordflow">case</span> AF_INET6:
<a name="l04079"></a>04079       <a class="code" href="group__DBusString.html#ga374640ddfa2f0b27a8356e2379ba8043" title="Initializes a constant string.">_dbus_string_init_const</a> (&amp;path_str, hostip);
<a name="l04080"></a>04080       <span class="keywordflow">if</span> (inet_ntop (AF_INET6, &amp;socket.ipv6.sin6_addr, hostip, sizeof (hostip)))
<a name="l04081"></a>04081         <span class="keywordflow">if</span> (<a class="code" href="group__DBusString.html#gab0078cf7e0e5bd784ec6d6e0cc3923a2" title="Appends a printf-style formatted string to the DBusString.">_dbus_string_append_printf</a> (address, <span class="stringliteral">&quot;tcp:family=ipv6,port=%u,host=&quot;</span>,
<a name="l04082"></a>04082                                         ntohs (socket.ipv6.sin6_port)) &amp;&amp;
<a name="l04083"></a>04083             <a class="code" href="group__DBusAddressInternals.html#ga1ecc2f460303cd70c34e7667e8b12b37" title="Appends an escaped version of one string to another string, using the D-Bus address escaping mechanis...">_dbus_address_append_escaped</a> (address, &amp;path_str))
<a name="l04084"></a>04084           <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>;
<a name="l04085"></a>04085       <span class="keywordflow">break</span>;
<a name="l04086"></a>04086 <span class="preprocessor">#endif</span>
<a name="l04087"></a>04087 <span class="preprocessor"></span>    <span class="keywordflow">default</span>:
<a name="l04088"></a>04088       <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error,
<a name="l04089"></a>04089                       <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (EINVAL),
<a name="l04090"></a>04090                       <span class="stringliteral">&quot;Failed to read address from socket: Unknown socket type.&quot;</span>);
<a name="l04091"></a>04091       <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l04092"></a>04092     }
<a name="l04093"></a>04093  err:
<a name="l04094"></a>04094   <a class="code" href="group__DBusErrors.html#ga89d2ad4bde21f9e0057fac07a79885e3" title="Assigns an error name and message to a DBusError.">dbus_set_error</a> (error,
<a name="l04095"></a>04095                   <a class="code" href="group__DBusInternalsUtils.html#ga2212aa0e5732257598a6597748c658e4" title="Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name.">_dbus_error_from_errno</a> (errno),
<a name="l04096"></a>04096                   <span class="stringliteral">&quot;Failed to open socket: %s&quot;</span>,
<a name="l04097"></a>04097                   _dbus_strerror (errno));
<a name="l04098"></a>04098   <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>;
<a name="l04099"></a>04099 }
<a name="l04100"></a>04100 
<a name="l04101"></a>04101 <span class="comment">/* tests in dbus-sysdeps-util.c */</span>
</pre></div></div><!-- contents -->


<hr class="footer"/><address class="footer"><small>
Generated on Thu Mar 3 2016 17:50:31 for D-Bus by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>

</body>
</html>