Compare commits

..

1 Commits

Author SHA1 Message Date
Hongcai Deng 165ed6f176
Merge a16fde8070 into a0654b83c0 2025-02-03 20:29:32 +08:00
2 changed files with 8 additions and 20 deletions

View File

@ -112,8 +112,7 @@ static int do_stop(const char *pidFilename, const bool bShowError, pid_t *pid)
}
}
int process_stop_ex(const char *pidFilename,
const bool bShowError, bool *force)
int process_stop_ex(const char *pidFilename, const bool bShowError)
{
#define MAX_WAIT_COUNT 300
pid_t pid = 0;
@ -121,7 +120,6 @@ int process_stop_ex(const char *pidFilename,
int sig;
int i;
*force = false;
if ((result=do_stop(pidFilename, bShowError, &pid)) != 0) {
return result;
}
@ -133,15 +131,14 @@ int process_stop_ex(const char *pidFilename,
break;
}
fc_sleep_ms(100);
usleep(100 * 1000);
}
if (i == MAX_WAIT_COUNT) {
if (kill(pid, SIGKILL) == 0) {
fprintf(stderr, "waiting for pid [%d] exit timeout, "
"force kill!\n", (int)pid);
*force = true;
fc_sleep_ms(100);
usleep(100 * 1000);
}
}
@ -152,16 +149,12 @@ int process_stop_ex(const char *pidFilename,
int process_restart(const char *pidFilename)
{
const bool bShowError = false;
bool force;
int result;
result = process_stop_ex(pidFilename, bShowError, &force);
result = process_stop_ex(pidFilename, bShowError);
if (result == ENOENT || result == ESRCH) {
result = 0;
} else if (result == 0) {
if (force) {
sleep(1);
}
fprintf(stderr, "starting ...\n");
}
@ -339,6 +332,7 @@ int get_base_path_from_conf_file_ex(const char *filename, char *base_path,
int process_action(const char *pidFilename, const char *action, bool *stop)
{
const bool bShowError = true;
int result;
pid_t pid;
@ -351,7 +345,7 @@ int process_action(const char *pidFilename, const char *action, bool *stop)
if (strcmp(action, "stop") == 0)
{
*stop = true;
return process_stop(pidFilename);
return process_stop_ex(pidFilename, bShowError);
}
else if (strcmp(action, "status") == 0)
{

View File

@ -39,15 +39,9 @@ int write_to_pid_file(const char *pidFilename);
int delete_pid_file(const char *pidFilename);
int process_stop_ex(const char *pidFilename,
const bool bShowError, bool *force);
int process_stop_ex(const char *pidFilename, const bool bShowError);
static inline int process_stop(const char *pidFilename)
{
const bool bShowError = true;
bool force;
return process_stop_ex(pidFilename, bShowError, &force);
}
#define process_stop(pidFilename) process_stop_ex(pidFilename, true)
int process_restart(const char *pidFilename);