1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
pid_t pid;
pid_t sid;
int res = EXIT_FAILURE;
int start_pipe[2];
// Set a PASSWORD environment variable to test the search pattern
// within process memory pages using regex metacharacters.
if (setenv("PASSWORD", "123 Hello.*?[^]@WORLD(|x)", 1) != 0) {
perror("setenv");
return 1;
}
if (pipe(start_pipe)) {
perror("pipe failed!");
goto out;
}
pid = fork();
if (pid < 0) {
perror("fork failed!");
goto out;
}
if (pid == 0) {
close(start_pipe[0]);
sid = setsid();
if (sid < 0) {
perror("setsid failed!");
res = EXIT_FAILURE;
write(start_pipe[1], &res, sizeof(res));
close(start_pipe[1]);
exit(1);
}
// Create a file descriptor for "crit x ./ fd" test
open("/dev/null", O_RDONLY);
chdir("/");
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
res = EXIT_SUCCESS;
write(start_pipe[1], &res, sizeof(res));
close(start_pipe[1]);
while (1) {
sleep(1);
}
}
close(start_pipe[1]);
read(start_pipe[0], &res, sizeof(res));
close(start_pipe[0]);
out:
if (res == EXIT_SUCCESS)
printf("%d\n", pid);
return res;
}
|