diff --git a/.testms b/.testms new file mode 100644 index 0000000..53ecffa --- /dev/null +++ b/.testms @@ -0,0 +1,114 @@ +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> bonjour, je suis un message vert de debug +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> à zipper +jobs.c +jobs.h +latex +Makefile +minishell +minishell.c +readcmd.c +readcmd.h +README.md +sujet.pdf +test1 +test.sh +utils.c +utils.h +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> total 276K +drwxr-xr-x 6 laurent laurent 4.0K May 23 18:53 . +drwxrwxrwx 9 laurent laurent 4.0K May 5 08:07 .. +drwxr-xr-x 2 laurent laurent 4.0K May 23 16:32 à zipper +drwxr-xr-x 8 laurent laurent 4.0K May 23 16:28 .git +-rw-r--r-- 1 laurent laurent 2.6K May 23 18:12 jobs.c +-rw-r--r-- 1 laurent laurent 403 May 23 16:22 jobs.h +drwxr-xr-x 4 laurent laurent 4.0K Apr 25 20:56 latex +-rw-r--r-- 1 laurent laurent 205 May 10 15:49 Makefile +-rwxr-xr-x 1 laurent laurent 27K May 23 18:53 minishell +-rw-r--r-- 1 laurent laurent 7.2K May 23 18:51 minishell.c +-rwxr-xr-x 1 laurent laurent 5.0K Apr 21 14:03 readcmd.c +-rwxr-xr-x 1 laurent laurent 2.2K May 23 16:24 readcmd.h +-rwxr-xr-x 1 laurent laurent 2.1K Apr 13 10:42 README.md +-rw-r--r-- 1 laurent laurent 163K Apr 25 20:25 sujet.pdf +-rw-r--r-- 1 laurent laurent 1.9K May 23 16:41 test1 +-rw-r--r-- 1 laurent laurent 452 May 23 18:53 .testms +-rw-r--r-- 1 laurent laurent 2.3K May 23 18:26 test.sh +-rw-r--r-- 1 laurent laurent 4.6K May 23 18:09 utils.c +-rw-r--r-- 1 laurent laurent 165 May 23 16:22 utils.h +drwxr-xr-x 2 laurent laurent 4.0K Apr 20 21:34 .vscode +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> -rwxr-xr-x 1 laurent laurent 27K May 23 18:53 minishell +-rw-r--r-- 1 laurent laurent 7.2K May 23 18:51 minishell.c +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> 2 18 116 +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> -rw-r--r-- 1 laurent laurent 1.9K May 23 16:41 test1 +drwxr-xr-x 6 laurent laurent 4.0K May 23 18:53 . +drwxrwxrwx 9 laurent laurent 4.0K May 5 08:07 .. +-rwxr-xr-x 1 laurent laurent 5.0K Apr 21 14:03 readcmd.c +-rw-r--r-- 1 laurent laurent 7.2K May 23 18:51 minishell.c +-rw-r--r-- 1 laurent laurent 2.6K May 23 18:12 jobs.c +-rw-r--r-- 1 laurent laurent 4.6K May 23 18:09 utils.c +-rwxr-xr-x 1 laurent laurent 2.1K Apr 13 10:42 README.md +drwxr-xr-x 2 laurent laurent 4.0K Apr 20 21:34 .vscode +-rw-r--r-- 1 laurent laurent 205 May 10 15:49 Makefile +-rw-r--r-- 1 laurent laurent 163K Apr 25 20:25 sujet.pdf +-rwxr-xr-x 1 laurent laurent 2.2K May 23 16:24 readcmd.h +-rw-r--r-- 1 laurent laurent 403 May 23 16:22 jobs.h +-rw-r--r-- 1 laurent laurent 165 May 23 16:22 utils.h +-rw-r--r-- 1 laurent laurent 2.3K May 23 18:26 test.sh +total 276K +-rwxr-xr-x 1 laurent laurent 27K May 23 18:53 minishell +drwxr-xr-x 2 laurent laurent 4.0K May 23 16:32 à zipper +-rw-r--r-- 1 laurent laurent 2.0K May 23 18:53 .testms +drwxr-xr-x 8 laurent laurent 4.0K May 23 16:28 .git +drwxr-xr-x 4 laurent laurent 4.0K Apr 25 20:56 latex +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> [1] 30197 +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> [2] 30200 +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> [3] 30203 +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> [4] 30206 +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> [5] 30209 +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> [6] 30212 +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> [7] 30215 +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> [8] 30218 +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> [9] 30221 +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> [10] 30224 +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> [11] 30227 +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> [8] 30218 stopped: sleep 12 +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> [1] 30197 running: sleep 5 + +[1] 30197 stopped: sleep 5 +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> [1] 30197 continued: sleep 5 +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> [1] 30197 : sleep 5 +[2] 30200 : sleep 6 +[3] 30203 : sleep 7 +[4] 30206 : sleep 8 +[5] 30209 : sleep 9 +[6] 30212 : sleep 10 +[7] 30215 : sleep 11 +[8] 30218 : sleep 12 +[9] 30221 : sleep 13 +[10] 30224 : sleep 14 +[11] 30227 : sleep 15 +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> /home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> /home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés >>> /home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés >>> +[1] 30197 exited: sleep 5 +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés >>> +[2] 30200 exited: sleep 6 +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés >>> +[3] 30203 exited: sleep 7 +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés >>> +[4] 30206 exited: sleep 8 +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés >>> +[5] 30209 exited: sleep 9 +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés >>> +[6] 30212 exited: sleep 10 +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés >>> +[7] 30215 exited: sleep 11 +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés >>> +[9] 30221 exited: sleep 13 +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés >>> +[10] 30224 exited: sleep 14 +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés >>> +[11] 30227 exited: sleep 15 +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés >>> \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index bc67dc0..0a8465f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,6 +8,7 @@ "*.bak": "c", "*.tcc": "c", "errno.h": "c", - "string.h": "c" + "string.h": "c", + "system_error": "c" } } \ No newline at end of file diff --git a/jobs.c b/jobs.c index a00d631..41c3b74 100644 --- a/jobs.c +++ b/jobs.c @@ -110,7 +110,6 @@ void liberer(list *l_ptr) free(cursor2free); } - free(*l_ptr); *l_ptr = NULL; } diff --git a/minishell b/minishell index a83f702..faadff2 100755 Binary files a/minishell and b/minishell differ diff --git a/minishell.c b/minishell.c index 1b2457c..15b6e88 100644 --- a/minishell.c +++ b/minishell.c @@ -33,13 +33,15 @@ int file_in, file_out; int pipes[256][2]; int sous_fils[256]; +struct sigaction action; + int main(int argc, char *argv[]) { + setvbuf(stdout, NULL, _IONBF, 0); // pratique pour test.sh, optionnel sinon (normalement) initialiser(&jobs); getcwd(initcd, sizeof(initcd)); // gestion des signaux - struct sigaction action; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO | SA_RESTART; action.sa_handler = handler_sigchld; @@ -178,14 +180,10 @@ int main(int argc, char *argv[]) for (int i = 0; i <= nb_pipe; i++) { // on attend chaque sous-fils if (waitpid(sous_fils[i], &wait_code, 0) == -1) - { // wait failed ? - fprintf(stderr, "ERROR: waiting for %d failed, (%d) %s\n", wait_code, errno, strerror(errno)); - exit(errno); - } // TODO: factoriser dans une fonction, cf dessous ? - if (wait_code) - { // execvp failed ? - fprintf(stderr, "ERROR: child failed, (%d) %s\n", wait_code, strerror(wait_code)); - } + if (wait_code) + { // execvp failed ? + fprintf(stderr, "ERROR: child n°%d failed, (%d) %s\n", i, wait_code, strerror(wait_code)); + } } exit(0); // on termine le fils } @@ -207,7 +205,7 @@ int main(int argc, char *argv[]) { // foreground if (waitpid(pid_fils, &wait_code, 0) == -1) { // wait failed ? - fprintf(stderr, "ERROR: waiting for %d failed, (%d) %s\n", wait_code, errno, strerror(errno)); + fprintf(stderr, "ERROR: waiting for %d failed, (%d) %s\n", pid_fils, errno, strerror(errno)); exit(errno); } if (wait_code) diff --git a/test.sh b/test.sh index 60e6a64..fcdde66 100644 --- a/test.sh +++ b/test.sh @@ -1,2 +1,114 @@ -sleep 4 -printf "\n\n --- bonjour --- \n\n" +green=`tput setaf 2` +reset=`tput sgr0` + +extralongpipe=`printf '| sort | uniq | rev %.0s' {1..20}` + +rm .testms > /dev/null +touch .testms +clear +tail -f .testms & +tailpid=$! + +tmux kill-session -t testms > /dev/null 2>&1 +tmux new-session -d -s testms './minishell > .testms' + +sleep 0.5 + +echo "${green}echo bonjour, je suis un message vert de debug${reset}" +tmux send-keys -t testms -l "echo bonjour, je suis un message vert de debug" +tmux send-keys -t testms Enter + +sleep 0.5 + +echo "${green}ls${reset}" +tmux send-keys -t testms -l "ls" +tmux send-keys -t testms Enter + +sleep 0.5 + +echo "${green}ls -l${reset}" +tmux send-keys -t testms -l "ls -lah" +tmux send-keys -t testms Enter + +sleep 0.5 + +echo "${green}ls -lah | grep mini${reset}" +tmux send-keys -t testms -l "ls -lah | grep mini" +tmux send-keys -t testms Enter + +sleep 0.5 + +echo "${green}ls -lah | grep mini | wc${reset}" +tmux send-keys -t testms -l "ls -lah | grep mini | wc" +tmux send-keys -t testms Enter + +sleep 0.5 + +echo "${green}ls -lah | sort | rev | sort | ... ${reset}" +tmux send-keys -t testms -l "ls -lah $extralongpipe" +tmux send-keys -t testms Enter + +sleep 0.5 + +echo "${green}^C${reset}" +tmux send-keys -t testms C-c +echo "${green}^C${reset}" +tmux send-keys -t testms C-c +echo "${green}^C${reset}" +tmux send-keys -t testms C-c + +for i in {5..15} +do + echo "${green}sleep $i &${reset}" + tmux send-keys -t testms -l "sleep $i &" + tmux send-keys -t testms Enter +done + +sleep 0.5 + +echo "${green}stop 8${reset}" +tmux send-keys -t testms -l "stop 8" +tmux send-keys -t testms Enter + +echo "${green}fg 1${reset}" +tmux send-keys -t testms -l "fg 1" +tmux send-keys -t testms Enter + +sleep 0.5 + +echo "${green}^Z${reset}" +tmux send-keys -t testms C-z + +sleep 0.5 + +echo "${green}bg 1${reset}" +tmux send-keys -t testms -l "bg 1" +tmux send-keys -t testms Enter + +sleep 0.5 + +echo "${green}jobs${reset}" +tmux send-keys -t testms -l "jobs" +tmux send-keys -t testms Enter + +sleep 0.5 + +echo "${green}pwd${reset}" +tmux send-keys -t testms -l "pwd" +tmux send-keys -t testms Enter + +sleep 0.5 + +echo "${green}cd ..${reset}" +tmux send-keys -t testms -l "cd .." +tmux send-keys -t testms Enter +sleep 0.5 + +echo "${green}pwd${reset}" +tmux send-keys -t testms -l "pwd" +tmux send-keys -t testms Enter + +sleep 12 + +tmux send-keys -t testms C-d +kill $tailpid diff --git a/test1 b/test1 new file mode 100644 index 0000000..6cdcf35 --- /dev/null +++ b/test1 @@ -0,0 +1,36 @@ +à zipper +jobs.c +jobs.h +latex +Makefile +minishell +minishell.c +readcmd.c +readcmd.h +README.md +sujet.pdf +test1 +test.sh +utils.c +utils.h +message de test +total 256 +drwxr-xr-x 2 laurent laurent 4096 May 23 16:32 à zipper +-rw-r--r-- 1 laurent laurent 2676 May 23 16:25 jobs.c +-rw-r--r-- 1 laurent laurent 403 May 23 16:22 jobs.h +drwxr-xr-x 4 laurent laurent 4096 Apr 25 20:56 latex +-rw-r--r-- 1 laurent laurent 205 May 10 15:49 Makefile +-rwxr-xr-x 1 laurent laurent 27264 May 23 16:20 minishell +-rw-r--r-- 1 laurent laurent 7450 May 23 16:23 minishell.c +-rwxr-xr-x 1 laurent laurent 5115 Apr 21 14:03 readcmd.c +-rwxr-xr-x 1 laurent laurent 2163 May 23 16:24 readcmd.h +-rwxr-xr-x 1 laurent laurent 2063 Apr 13 10:42 README.md +-rw-r--r-- 1 laurent laurent 166500 Apr 25 20:25 sujet.pdf +-rw-r--r-- 1 laurent laurent 147 May 23 16:38 test1 +-rw-r--r-- 1 laurent laurent 113 May 23 16:38 test.sh +-rw-r--r-- 1 laurent laurent 4583 May 23 16:24 utils.c +-rw-r--r-- 1 laurent laurent 165 May 23 16:22 utils.h + 1 9 59 +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> /home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> /home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> /home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> minishell +minishell.c +/home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> /home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> /home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> /home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> /home/laurent/Documents/Cours/ENSEEIHT/S6 - Systèmes d'Exploitation Centralisés/projet >>> \ No newline at end of file diff --git a/utils.c b/utils.c index 44e5b2d..84a57af 100644 --- a/utils.c +++ b/utils.c @@ -20,6 +20,7 @@ extern list jobs; extern struct cmdline *cmd; extern jmp_buf goto_prompt; extern char initcd[]; +extern struct sigaction action; int builtin() { @@ -92,6 +93,7 @@ int builtin() pid_fils = job->pid; } kill(pid_fils, SIGCONT); + printf("[%d] %d running: %s\n", job->id, job->pid, job->cmd); pause(); waitpid(pid_fils, NULL, 0); return 2; @@ -187,7 +189,7 @@ void handler_sigtstp(int sig_num) printf("\n"); if (!prompting) { - ajouter(&jobs, pid_fils, *(cmd->seq)); + //ajouter(&jobs, pid_fils, *(cmd->seq)); kill(pid_fils, SIGSTOP); pause(); } diff --git a/à zipper/FAINSIN_Laurent.tar b/à zipper/FAINSIN_Laurent.tar deleted file mode 100644 index 86d2316..0000000 Binary files a/à zipper/FAINSIN_Laurent.tar and /dev/null differ diff --git a/à zipper/Makefile b/à zipper/Makefile index 1d3ffb8..e4cd28a 100644 --- a/à zipper/Makefile +++ b/à zipper/Makefile @@ -1,9 +1,9 @@ CC = gcc -LDFLAGS = -Wall +LDFLAGS = -Wall -g all: minishell Q1 Q3 Q4 Q5 Q6 Q7 -minishell: jobs.c readcmd.c minishell.c +minishell: utils.c jobs.c readcmd.c minishell.c $(CC) $(LDFLAGS) $^ -o $@ Q1: jobs.c readcmd.c Q1.c @@ -24,11 +24,11 @@ Q6: jobs.c readcmd.c Q6.c Q7: jobs.c readcmd.c Q7.c $(CC) $(LDFLAGS) $^ -o $@ - clean: - rm minishell readcmd jobs Q1 Q3 Q4 Q5 Q6 Q7 + rm minishell readcmd jobs utils Q1 Q3 Q4 Q5 Q6 Q7 .PHONY: clean all readcmd.o: readcmd.h jobs.o: jobs.h +utils.o: utils.h diff --git a/à zipper/README.md b/à zipper/README.md deleted file mode 100755 index 489d8b9..0000000 --- a/à zipper/README.md +++ /dev/null @@ -1,38 +0,0 @@ -Introduction ------------- -Le code fourni a pour but de vous décharger du travail d'analyse d'une ligne de commande, -avant son interprétation par le shell. Il propose une fonction `readcmd()` qui fournit -le résultat de cette analyse. - -Le source est fourni non pas à titre d'exemple (il n'est pas d'une clarté éblouissante), -mais à titre de documentation (et de spécification :)) ; il n'est ni - nécessaire, ni conseillé de le modifier pour réaliser le travail demandé : l'analyse - réalisée est suffisante pour la syntaxe des commandes que votre shell doit interpréter. - - Ce code est a priori tout à fait fiable, mais n'hésitez cependant pas à nous signaler - ce qui vous apparaîtrait comme des anomalies, ou des lacunes dans la documentation. - -La structure `cmdline` ----------------------- -L'appel à readcmd() retourne une structure cmdline, qui contient le résultat de l'analyse -de la ligne de commande pour le shell. -Cette structure contient notamment : - -- l'indication du fait que la commande doit être lancée en tâche de fond ou non -- les redirections éventuelles -- la décomposition de la ligne de commande en commandes élémentaires, et la décomposition - de chaque commande en mots. Le champ `seq` référence le résultat de cette décomposition, - qui est vu comme un tableau à deux dimensions [commandes élémentaires, mots de la commande] - - **Pour plus de détails, voir le fichier d'en-tête `readcmd.h`.** - -**Exemples :** - -- "ls -l" : seq[0][0] = "ls", seq[0][1] = "-l", seq[0][2] = NULL, seq[1] = NULL, backgrounded = NULL, in = NULL, out = NULL -- "ls -l > toto" : seq[0][0] = "ls", seq[0][1] = "-l", seq[0][2] = NULL, - seq[1] = NULL, backgrounded = NULL, in = NULL, out => "toto" -- "ls | grep toto | wc -l" : seq[0][0] = "ls", seq[0][1] = NULL, -seq[1][0] = "grep", seq[1][1] = "toto", seq[1][2] = NULL, -seq[2][0] = "wc", seq[0][1] = "-l", seq[0][2] = NULL, -seq[3] = NULL, backgrounded = NULL, in = NULL, out = NULL -- "sleep 100 &" : seq[0][0] = "sleep", seq[0][1] = "20", backgrounded != NULL, in = NULL, out = NULL \ No newline at end of file