2016-05-03 04:28:06 +00:00
|
|
|
// Functions that we may safely call after fork(), of which there are very few. In particular we
|
|
|
|
// cannot allocate memory, since we're insane enough to call fork from a multithreaded process.
|
2012-02-28 03:20:27 +00:00
|
|
|
#ifndef FISH_POSTFORK_H
|
|
|
|
#define FISH_POSTFORK_H
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2017-02-13 04:24:22 +00:00
|
|
|
#include <stddef.h>
|
2016-04-21 06:00:54 +00:00
|
|
|
#include <unistd.h>
|
2012-08-15 07:57:56 +00:00
|
|
|
#if HAVE_SPAWN_H
|
|
|
|
#include <spawn.h>
|
|
|
|
#endif
|
|
|
|
#ifndef FISH_USE_POSIX_SPAWN
|
2012-11-19 00:30:30 +00:00
|
|
|
#define FISH_USE_POSIX_SPAWN HAVE_SPAWN_H
|
2012-08-15 07:57:56 +00:00
|
|
|
#endif
|
|
|
|
|
2019-01-28 22:35:56 +00:00
|
|
|
class dup2_list_t;
|
2016-04-21 06:00:54 +00:00
|
|
|
class job_t;
|
|
|
|
class process_t;
|
2012-08-15 07:57:56 +00:00
|
|
|
|
2017-08-06 23:05:51 +00:00
|
|
|
bool set_child_group(job_t *j, pid_t child_pid); // called by parent
|
|
|
|
bool child_set_group(job_t *j, process_t *p); // called by child
|
2012-02-29 19:27:14 +00:00
|
|
|
|
2016-05-03 04:28:06 +00:00
|
|
|
/// Initialize a new child process. This should be called right away after forking in the child
|
|
|
|
/// process. If job control is enabled for this job, the process is put in the process group of the
|
|
|
|
/// job, all signal handlers are reset, signals are unblocked (this function may only be called
|
|
|
|
/// inside the exec function, which blocks all signals), and all IO redirections and other file
|
|
|
|
/// descriptor actions are performed.
|
|
|
|
///
|
2019-07-01 17:57:09 +00:00
|
|
|
/// Assign the terminal to new_termowner unless it is INVALID_PID.
|
|
|
|
///
|
2019-10-19 01:36:03 +00:00
|
|
|
/// \return 0 on success, -1 on failure. When this function returns, signals are always unblocked.
|
2019-07-01 17:57:09 +00:00
|
|
|
/// On failure, signal handlers, io redirections and process group of the process is undefined.
|
2020-04-21 17:24:33 +00:00
|
|
|
int child_setup_process(pid_t new_termowner, const job_t &job, bool is_forked,
|
|
|
|
const dup2_list_t &dup2s);
|
2012-02-28 03:20:27 +00:00
|
|
|
|
2019-11-23 20:36:44 +00:00
|
|
|
/// Call fork(), retrying on failure a few times.
|
|
|
|
pid_t execute_fork();
|
2012-02-28 23:11:46 +00:00
|
|
|
|
2016-05-03 04:28:06 +00:00
|
|
|
/// Report an error from failing to exec or posix_spawn a command.
|
|
|
|
void safe_report_exec_error(int err, const char *actual_cmd, const char *const *argv,
|
|
|
|
const char *const *envv);
|
2012-08-15 07:57:56 +00:00
|
|
|
|
2020-04-05 02:15:08 +00:00
|
|
|
#ifdef FISH_USE_POSIX_SPAWN
|
2016-05-03 04:28:06 +00:00
|
|
|
/// Initializes and fills in a posix_spawnattr_t; on success, the caller should destroy it via
|
|
|
|
/// posix_spawnattr_destroy.
|
|
|
|
bool fork_actions_make_spawn_properties(posix_spawnattr_t *attr,
|
2019-01-29 08:34:38 +00:00
|
|
|
posix_spawn_file_actions_t *actions, const job_t *j,
|
|
|
|
const dup2_list_t &dup2s);
|
2012-08-15 07:57:56 +00:00
|
|
|
#endif
|
|
|
|
|
2012-02-28 03:20:27 +00:00
|
|
|
#endif
|