Skip to content

Commit

Permalink
moremem
Browse files Browse the repository at this point in the history
  • Loading branch information
txthinking committed Sep 1, 2020
1 parent 352c53c commit cdb3876
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 15 deletions.
1 change: 0 additions & 1 deletion joker.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <pwd.h>

void help();
void list();
void run(int argc, char *argv[]);

#endif
14 changes: 2 additions & 12 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int main(int argc, char *argv[])
}

struct passwd *pw = getpwuid(getuid());
char *s = (char *) malloc(strlen(pw->pw_dir) + 7);
char *s = (char *) malloc(strlen(pw->pw_dir) + 7*100);
sprintf(s, "%s/.joker", pw->pw_dir);
struct stat st = {0};
if (stat(s, &st) == -1) {
Expand All @@ -57,20 +57,17 @@ int main(int argc, char *argv[])
if(argc == 3 && strcmp(argv[1], "stop") == 0){
int pid = atoi(argv[2]);
if(pid == 0){
list();
return 0;
}
int i = kill(pid, SIGTERM);
if(i != 0){
printf("%s\n", "stop failed");
list();
return 0;
}
list();
return 0;
}
if(argc == 3 && strcmp(argv[1], "log") == 0){
char *s = (char *) malloc(4+strlen(pw->pw_dir) + 8 + strlen(argv[2]));
char *s = (char *) malloc(4*100+strlen(pw->pw_dir) + 8*100 + strlen(argv[2]));
sprintf(s, "cat %s/.joker/%s", pw->pw_dir, argv[2]);
int i;
i = system(s);
Expand All @@ -79,12 +76,5 @@ int main(int argc, char *argv[])
}

run(argc, argv);
list();
return 0;
}

void list()
{
system("sleep 1");
system("ps -x | grep \"`ps -e -o command | grep joker | grep -v grep | cut -d\" \" -f2-`\" | grep -v joker | grep -v grep");
}
4 changes: 2 additions & 2 deletions run.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void run(int argc, char *argv[])
char *l[argc];
int i = 1;
for(;i<argc;i++){
l[i-1] = (char *)malloc(strlen(argv[i]));
l[i-1] = (char *)malloc(strlen(argv[i])+1);
l[i-1] = strcpy(l[i-1], argv[i]);
}
l[i-1] = NULL;
Expand All @@ -62,7 +62,7 @@ void run(int argc, char *argv[])
close(io[1]);

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

0 comments on commit cdb3876

Please sign in to comment.