perf: fix something

This commit is contained in:
iridiumR 2022-09-18 23:22:20 +08:00
parent 54ea6337e9
commit d9f5d5a708
No known key found for this signature in database
GPG key ID: 5574BE4450D55618
2 changed files with 29 additions and 21 deletions

25
exec.c
View file

@ -2,21 +2,21 @@
* @Author: 1ridic * @Author: 1ridic
* @Date: 2022-09-18 14:14:23 * @Date: 2022-09-18 14:14:23
* @Last Modified by: 1ridic * @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 <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/types.h>
#include <string.h> #include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h> #include <unistd.h>
#include "builtin.h"
extern int (*builtin_func[]) (char **); extern int (*builtin_func[])(char **);
extern char* builtin_cmd[]; extern char *builtin_cmd[];
int forkExec(char **args) { int forkExec(char **args) {
pid_t pid; pid_t pid;
int status;
#ifdef DEBUG #ifdef DEBUG
printf("debug: fork enter.\n"); printf("debug: fork enter.\n");
#endif #endif
@ -34,11 +34,18 @@ int forkExec(char **args) {
extern char volatile isWaiting; extern char volatile isWaiting;
isWaiting = 1; isWaiting = 1;
/* parent process: wait child process*/ /* parent process: wait child process*/
pid=wait(&status); int stat_val;
waitpid(pid, &stat_val, 0);
if (WIFEXITED(stat_val)) {
isWaiting = 0; isWaiting = 0;
return WEXITSTATUS(stat_val);
} }
return WEXITSTATUS(status); else if (WIFSIGNALED(stat_val)) {
isWaiting = 1;
return WTERMSIG(stat_val);
}
}
return -1;
} }
int commandExec(char **args) { int commandExec(char **args) {

7
main.c
View file

@ -2,13 +2,13 @@
* @Author: 1ridic * @Author: 1ridic
* @Date: 2022-09-18 14:13:59 * @Date: 2022-09-18 14:13:59
* @Last Modified by: 1ridic * @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 <signal.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <strings.h> #include <string.h>
#include "loop.h" #include "loop.h"
char volatile isWaiting = 0; char volatile isWaiting = 0;
@ -33,7 +33,8 @@ int main(int argc, char *argv[]) {
fprintf(stdout,"\033[H\033[J"); fprintf(stdout,"\033[H\033[J");
/* open history file */ /* open history file */
extern FILE* hf; 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 #ifdef DEBUG
fprintf(stdout,"DEBUG is defined\n"); fprintf(stdout,"DEBUG is defined\n");