Lines Matching refs:subproc
1797 subproc_finalize(subproc_t *subproc)
1800 for (i = 0; i < subproc->argc; i++) {
1801 if (subproc->argv[i] != NULL) {
1802 free(subproc->argv[i]);
1803 subproc->argv[i] = NULL;
1806 if (subproc->dispatch_source != NULL) {
1807 dispatch_release(subproc->dispatch_source);
1809 if (subproc->output_fd != NULL) {
1810 ioloop_file_descriptor_release(subproc->output_fd);
1812 if (subproc->finalize != NULL) {
1813 subproc->finalize(subproc->context);
1815 free(subproc);
1820 subproc_t *subproc = context;
1821 subproc->dispatch_source = NULL;
1822 RELEASE_HERE(subproc, subproc);
1828 subproc_t *subproc = context;
1832 pid = waitpid(subproc->pid, &status, WNOHANG);
1836 subproc->callback(subproc, status, NULL);
1838 dispatch_source_cancel(subproc->dispatch_source);
1845 subproc_t *subproc = context;
1846 RELEASE_HERE(subproc, subproc);
1850 ioloop_subproc_release_(subproc_t *subproc, const char *file, int line)
1852 RELEASE(subproc, subproc);
1861 subproc_t *subproc;
1872 callback(NULL, 0, "too many subproc args");
1876 subproc = calloc(1, sizeof *subproc);
1877 if (subproc == NULL) {
1881 RETAIN_HERE(subproc, subproc); // For the create rule
1883 rv = pipe(subproc->pipe_fds);
1886 RELEASE_HERE(subproc, subproc);
1889 subproc->output_fd = ioloop_file_descriptor_create(subproc->pipe_fds[0], subproc, subproc_output_finalize);
1890 RETAIN_HERE(subproc, subproc); // For the file descriptor
1891 if (subproc->output_fd == NULL) {
1893 close(subproc->pipe_fds[0]);
1894 close(subproc->pipe_fds[1]);
1895 RELEASE_HERE(subproc, subproc);
1900 subproc->argv[0] = strdup(exepath);
1901 if (subproc->argv[0] == NULL) {
1902 RELEASE_HERE(subproc, subproc);
1906 subproc->argc++;
1908 subproc->argv[i + 1] = strdup(argv[i]);
1909 if (subproc->argv[i + 1] == NULL) {
1910 RELEASE_HERE(subproc, subproc);
1914 subproc->argc++;
1920 posix_spawn_file_actions_adddup2(&actions, subproc->pipe_fds[1], STDOUT_FILENO);
1921 posix_spawn_file_actions_addclose(&actions, subproc->pipe_fds[0]);
1922 posix_spawn_file_actions_addclose(&actions, subproc->pipe_fds[1]);
1926 rv = posix_spawn(&subproc->pid, exepath, &actions, &attrs, subproc->argv, environ);
1930 ERROR("posix_spawn failed for " PUB_S_SRP ": " PUB_S_SRP, subproc->argv[0], strerror(errno));
1931 callback(subproc, 0, strerror(errno));
1932 RELEASE_HERE(subproc, subproc);
1935 subproc->callback = callback;
1936 subproc->context = context;
1938 subproc->dispatch_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_PROC, subproc->pid, DISPATCH_PROC_EXIT,
1940 if (subproc->dispatch_source == NULL) {
1944 dispatch_retain(subproc->dispatch_source);
1945 dispatch_source_set_event_handler_f(subproc->dispatch_source, subproc_event);
1946 dispatch_source_set_cancel_handler_f(subproc->dispatch_source, subproc_cancel);
1947 dispatch_set_context(subproc->dispatch_source, subproc);
1948 dispatch_activate(subproc->dispatch_source);
1949 RETAIN_HERE(subproc, subproc); // Dispatch has a reference
1952 if (output_callback != NULL && subproc->output_fd != NULL) {
1953 close(subproc->pipe_fds[1]);
1954 ioloop_add_reader(subproc->output_fd, output_callback);
1956 return subproc;