Skip to content

Commit d33b865

Browse files
cs17899219madeye
authored andcommitted
Add a signal SIGUSR1 for safely stop the server (#677)
1 parent d8598d3 commit d33b865

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/local.c

+11
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,9 @@ static void signal_cb(EV_P_ ev_signal *w, int revents)
940940
switch (w->signum) {
941941
case SIGINT:
942942
case SIGTERM:
943+
#ifndef __MINGW32__
944+
case SIGUSR1:
945+
#endif
943946
ev_unloop(EV_A_ EVUNLOOP_ALL);
944947
}
945948
}
@@ -1328,6 +1331,11 @@ int start_ss_local_server(profile_t profile)
13281331
ev_signal_init(&sigterm_watcher, signal_cb, SIGTERM);
13291332
ev_signal_start(EV_DEFAULT, &sigint_watcher);
13301333
ev_signal_start(EV_DEFAULT, &sigterm_watcher);
1334+
#ifndef __MINGW32__
1335+
struct ev_signal sigusr1_watcher;
1336+
ev_signal_init(&sigusr1_watcher, signal_cb, SIGUSR1);
1337+
ev_signal_start(EV_DEFAULT, &sigusr1_watcher);
1338+
#endif
13311339

13321340
// Setup keys
13331341
LOGI("initializing ciphers... %s", method);
@@ -1405,6 +1413,9 @@ int start_ss_local_server(profile_t profile)
14051413

14061414
ev_signal_stop(EV_DEFAULT, &sigint_watcher);
14071415
ev_signal_stop(EV_DEFAULT, &sigterm_watcher);
1416+
#ifndef __MINGW32__
1417+
ev_signal_stop(EV_DEFAULT, &sigusr1_watcher);
1418+
#endif
14081419

14091420
// cannot reach here
14101421
return 0;

src/shadowsocks.h

+2
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,7 @@ int start_ss_local_server(profile_t profile);
8383

8484
// To stop the service on posix system, just kill the daemon process
8585
// kill(pid, SIGKILL);
86+
// Otherwise, If you start the service in a thread, you may need to send a signal SIGUSER1 to the thread.
87+
// pthread_kill(pthread_t, SIGUSR1);
8688

8789
#endif // _SHADOWSOCKS_H

0 commit comments

Comments
 (0)