summaryrefslogtreecommitdiffhomepage
path: root/src/exec.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/exec.c')
-rw-r--r--src/exec.c88
1 files changed, 44 insertions, 44 deletions
diff --git a/src/exec.c b/src/exec.c
index 0cf9602..fbc46ba 100644
--- a/src/exec.c
+++ b/src/exec.c
@@ -110,7 +110,7 @@ static cmdent *ctab[CTAB_SIZE];
* @brief Find a name in the command table.
* @param name Command name.
* @param create Add an empty entry if it is not there.
- * @return The entry, or NULL.
+ * @return The entry, or nullptr.
*/
static cmdent *cmd_lookup(const char *name, bool create) {
unsigned h = 5381;
@@ -122,7 +122,7 @@ static cmdent *cmd_lookup(const char *name, bool create) {
return e;
}
if (!create)
- return NULL;
+ return nullptr;
size_t len = strlen(name) + 1;
cmdent *e = xmalloc(sizeof *e + len);
*e = (cmdent){.next = *bucket, .hash = h};
@@ -138,7 +138,7 @@ void hash_clear(void) {
for (size_t i = 0; i < CTAB_SIZE; i++) {
for (cmdent *e = ctab[i]; e; e = e->next) {
free(e->path);
- e->path = NULL;
+ e->path = nullptr;
}
}
}
@@ -208,10 +208,10 @@ static int eval_time(const node *n, unsigned flags) {
struct timeval t1;
getrusage(RUSAGE_SELF, &s0);
getrusage(RUSAGE_CHILDREN, &c0);
- gettimeofday(&t0, NULL);
+ gettimeofday(&t0, nullptr);
int status =
n->u.time.body ? eval_node(n->u.time.body, flags & ~EV_EXIT) : 0;
- gettimeofday(&t1, NULL);
+ gettimeofday(&t1, nullptr);
getrusage(RUSAGE_SELF, &s1);
getrusage(RUSAGE_CHILDREN, &c1);
bool posix = n->u.time.posix;
@@ -319,7 +319,7 @@ static char **zos_environ(char **envp, const char *name, bool foreground) {
memcpy(env, envp, n * sizeof *env);
for (int i = 0; i < nadd; i++)
env[n + (size_t)i] = add[i];
- env[n + (size_t)nadd] = NULL;
+ env[n + (size_t)nadd] = nullptr;
return env;
}
@@ -336,7 +336,7 @@ static void path_changed(const char *value) {
* @param name File name without a slash.
* @param path Colon-separated directories.
* @param executable Require a regular file with execute permission.
- * @return The full path in scratch memory, or NULL.
+ * @return The full path in scratch memory, or nullptr.
*/
char *path_search(const char *name, const char *path, bool executable) {
size_t nlen = strlen(name);
@@ -356,7 +356,7 @@ char *path_search(const char *name, const char *path, bool executable) {
(!executable || (st.st_mode & 0111)))
return full;
if (!colon)
- return NULL;
+ return nullptr;
p = colon + 1;
}
}
@@ -470,7 +470,7 @@ bool func_unset(const char *name) {
if (!e || !e->fn)
return false;
func_unref(e->fn);
- e->fn = NULL;
+ e->fn = nullptr;
return true;
}
@@ -555,21 +555,21 @@ pid_t fork_shell(void) {
* (ENOEXEC): the interpreter named on its `#!` line, or this shell.
* @param path The file.
* @param argv The arguments it was to be run with.
- * @return The new vector in scratch memory, or NULL if the file is not
+ * @return The new vector in scratch memory, or nullptr if the file is not
* a script.
*/
static char **script_argv(const char *path, char **argv) {
char head[256];
int fd = open(path, O_RDONLY);
if (fd < 0)
- return NULL;
+ return nullptr;
ssize_t n = read(fd, head, sizeof head - 1);
close(fd);
if (n < 0)
- return NULL;
+ return nullptr;
if (memchr(head, '\0', (size_t)n)) {
errno = ENOEXEC; /* a binary we cannot run, not a script */
- return NULL;
+ return nullptr;
}
head[n] = '\0';
@@ -593,7 +593,7 @@ static char **script_argv(const char *path, char **argv) {
alen--;
if (!*interp) {
errno = ENOEXEC;
- return NULL;
+ return nullptr;
}
nv[k++] = arena_strndup(&scratch, interp, strlen(interp));
if (alen)
@@ -604,7 +604,7 @@ static char **script_argv(const char *path, char **argv) {
nv[k++] = (char *)path;
for (int i = 1; i < argc; i++)
nv[k++] = argv[i];
- nv[k] = NULL;
+ nv[k] = nullptr;
return nv;
}
@@ -642,7 +642,7 @@ static int exec_error(const char *name, int err) {
void shell_exec(char **argv, char **envp) {
cmdinfo ci;
find_command(argv[0], &ci, FC_NOFUNC);
- const char *path = ci.kind == C_EXTERNAL ? ci.path : NULL;
+ const char *path = ci.kind == C_EXTERNAL ? ci.path : nullptr;
if (!path && !strchr(argv[0], '/')) {
const char *search = var_get("PATH");
path = path_search(argv[0], search ? search : default_path, true);
@@ -753,12 +753,12 @@ static void simple_prep(node *n, simple_cmd *sc) {
sc->cmd = (cmdinfo){0};
cmdsub_ran = false;
cur_lineno = n->lineno;
- sc->atext = NULL;
+ sc->atext = nullptr;
sc->nassign = 0;
sc->argv = expand_words(n->u.simple.args, &sc->argc);
if (!sc->argc)
return;
- path_override = NULL;
+ path_override = nullptr;
if (n->u.simple.assigns) {
/* Expanded once, here, after the words (POSIX order). */
for (const word *w = n->u.simple.assigns; w; w = w->next)
@@ -779,7 +779,7 @@ static void simple_prep(node *n, simple_cmd *sc) {
for (;;) {
find_command(sc->argv[0], &sc->cmd, flags);
if (sc->cmd.kind != C_BUILTIN || sc->cmd.bi->fn != builtin_command) {
- path_override = NULL;
+ path_override = nullptr;
return;
}
/* "command [-p] name ...": look `name` up afresh, minus functions. */
@@ -792,7 +792,7 @@ static void simple_prep(node *n, simple_cmd *sc) {
if (i < sc->argc && !strcmp(sc->argv[i], "--"))
i++;
if (i >= sc->argc || sc->argv[i][0] == '-') {
- path_override = NULL;
+ path_override = nullptr;
return; /* -v, -V or nothing: the builtin handles it */
}
sc->argv += i;
@@ -914,7 +914,7 @@ static void tag_prefix_end(const tag_mode saved[3], int in, int out) {
* @param flags EV_EXIT allows replacing the shell with exec.
* @param in Descriptor for its stdin, or -1.
* @param out Descriptor for its stdout, or -1.
- * @param async When not NULL, receives the pid and the command is not
+ * @param async When not nullptr, receives the pid and the command is not
* waited for (pipeline stages, `&`, command substitution).
* @return The exit status. 0 for an async launch.
*/
@@ -944,7 +944,7 @@ static int run_external(simple_cmd *sc, unsigned flags, int in, int out,
}
/* Under job control a foreground command is a job of its own. */
job *jb =
- !async && jc_active() && !job_launching ? job_begin(n, true) : NULL;
+ !async && jc_active() && !job_launching ? job_begin(n, true) : nullptr;
int status = 0;
pid_t pid = spawn_command(sc->cmd.path, sc->argv, envp, &plan, &status);
plan_close(&plan);
@@ -1080,7 +1080,7 @@ int call_function(func *fn, int argc, char **argv, unsigned flags) {
fn->refs++;
func_depth++;
loop_depth = 0;
- shellparam = (shparam){argc - 1, argv + 1, NULL};
+ shellparam = (shparam){argc - 1, argv + 1, nullptr};
if (setjmp(jl.buf) == 0) {
exc_handler = &jl;
eval_node(fn->body, flags & EV_TESTED);
@@ -1149,7 +1149,7 @@ static int simple_run(simple_cmd *sc, unsigned flags) {
case C_FUNC:
return run_function(sc, flags);
case C_EXTERNAL:
- return run_external(sc, flags, -1, -1, NULL);
+ return run_external(sc, flags, -1, -1, nullptr);
case C_NOTFOUND: {
/* The message belongs on the command's stderr, not ours. */
redirsave rs;
@@ -1370,7 +1370,7 @@ static void read_all(int fd, strbuf *sb);
* @param st The stages.
* @param nc Number of commands.
* @param total Number of stage slots (one more when capturing).
- * @param jb The job, under job control. Else NULL.
+ * @param jb The job, under job control. Else nullptr.
* @return Status of the last command, or with `pipefail` of the last one
* that failed.
*/
@@ -1414,7 +1414,7 @@ static int pipe_finish(stage *st, int nc, int total, job *jb) {
*
* @param n The N_PIPE node.
* @param flags Evaluation flags.
- * @param cap Where to collect the output, or NULL.
+ * @param cap Where to collect the output, or nullptr.
* @return The pipeline's exit status.
*/
static int eval_pipe(node *n, unsigned flags, strbuf *cap) {
@@ -1448,7 +1448,7 @@ static int eval_pipe(node *n, unsigned flags, strbuf *cap) {
* every stage is a process, the last included: a stage running inside
* the shell could not be stopped with the rest of the job.
*/
- job *jb = !cap && jc_active() && !job_launching ? job_begin(n, true) : NULL;
+ job *jb = !cap && jc_active() && !job_launching ? job_begin(n, true) : nullptr;
varscope vs;
scope_push(&vs, true, false);
bool any_deferred = false;
@@ -1468,7 +1468,7 @@ static int eval_pipe(node *n, unsigned flags, strbuf *cap) {
if (st[i].deferred)
run_deferred(st, total, i, !cap);
}
- sigaction(SIGPIPE, &old, NULL);
+ sigaction(SIGPIPE, &old, nullptr);
}
if (cap)
read_all(st[nc].in, cap);
@@ -1506,7 +1506,7 @@ static int eval_pipe(node *n, unsigned flags, strbuf *cap) {
if (st[i].deferred)
run_deferred(st, nc, i, true);
}
- sigaction(SIGPIPE, &old, NULL);
+ sigaction(SIGPIPE, &old, nullptr);
}
if (!last_started) {
redirsave rs;
@@ -1525,10 +1525,10 @@ static int eval_pipe(node *n, unsigned flags, strbuf *cap) {
exc_handler = prev;
if (raised) {
- pipe_finish(st, nc, total, NULL);
+ pipe_finish(st, nc, total, nullptr);
exc_raise(exc_code);
}
- return pipe_finish(st, nc, total, NULL);
+ return pipe_finish(st, nc, total, nullptr);
}
/* ---- background commands --------------------------------------------- */
@@ -1559,7 +1559,7 @@ static int eval_background(node *body) {
* keeps its stdin and signal settings: it is the group, not ignored
* signals, that protects it from the keyboard.
*/
- job *jb = jc_active() ? job_begin(body, false) : NULL;
+ job *jb = jc_active() ? job_begin(body, false) : nullptr;
if (prepped && sc.argc && sc.cmd.kind == C_EXTERNAL) {
if (jb) {
run_external(&sc, 0, -1, -1, &pid);
@@ -1571,8 +1571,8 @@ static int eval_background(node *body) {
sigaction(SIGINT, &ignore, &old_int);
sigaction(SIGQUIT, &ignore, &old_quit);
run_external(&sc, 0, null, -1, &pid);
- sigaction(SIGINT, &old_int, NULL);
- sigaction(SIGQUIT, &old_quit, NULL);
+ sigaction(SIGINT, &old_int, nullptr);
+ sigaction(SIGQUIT, &old_quit, nullptr);
if (null >= 0)
close(null);
}
@@ -1586,8 +1586,8 @@ static int eval_background(node *body) {
pid = fork_shell();
if (pid == 0) {
if (!jb) {
- sigaction(SIGINT, &ignore, NULL);
- sigaction(SIGQUIT, &ignore, NULL);
+ sigaction(SIGINT, &ignore, nullptr);
+ sigaction(SIGQUIT, &ignore, nullptr);
int null = open("/dev/null", O_RDONLY);
if (null >= 0) {
dup2(null, 0);
@@ -1626,7 +1626,7 @@ static void read_all(int fd, strbuf *sb) {
/**
* @brief Run a command substitution in a forked subshell (the general case).
* @param n The command.
- * @param sc Its prepared form if it is a simple command, else NULL.
+ * @param sc Its prepared form if it is a simple command, else nullptr.
* @param sb Receives the output.
* @return The exit status.
*/
@@ -1661,7 +1661,7 @@ static int cmdsub_collect(node *n, strbuf *sb) {
if (n->kind == N_PIPE)
return eval_pipe(n, 0, sb);
if (n->kind != N_SIMPLE)
- return cmdsub_fork(n, NULL, sb);
+ return cmdsub_fork(n, nullptr, sb);
const redir *r = n->redirs;
if (!n->u.simple.args && !n->u.simple.assigns && r && !r->next &&
@@ -1709,7 +1709,7 @@ static int cmdsub_collect(node *n, strbuf *sb) {
/**
* @brief Run a command substitution.
- * @param n The command, or NULL for an empty `$()`.
+ * @param n The command, or nullptr for an empty `$()`.
* @param lenp Receives the length of the output.
* @return The output with trailing newlines removed, in scratch memory.
*/
@@ -1722,7 +1722,7 @@ char *cmdsub_run(node *n, size_t *lenp) {
* happens to be half launched (a pipeline stage's arguments). */
job *launching = job_launching;
varscope vs;
- job_launching = NULL;
+ job_launching = nullptr;
scope_push(&vs, true, false);
status = cmdsub_collect(n, &sb);
scope_pop();
@@ -1840,7 +1840,7 @@ static int eval_subshell(node *n, unsigned flags) {
if (!ok)
return exitstatus;
}
- job *jb = jc_active() && !job_launching ? job_begin(n, true) : NULL;
+ job *jb = jc_active() && !job_launching ? job_begin(n, true) : nullptr;
pid_t pid = fork_shell();
if (pid) {
if (!jb)
@@ -1869,7 +1869,7 @@ static int eval_subshell(node *n, unsigned flags) {
* a failing command the ERR trap and `errexit` are applied, and pending
* trap actions run.
*
- * @param n The command, or NULL for an empty one.
+ * @param n The command, or nullptr for an empty one.
* @param flags EV_EXIT if nothing follows the command, EV_TESTED if its
* status is being tested.
* @return The exit status, also left in `$?`.
@@ -1904,7 +1904,7 @@ int eval_node(node *n, unsigned flags) {
break;
}
case N_PIPE:
- status = eval_pipe(n, flags, NULL);
+ status = eval_pipe(n, flags, nullptr);
leaf = true;
break;
case N_SUBSHELL:
@@ -2053,7 +2053,7 @@ int run_input(unsigned flags) {
skip_kind = SKIP_NONE;
loop_depth = saved_loop;
dot_depth = 0;
- job_launching = NULL;
+ job_launching = nullptr;
}
exc_handler = &jl;
if (flags & RI_TOP)