add: hostname, user and current path of user
This commit is contained in:
parent
936980df04
commit
87f340eec1
@ -16,7 +16,7 @@ int execute_cmd(char **args) {
|
||||
if (pid == 0) {
|
||||
// Ce que va exécuter l'enfant
|
||||
int status_code = execvp(args[0], args);
|
||||
perror("seyshell");
|
||||
perror(args[0]);
|
||||
return status_code;
|
||||
} else {
|
||||
// Ce que va exécuter le parent
|
||||
|
||||
@ -50,12 +50,20 @@ char **split_line(char *line) {
|
||||
}
|
||||
|
||||
void shell_loop(void) {
|
||||
char *user = getenv("USER");
|
||||
char *hostname = malloc(BUFSIZE * sizeof(char));
|
||||
if (hostname == NULL) {
|
||||
dprintf(STDERR_FILENO, "Allocation error");
|
||||
}
|
||||
gethostname(hostname, sizeof(hostname));
|
||||
|
||||
char *line;
|
||||
char **args;
|
||||
int status = 1;
|
||||
|
||||
do {
|
||||
dprintf(STDOUT_FILENO, "> ");
|
||||
|
||||
dprintf(STDOUT_FILENO, "%s@%s %s> ", user, hostname, getenv("PWD"));
|
||||
line = read_line();
|
||||
args = split_line(line);
|
||||
status = execute_cmd(args);
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void shell_loop(void);
|
||||
Loading…
Reference in New Issue
Block a user