perf: fix something
This commit is contained in:
parent
54ea6337e9
commit
d9f5d5a708
2 changed files with 29 additions and 21 deletions
37
exec.c
37
exec.c
|
@ -2,31 +2,31 @@
|
|||
* @Author: 1ridic
|
||||
* @Date: 2022-09-18 14:14:23
|
||||
* @Last Modified by: 1ridic
|
||||
* @Last Modified time: 2022-09-18 14:44:37
|
||||
* @Last Modified time: 2022-09-18 23:21:56
|
||||
*/
|
||||
#include "builtin.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include "builtin.h"
|
||||
|
||||
extern int (*builtin_func[]) (char **);
|
||||
extern char* builtin_cmd[];
|
||||
extern int (*builtin_func[])(char **);
|
||||
extern char *builtin_cmd[];
|
||||
|
||||
int forkExec(char **args) {
|
||||
pid_t pid;
|
||||
int status;
|
||||
#ifdef DEBUG
|
||||
printf("debug: fork enter.\n");
|
||||
printf("debug: fork enter.\n");
|
||||
#endif
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
/* child process */
|
||||
if (execvp(args[0], args) == -1) {
|
||||
perror("dish");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (execvp(args[0], args) == -1) {
|
||||
perror("dish");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} else if (pid < 0) {
|
||||
/* fork error */
|
||||
perror("dish");
|
||||
|
@ -34,11 +34,18 @@ int forkExec(char **args) {
|
|||
extern char volatile isWaiting;
|
||||
isWaiting = 1;
|
||||
/* parent process: wait child process*/
|
||||
pid=wait(&status);
|
||||
isWaiting = 0;
|
||||
|
||||
int stat_val;
|
||||
waitpid(pid, &stat_val, 0);
|
||||
if (WIFEXITED(stat_val)) {
|
||||
isWaiting = 0;
|
||||
return WEXITSTATUS(stat_val);
|
||||
}
|
||||
else if (WIFSIGNALED(stat_val)) {
|
||||
isWaiting = 1;
|
||||
return WTERMSIG(stat_val);
|
||||
}
|
||||
}
|
||||
return WEXITSTATUS(status);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int commandExec(char **args) {
|
||||
|
|
7
main.c
7
main.c
|
@ -2,13 +2,13 @@
|
|||
* @Author: 1ridic
|
||||
* @Date: 2022-09-18 14:13:59
|
||||
* @Last Modified by: 1ridic
|
||||
* @Last Modified time: 2022-09-18 22:34:28
|
||||
* @Last Modified time: 2022-09-18 23:21:37
|
||||
*/
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
#include <string.h>
|
||||
#include "loop.h"
|
||||
|
||||
char volatile isWaiting = 0;
|
||||
|
@ -33,7 +33,8 @@ int main(int argc, char *argv[]) {
|
|||
fprintf(stdout,"\033[H\033[J");
|
||||
/* open history file */
|
||||
extern FILE* hf;
|
||||
hf = fopen(strcat(getenv("HOME"), "/.dish_history"), "a+");
|
||||
const char* hf_path=strcat(getenv("HOME"), "/.dish_history");
|
||||
hf = fopen(hf_path, "a+");
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stdout,"DEBUG is defined\n");
|
||||
|
|
Loading…
Reference in a new issue