@ -23,7 +23,7 @@ import sys
import logging
import logging
import signal
import signal
import time
import time
from shadowsocks import common
from shadowsocks import common , utils
# this module is ported from ShadowVPN daemon.c
# this module is ported from ShadowVPN daemon.c
@ -58,7 +58,7 @@ def write_pid_file(pid_file, pid):
fd = os . open ( pid_file , os . O_RDWR | os . O_CREAT ,
fd = os . open ( pid_file , os . O_RDWR | os . O_CREAT ,
stat . S_IRUSR | stat . S_IWUSR )
stat . S_IRUSR | stat . S_IWUSR )
except OSError as e :
except OSError as e :
logging . error ( e )
utils . print_exception ( e )
return - 1
return - 1
flags = fcntl . fcntl ( fd , fcntl . F_GETFD )
flags = fcntl . fcntl ( fd , fcntl . F_GETFD )
assert flags != - 1
assert flags != - 1
@ -127,7 +127,7 @@ def daemon_start(pid_file, log_file):
freopen ( log_file , ' a ' , sys . stdout )
freopen ( log_file , ' a ' , sys . stdout )
freopen ( log_file , ' a ' , sys . stderr )
freopen ( log_file , ' a ' , sys . stderr )
except IOError as e :
except IOError as e :
logging . error ( e )
utils . print_exception ( e )
sys . exit ( 1 )
sys . exit ( 1 )
@ -140,7 +140,7 @@ def daemon_stop(pid_file):
if not buf :
if not buf :
logging . error ( ' not running ' )
logging . error ( ' not running ' )
except IOError as e :
except IOError as e :
logging . error ( e )
utils . print_exception ( e )
if e . errno == errno . ENOENT :
if e . errno == errno . ENOENT :
# always exit 0 if we are sure daemon is not running
# always exit 0 if we are sure daemon is not running
logging . error ( ' not running ' )
logging . error ( ' not running ' )
@ -155,7 +155,7 @@ def daemon_stop(pid_file):
logging . error ( ' not running ' )
logging . error ( ' not running ' )
# always exit 0 if we are sure daemon is not running
# always exit 0 if we are sure daemon is not running
return
return
logging . error ( e )
utils . print_exception ( e )
sys . exit ( 1 )
sys . exit ( 1 )
else :
else :
logging . error ( ' pid is not positive: %d ' , pid )
logging . error ( ' pid is not positive: %d ' , pid )