Current File : //usr/share/doc/dbus/api/dbus-server-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-server-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-server-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-server-unix.c Server implementation for Unix network protocols.</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2002, 2003, 2004  Red Hat Inc.</span>
<a name="l00005"></a>00005 <span class="comment"> *</span>
<a name="l00006"></a>00006 <span class="comment"> * Licensed under the Academic Free License version 2.1</span>
<a name="l00007"></a>00007 <span class="comment"> *</span>
<a name="l00008"></a>00008 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
<a name="l00009"></a>00009 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
<a name="l00010"></a>00010 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
<a name="l00011"></a>00011 <span class="comment"> * (at your option) any later version.</span>
<a name="l00012"></a>00012 <span class="comment"> *</span>
<a name="l00013"></a>00013 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
<a name="l00014"></a>00014 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00015"></a>00015 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<a name="l00016"></a>00016 <span class="comment"> * GNU General Public License for more details.</span>
<a name="l00017"></a>00017 <span class="comment"> *</span>
<a name="l00018"></a>00018 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
<a name="l00019"></a>00019 <span class="comment"> * along with this program; if not, write to the Free Software</span>
<a name="l00020"></a>00020 <span class="comment"> * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA</span>
<a name="l00021"></a>00021 <span class="comment"> *</span>
<a name="l00022"></a>00022 <span class="comment"> */</span>
<a name="l00023"></a>00023 
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;config.h&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &quot;dbus-internals.h&quot;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &quot;dbus-server-unix.h&quot;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &quot;dbus-server-socket.h&quot;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &quot;dbus-server-launchd.h&quot;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include &quot;dbus-transport-unix.h&quot;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &quot;dbus-connection-internal.h&quot;</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &quot;dbus-sysdeps-unix.h&quot;</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include &quot;dbus-string.h&quot;</span>
<a name="l00033"></a>00033 
<a name="l00053"></a>00053 DBusServerListenResult
<a name="l00054"></a><a class="code" href="group__DBusServerUnix.html#gaec00cdf4977b9bd33621df684406a779">00054</a> <a class="code" href="group__DBusServerUnix.html#gaec00cdf4977b9bd33621df684406a779" title="Tries to interpret the address entry in a platform-specific way, creating a platform-specific server ...">_dbus_server_listen_platform_specific</a> (<a class="code" href="structDBusAddressEntry.html" title="Internals of DBusAddressEntry.">DBusAddressEntry</a> *entry,
<a name="l00055"></a>00055                                        <a class="code" href="structDBusServer.html" title="Internals of DBusServer object.">DBusServer</a>      **server_p,
<a name="l00056"></a>00056                                        <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>        *error)
<a name="l00057"></a>00057 {
<a name="l00058"></a>00058   <span class="keyword">const</span> <span class="keywordtype">char</span> *method;
<a name="l00059"></a>00059 
<a name="l00060"></a>00060   *server_p = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00061"></a>00061 
<a name="l00062"></a>00062   method = <a class="code" href="group__DBusAddress.html#ga7e6b2572d6e637826acada01377b5487" title="Returns the method string of an address entry.">dbus_address_entry_get_method</a> (entry);
<a name="l00063"></a>00063 
<a name="l00064"></a>00064   <span class="keywordflow">if</span> (strcmp (method, <span class="stringliteral">&quot;unix&quot;</span>) == 0)
<a name="l00065"></a>00065     {
<a name="l00066"></a>00066       <span class="keyword">const</span> <span class="keywordtype">char</span> *path = <a class="code" href="group__DBusAddress.html#gae6f014689b49099e835b1f97d032034e" title="Returns a value from a key of an entry.">dbus_address_entry_get_value</a> (entry, <span class="stringliteral">&quot;path&quot;</span>);
<a name="l00067"></a>00067       <span class="keyword">const</span> <span class="keywordtype">char</span> *tmpdir = <a class="code" href="group__DBusAddress.html#gae6f014689b49099e835b1f97d032034e" title="Returns a value from a key of an entry.">dbus_address_entry_get_value</a> (entry, <span class="stringliteral">&quot;tmpdir&quot;</span>);
<a name="l00068"></a>00068       <span class="keyword">const</span> <span class="keywordtype">char</span> *<span class="keyword">abstract</span> = <a class="code" href="group__DBusAddress.html#gae6f014689b49099e835b1f97d032034e" title="Returns a value from a key of an entry.">dbus_address_entry_get_value</a> (entry, <span class="stringliteral">&quot;abstract&quot;</span>);
<a name="l00069"></a>00069 
<a name="l00070"></a>00070       <span class="keywordflow">if</span> (path == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a> &amp;&amp; tmpdir == <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">abstract</span> == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l00071"></a>00071         {
<a name="l00072"></a>00072           <a class="code" href="group__DBusAddressInternals.html#ga5b6409826263c7d62570c56889f7ddb2" title="Sets DBUS_ERROR_BAD_ADDRESS.">_dbus_set_bad_address</a>(error, <span class="stringliteral">&quot;unix&quot;</span>,
<a name="l00073"></a>00073                                 <span class="stringliteral">&quot;path or tmpdir or abstract&quot;</span>,
<a name="l00074"></a>00074                                 <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l00075"></a>00075           <span class="keywordflow">return</span> DBUS_SERVER_LISTEN_BAD_ADDRESS;
<a name="l00076"></a>00076         }
<a name="l00077"></a>00077 
<a name="l00078"></a>00078       <span class="keywordflow">if</span> ((path &amp;&amp; tmpdir) ||
<a name="l00079"></a>00079           (path &amp;&amp; <span class="keyword">abstract</span>) ||
<a name="l00080"></a>00080           (tmpdir &amp;&amp; <span class="keyword">abstract</span>))
<a name="l00081"></a>00081         {
<a name="l00082"></a>00082           <a class="code" href="group__DBusAddressInternals.html#ga5b6409826263c7d62570c56889f7ddb2" title="Sets DBUS_ERROR_BAD_ADDRESS.">_dbus_set_bad_address</a>(error, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>,
<a name="l00083"></a>00083                                 <span class="stringliteral">&quot;cannot specify two of \&quot;path\&quot; and \&quot;tmpdir\&quot; and \&quot;abstract\&quot; at the same time&quot;</span>);
<a name="l00084"></a>00084           <span class="keywordflow">return</span> DBUS_SERVER_LISTEN_BAD_ADDRESS;
<a name="l00085"></a>00085         }
<a name="l00086"></a>00086 
<a name="l00087"></a>00087       <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="l00088"></a>00088         {
<a name="l00089"></a>00089           <a class="code" href="structDBusString.html">DBusString</a> full_path;
<a name="l00090"></a>00090           <a class="code" href="structDBusString.html">DBusString</a> filename;
<a name="l00091"></a>00091 
<a name="l00092"></a>00092           <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga348252317f7bb8ac43529972945830ae" title="Initializes a string.">_dbus_string_init</a> (&amp;full_path))
<a name="l00093"></a>00093             {
<a name="l00094"></a>00094               <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="l00095"></a>00095               <span class="keywordflow">return</span> DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
<a name="l00096"></a>00096             }
<a name="l00097"></a>00097 
<a name="l00098"></a>00098           <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga348252317f7bb8ac43529972945830ae" title="Initializes a string.">_dbus_string_init</a> (&amp;filename))
<a name="l00099"></a>00099             {
<a name="l00100"></a>00100               <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a> (&amp;full_path);
<a name="l00101"></a>00101               <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="l00102"></a>00102               <span class="keywordflow">return</span> DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
<a name="l00103"></a>00103             }
<a name="l00104"></a>00104 
<a name="l00105"></a>00105           <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;filename,
<a name="l00106"></a>00106                                     <span class="stringliteral">&quot;dbus-&quot;</span>) ||
<a name="l00107"></a>00107               !<a class="code" href="group__DBusInternalsUtils.html#ga709ce349c6ee05263850444fb4e0177d" title="Generates the given number of random bytes, where the bytes are chosen from the alphanumeric ASCII su...">_dbus_generate_random_ascii</a> (&amp;filename, 10) ||
<a name="l00108"></a>00108               !<a class="code" href="group__DBusString.html#ga100c5ce0696822c5a4cfbdfaba674d96" title="Appends a nul-terminated C-style string to a DBusString.">_dbus_string_append</a> (&amp;full_path, tmpdir) ||
<a name="l00109"></a>00109               !<a class="code" href="group__DBusSysdeps.html#gae3a3fdc0c6001e367584bb016aca495d" title="Appends the given filename to the given directory.">_dbus_concat_dir_and_file</a> (&amp;full_path, &amp;filename))
<a name="l00110"></a>00110             {
<a name="l00111"></a>00111               <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a> (&amp;full_path);
<a name="l00112"></a>00112               <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a> (&amp;filename);
<a name="l00113"></a>00113               <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="l00114"></a>00114               <span class="keywordflow">return</span> DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
<a name="l00115"></a>00115             }
<a name="l00116"></a>00116 
<a name="l00117"></a>00117           <span class="comment">/* Always use abstract namespace if possible with tmpdir */</span>
<a name="l00118"></a>00118 
<a name="l00119"></a>00119           *server_p =
<a name="l00120"></a>00120             <a class="code" href="group__DBusServerUnix.html#ga21ce093bda6ce6c7f94d1d894b6b4358" title="Creates a new server listening on the given Unix domain socket.">_dbus_server_new_for_domain_socket</a> (<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;full_path),
<a name="l00121"></a>00121 #ifdef HAVE_ABSTRACT_SOCKETS
<a name="l00122"></a>00122                                                 <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>,
<a name="l00123"></a>00123 #<span class="keywordflow">else</span>
<a name="l00124"></a>00124                                                 <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>,
<a name="l00125"></a>00125 #endif
<a name="l00126"></a>00126                                                 error);
<a name="l00127"></a>00127 
<a name="l00128"></a>00128           <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a> (&amp;full_path);
<a name="l00129"></a>00129           <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a> (&amp;filename);
<a name="l00130"></a>00130         }
<a name="l00131"></a>00131       <span class="keywordflow">else</span>
<a name="l00132"></a>00132         {
<a name="l00133"></a>00133           <span class="keywordflow">if</span> (path)
<a name="l00134"></a>00134             *server_p = <a class="code" href="group__DBusServerUnix.html#ga21ce093bda6ce6c7f94d1d894b6b4358" title="Creates a new server listening on the given Unix domain socket.">_dbus_server_new_for_domain_socket</a> (path, <a class="code" href="group__DBusMacros.html#gaa93f0eb578d23995850d61f7d61c55c1" title="Expands to &quot;0&quot;.">FALSE</a>, error);
<a name="l00135"></a>00135           <span class="keywordflow">else</span>
<a name="l00136"></a>00136             *server_p = <a class="code" href="group__DBusServerUnix.html#ga21ce093bda6ce6c7f94d1d894b6b4358" title="Creates a new server listening on the given Unix domain socket.">_dbus_server_new_for_domain_socket</a> (<span class="keyword">abstract</span>, <a class="code" href="group__DBusMacros.html#gaa8cecfc5c5c054d2875c03e77b7be15d" title="Expands to &quot;1&quot;.">TRUE</a>, error);
<a name="l00137"></a>00137         }
<a name="l00138"></a>00138 
<a name="l00139"></a>00139       <span class="keywordflow">if</span> (*server_p != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l00140"></a>00140         {
<a name="l00141"></a>00141           _DBUS_ASSERT_ERROR_IS_CLEAR(error);
<a name="l00142"></a>00142           <span class="keywordflow">return</span> DBUS_SERVER_LISTEN_OK;
<a name="l00143"></a>00143         }
<a name="l00144"></a>00144       <span class="keywordflow">else</span>
<a name="l00145"></a>00145         {
<a name="l00146"></a>00146           _DBUS_ASSERT_ERROR_IS_SET(error);
<a name="l00147"></a>00147           <span class="keywordflow">return</span> DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
<a name="l00148"></a>00148         }
<a name="l00149"></a>00149     }
<a name="l00150"></a>00150   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp (method, <span class="stringliteral">&quot;systemd&quot;</span>) == 0)
<a name="l00151"></a>00151     {
<a name="l00152"></a>00152       <span class="keywordtype">int</span> i, n, *fds;
<a name="l00153"></a>00153       <a class="code" href="structDBusString.html">DBusString</a> address;
<a name="l00154"></a>00154 
<a name="l00155"></a>00155       n = <a class="code" href="group__DBusSysdepsUnix.html#ga71aa508a7790c6d1c9c0159defcdd4a6" title="Acquires one or more sockets passed in from systemd.">_dbus_listen_systemd_sockets</a> (&amp;fds, error);
<a name="l00156"></a>00156       <span class="keywordflow">if</span> (n &lt; 0)
<a name="l00157"></a>00157         {
<a name="l00158"></a>00158           _DBUS_ASSERT_ERROR_IS_SET (error);
<a name="l00159"></a>00159           <span class="keywordflow">return</span> DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
<a name="l00160"></a>00160         }
<a name="l00161"></a>00161 
<a name="l00162"></a>00162       <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga348252317f7bb8ac43529972945830ae" title="Initializes a string.">_dbus_string_init</a> (&amp;address))
<a name="l00163"></a>00163           <span class="keywordflow">goto</span> systemd_oom;
<a name="l00164"></a>00164 
<a name="l00165"></a>00165       <span class="keywordflow">for</span> (i = 0; i &lt; n; i++)
<a name="l00166"></a>00166         {
<a name="l00167"></a>00167           <span class="keywordflow">if</span> (i &gt; 0)
<a name="l00168"></a>00168             {
<a name="l00169"></a>00169               <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;address, <span class="stringliteral">&quot;;&quot;</span>))
<a name="l00170"></a>00170                 <span class="keywordflow">goto</span> systemd_oom;
<a name="l00171"></a>00171             }
<a name="l00172"></a>00172           <span class="keywordflow">if</span> (!<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> (fds[i], &amp;address, error))
<a name="l00173"></a>00173             <span class="keywordflow">goto</span> systemd_err;
<a name="l00174"></a>00174         }
<a name="l00175"></a>00175 
<a name="l00176"></a>00176       *server_p = <a class="code" href="group__DBusServerSocket.html#ga93d00891e32dbc05a33d3c69ca2ffef6" title="Creates a new server listening on the given file descriptor.">_dbus_server_new_for_socket</a> (fds, n, &amp;address, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l00177"></a>00177       <span class="keywordflow">if</span> (*server_p == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l00178"></a>00178         <span class="keywordflow">goto</span> systemd_oom;
<a name="l00179"></a>00179 
<a name="l00180"></a>00180       <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> (fds);
<a name="l00181"></a>00181 
<a name="l00182"></a>00182       <span class="keywordflow">return</span> DBUS_SERVER_LISTEN_OK;
<a name="l00183"></a>00183   systemd_oom:
<a name="l00184"></a>00184       _DBUS_SET_OOM (error);
<a name="l00185"></a>00185   systemd_err:
<a name="l00186"></a>00186       <span class="keywordflow">for</span> (i = 0; i &lt; n; i++)
<a name="l00187"></a>00187         {
<a name="l00188"></a>00188           <a class="code" href="group__DBusSysdeps.html#ga701f9b3087c196404f66ff95b4ace0b8" title="Closes a socket.">_dbus_close_socket</a> (fds[i], <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l00189"></a>00189         }
<a name="l00190"></a>00190       <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> (fds);
<a name="l00191"></a>00191       <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a> (&amp;address);
<a name="l00192"></a>00192 
<a name="l00193"></a>00193       <span class="keywordflow">return</span> DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
<a name="l00194"></a>00194     }
<a name="l00195"></a>00195 <span class="preprocessor">#ifdef DBUS_ENABLE_LAUNCHD</span>
<a name="l00196"></a>00196 <span class="preprocessor"></span>  <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp (method, <span class="stringliteral">&quot;launchd&quot;</span>) == 0)
<a name="l00197"></a>00197     {
<a name="l00198"></a>00198       <span class="keyword">const</span> <span class="keywordtype">char</span> *launchd_env_var = <a class="code" href="group__DBusAddress.html#gae6f014689b49099e835b1f97d032034e" title="Returns a value from a key of an entry.">dbus_address_entry_get_value</a> (entry, <span class="stringliteral">&quot;env&quot;</span>);
<a name="l00199"></a>00199       <span class="keywordflow">if</span> (launchd_env_var == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l00200"></a>00200         {
<a name="l00201"></a>00201           <a class="code" href="group__DBusAddressInternals.html#ga5b6409826263c7d62570c56889f7ddb2" title="Sets DBUS_ERROR_BAD_ADDRESS.">_dbus_set_bad_address</a> (error, <span class="stringliteral">&quot;launchd&quot;</span>, <span class="stringliteral">&quot;env&quot;</span>, <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>);
<a name="l00202"></a>00202           <span class="keywordflow">return</span> DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
<a name="l00203"></a>00203         }
<a name="l00204"></a>00204       *server_p = <a class="code" href="group__DBusServerLaunchd.html#ga5d09a40275e9a28d35ef3474875487a2" title="Creates a new server from launchd.">_dbus_server_new_for_launchd</a> (launchd_env_var, error);
<a name="l00205"></a>00205 
<a name="l00206"></a>00206       <span class="keywordflow">if</span> (*server_p != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l00207"></a>00207         {
<a name="l00208"></a>00208           _DBUS_ASSERT_ERROR_IS_CLEAR(error);
<a name="l00209"></a>00209           <span class="keywordflow">return</span> DBUS_SERVER_LISTEN_OK;
<a name="l00210"></a>00210         }
<a name="l00211"></a>00211       <span class="keywordflow">else</span>
<a name="l00212"></a>00212         {
<a name="l00213"></a>00213           _DBUS_ASSERT_ERROR_IS_SET(error);
<a name="l00214"></a>00214           <span class="keywordflow">return</span> DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
<a name="l00215"></a>00215         }
<a name="l00216"></a>00216     }
<a name="l00217"></a>00217 <span class="preprocessor">#endif</span>
<a name="l00218"></a>00218 <span class="preprocessor"></span>  <span class="keywordflow">else</span>
<a name="l00219"></a>00219     {
<a name="l00220"></a>00220       <span class="comment">/* If we don&#39;t handle the method, we return NULL with the</span>
<a name="l00221"></a>00221 <span class="comment">       * error unset</span>
<a name="l00222"></a>00222 <span class="comment">       */</span>
<a name="l00223"></a>00223       _DBUS_ASSERT_ERROR_IS_CLEAR(error);
<a name="l00224"></a>00224       <span class="keywordflow">return</span> DBUS_SERVER_LISTEN_NOT_HANDLED;
<a name="l00225"></a>00225     }
<a name="l00226"></a>00226 }
<a name="l00227"></a>00227 
<a name="l00236"></a>00236 <a class="code" href="structDBusServer.html" title="Internals of DBusServer object.">DBusServer</a>*
<a name="l00237"></a><a class="code" href="group__DBusServerUnix.html#ga21ce093bda6ce6c7f94d1d894b6b4358">00237</a> <a class="code" href="group__DBusServerUnix.html#ga21ce093bda6ce6c7f94d1d894b6b4358" title="Creates a new server listening on the given Unix domain socket.">_dbus_server_new_for_domain_socket</a> (<span class="keyword">const</span> <span class="keywordtype">char</span>     *path,
<a name="l00238"></a>00238                                     <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="l00239"></a>00239                                     <a class="code" href="structDBusError.html" title="Object representing an exception.">DBusError</a>      *error)
<a name="l00240"></a>00240 {
<a name="l00241"></a>00241   <a class="code" href="structDBusServer.html" title="Internals of DBusServer object.">DBusServer</a> *server;
<a name="l00242"></a>00242   <span class="keywordtype">int</span> listen_fd;
<a name="l00243"></a>00243   <a class="code" href="structDBusString.html">DBusString</a> address;
<a name="l00244"></a>00244   <span class="keywordtype">char</span> *path_copy;
<a name="l00245"></a>00245   <a class="code" href="structDBusString.html">DBusString</a> path_str;
<a name="l00246"></a>00246 
<a name="l00247"></a>00247   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
<a name="l00248"></a>00248 
<a name="l00249"></a>00249   <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#ga348252317f7bb8ac43529972945830ae" title="Initializes a string.">_dbus_string_init</a> (&amp;address))
<a name="l00250"></a>00250     {
<a name="l00251"></a>00251       <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="l00252"></a>00252       <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="l00253"></a>00253     }
<a name="l00254"></a>00254 
<a name="l00255"></a>00255   <a class="code" href="group__DBusString.html#ga374640ddfa2f0b27a8356e2379ba8043" title="Initializes a constant string.">_dbus_string_init_const</a> (&amp;path_str, path);
<a name="l00256"></a>00256   <span class="keywordflow">if</span> ((<span class="keyword">abstract</span> &amp;&amp;
<a name="l00257"></a>00257        !<a class="code" href="group__DBusString.html#ga100c5ce0696822c5a4cfbdfaba674d96" title="Appends a nul-terminated C-style string to a DBusString.">_dbus_string_append</a> (&amp;address, <span class="stringliteral">&quot;unix:abstract=&quot;</span>)) ||
<a name="l00258"></a>00258       (!<span class="keyword">abstract</span> &amp;&amp;
<a name="l00259"></a>00259        !<a class="code" href="group__DBusString.html#ga100c5ce0696822c5a4cfbdfaba674d96" title="Appends a nul-terminated C-style string to a DBusString.">_dbus_string_append</a> (&amp;address, <span class="stringliteral">&quot;unix:path=&quot;</span>)) ||
<a name="l00260"></a>00260       !<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> (&amp;address, &amp;path_str))
<a name="l00261"></a>00261     {
<a name="l00262"></a>00262       <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="l00263"></a>00263       <span class="keywordflow">goto</span> failed_0;
<a name="l00264"></a>00264     }
<a name="l00265"></a>00265 
<a name="l00266"></a>00266   <span class="keywordflow">if</span> (<span class="keyword">abstract</span>)
<a name="l00267"></a>00267     {
<a name="l00268"></a>00268       path_copy = <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>;
<a name="l00269"></a>00269     }
<a name="l00270"></a>00270   <span class="keywordflow">else</span>
<a name="l00271"></a>00271     {
<a name="l00272"></a>00272       path_copy = <a class="code" href="group__DBusInternalsUtils.html#ga9d00d77f6595b9d7ac1baf59d44bf58c" title="Duplicates a string.">_dbus_strdup</a> (path);
<a name="l00273"></a>00273       <span class="keywordflow">if</span> (path_copy == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l00274"></a>00274         {
<a name="l00275"></a>00275           <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="l00276"></a>00276           <span class="keywordflow">goto</span> failed_0;
<a name="l00277"></a>00277         }
<a name="l00278"></a>00278     }
<a name="l00279"></a>00279 
<a name="l00280"></a>00280   listen_fd = <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> (path, <span class="keyword">abstract</span>, error);
<a name="l00281"></a>00281 
<a name="l00282"></a>00282   <span class="keywordflow">if</span> (listen_fd &lt; 0)
<a name="l00283"></a>00283     {
<a name="l00284"></a>00284       _DBUS_ASSERT_ERROR_IS_SET (error);
<a name="l00285"></a>00285       <span class="keywordflow">goto</span> failed_1;
<a name="l00286"></a>00286     }
<a name="l00287"></a>00287 
<a name="l00288"></a>00288   server = <a class="code" href="group__DBusServerSocket.html#ga93d00891e32dbc05a33d3c69ca2ffef6" title="Creates a new server listening on the given file descriptor.">_dbus_server_new_for_socket</a> (&amp;listen_fd, 1, &amp;address, 0);
<a name="l00289"></a>00289   <span class="keywordflow">if</span> (server == <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l00290"></a>00290     {
<a name="l00291"></a>00291       <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="l00292"></a>00292       <span class="keywordflow">goto</span> failed_2;
<a name="l00293"></a>00293     }
<a name="l00294"></a>00294 
<a name="l00295"></a>00295   <span class="keywordflow">if</span> (path_copy != <a class="code" href="group__DBusMacros.html#ga070d2ce7b6bb7e5c05602aa8c308d0c4" title="A null pointer, defined appropriately for C or C++.">NULL</a>)
<a name="l00296"></a>00296     <a class="code" href="group__DBusServerSocket.html#gaa9518c980672f1b8dba8f5a981b93fd9" title="This is a bad hack since it&#39;s really unix domain socket specific.">_dbus_server_socket_own_filename</a>(server, path_copy);
<a name="l00297"></a>00297 
<a name="l00298"></a>00298   <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a> (&amp;address);
<a name="l00299"></a>00299 
<a name="l00300"></a>00300   <span class="keywordflow">return</span> server;
<a name="l00301"></a>00301 
<a name="l00302"></a>00302  failed_2:
<a name="l00303"></a>00303   <a class="code" href="group__DBusSysdeps.html#ga701f9b3087c196404f66ff95b4ace0b8" title="Closes a socket.">_dbus_close_socket</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="l00304"></a>00304  failed_1:
<a name="l00305"></a>00305   <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> (path_copy);
<a name="l00306"></a>00306  failed_0:
<a name="l00307"></a>00307   <a class="code" href="group__DBusString.html#ga781ca91acda49a834dce7d0ed0eef212" title="Frees a string created by _dbus_string_init().">_dbus_string_free</a> (&amp;address);
<a name="l00308"></a>00308 
<a name="l00309"></a>00309   <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="l00310"></a>00310 }
<a name="l00311"></a>00311 
</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>