Lines Matching refs:proc
160 modify(Proc_t* proc, int forked, int op, long arg1, long arg2)
247 m->next = proc->mods;
248 proc->mods = m;
300 proc->pgrp = arg1;
307 proc->mods = m->next;
311 proc->mods = m->next;
315 NoP(proc);
327 restore(Proc_t* proc)
333 NoP(proc);
335 m = proc->mods;
336 proc->mods = 0;
389 * fork and exec or spawn proc(argv) and return a Proc_t handle
402 register Proc_t* proc = 0;
463 proc = &proc_default;
464 else if (!(proc = newof(0, Proc_t, 1, 0)))
466 proc->pid = -1;
467 proc->pgrp = 0;
468 proc->rfd = -1;
469 proc->wfd = -1;
470 proc->flags = flags;
503 proc->pid = 0;
508 proc->pid = 0;
518 proc->sigint = signal(SIGINT, SIG_IGN);
519 proc->sigquit = signal(SIGQUIT, SIG_IGN);
524 sigprocmask(SIG_BLOCK, &mask, &proc->mask);
528 proc->mask = sigblock(mask);
530 proc->sigchld = signal(SIGCHLD, SIG_DFL);
537 proc->pid = fork();
540 else if (!proc->pid)
542 if (proc->sigint != SIG_IGN)
544 proc->sigint = SIG_DFL;
545 signal(SIGINT, proc->sigint);
547 if (proc->sigquit != SIG_IGN)
549 proc->sigquit = SIG_DFL;
550 signal(SIGQUIT, proc->sigquit);
554 sigprocmask(SIG_SETMASK, &proc->mask, NiL);
557 sigsetmask(proc->mask);
559 if (proc->sigchld != SIG_IGN)
565 else if (proc->pid == -1)
570 if (!proc->pid)
581 if (!(proc->pid = fork()))
588 if (proc->pid > 0)
589 write(pop[1], &proc->pid, sizeof(proc->pid));
612 modify(proc, forked, PROC_sig_ign, SIGHUP, 0);
614 modify(proc, forked, PROC_sig_dfl, SIGTERM, 0);
616 modify(proc, forked, PROC_sig_ign, SIGTSTP, 0);
619 modify(proc, forked, PROC_sig_ign, SIGTTIN, 0);
622 modify(proc, forked, PROC_sig_ign, SIGTTOU, 0);
627 modify(proc, forked, PROC_sig_ign, SIGINT, 0);
629 modify(proc, forked, PROC_sig_ign, SIGQUIT, 0);
633 modify(proc, forked, PROC_sys_pgrp, -1, 0);
648 if (modify(proc, forked, PROC_fd_dup|PROC_FD_CHILD, pio[0], PROC_ARG_NULL))
650 if (modify(proc, forked, PROC_fd_dup|PROC_FD_CHILD, pio[1], 1))
653 if (modify(proc, forked, PROC_fd_dup, 1, 0))
656 if (modify(proc, forked, PROC_fd_dup|PROC_FD_CHILD, poi[0], 0))
658 if (poi[1] != 0 && modify(proc, forked, PROC_fd_dup|PROC_FD_CHILD, poi[1], PROC_ARG_NULL))
664 if (modify(proc, forked, PROC_fd_dup|PROC_FD_CHILD, pio[!!procfd], !!procfd))
666 if (pio[!procfd] != !!procfd && modify(proc, forked, PROC_fd_dup|PROC_FD_CHILD, pio[!procfd], PROC_ARG_NULL))
677 if (modify(proc, forked, PROC_OP(n), PROC_ARG(n, 1), PROC_ARG(n, 2)))
681 if (modify(proc, forked, PROC_OP(n), PROC_ARG(n, 1), 0))
722 return proc;
747 else if ((proc->pid = spawnveg(path, p, environ, proc->pgrp)) != -1)
776 proc->pid = spawnveg(env + 2, p, environ, proc->pgrp);
798 restore(proc);
803 if (proc->pid != -1)
810 proc->sigint = signal(SIGINT, SIG_IGN);
811 proc->sigquit = signal(SIGQUIT, SIG_IGN);
816 sigprocmask(SIG_BLOCK, &mask, &proc->mask);
820 proc->mask = sigblock(mask);
822 proc->sigchld = signal(SIGCHLD, SIG_DFL);
837 if (proc->pgrp < 0)
838 proc->pgrp = proc->pid;
839 else if (proc->pgrp > 0)
841 if (proc->pgrp == 1)
842 proc->pgrp = proc->pid;
843 if (setpgid(proc->pid, proc->pgrp) < 0 && proc->pid != proc->pgrp && errno == EPERM)
844 setpgid(proc->pid, proc->pid);
862 proc->wfd = pio[1];
867 proc->wfd = pio[0];
869 proc->wfd = poi[1];
874 proc->rfd = pio[0];
878 if (proc->rfd > 2)
879 fcntl(proc->rfd, F_SETFD, FD_CLOEXEC);
880 if (proc->wfd > 2)
881 fcntl(proc->wfd, F_SETFD, FD_CLOEXEC);
883 if (!proc->pid)
884 proc->pid = getpid();
887 while (waitpid(proc->pid, &i, 0) == -1 && errno == EINTR);
888 if (read(pop[0], &proc->pid, sizeof(proc->pid)) != sizeof(proc->pid))
892 return proc;
897 if (proc->sigint != SIG_IGN)
898 signal(SIGINT, proc->sigint);
899 if (proc->sigquit != SIG_IGN)
900 signal(SIGQUIT, proc->sigquit);
903 sigprocmask(SIG_SETMASK, &proc->mask, NiL);
906 sigsetmask(proc->mask);
908 if (proc->sigchld != SIG_DFL)
909 signal(SIGCHLD, proc->sigchld);
940 procfree(proc);