Re: [Cppcms-users] Segmentaion fault occurs to booster::aio::io_service running in booster::thread
Brought to you by:
artyom-beilis
From: CN <cn...@fa...> - 2016-05-10 06:47:48
|
Dear Artyom, Thanks for taking time answering! The program no longer causes segmentation fault after signals arrive if parameter "daemon.enable" in file "t.js" is set to "false" and launched by this shell script: ========= #!/bin/sh ### BEGIN INIT INFO # Provides: t # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: My Program # Description: Test signals. ### END INIT INFO PATH=/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/tmp/a.out NAME=t CONFIGFILE="-c /tmp/t.js" DESC="My Program" SCRIPTNAME=/etc/init.d/$NAME PIDFILE=/tmp/t.pid test -x $DAEMON || exit 0 . /lib/lsb/init-functions case "$1" in start) log_daemon_msg "Starting $DESC" $NAME start-stop-daemon --start --oknodo --quiet --pidfile $PIDFILE --exec $DAEMON -b -m -- $CONFIGFILE log_end_msg $? ;; stop) log_daemon_msg "Stopping $DESC" $NAME start-stop-daemon --stop --retry TERM/10 --quiet --pidfile $PIDFILE --exec $DAEMON --remove-pidfile log_end_msg $? ;; reload|force-reload) log_daemon_msg "Reloading $DESC" $NAME start-stop-daemon --stop --signal HUP --retry 10 --quiet --pidfile $PIDFILE --exec $DAEMON log_end_msg $? ;; restart) log_daemon_msg "Restarting $DESC" $NAME $0 stop $0 start ;; status) status_of_proc -p "$PIDFILE" "$DAEMON" "$NAME" && exit 0 || exit $? ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload|status}" >&2 exit 1 ;; esac exit 0 ========= Please note the "-b -m" options under "start)", in case this script is *generally correct* and also useful to anyone in this community. Best regards, CN On Tue, May 10, 2016, at 01:43 PM, Artyom Beilis wrote: > Ok I got what is the problem: > > Few things: > > I've run your code and it indeed crashes **when it runs as daemon > using its internal tool** > I still don't know why exactly it crashes but I assume it is related to > forking. > > Note that threads do not go well through forking (that is required to > create a daemon), actually they all become suspended and you need to > wake them up - but in general it is very bad practice. > IF you want to run your threads AND use daemonization services > (regarding restarting of the process) you need to start your threads > in cppcms::service::after_fork callback - otherwise > they'll be suspended after fork. > > On the side note: I think cppcms needs something like daemonize that > can be called prior to service::run().... something to add to feature > requests. > > Additional problem currently unsolved: > > Essentially cppcms service daemonization is intended to use when > cppcms::service is master loop and responsible on the application life > time. For example it can even start several independent processes in > prefork mode. > See when you can service::run() it performs daemonization if it isn't > already a daemon and in service::~service() it removes the lock file. > So it is problematic to start/stop the service several times (but I > think this is at least fixable) > > If you want to restart the service on your own - which is very > legitimate requirement, for example for creating web interfaces for > existing services than you can't use the internal daemonization tool. > You need to fork-off and run as daemon before you start your threads & > run the service. > > Regards, > > Artyom -- http://www.fastmail.com - Same, same, but different... |