]> arthur.barton.de Git - netatalk.git/commitdiff
Start a DBUS session daemon from netatalk master process
authorFrank Lahm <franklahm@googlemail.com>
Mon, 16 Jul 2012 17:51:23 +0000 (19:51 +0200)
committerFrank Lahm <franklahm@googlemail.com>
Wed, 15 Aug 2012 18:15:11 +0000 (20:15 +0200)
config/.gitignore
config/Makefile.am
config/dbus-session.conf.tmpl [new file with mode: 0644]
etc/netatalk/netatalk.c

index ec0b4097416de6cd166138540731526921984658..4263f60026fcbfdd86ac9a0e8790068814daf49a 100644 (file)
@@ -2,3 +2,4 @@ Makefile
 Makefile.in
 *.o
 afp.conf
+dbus-session.conf
\ No newline at end of file
index 4763046063a2ce5cd491e74dd8f0c46a831fa96c..61737f7bcdd18387264457c2b1c0aaf0c91e19af 100644 (file)
@@ -3,8 +3,8 @@
 SUBDIRS = pam
 SUFFIXES = .tmpl .
 
-TMPLFILES = afp.conf.tmpl
-GENFILES = afp.conf
+TMPLFILES = afp.conf.tmpl dbus-session.conf.tmpl
+GENFILES = afp.conf dbus-session.conf
 CLEANFILES = $(GENFILES)
 EXTRA_DIST = afp.conf.tmpl
 
diff --git a/config/dbus-session.conf.tmpl b/config/dbus-session.conf.tmpl
new file mode 100644 (file)
index 0000000..aa132fd
--- /dev/null
@@ -0,0 +1,61 @@
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+<busconfig>
+  <!-- Our well-known bus type, don't change this -->
+  <type>session</type>
+
+  <!-- If we fork, keep the user's original umask to avoid affecting
+       the behavior of child processes. -->
+  <keep_umask/>
+
+  <listen>unix:path=/tmp/spotlight.ipc</listen>
+  <allow_anonymous />
+
+  <standard_session_servicedirs />
+
+  <policy context="default">
+    <!-- Allow everything to be sent -->
+    <allow send_destination="*" eavesdrop="true"/>
+    <!-- Allow everything to be received -->
+    <allow eavesdrop="true"/>
+    <!-- Allow anyone to own anything -->
+    <allow own="*"/>
+  </policy>
+
+  <!-- raise the service start timeout to 40 seconds as it can timeout
+       on the live cd on slow machines -->
+  <limit name="service_start_timeout">60000</limit>
+
+  <!-- Config files are placed here that among other things, 
+       further restrict the above policy for specific services. -->
+  <includedir>/etc/dbus-1/session.d</includedir>
+
+  <!-- This is included last so local configuration can override what's 
+       in this standard file -->
+  <include ignore_missing="yes">session-local.conf</include>
+
+  <include if_selinux_enabled="yes" selinux_root_relative="yes">contexts/dbus_contexts</include>
+
+  <!-- For the session bus, override the default relatively-low limits 
+       with essentially infinite limits, since the bus is just running 
+       as the user anyway, using up bus resources is not something we need 
+       to worry about. In some cases, we do set the limits lower than 
+       "all available memory" if exceeding the limit is almost certainly a bug, 
+       having the bus enforce a limit is nicer than a huge memory leak. But the 
+       intent is that these limits should never be hit. -->
+
+  <!-- the memory limits are 1G instead of say 4G because they can't exceed 32-bit signed int max -->
+  <limit name="max_incoming_bytes">1000000000</limit>
+  <limit name="max_outgoing_bytes">1000000000</limit>
+  <limit name="max_message_size">1000000000</limit>
+  <limit name="service_start_timeout">120000</limit>  
+  <limit name="auth_timeout">240000</limit>
+  <limit name="max_completed_connections">100000</limit>  
+  <limit name="max_incomplete_connections">10000</limit>
+  <limit name="max_connections_per_user">100000</limit>
+  <limit name="max_pending_service_starts">10000</limit>
+  <limit name="max_names_per_connection">50000</limit>
+  <limit name="max_match_rules_per_connection">50000</limit>
+  <limit name="max_replies_per_connection">50000</limit>
+
+</busconfig>
index b35d264c81819787dbd2197d7f5de21bb640926a..427619058a7d036664a7590d566cf073289fb53c 100644 (file)
@@ -45,11 +45,12 @@ static void kill_childs(int sig, ...);
 /* static variables */
 static AFPObj obj;
 static sig_atomic_t got_chldsig;
-static pid_t afpd_pid = -1,  cnid_metad_pid = -1;
-static uint afpd_restarts, cnid_metad_restarts;
+static pid_t afpd_pid = -1,  cnid_metad_pid = -1, dbus_pid = -1;
+static uint afpd_restarts, cnid_metad_restarts, dbus_restarts;
 static struct event_base *base;
 struct event *sigterm_ev, *sigquit_ev, *sigchld_ev, *timer_ev;
 static int in_shutdown;
+static const char *dbus_path;
 
 /******************************************************************
  * libevent helper functions
@@ -106,14 +107,16 @@ static void sigterm_cb(evutil_socket_t fd, short what, void *arg)
     event_del(sigquit_ev);
     event_del(timer_ev);
 
-    kill_childs(SIGTERM, &afpd_pid, &cnid_metad_pid, NULL);
+    system("tracker-control -t");
+    kill_childs(SIGTERM, &afpd_pid, &cnid_metad_pid, &dbus_pid, NULL);
 }
 
 /* SIGQUIT callback */
 static void sigquit_cb(evutil_socket_t fd, short what, void *arg)
 {
     LOG(log_note, logtype_afpd, "Exiting on SIGQUIT");
-    kill_childs(SIGQUIT, &afpd_pid, &cnid_metad_pid, NULL);
+    system("tracker-control -t");
+    kill_childs(SIGQUIT, &afpd_pid, &cnid_metad_pid, &dbus_pid, NULL);
 }
 
 /* SIGCHLD callback */
@@ -122,30 +125,30 @@ static void sigchld_cb(evutil_socket_t fd, short what, void *arg)
     int status, i;
     pid_t pid;
 
-    LOG(log_debug, logtype_afpd, "Got SIGCHLD event");
-  
     while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
         if (WIFEXITED(status)) {
             if (WEXITSTATUS(status))
-                LOG(log_info, logtype_afpd, "child[%d]: exited %d", pid, WEXITSTATUS(status));
+                LOG(log_info, logtype_default, "child[%d]: exited %d", pid, WEXITSTATUS(status));
             else
-                LOG(log_info, logtype_afpd, "child[%d]: done", pid);
+                LOG(log_info, logtype_default, "child[%d]: done", pid);
         } else {
             if (WIFSIGNALED(status))
-                LOG(log_info, logtype_afpd, "child[%d]: killed by signal %d", pid, WTERMSIG(status));
+                LOG(log_info, logtype_default, "child[%d]: killed by signal %d", pid, WTERMSIG(status));
             else
-                LOG(log_info, logtype_afpd, "child[%d]: died", pid);
+                LOG(log_info, logtype_default, "child[%d]: died", pid);
         }
 
         if (pid == afpd_pid)
             afpd_pid = -1;
-        else if (pid = cnid_metad_pid)
+        else if (pid == cnid_metad_pid)
             cnid_metad_pid = -1;
+        else if (pid == dbus_pid)
+            dbus_pid = -1;
         else
             LOG(log_error, logtype_afpd, "Bad pid: %d", pid);
     }
 
-    if (in_shutdown && afpd_pid == -1 && cnid_metad_pid == -1)
+    if (in_shutdown && afpd_pid == -1 && cnid_metad_pid == -1 && dbus_pid == -1)
         event_base_loopbreak(base);
 }
 
@@ -161,7 +164,7 @@ static void timer_cb(evutil_socket_t fd, short what, void *arg)
         afpd_restarts++;
         LOG(log_note, logtype_afpd, "Restarting 'afpd' (restarts: %u)", afpd_restarts);
         if ((afpd_pid = run_process(_PATH_AFPD, "-d", "-F", obj.options.configfile, NULL)) == -1) {
-            LOG(log_error, logtype_afpd, "Error starting 'afpd'");
+            LOG(log_error, logtype_default, "Error starting 'afpd'");
         }
     }
 
@@ -169,7 +172,15 @@ static void timer_cb(evutil_socket_t fd, short what, void *arg)
         cnid_metad_restarts++;
         LOG(log_note, logtype_afpd, "Restarting 'cnid_metad' (restarts: %u)", cnid_metad_restarts);
         if ((cnid_metad_pid = run_process(_PATH_CNID_METAD, "-d", "-F", obj.options.configfile, NULL)) == -1) {
-            LOG(log_error, logtype_afpd, "Error starting 'cnid_metad'");
+            LOG(log_error, logtype_default, "Error starting 'cnid_metad'");
+        }
+    }
+
+    if (dbus_pid == -1) {
+        dbus_restarts++;
+        LOG(log_note, logtype_afpd, "Restarting 'dbus' (restarts: %u)", dbus_restarts);
+        if ((dbus_pid = run_process(dbus_path, "--config-file=" _PATH_CONFDIR "dbus.session.conf", NULL)) == -1) {
+            LOG(log_error, logtype_default, "Error starting '%s'", dbus_path);
         }
     }
 }
@@ -289,6 +300,16 @@ int main(int argc, char **argv)
         netatalk_exit(EXITERR_CONF);
     }
 
+    dbus_path = iniparser_getstring(obj.iniconfig, INISEC_GLOBAL, "dbus path", "/bin/dbus-daemon");
+    LOG(log_debug, logtype_default, "DBUS: '%s'", dbus_path);
+    if ((dbus_pid = run_process(dbus_path, "--config-file=" _PATH_CONFDIR "dbus-session.conf", NULL)) == -1) {
+        LOG(log_error, logtype_default, "Error starting '%s'", dbus_path);
+        netatalk_exit(EXITERR_CONF);
+    }
+
+    setenv("DBUS_SESSION_BUS_ADDRESS", "unix:path=/tmp/spotlight.ipc", 1);
+    system("tracker-control -s");
+
     if ((base = event_base_new()) == NULL) {
         LOG(log_error, logtype_afpd, "Error starting event loop");
         netatalk_exit(EXITERR_CONF);
@@ -321,7 +342,9 @@ int main(int argc, char **argv)
             LOG(log_error, logtype_afpd, "AFP service did not shutdown, killing it");
         if (cnid_metad_pid != -1)
             LOG(log_error, logtype_afpd, "CNID database service did not shutdown, killing it");
-        kill_childs(SIGKILL, &afpd_pid, &cnid_metad_pid, NULL);
+        if (dbus_pid != -1)
+            LOG(log_error, logtype_afpd, "DBUS session daemon still running, killing it");
+        kill_childs(SIGKILL, &afpd_pid, &cnid_metad_pid, &dbus_pid, NULL);
     }
 
     LOG(log_note, logtype_afpd, "Netatalk AFP server exiting");