Browse Source

refine #128

pull/140/head
Max Lv 10 years ago
parent
commit
7adc9037ae
2 changed files with 35 additions and 27 deletions
  1. 40
      src/local.c
  2. 22
      src/shadowsocks.h

40
src/local.c

@ -1166,31 +1166,33 @@ int main (int argc, char **argv)
} }
#else #else
int start_ss_service(profile_t profile)
int start_ss_service(profile_t profile, int background)
{ {
#ifndef __MINGW32__ #ifndef __MINGW32__
/* Our process ID and Session ID */
pid_t pid;
if (background) {
/* Our process ID and Session ID */
pid_t pid;
/* Fork off the parent process */
pid = fork();
if (pid < 0)
{
return -1;
}
/* Fork off the parent process */
pid = fork();
if (pid < 0)
{
return -1;
}
/* If we got a good PID, then
we can exit the parent process. */
if (pid > 0)
{
return pid;
}
/* If we got a good PID, then
we can exit the parent process. */
if (pid > 0)
{
return pid;
}
/* Close out the standard file descriptors */
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
/* Close out the standard file descriptors */
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
}
#endif #endif
srand(time(NULL)); srand(time(NULL));

22
src/shadowsocks.h

@ -40,8 +40,7 @@ typedef struct {
int verbose; // verbose mode int verbose; // verbose mode
} profile_t; } profile_t;
/*
* An example profile
/* An example profile
const profile_t EXAMPLE_PROFILE = { const profile_t EXAMPLE_PROFILE = {
.remote_host = "example.com", .remote_host = "example.com",
@ -57,14 +56,21 @@ const profile_t EXAMPLE_PROFILE = {
.udp_relay = 0, .udp_relay = 0,
.verbose = 0 .verbose = 0
}; };
*/ */
// Create and start a shadowsocks service,
// If success, return the pid, if not, return -1
// On win32, this function won't return,
// you have to call it in on other processes
int start_ss_service(profile_t profile);
/*
* Create and start a shadowsocks service.
*
* If background is set to true, the service will run in a child process and
* return the pid if success. Otherwise, calling this function will block the
* current thread forever.
*
* On Win32, background mode is invalid. This function will always block the
* caller and never return.
*
* If failed, -1 is returned.
*/
int start_ss_service(profile_t profile, int background);
// To stop the service on posix system, just kill the daemon process // To stop the service on posix system, just kill the daemon process
// kill(pid, SIGKILL); // kill(pid, SIGKILL);

Loading…
Cancel
Save