don't fail if no pa is srunning

git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1670 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
Lennart Poettering 2007-08-15 21:03:53 +00:00
parent a96c5f8137
commit 1ff47862c4

View file

@ -77,17 +77,7 @@ static void drain(void) {
pa_operation_unref(o); pa_operation_unref(o);
} }
static void suspend_complete(pa_context *c, int success, void *userdata) { static void start_child(void) {
static int n = 0;
n++;
if (!success) {
fprintf(stderr, "Failure to suspend: %s\n", pa_strerror(pa_context_errno(c)));
quit(1);
}
if (n >= 2) {
if ((child_pid = fork()) < 0) { if ((child_pid = fork()) < 0) {
@ -111,7 +101,21 @@ static void suspend_complete(pa_context *c, int success, void *userdata) {
/* parent */ /* parent */
dead = 0; dead = 0;
} }
}
static void suspend_complete(pa_context *c, int success, void *userdata) {
static int n = 0;
n++;
if (!success) {
fprintf(stderr, "Failure to suspend: %s\n", pa_strerror(pa_context_errno(c)));
quit(1);
return;
} }
if (n >= 2)
start_child();
} }
static void resume_complete(pa_context *c, int success, void *userdata) { static void resume_complete(pa_context *c, int success, void *userdata) {
@ -150,7 +154,18 @@ static void context_state_callback(pa_context *c, void *userdata) {
case PA_CONTEXT_FAILED: case PA_CONTEXT_FAILED:
default: default:
fprintf(stderr, "Connection failure: %s\n", pa_strerror(pa_context_errno(c))); fprintf(stderr, "Connection failure: %s\n", pa_strerror(pa_context_errno(c)));
pa_context_unref(context);
context = NULL;
if (child_pid == (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); quit(1);
break;
} }
} }
@ -177,8 +192,13 @@ static void sigchld_callback(pa_mainloop_api *m, pa_signal_event *e, int sig, vo
child_ret = 1; child_ret = 1;
} }
if (context) {
/* A context is around, so let's resume */
pa_operation_unref(pa_context_suspend_sink_by_index(context, PA_INVALID_INDEX, 0, resume_complete, NULL)); pa_operation_unref(pa_context_suspend_sink_by_index(context, PA_INVALID_INDEX, 0, resume_complete, NULL));
pa_operation_unref(pa_context_suspend_source_by_index(context, PA_INVALID_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) { static void help(const char *argv0) {
@ -261,7 +281,7 @@ int main(int argc, char *argv[]) {
} }
pa_context_set_state_callback(context, context_state_callback, NULL); 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) { if (pa_mainloop_run(m, &ret) < 0) {
fprintf(stderr, "pa_mainloop_run() failed.\n"); fprintf(stderr, "pa_mainloop_run() failed.\n");