This repository has been archived by the owner on Nov 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix exit codes to match bash on 42 systems
- Loading branch information
Showing
2 changed files
with
19 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: mcombeau <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/09/17 19:03:08 by mcombeau #+# #+# */ | ||
/* Updated: 2022/11/05 11:38:53 by mcombeau ### ########.fr */ | ||
/* Updated: 2022/11/11 14:22:23 by mcombeau ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -34,6 +34,20 @@ static void update_wds(t_data *data, char *wd) | |
free_ptr(wd); | ||
} | ||
|
||
/* chdir_errno_mod: | ||
* chdir can sometimes set errno to ESTALE ("Stale file handle") | ||
* when a parent directory is removed on some systems. This is due | ||
* to the inode table entry being recycled. This is a fix to display | ||
* "no such file or directory" error instead. | ||
*/ | ||
static bool chdir_errno_mod(char *path) | ||
{ | ||
if (errno == ESTALE) | ||
errno = ENOENT; | ||
errmsg_cmd("cd", path, strerror(errno), errno); | ||
return (false); | ||
} | ||
|
||
/* change_dir: | ||
* Changes the current working directory and updates the | ||
* OLDPWD environment variable. | ||
|
@@ -47,10 +61,7 @@ static bool change_dir(t_data *data, char *path) | |
|
||
ret = NULL; | ||
if (chdir(path) != 0) | ||
{ | ||
errmsg_cmd("cd", path, strerror(errno), errno); | ||
return (false); | ||
} | ||
return (chdir_errno_mod(path)); | ||
ret = getcwd(cwd, PATH_MAX); | ||
if (!ret) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: mcombeau <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2022/09/17 17:08:47 by mcombeau #+# #+# */ | ||
/* Updated: 2022/11/07 17:17:18 by mcombeau ### ########.fr */ | ||
/* Updated: 2022/11/11 13:57:52 by mcombeau ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -49,7 +49,7 @@ void minishell_interactive(t_data *data) | |
if (parse_user_input(data) == true) | ||
g_last_exit_code = execute(data); | ||
else | ||
g_last_exit_code = 2; | ||
g_last_exit_code = 1; | ||
free_data(data, false); | ||
} | ||
} | ||
|
@@ -80,7 +80,7 @@ void minishell_noninteractive(t_data *data, char *arg) | |
if (parse_user_input(data) == true) | ||
g_last_exit_code = execute(data); | ||
else | ||
g_last_exit_code = 2; | ||
g_last_exit_code = 1; | ||
i++; | ||
free_data(data, false); | ||
} | ||
|