Lines Matching +full:- +full:- +full:pid

21 #include "capsicum-test.h"
25 // see and reap any specific pid. Define this to nothing for platforms
30 //------------------------------------------------
38 pid_t pid = -1; in pdwait4_()
39 int rc = pdgetpid(pd, &pid); in pdwait4_()
44 return wait4(pid, status, options, ru); in pdwait4_()
49 fprintf(f, " User CPU time=%ld.%06ld\n", (long)ru->ru_utime.tv_sec, (long)ru->ru_utime.tv_usec); in print_rusage()
50 …fprintf(f, " System CPU time=%ld.%06ld\n", (long)ru->ru_stime.tv_sec, (long)ru->ru_stime.tv_usec); in print_rusage()
51 fprintf(f, " Max RSS=%ld\n", ru->ru_maxrss); in print_rusage()
62 (long)stat->st_dev, (long)stat->st_ino, stat->st_mode, in print_stat()
63 (long)stat->st_nlink, stat->st_uid, stat->st_gid, in print_stat()
64 (long)stat->st_rdev, (long)stat->st_size, (long)stat->st_blksize, in print_stat()
65 (long)stat->st_blocks, in print_stat()
67 (long)stat->st_birthtime, in print_stat()
69 (long)stat->st_atime, (long)stat->st_mtime, (long)stat->st_ctime); in print_stat()
81 void CheckChildFinished(pid_t pid, bool signaled=false) { in CheckChildFinished() argument
86 rc = waitpid(pid, &status, __WALL); in CheckChildFinished()
91 } else if (rc == pid) { in CheckChildFinished()
95 EXPECT_EQ(pid, rc); in CheckChildFinished()
96 if (rc == pid) { in CheckChildFinished()
106 //------------------------------------------------
110 int pd = -1; in TEST()
114 int pid = pdfork(&pd, 0); in TEST() local
115 EXPECT_OK(pid); in TEST()
116 if (pid == 0) { in TEST()
117 // Child: check pid values. in TEST()
118 EXPECT_EQ(-1, pd); in TEST()
132 EXPECT_NE(-1, pd); in TEST()
133 EXPECT_PID_ALIVE(pid); in TEST()
136 EXPECT_EQ(pid, pid_got); in TEST()
142 EXPECT_PID_ZOMBIE(pid); in TEST()
150 EXPECT_EQ(pid, waitrc); in TEST()
152 fprintf(stderr, "For pd %d pid %d:\n", pd, pid); in TEST()
155 EXPECT_PID_GONE(pid); in TEST()
159 EXPECT_EQ(-1, pdwait4_(pd, &status, 0, &ru)); in TEST()
166 int pd = -1; in TEST()
167 int pid = pdfork(&pd, PD_DAEMON<<5); in TEST() local
168 if (pid == 0) { in TEST()
171 EXPECT_EQ(-1, pid); in TEST()
173 if (pid > 0) waitpid(pid, NULL, __WALL); in TEST()
178 EXPECT_NE(-1, now); in TEST()
181 int pd = -1; in TEST()
182 pid_t pid = pdfork(&pd, 0); in TEST() local
183 EXPECT_OK(pid); in TEST()
184 if (pid == 0) { in TEST()
186 EXPECT_EQ(-1, pdgetpid(pd, &pid)); in TEST()
202 EXPECT_LT((now - stat.st_atime), 2); in TEST()
208 pid_t pd_pid = -1; in TEST()
210 EXPECT_EQ(pid, pd_pid); in TEST()
211 CheckChildFinished(pid); in TEST()
215 int pd = -1; in TEST()
216 pid_t pid = pdfork(&pd, 0); in TEST() local
217 EXPECT_OK(pid); in TEST()
218 if (pid == 0) { in TEST()
222 CheckChildFinished(pid); in TEST()
228 // pd*() operations should fail on a non-process descriptor. in TEST()
229 EXPECT_EQ(-1, pdkill(fd, SIGUSR1)); in TEST()
231 EXPECT_EQ(-1, pdwait4_(fd, &status, 0, NULL)); in TEST()
232 pid_t pid; in TEST() local
233 EXPECT_EQ(-1, pdgetpid(fd, &pid)); in TEST()
297 pid_t pid; in TEST() local
298 EXPECT_OK(pdgetpid(pd, &pid)); in TEST()
301 EXPECT_EQ(pid, pdwait4_(pd, &status, 0, NULL)); in TEST()
305 //------------------------------------------------
313 PipePdforkBase(int pdfork_flags) : pd_(-1), pid_(-1) { in PipePdforkBase()
323 // Child process: blocking-read an int from the pipe then exit with that value. in PipePdforkBase()
417 // pid A: main process, here in TEST_F()
418 // |--pid B: pdfork()ed process, blocked on read() in TEST_F()
419 // |--pid C: fork()ed process, in read() above in TEST_F()
420 // +--pid D: doppel process, here in TEST_F()
437 // - pid C will finish its two read() calls, write to the pipe and exit. in TEST_F()
438 // - pid B will unblock from read(), and exit in TEST_F()
439 // - this will generate an event on the process descriptor... in TEST_F()
440 // - ...in both process A and process D. in TEST_F()
472 fprintf(stderr, "For pd %d -> pid %d:\n", pd_, pid_); in TEST_F()
508 // ...and the underlying pid in TEST_F()
510 sprintf(pidline, "pid:\t%d", pid_); in TEST_F()
524 pd_ = -1; in TEST_F()
529 EXPECT_EQ(-1, waitpid(pid_, NULL, __WALL)); in TEST_F()
534 EXPECT_EQ(-1, rc); in TEST_F()
537 // Closing all process descriptors means the the child can only be reaped via pid. in TEST_F()
550 pd_ = -1; in TEST_F()
557 EXPECT_EQ(-1, pdwait4_(pd_, &status, WNOHANG, NULL)); in TEST_F()
559 // ...but can pdwait4() the still-open process descriptor. in TEST_F()
575 pid_t pid = pdfork(&pd, 0); in FORK_TEST() local
576 EXPECT_OK(pid); in FORK_TEST()
577 if (pid == 0) { in FORK_TEST()
585 "please pass the -u <uid> flag."; in FORK_TEST()
590 // Fail to kill child with normal PID operation. in FORK_TEST()
591 EXPECT_EQ(-1, kill(pid, SIGKILL)); in FORK_TEST()
593 EXPECT_PID_ALIVE(pid); in FORK_TEST()
601 EXPECT_SYSCALL_FAIL(EBADF, pdkill(pid, SIGKILL)); in FORK_TEST()
602 EXPECT_PID_ALIVE(pid); in FORK_TEST()
605 EXPECT_PID_GONE(pid); in FORK_TEST()
611 EXPECT_PID_ZOMBIE(pid); in FORK_TEST()
615 EXPECT_EQ(pid, rc); in FORK_TEST()
623 // If we waitpid(pid) first... in TEST_F()
642 // ...the zombie is reaped and cannot subsequently waitpid(pid). in TEST_F()
643 EXPECT_EQ(-1, waitpid(pid_, &status, __WALL)); in TEST_F()
650 pd_ = -1; in TEST_F()
653 // Can still explicitly kill it via the pid. in TEST_F()
660 static void TestPdkill(pid_t pid, int pd) { in TestPdkill() argument
661 EXPECT_PID_ALIVE(pid); in TestPdkill()
664 EXPECT_PID_ALIVE(pid); in TestPdkill()
668 EXPECT_PID_DEAD(pid); in TestPdkill()
670 // pdkill() on zombie is no-op. in TestPdkill()
675 // pdkill() on reaped process gives -ESRCH. in TestPdkill()
676 CheckChildFinished(pid, true); in TestPdkill()
677 EXPECT_EQ(-1, pdkill(pd, SIGINT)); in TestPdkill()
690 int pd = -1; in TEST()
693 int pid = pdfork(&pd, 0); in TEST() local
694 EXPECT_OK(pid); in TEST()
695 if (pid == 0) { in TEST()
714 EXPECT_EQ(-1, pdkill(pd, 0xFFFF)); in TEST()
718 EXPECT_PID_ALIVE(pid); in TEST()
720 EXPECT_PID_DEAD(pid); in TEST()
724 int rc = waitpid(pid, &status, __WALL); in TEST()
726 EXPECT_EQ(pid, rc); in TEST()
733 // pid A: main process, here in PdforkParentDeath()
734 // +--pid B: fork()ed process, starts a child process with pdfork() then in PdforkParentDeath()
736 // +--pid C: pdfork()ed process, looping forever in PdforkParentDeath()
762 EXPECT_EQ(grandchild, grandchild2) << "received invalid grandchild pid"; in PdforkParentDeath()
766 // Send grandchild pid to parent. in PdforkParentDeath()
768 … if (verbose) fprintf(stderr, " [%d] sent grandchild pid %d to parent\n", getpid_(), grandchild); in PdforkParentDeath()
771 …if (verbose) fprintf(stderr, " [%d] parent acknowledged grandchild pid %d\n", getpid_(), grandchi… in PdforkParentDeath()
812 // Can waitpid() for the specific pid of the pdfork()ed child. in TEST_F()
829 EXPECT_EQ(-1, waitpid(pid_, NULL, __WALL)); in TEST_F()
833 // Can waitpid() for the specific pid of the pdfork()ed child. in TEST_F()
864 // Wildcard waitpid(-1) should not see the pdfork()ed child because in TEST_F()
867 EXPECT_EQ(-1, waitpid(-1, &rc, WNOHANG)); in TEST_F()
871 pd_ = -1; in TEST_F()
879 pid_t pid = pdfork(&pd, 0); in FORK_TEST() local
880 EXPECT_OK(pid); in FORK_TEST()
882 if (pid == 0) { in FORK_TEST()
897 // Return non-zero if we didn't see SIGINT. in FORK_TEST()
901 // Parent: get child's PID. in FORK_TEST()
904 EXPECT_EQ(pid, pd_pid); in FORK_TEST()
914 CheckChildFinished(pid); in FORK_TEST()
921 pid_t pid = pdfork(&pd, 0); in FORK_TEST() local
922 EXPECT_OK(pid); in FORK_TEST()
924 if (pid == 0) { in FORK_TEST()
944 CheckChildFinished(pid, true); in FORK_TEST()
947 //------------------------------------------------
949 // - capability mode
950 // - capabilities
975 int pd = -1; in TEST()
976 pid_t pid = pdfork(&pd, 0); in TEST() local
977 EXPECT_OK(pid); in TEST()
978 if (pid == 0) { in TEST()
1002 EXPECT_EQ(pid, other_pid); in TEST()
1006 EXPECT_EQ(pid, rc); in TEST()
1010 //------------------------------------------------
1044 EXPECT_EQ(CMSG_LEN(sizeof(int)), cmptr->cmsg_len); in TEST_F()
1053 if (verbose) fprintf(stderr, " [%d] process descriptor %d is pid %d\n", getpid_(), pd, other); in TEST_F()
1069 // Send the process descriptor over the pipe to the sub-process in TEST_F()
1072 cmptr->cmsg_level = SOL_SOCKET; in TEST_F()
1073 cmptr->cmsg_type = SCM_RIGHTS; in TEST_F()
1074 cmptr->cmsg_len = CMSG_LEN(sizeof(int)); in TEST_F()
1091 rc = WIFEXITED(status) ? WEXITSTATUS(status) : -1; in TEST_F()