[pulseaudio-commits] r1670 - /branches/lennart/src/utils/pasuspender.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Wed Aug 15 14:03:54 PDT 2007


Author: lennart
Date: Wed Aug 15 23:03:53 2007
New Revision: 1670

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1670&root=3Dpulseaudio&vi=
ew=3Drev
Log:
don't fail if no pa is srunning

Modified:
    branches/lennart/src/utils/pasuspender.c

Modified: branches/lennart/src/utils/pasuspender.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/utils/pasu=
spender.c?rev=3D1670&root=3Dpulseaudio&r1=3D1669&r2=3D1670&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/utils/pasuspender.c (original)
+++ branches/lennart/src/utils/pasuspender.c Wed Aug 15 23:03:53 2007
@@ -77,6 +77,32 @@
         pa_operation_unref(o);
 }
 =

+static void start_child(void) {
+    =

+    if ((child_pid =3D fork()) < 0) {
+        =

+        fprintf(stderr, "fork(): %s\n", strerror(errno));
+        quit(1);
+        =

+    } else if (child_pid =3D=3D 0) {
+        /* Child */
+        =

+#ifdef __linux__
+        prctl(PR_SET_PDEATHSIG, SIGTERM, 0, 0, 0);
+#endif
+        =

+        if (execvp(child_argv[0], child_argv) < 0)
+            fprintf(stderr, "execvp(): %s\n", strerror(errno));
+        =

+        _exit(1);
+        =

+    } else {
+        =

+        /* parent */
+        dead =3D 0;
+    }
+}
+
 static void suspend_complete(pa_context *c, int success, void *userdata) {
     static int n =3D 0;
 =

@@ -85,33 +111,11 @@
     if (!success) {
         fprintf(stderr, "Failure to suspend: %s\n", pa_strerror(pa_context=
_errno(c)));
         quit(1);
-    }
-
-    if (n >=3D 2) {
-        =

-        if ((child_pid =3D fork()) < 0) {
-
-            fprintf(stderr, "fork(): %s\n", strerror(errno));
-            quit(1);
-            =

-        } else if (child_pid =3D=3D 0) {
-            /* Child */
-
-#ifdef __linux__
-            prctl(PR_SET_PDEATHSIG, SIGTERM, 0, 0, 0);
-#endif
-            =

-            if (execvp(child_argv[0], child_argv) < 0)
-                fprintf(stderr, "execvp(): %s\n", strerror(errno));
-
-            _exit(1);
-
-        } else {
-
-            /* parent */
-            dead =3D 0;
-        }
-    }
+        return;
+    }
+
+    if (n >=3D 2)
+        start_child();
 }
 =

 static void resume_complete(pa_context *c, int success, void *userdata) {
@@ -150,7 +154,18 @@
         case PA_CONTEXT_FAILED:
         default:
             fprintf(stderr, "Connection failure: %s\n", pa_strerror(pa_con=
text_errno(c)));
-            quit(1);
+
+            pa_context_unref(context);
+            context =3D NULL;
+
+            if (child_pid =3D=3D (pid_t) -1)
+                /* not started yet, then we do it now */
+                start_child();
+            else if (dead)
+                /* already started, and dead, so let's quit */
+                quit(1);
+
+            break;
     }
 }
 =

@@ -177,8 +192,13 @@
         child_ret =3D 1;
     }
 =

-    pa_operation_unref(pa_context_suspend_sink_by_index(context, PA_INVALI=
D_INDEX, 0, resume_complete, NULL));
-    pa_operation_unref(pa_context_suspend_source_by_index(context, PA_INVA=
LID_INDEX, 0, resume_complete, NULL));
+    if (context) {
+        /* A context is around, so let's resume */
+        pa_operation_unref(pa_context_suspend_sink_by_index(context, PA_IN=
VALID_INDEX, 0, resume_complete, NULL));
+        pa_operation_unref(pa_context_suspend_source_by_index(context, PA_=
INVALID_INDEX, 0, resume_complete, NULL));
+    } else
+        /* Hmm, no context here, so let's terminate right away */
+        quit(0);
 }
 =

 static void help(const char *argv0) {
@@ -261,7 +281,7 @@
     }
 =

     pa_context_set_state_callback(context, context_state_callback, NULL);
-    pa_context_connect(context, server, 0, NULL);
+    pa_context_connect(context, server, PA_CONTEXT_NOAUTOSPAWN, NULL);
 =

     if (pa_mainloop_run(m, &ret) < 0) {
         fprintf(stderr, "pa_mainloop_run() failed.\n");




More information about the pulseaudio-commits mailing list