-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
58 lines (45 loc) · 1.09 KB
/
main.c
File metadata and controls
58 lines (45 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include "shell.h"
void ignore_sigint(int sig_num);
void ignore_sigint(int sig_num)
{
while (waitpid(-1, NULL, WNOHANG) > 0) {
}
printf("\n");;
}
int main(int argc, char **argv, char **envp)
{
SHELL_CONF *conf;
int status;
char *buffer;
char **args;
conf = NULL;
status = 1;
struct sigaction sa;
memset(&sa, 0, sizeof(struct sigaction));
sa.sa_handler = ignore_sigint;
sa.sa_flags = 0;// not SA_RESTART!;
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
if (init_shell(&conf, envp) != 0)
{
printf("%s", colorTypes[1]);
printf("BSH ERROR : Memory error !\n");
printf("%s", colorTypes[sizeof(colorTypes) / 8 -1]);
exit(-1);
}
while(status)
{
show_prompt(conf);
buffer = readCommandInput();
if (buffer != NULL){
args = splitCommandInput(buffer);
status = shell_execute(args, conf);
}
readShellConf(conf);
}
free(buffer);
free_shell(conf);
}