[pulseaudio-commits] r2513 - in /trunk: man/pulseaudio.1.xml.in src/daemon/cmdline.c src/daemon/daemon-conf.h src/daemon/main.c src/pulsecore/pid.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Wed Jun 11 10:38:54 PDT 2008


Author: lennart
Date: Wed Jun 11 19:38:50 2008
New Revision: 2513

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=2513&root=pulseaudio&view=rev
Log:
add new switch --start to the PA binary which allows starting PA if it is not running yet. In contrast to normal startup an already running PA will not be considered an error. Also, take the autospawn lock so we can guarantee that after this call returns PA is ralive and running

Modified:
    trunk/man/pulseaudio.1.xml.in
    trunk/src/daemon/cmdline.c
    trunk/src/daemon/daemon-conf.h
    trunk/src/daemon/main.c
    trunk/src/pulsecore/pid.c

Modified: trunk/man/pulseaudio.1.xml.in
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/man/pulseaudio.1.xml.in?rev=2513&root=pulseaudio&r1=2512&r2=2513&view=diff
==============================================================================
--- trunk/man/pulseaudio.1.xml.in (original)
+++ trunk/man/pulseaudio.1.xml.in Wed Jun 11 19:38:50 2008
@@ -33,6 +33,7 @@
     <cmd>pulseaudio <opt>--dump-modules</opt></cmd>
     <cmd>pulseaudio <opt>--dump-resample-methods</opt></cmd>
     <cmd>pulseaudio <opt>--cleanup-shm</opt></cmd>
+    <cmd>pulseaudio <opt>--start</opt></cmd>
     <cmd>pulseaudio <opt>--kill</opt></cmd>
     <cmd>pulseaudio <opt>--check</opt></cmd>
   </synopsis>
@@ -88,6 +89,16 @@
       on systems with POSIX shared memory segments implemented via a
       virtual file system mounted to <file>/dev/shm</file>
       (e.g. Linux).</p></optdesc>
+    </option>
+
+    <option>
+      <p><opt>--start</opt></p>
+
+      <optdesc><p>Start PulseAudio if it is not running yet. This is
+      different from starting PulseAudio without <opt>--start</opt>
+      which would fail if PA is already running. PulseAudio is
+      guaranteed to be fully initialized when this call
+      returns. Implies <opt>--daemon</p>.</optdesc>
     </option>
 
     <option>

Modified: trunk/src/daemon/cmdline.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/daemon/cmdline.c?rev=2513&root=pulseaudio&r1=2512&r2=2513&view=diff
==============================================================================
--- trunk/src/daemon/cmdline.c (original)
+++ trunk/src/daemon/cmdline.c Wed Jun 11 19:38:50 2008
@@ -66,7 +66,8 @@
     ARG_DISABLE_SHM,
     ARG_DUMP_RESAMPLE_METHODS,
     ARG_SYSTEM,
-    ARG_CLEANUP_SHM
+    ARG_CLEANUP_SHM,
+    ARG_START
 };
 
 /* Tabel for getopt_long() */
@@ -91,6 +92,7 @@
     {"dl-search-path",              1, 0, ARG_DL_SEARCH_PATH},
     {"resample-method",             1, 0, ARG_RESAMPLE_METHOD},
     {"kill",                        0, 0, ARG_KILL},
+    {"start",                       0, 0, ARG_START},
     {"use-pid-file",                2, 0, ARG_USE_PID_FILE},
     {"check",                       0, 0, ARG_CHECK},
     {"system",                      2, 0, ARG_SYSTEM},
@@ -119,6 +121,7 @@
            "      --dump-modules                    Dump list of available modules\n"
            "      --dump-resample-methods           Dump available resample methods\n"
            "      --cleanup-shm                     Cleanup stale shared memory segments\n"
+           "      --start                           Start the daemon if it is not running\n"
            "  -k  --kill                            Kill a running daemon\n"
            "      --check                           Check for a running daemon\n\n"
 
@@ -207,6 +210,11 @@
                 conf->cmd = PA_CMD_KILL;
                 break;
 
+            case ARG_START:
+                conf->cmd = PA_CMD_START;
+                conf->daemonize = TRUE;
+                break;
+
             case ARG_CHECK:
                 conf->cmd = PA_CMD_CHECK;
                 break;

Modified: trunk/src/daemon/daemon-conf.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/daemon/daemon-conf.h?rev=2513&root=pulseaudio&r1=2512&r2=2513&view=diff
==============================================================================
--- trunk/src/daemon/daemon-conf.h (original)
+++ trunk/src/daemon/daemon-conf.h Wed Jun 11 19:38:50 2008
@@ -37,6 +37,7 @@
 /* The actual command to execute */
 typedef enum pa_daemon_conf_cmd {
     PA_CMD_DAEMON,  /* the default */
+    PA_CMD_START,
     PA_CMD_HELP,
     PA_CMD_VERSION,
     PA_CMD_DUMP_CONF,

Modified: trunk/src/daemon/main.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/daemon/main.c?rev=2513&root=pulseaudio&r1=2512&r2=2513&view=diff
==============================================================================
--- trunk/src/daemon/main.c (original)
+++ trunk/src/daemon/main.c Wed Jun 11 19:38:50 2008
@@ -96,6 +96,8 @@
 #include "ltdl-bind-now.h"
 #include "polkit.h"
 
+#define AUTOSPAWN_LOCK "autospawn.lock"
+
 #ifdef HAVE_LIBWRAP
 /* Only one instance of these variables */
 int allow_severity = LOG_INFO;
@@ -344,6 +346,8 @@
     pa_time_event *win32_timer;
     struct timeval win32_tv;
 #endif
+    char *lf = NULL;
+    int autospawn_lock_fd = -1;
 
 #if defined(__linux__) && defined(__OPTIMIZE__)
     /*
@@ -486,13 +490,13 @@
     if (conf->high_priority && !pa_can_high_priority())
         pa_log_warn("High-priority scheduling enabled in configuration but not allowed by policy.");
 
-    if (conf->high_priority && conf->cmd == PA_CMD_DAEMON)
+    if (conf->high_priority && (conf->cmd == PA_CMD_DAEMON || conf->cmd == PA_CMD_START))
         pa_raise_priority(conf->nice_level);
 
     if (suid_root) {
         pa_bool_t drop;
 
-        drop = conf->cmd != PA_CMD_DAEMON || !conf->realtime_scheduling;
+        drop = (conf->cmd != PA_CMD_DAEMON && conf->cmd != PA_CMD_START) || !conf->realtime_scheduling;
 
 #ifdef RLIMIT_RTPRIO
         if (!drop) {
@@ -608,7 +612,7 @@
             goto finish;
 
         default:
-            pa_assert(conf->cmd == PA_CMD_DAEMON);
+            pa_assert(conf->cmd == PA_CMD_DAEMON || conf->cmd == PA_CMD_START);
     }
 
     if (real_root && !conf->system_instance)
@@ -618,6 +622,15 @@
         goto finish;
     }
 
+    if (conf->cmd == PA_CMD_START) {
+        /* If we shall start PA only when it is not running yet, we
+         * first take the autospawn lock to make things
+         * synchronous. */
+
+        lf = pa_runtime_path(AUTOSPAWN_LOCK);
+        autospawn_lock_fd = pa_lock_lockfile(lf);
+    }
+
     if (conf->daemonize) {
         pid_t child;
         int tty_fd;
@@ -659,6 +672,14 @@
                 pa_log_info("Daemon startup successful.");
 
             goto finish;
+        }
+
+        if (autospawn_lock_fd >= 0) {
+            /* The lock file is unlocked from the parent, so we need
+             * to close it in the child */
+
+            pa_close(autospawn_lock_fd);
+            autospawn_lock_fd = -1;
         }
 
         pa_assert_se(pa_close(daemon_pipe[0]) == 0);
@@ -728,7 +749,20 @@
     pa_log_info("Running in system mode: %s", pa_yes_no(pa_in_system_mode()));
 
     if (conf->use_pid_file) {
-        if (pa_pid_file_create("pulseaudio") < 0) {
+        int z;
+
+        if ((z = pa_pid_file_create("pulseaudio")) != 0) {
+
+            if (conf->cmd == PA_CMD_START && z > 0) {
+                /* If we are already running and with are run in
+                 * --start mode, then let's return this as success. */
+
+                pa_log_info("z=%i rock!", z);
+
+                retval = 0;
+                goto finish;
+            }
+
             pa_log("pa_pid_file_create() failed.");
             goto finish;
         }
@@ -826,11 +860,12 @@
         goto finish;
     }
 
-
 #ifdef HAVE_FORK
-    if (conf->daemonize) {
+    if (daemon_pipe[1] >= 0) {
         int ok = 0;
         pa_loop_write(daemon_pipe[1], &ok, sizeof(ok), NULL);
+        pa_close(daemon_pipe[1]);
+        daemon_pipe[1] = -1;
     }
 #endif
 
@@ -844,6 +879,12 @@
 
 finish:
 
+    if (autospawn_lock_fd >= 0)
+        pa_unlock_lockfile(lf, autospawn_lock_fd);
+
+    if (lf)
+        pa_xfree(lf);
+
 #ifdef OS_IS_WIN32
     if (win32_timer)
         pa_mainloop_get_api(mainloop)->time_free(win32_timer);
@@ -860,6 +901,9 @@
     pa_signal_done();
 
 #ifdef HAVE_FORK
+    if (daemon_pipe[1] >= 0)
+        pa_loop_write(daemon_pipe[1], &retval, sizeof(retval), NULL);
+
     pa_close_pipe(daemon_pipe);
 #endif
 

Modified: trunk/src/pulsecore/pid.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/pid.c?rev=2513&root=pulseaudio&r1=2512&r2=2513&view=diff
==============================================================================
--- trunk/src/pulsecore/pid.c (original)
+++ trunk/src/pulsecore/pid.c Wed Jun 11 19:38:50 2008
@@ -220,6 +220,7 @@
 
             if (ours) {
                 pa_log("Daemon already running.");
+                ret = 1;
                 goto fail;
             }
         }




More information about the pulseaudio-commits mailing list