Lines Matching full:process

59 #include <tests/tap/process.h>
67 /* How long to wait for the process to start in seconds. */
71 * Used to store information about a background process. This contains
72 * everything required to stop the process and clean up after it.
74 struct process { struct
75 pid_t pid; /* PID of child process */ argument
76 char *pidfile; /* PID file to delete on process stop */ argument
78 char *logfile; /* Log file of process output */ argument
79 bool is_child; /* Whether we can waitpid for process */ argument
80 struct process *next; /* Next process in global list */ argument
88 static struct process *processes = NULL;
95 * process exit status.
230 * Free the resources associated with tracking a process, without doing
231 * anything to the process. This is kept separate so that we can free
232 * resources during shutdown in a non-primary process.
235 process_free(struct process *process) in process_free() argument
237 struct process **prev; in process_free()
240 if (process == NULL) in process_free()
243 /* Remove the process from the global list. */ in process_free()
245 while (*prev != NULL && *prev != process) in process_free()
247 if (*prev == process) in process_free()
248 *prev = process->next; in process_free()
251 free(process->pidfile); in process_free()
252 free(process->logfile); in process_free()
253 test_tmpdir_free(process->tmpdir); in process_free()
254 free(process); in process_free()
259 * Kill a process and wait for it to exit. Returns the status of the process.
260 * Calls bail on a system failure or a failure of the process to exit.
267 process_kill(struct process *process) in process_kill() argument
272 unsigned long pid = process->pid; in process_kill()
274 /* If the process is not a child, just kill it and hope. */ in process_kill()
275 if (!process->is_child) { in process_kill()
276 if (kill(process->pid, SIGTERM) < 0 && errno != ESRCH) in process_kill()
277 sysbail("cannot send SIGTERM to process %lu", pid); in process_kill()
281 /* Check if the process has already exited. */ in process_kill()
282 result = waitpid(process->pid, &status, WNOHANG); in process_kill()
284 sysbail("cannot wait for child process %lu", pid); in process_kill()
289 * Kill the process and wait for it to exit. I don't want to go to the in process_kill()
291 * effectively poll every tenth of a second for process exit (and in process_kill()
295 if (kill(process->pid, SIGTERM) < 0 && errno != ESRCH) in process_kill()
296 sysbail("cannot send SIGTERM to child process %lu", pid); in process_kill()
301 result = waitpid(process->pid, &status, WNOHANG); in process_kill()
303 sysbail("cannot wait for child process %lu", pid); in process_kill()
308 /* The process still hasn't exited. Bail. */ in process_kill()
309 bail("child process %lu did not exit on SIGTERM", pid); in process_kill()
317 * Stop a particular process given its process struct. This kills the
318 * process, waits for it to exit if possible (giving it at most five seconds),
323 process_stop(struct process *process) in process_stop() argument
326 unsigned long pid = process->pid; in process_stop()
328 /* Stop the process. */ in process_stop()
329 status = process_kill(process); in process_stop()
332 if (process->is_child) in process_stop()
333 diag("stopped process %lu (exit status %d)", pid, status); in process_stop()
335 diag("stopped process %lu", pid); in process_stop()
338 diag_file_remove(process->logfile); in process_stop()
339 unlink(process->pidfile); in process_stop()
340 unlink(process->logfile); in process_stop()
343 process_free(process); in process_stop()
349 * process shutdown. The first argument, which says whether the test was
351 * regardless. The second argument says whether this is the primary process,
353 * but don't stop the process.
368 * Read the PID of a process from a file. This is necessary when running
369 * under fakeroot to get the actual PID of the remctld process.
392 * Start a process and return its status information. The status information
396 * The boolean argument says whether to start the process under fakeroot. If
402 static struct process *
410 struct process *process; in process_start_internal() local
418 /* Create the process struct and log file. */ in process_start_internal()
419 process = bcalloc(1, sizeof(struct process)); in process_start_internal()
420 process->pidfile = bstrdup(pidfile); in process_start_internal()
421 process->tmpdir = test_tmpdir(); in process_start_internal()
427 basprintf(&process->logfile, "%s/%s.log.XXXXXX", process->tmpdir, name); in process_start_internal()
428 log_fd = mkstemp(process->logfile); in process_start_internal()
446 * Fork off the child process, redirect its standard output and standard in process_start_internal()
449 process->pid = fork(); in process_start_internal()
450 if (process->pid < 0) in process_start_internal()
452 else if (process->pid == 0) { in process_start_internal()
476 * kill the process and then bail. in process_start_internal()
479 kill(process->pid, SIGTERM); in process_start_internal()
481 waitpid(process->pid, NULL, 0); in process_start_internal()
492 process->pid = read_pidfile(pidfile); in process_start_internal()
493 process->is_child = !fakeroot; in process_start_internal()
496 diag_file_add(process->logfile); in process_start_internal()
499 * Add the process to our global list and set our cleanup handler if this in process_start_internal()
500 * is the first process we started. in process_start_internal()
504 process->next = processes; in process_start_internal()
505 processes = process; in process_start_internal()
508 return process; in process_start_internal()
513 * Start a process and return the opaque process struct. The process must
516 struct process *
524 * Start a process under fakeroot and return the opaque process struct. If
525 * fakeroot is not available, calls skip_all. The process must create pidfile
528 struct process *