Skip to content

Commit

Permalink
fixed #6
Browse files Browse the repository at this point in the history
  • Loading branch information
txthinking committed Mar 16, 2021
1 parent 9befd52 commit 4919ae9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
13 changes: 10 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int main(int argc, char *argv[])
return 0;
}
if(argc == 2 && (strcmp(argv[1], "version") == 0 || strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-v") == 0)){
printf("v20200902\n");
printf("v20210214\n");
return 0;
}

Expand All @@ -51,7 +51,7 @@ int main(int argc, char *argv[])

if(argc == 2 && strcmp(argv[1], "list") == 0){
int i;
i = system("s=`ps -e -o command | grep joker | grep -v grep | grep -v \"joker list\"`; if [ -n \"$s\" ]; then ps -x | grep \"`echo \"$s\" | cut -d' ' -f2-`\" | grep -v joker | grep -v grep; fi;");
i = system("s=`ps -e -o command | grep joker | grep -v grep | grep -v \"joker list\"`; if [ -n \"$s\" ]; then ps -x | grep -F \"`echo \"$s\" | cut -d' ' -f2-`\" | grep -v joker | grep -v grep; fi;");
return i;
}
if(argc == 3 && strcmp(argv[1], "stop") == 0){
Expand All @@ -75,6 +75,13 @@ int main(int argc, char *argv[])
return i;
}

run(argc, argv);
pid_t pid = fork();
if (pid > 0) {
run(argc, argv);
waitpid(pid, NULL, 0);
}
if (pid == 0) {
execl("/bin/sh", "sh", "-c", "sleep 1 && echo && echo \"log file: ~/.joker/`cat /tmp/jokerlastid`\" && echo", NULL);
}
return 0;
}
5 changes: 5 additions & 0 deletions run.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ void run(int argc, char *argv[])
// TODO ignore kill-like signal
close(io[1]);

char *s0 = (char *) malloc(24*100 + 7*100);
sprintf(s0, "echo %d > /tmp/jokerlastid", pid);
system(s0);
free(s0);

struct passwd *pw = getpwuid(getuid());
char *s = (char *) malloc(strlen(pw->pw_dir) + 8*100 + 7*100);
sprintf(s, "%s/.joker/%d", pw->pw_dir, pid);
Expand Down

0 comments on commit 4919ae9

Please sign in to comment.