From: nicm Date: Fri, 19 Feb 2021 09:09:16 +0000 (+0000) Subject: Check return value of chdir() to stop a silly warning with some X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=f93f4929030638a9dfe58b64856c183d41da4fc6;p=openbsd Check return value of chdir() to stop a silly warning with some compilers, GitHub issue 2573. --- diff --git a/usr.bin/tmux/job.c b/usr.bin/tmux/job.c index def796c05e5..946c384d8e5 100644 --- a/usr.bin/tmux/job.c +++ b/usr.bin/tmux/job.c @@ -1,4 +1,4 @@ -/* $OpenBSD: job.c,v 1.58 2020/05/16 15:24:28 nicm Exp $ */ +/* $OpenBSD: job.c,v 1.59 2021/02/19 09:09:16 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -114,10 +114,10 @@ job_run(const char *cmd, struct session *s, const char *cwd, proc_clear_signals(server_proc, 1); sigprocmask(SIG_SETMASK, &oldset, NULL); - if (cwd == NULL || chdir(cwd) != 0) { - if ((home = find_home()) == NULL || chdir(home) != 0) - chdir("/"); - } + if ((cwd == NULL || chdir(cwd) != 0) && + ((home = find_home()) == NULL || chdir(home) != 0) && + chdir("/") != 0) + fatal("chdir failed"); environ_push(env); environ_free(env); diff --git a/usr.bin/tmux/spawn.c b/usr.bin/tmux/spawn.c index 57bc0188d30..0865fcf3145 100644 --- a/usr.bin/tmux/spawn.c +++ b/usr.bin/tmux/spawn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: spawn.c,v 1.24 2020/05/21 07:24:13 nicm Exp $ */ +/* $OpenBSD: spawn.c,v 1.25 2021/02/19 09:09:16 nicm Exp $ */ /* * Copyright (c) 2019 Nicholas Marriott @@ -379,10 +379,10 @@ spawn_pane(struct spawn_context *sc, char **cause) * Child process. Change to the working directory or home if that * fails. */ - if (chdir(new_wp->cwd) != 0) { - if ((tmp = find_home()) == NULL || chdir(tmp) != 0) - chdir("/"); - } + if (chdir(new_wp->cwd) != 0 && + ((tmp = find_home()) == NULL || chdir(tmp) != 0) && + chdir("/") != 0) + fatal("chdir failed"); /* * Update terminal escape characters from the session if available and