Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Benoit
minishell
Commits
53c07031
Commit
53c07031
authored
Feb 01, 2021
by
abenoit
Browse files
error handling extended and status variable assignation
parent
4ef8c985
Changes
9
Hide whitespace changes
Inline
Side-by-side
bbrunet_tests
0 → 100644
View file @
53c07031
cd ../../../../../..
pwd
cd /home/user42/
pwd
cd $HOME/Bureau
pwd
unset HOME; cd
pwd
export HOME= ; cd
pwd
cd too many arguments
pwd
cd ./path_not_found
pwd
cd -
pwd
mkdir a; mkdir a/b; cd a/b; rm -r ../../a; cd ..
pwd
cd home/.. avec CDPATH set à /
pwd
cd home/dir avec CDPATH set à /
pwd
cd . avec CDPATH set
pwd
cd .. avec CDPATH set
pwd
echo -n -n -nnnn -nnnnm ; echo a
echo -n -nnn hello -n ; echo a
env ; export ; env
cd random_cmd
echo $?
cd random_cmd ; cd $?
echo $?
./file_that_is_not_an_executable ;
echo $?
cat bla
echo $?
grid.txt
echo $?
not_cmd
echo $?
export test=a ; echo $test
ls bonjour
echo $?
export var=a ; export $var=test ; echo $var $a
unset var
export $var=test
export var = plop
export var = test
echo $var
export "" test=a
echo $?
env
echo ~
export var=te"st
echo $var
export var=te"st ; echo $var
.
echo $SHLVL
env -i ./minishell
echo $SHLVL
""
echo $?
echo "\s" ; echo "\\s"
echo "12\""
echo "bip | bip ; coyotte > < \" "
echo \>
echo $USER$var\$USER$USER\$USERtest$USER
echo bonjour \; ls
$
$LESS$VAR
..
echo $?
echo '"abc"'
echo "'abc'"
echo "" bonjour
echo a
echo\ a
export ""
unset ""
export "test=ici"=coucou ; echo $test
export var="cat Makefile | grep >" ; echo $var
cat | cat | cat | ls
\n
\n
\n
cat Makefile | grep pr | head -n 5 | cd file_not_exit
echo $?
cat Makefile | grep pr | head -n 5 | hello
echo $?
ls | exit
sleep 5 | exit
<a cat <b <c
<a cat <b <c avec b n'existe pas (ou pas les droits)
> test | echo blabla; rm test
>a cat <b >>c
>a ls >b >>c >d
>a ls <machin >>c >d avec machin n'exite pas
>file
cat -e > test1 < test2
cat < test
echo 2 > out1 >> out2
echo 2 >> out1 > out2
echo bonjour > test\ 1
echo test > file test1
not_cmd bonjour > salut
ctrl-\
ctrl-C
export var=" truc"; echo $var
export var="truc "; echo $var | cat -e
echo "$tests""Makefile"
echo "$tests"Makefile
echo "$tests" "Makefile"
$bla (non-export)
echo $var bonjour ($var non export)
export $var (var non export)
export test=123\" ; echo $test
export test=123\\ ; echo $test
export test=123\' ; echo $test ; echo $test
export test=" foo bar " ; echo $test
export test=" foo bar " ; echo ab$test
export test=" foo bar " ; echo "ab"$test
export test=" foo bar " ; echo ab"$test" | cat -e
export test=" foo bar " ; echo "$test"
export test=" foo bar " ; echo ""$test""
export test=" foo bar " ; echo """$test"""
export var=s\ -la ; l$var
export var=at ; c$var Makefile
export loop='bonjour$loop' ; echo $loop
export test="file1 file2" ; >$test
export test="file1 file2" ; >"$test"
export test="file1 file2" ; >$test >hey
export test="file1 file2" ; >hey >$test
|
echo bonjour ; |
echo bonjour > > out
echo bonjour > $test
echo bonjour > $test w/ test="o1 o2"
echo bonjour >>> test
echo bonjour | |
echo bonjour |;
unset PATH ; echo $PATH
unset PATH ; ls
unset "" test
unset =
unset PWD
unset var
/bin/echo bonjour
untestable
env -i ./minishell
env
inc/minishell.h
View file @
53c07031
...
...
@@ -61,6 +61,9 @@ enum e_retcode
AMBIG_REDIR
,
HOME_NOT_SET
,
NO_SUCH_FILE
,
INVALID_EXP_ID
,
INVALID_UNS_ID
,
INVALID_PWD_PATH
,
_PARSING_ERROR_
,
SQUOTE_MISSING
,
DQUOTE_MISSING
,
...
...
notes.txt
View file @
53c07031
...
...
@@ -46,7 +46,7 @@ a la fin avec rgrep:
erreurs de write et de ft_put* a terminer
gestion d'erreurs des fonctions autorisees une a une
prompt printing "minishell"
...
...
@@ -55,6 +55,8 @@ builtins: set stat_loc?
mkdir ok; cd ok; rmdir ../ok; pwd
cd: leaks in getcwd
mkdir ok ; cd ok ; rmdir ../ok ; cd ..
====> segfault a corriger
strerror au lieu de perror qui est pas autorise
...
...
src/builtins/ft_export.c
View file @
53c07031
...
...
@@ -215,7 +215,10 @@ static int ft_export_checks(char **args, t_xe *xe)
}
}
else
printf
(
"export: Variable identifier (name) invalid
\n
"
);
// ERROR CODE
{
xe
->
stat_loc
=
1
;
return
(
INVALID_EXP_ID
);
}
args
++
;
}
return
(
SUCCESS
);
...
...
src/builtins/ft_pwd.c
View file @
53c07031
...
...
@@ -9,9 +9,8 @@ int ft_pwd(char **args, t_xe *xe)
buf
=
getcwd
(
NULL
,
0
);
if
(
buf
==
NULL
)
{
printf
(
"pwd : erreur de détermination du répertoire actuel : getcwd : ne peut accéder aux répertoires parents : Aucun fichier ou dossier de ce type
\n
"
);
// ERROR CODE
xe
->
stat_loc
=
1
;
return
(
SUCCESS
);
// other code!
return
(
INVALID_PWD_PATH
);
// other code!
}
if
(
ft_putendl_fd
(
buf
,
STDOUT_FILENO
)
!=
WRITE_SUCCESS
)
{
...
...
src/builtins/ft_unset.c
View file @
53c07031
...
...
@@ -39,9 +39,8 @@ int ft_unset(char **args, t_xe *xe)
}
else
{
printf
(
"unset: Variable identifier (name) invalid
\n
"
);
// ERROR CODE
xe
->
stat_loc
=
1
;
return
(
SUCCESS
);
return
(
INVALID_UNS_ID
);
}
args
++
;
}
...
...
src/execution/exec_handler.c
View file @
53c07031
...
...
@@ -59,10 +59,10 @@ int parent_pipe_end(t_command *cur_command, t_xe *xe, int fd_in, int proc)
while
(
i
<
proc
)
{
wait
(
&
xe
->
stat_loc
);
if
(
WIF
SIGNAL
ED
(
xe
->
stat_loc
))
// check this return value!
{
xe
->
stat_loc
+=
128
;
}
if
(
WIF
EXIT
ED
(
xe
->
stat_loc
))
xe
->
stat_loc
=
WEXITSTATUS
(
xe
->
stat_loc
);
// if (WIFSIGNALED(xe->stat_loc)) // check this return value!
// xe->stat_loc += 128;
i
++
;
}
if
(
ret
!=
SUCCESS
)
...
...
src/execution/launch_command.c
View file @
53c07031
...
...
@@ -68,12 +68,8 @@ static int exec_cmd(char *cmd, char **args, t_xe *xe)
signal
(
SIGINT
,
SIG_IGN
);
// error if SIG_ERR? (check errno)
signal
(
SIGQUIT
,
SIG_IGN
);
// error if SIG_ERR? (check errno)
waitpid
(
pid
,
&
xe
->
stat_loc
,
0
);
// return value? error?
if
(
WIFSIGNALED
(
xe
->
stat_loc
))
// check this return value
{
xe
->
stat_loc
=
128
+
WTERMSIG
(
xe
->
stat_loc
);
}
else
if
(
xe
->
stat_loc
>
256
)
xe
->
stat_loc
=
xe
->
stat_loc
/
256
;
if
(
WIFEXITED
(
xe
->
stat_loc
))
xe
->
stat_loc
=
WEXITSTATUS
(
xe
->
stat_loc
);
signal_handler
();
// err
return
(
SUCCESS
);
}
...
...
src/ft_error.c
View file @
53c07031
...
...
@@ -26,7 +26,10 @@ int exec_error(int err_code, t_xe *xe)
const
char
*
err_msg
[]
=
{
"Ambiguous redirection"
,
"HOME not set"
,
"No such file or directory"
};
"No such file or directory"
,
"export: Variable identifier (name) invalid"
,
"unset: Variable identifier (name) invalid"
,
"pwd : erreur de détermination du répertoire actuel : getcwd : ne peut accéder aux répertoires parents : Aucun fichier ou dossier de ce type"
};
ft_putstr_fd
(
"command error: "
,
STDERR_FILENO
);
ft_putendl_fd
(
err_msg
[
err_code
-
_EXEC_ERROR_
-
1
],
STDERR_FILENO
);
...
...
@@ -57,21 +60,28 @@ static int err_output(int err_code)
int
clean_and_exit
(
int
ret
,
t_xe
*
xe
)
{
if
(
ret
==
ARG_ERR
)
{
if
(
ft_putstr_fd
(
"Minishell takes no argument"
,
STDERR_FILENO
)
!=
WRITE_SUCCESS
)
ft_error
(
WRITE_ERR
,
xe
);
// possible?
}
if
(
ret
==
CHILD_EXIT
)
ret
=
(
xe
->
stat_loc
);
else
ret
=
EXIT_SUCCESS
;
free_str_array
(
xe
->
exported
);
// besoin de free?
free_str_array
(
xe
->
env
);
// besoin de free?
free
(
xe
);
if
(
ret
==
ARG_ERR
)
ft_putstr_fd
(
"Minishell takes no argument"
,
STDERR_FILENO
);
if
(
ret
!=
CHILD_EXIT
)
if
(
isatty
(
STDIN_FILENO
))
// temp pour le testeur
if
(
ft_putstr_fd
(
"exit
\n
"
,
STDOUT_FILENO
)
!=
WRITE_SUCCESS
)
return
(
WRITE_ERR
);
// possible?
exit
(
EXIT_SUCCESS
);
exit
(
ret
);
}
int
ft_error
(
int
ret
,
t_xe
*
xe
)
{
ft_putstr_fd
(
"minishell: "
,
STDERR_FILENO
);
if
(
ret
>
CHILD_EXIT
)
ft_putstr_fd
(
"minishell: "
,
STDERR_FILENO
);
if
(
ret
>
_PARSING_ERROR_
)
// temp
return
(
parsing_error
(
ret
,
xe
));
else
if
(
ret
>
_EXEC_ERROR_
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment