Compare commits

...

3 Commits

Author SHA1 Message Date
Hongcai Deng 91fff46499
Merge a16fde8070 into aa144b5981 2025-02-23 23:45:16 +08:00
YuQing aa144b5981 process_stop_ex add parameter: force 2025-02-19 15:07:48 +08:00
Hongcai Deng a16fde8070 fix: compile error when build .so using .a
```
src/libfastcommon.a(hash.o): relocation R_X86_64_32 against `.data' can not be used when making a shared object; recompile with -fPIC
```

env: Ubuntu 14.04, gcc 4.8
2017-01-29 14:20:18 +08:00
3 changed files with 21 additions and 9 deletions

View File

@ -66,7 +66,7 @@ libfastcommon.a: $(FAST_STATIC_OBJS)
.c: .c:
$(COMPILE) -o $@ $< $(FAST_STATIC_OBJS) $(LIB_PATH) $(INC_PATH) $(COMPILE) -o $@ $< $(FAST_STATIC_OBJS) $(LIB_PATH) $(INC_PATH)
.c.o: .c.o:
$(COMPILE) -c -o $@ $< $(INC_PATH) $(COMPILE) -c -fPIC -o $@ $< $(INC_PATH)
.c.lo: .c.lo:
$(COMPILE) -c -fPIC -o $@ $< $(INC_PATH) $(COMPILE) -c -fPIC -o $@ $< $(INC_PATH)
install: install:

View File

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

View File

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