functional
git-svn-id: file:///raid/svn-personal/mokou/trunk@12 35d6bad2-6c5c-c749-ada2-a2c82cb3bd79
This commit is contained in:
parent
01d182a090
commit
fadd30a380
|
@ -62,6 +62,7 @@ int main(int argc, char** argv){
|
||||||
if(connect(sock, (struct sockaddr*)&sun, sizeof(sun)) == -1){
|
if(connect(sock, (struct sockaddr*)&sun, sizeof(sun)) == -1){
|
||||||
fprintf(stderr, "Connection failure: %s\n", strerror(errno));
|
fprintf(stderr, "Connection failure: %s\n", strerror(errno));
|
||||||
close(sock);
|
close(sock);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
send(sock, msg, strlen(msg), 0);
|
send(sock, msg, strlen(msg), 0);
|
||||||
|
|
||||||
|
|
|
@ -208,7 +208,8 @@ const char* mk_errors[] = {
|
||||||
"Failed to start",
|
"Failed to start",
|
||||||
"Service is dead",
|
"Service is dead",
|
||||||
"Bad signal",
|
"Bad signal",
|
||||||
"Could not stop the service"
|
"Could not stop the service",
|
||||||
|
"Could not run the stop command"
|
||||||
};
|
};
|
||||||
|
|
||||||
int mk_stop_service(const char* name){
|
int mk_stop_service(const char* name){
|
||||||
|
@ -256,22 +257,7 @@ int mk_stop_service(const char* name){
|
||||||
log = mk_strcat("Sending SIG", sys_signame[sig]);
|
log = mk_strcat("Sending SIG", sys_signame[sig]);
|
||||||
mk_log(log);
|
mk_log(log);
|
||||||
free(log);
|
free(log);
|
||||||
bool dead = false;
|
|
||||||
kill(pid, sig);
|
kill(pid, sig);
|
||||||
for(i = 0; i < 3; i++){
|
|
||||||
if(kill(pid, 0) == -1){
|
|
||||||
mk_log("Process died");
|
|
||||||
dead = true;
|
|
||||||
break;
|
|
||||||
}else{
|
|
||||||
mk_log("Process is still alive");
|
|
||||||
}
|
|
||||||
if(i != 2) sleep(1);
|
|
||||||
}
|
|
||||||
if(!dead){
|
|
||||||
mk_log("Could not kill the process");
|
|
||||||
return 6;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
char** pargv = malloc(sizeof(*pargv));
|
char** pargv = malloc(sizeof(*pargv));
|
||||||
|
@ -298,6 +284,46 @@ int mk_stop_service(const char* name){
|
||||||
if(srv->exec[i] == 0) break;
|
if(srv->exec[i] == 0) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool fail = false;
|
||||||
|
pid_t pid = fork();
|
||||||
|
if(pid == 0){
|
||||||
|
int n = open("/dev/null", O_RDWR);
|
||||||
|
dup2(n, 1);
|
||||||
|
dup2(n, 2);
|
||||||
|
execvp(pargv[0], pargv);
|
||||||
|
_exit(-1);
|
||||||
|
}else{
|
||||||
|
int status;
|
||||||
|
waitpid(pid, &status, 0);
|
||||||
|
if(WEXITSTATUS(status) != 0) fail = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i = 0; pargv[i] != NULL; i++) free(pargv[i]);
|
||||||
|
free(pargv);
|
||||||
|
|
||||||
|
if(fail){
|
||||||
|
mk_log("Failed to run stop command");
|
||||||
|
return 7;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
usleep(100);
|
||||||
|
|
||||||
|
bool dead = false;
|
||||||
|
for(i = 0; i < 3; i++){
|
||||||
|
if(kill(pid, 0) == -1){
|
||||||
|
mk_log("Process died");
|
||||||
|
dead = true;
|
||||||
|
break;
|
||||||
|
}else{
|
||||||
|
mk_log("Process is still alive");
|
||||||
|
}
|
||||||
|
if(i != 2) sleep(1);
|
||||||
|
}
|
||||||
|
if(!dead){
|
||||||
|
mk_log("Could not kill the process");
|
||||||
|
return 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
srv->stopped = true;
|
srv->stopped = true;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user