diff options
Diffstat (limited to 'polyp/polyplib-context.c')
-rw-r--r-- | polyp/polyplib-context.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/polyp/polyplib-context.c b/polyp/polyplib-context.c index a810bd98..caaa1dbb 100644 --- a/polyp/polyplib-context.c +++ b/polyp/polyplib-context.c @@ -571,9 +571,9 @@ static int is_running(void) { return 1; } -int pa_context_connect_spawn(struct pa_context *c, void (*atfork)(void)) { +int pa_context_connect_spawn(struct pa_context *c, void (*atfork)(void), void (*prefork)(void), void (*postfork)(void)) { pid_t pid; - int status; + int status, r; int fds[2] = { -1, -1} ; struct pa_iochannel *io; @@ -586,9 +586,16 @@ int pa_context_connect_spawn(struct pa_context *c, void (*atfork)(void)) { goto fail; } + if (prefork) + prefork(); + if ((pid = fork()) < 0) { pa_log(__FILE__": fork() failed: %s\n", strerror(errno)); pa_context_fail(c, PA_ERROR_INTERNAL); + + if (postfork) + postfork(); + goto fail; } else if (!pid) { char t[64]; @@ -610,7 +617,13 @@ int pa_context_connect_spawn(struct pa_context *c, void (*atfork)(void)) { } /* Parent */ - if (waitpid(pid, &status, 0) < 0) { + + r = waitpid(pid, &status, 0); + + if (postfork) + postfork(); + + if (r < 0) { pa_log(__FILE__": waitpid() failed: %s\n", strerror(errno)); pa_context_fail(c, PA_ERROR_INTERNAL); goto fail; |