Stop ssd from waiting by default - most daemons are good now.

This commit is contained in:
Roy Marples 2008-09-26 23:58:57 +00:00
parent 13d88731b7
commit c3e192a834
3 changed files with 47 additions and 17 deletions

View File

@ -52,6 +52,14 @@ rc_logger="NO"
# variables through, add them here. Use a * to allow all variables through. # variables through, add them here. Use a * to allow all variables through.
# rc_env_allow="VAR1 VAR2" # rc_env_allow="VAR1 VAR2"
# By default we assume that all daemons will start correctly.
# However, some do not - a classic example is that they fork and return 0 AND
# then child barfs on a configuration error. Or the daemon has a bug and the
# child crashes. You can set the number of milliseconds start-stop-daemon
# waits to check that the daemon is still running after starting here.
# The default is 0 - no checking.
# rc_start_wait=100
############################################################################## ##############################################################################
# MISC CONFIGURATION VARIABLES # MISC CONFIGURATION VARIABLES
# There variables are shared between many init scripts # There variables are shared between many init scripts

View File

@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.Dd September 22, 2008 .Dd September 27, 2008
.Dt START-STOP-DAEMON 8 SMM .Dt START-STOP-DAEMON 8 SMM
.Os OpenRC .Os OpenRC
.Sh NAME .Sh NAME
@ -155,6 +155,12 @@ assumed.
.Va SSD_NICELEVEL .Va SSD_NICELEVEL
can also set the scheduling priority of the daemon, but the command line can also set the scheduling priority of the daemon, but the command line
option takes precedence. option takes precedence.
.Pp
.Va SSD_STARTWAIT
overrides the number of milliseconds set in
.Pa /etc/rc.conf
.Nm
waits for to check the daemon is still running.
.Sh NOTE .Sh NOTE
.Nm .Nm
uses uses

View File

@ -36,7 +36,6 @@
/* nano seconds */ /* nano seconds */
#define POLL_INTERVAL 20000000 #define POLL_INTERVAL 20000000
#define WAIT_PIDFILE 500000000 #define WAIT_PIDFILE 500000000
#define START_WAIT 100000000
#define ONE_SECOND 1000000000 #define ONE_SECOND 1000000000
#include <sys/types.h> #include <sys/types.h>
@ -607,6 +606,7 @@ int start_stop_daemon(int argc, char **argv)
bool setumask = false; bool setumask = false;
mode_t numask; mode_t numask;
char **margv; char **margv;
unsigned int start_wait = 0;
TAILQ_INIT(&schedule); TAILQ_INIT(&schedule);
atexit(cleanup); atexit(cleanup);
@ -1090,12 +1090,14 @@ int start_stop_daemon(int argc, char **argv)
if (pamr == PAM_SUCCESS) if (pamr == PAM_SUCCESS)
pam_close_session(pamh, PAM_SILENT); pam_close_session(pamh, PAM_SILENT);
#endif #endif
eerrorx("%s: failed to exec `%s': %s", applet, exec, strerror(errno)); eerrorx("%s: failed to exec `%s': %s",
applet, exec,strerror(errno));
} }
/* Parent process */ /* Parent process */
if (!background) { if (!background) {
/* As we're not backgrounding the process, wait for our pid to return */ /* As we're not backgrounding the process, wait for our pid
* to return */
i = 0; i = 0;
spid = pid; spid = pid;
@ -1116,9 +1118,18 @@ int start_stop_daemon(int argc, char **argv)
/* Wait a little bit and check that process is still running /* Wait a little bit and check that process is still running
We do this as some badly written daemons fork and then barf */ We do this as some badly written daemons fork and then barf */
if (START_WAIT > 0) { if ((p = getenv("SSD_STARTWAIT")) ||
(p = rc_conf_value("rc_start_wait")))
{
if (sscanf(p, "%u", &start_wait) == 1)
start_wait *= 1000000;
else
start_wait = 0;
}
if (start_wait > 0) {
struct timespec ts; struct timespec ts;
int nloops = START_WAIT / POLL_INTERVAL; int nloops = start_wait / POLL_INTERVAL;
int nloopsp = WAIT_PIDFILE / POLL_INTERVAL; int nloopsp = WAIT_PIDFILE / POLL_INTERVAL;
bool alive = false; bool alive = false;
@ -1135,30 +1146,35 @@ int start_stop_daemon(int argc, char **argv)
} }
} }
/* We wait for a specific amount of time for a pidfile to be /* We wait for a specific amount of time for a pidfile
* created. Once everything is in place we then wait some more * to be created.
* to ensure that the daemon really is running and won't abort due * Once everything is in place we then wait some more
* to a config error. */ * to ensure that the daemon really is running and won't
* abort due to a config error. */
if (!background && pidfile && nloopsp) if (!background && pidfile && nloopsp)
nloopsp--; nloopsp--;
else else
nloops--; nloops--;
/* This is knarly. /* This is knarly.
If we backgrounded then we know the exact pid. * If we backgrounded then we know the exact pid.
Otherwise if we have a pidfile then it *may* know the exact pid. * Otherwise if we have a pidfile then it *may* know
Failing that, we'll have to query processes. * the exact pid.
We sleep first as some programs like ntp like to fork, and write * Failing that, we'll have to query processes.
their pidfile a LONG time later. */ * We sleep first as some programs like ntp like to
* fork, and write their pidfile a LONG time later. */
if (background) { if (background) {
if (kill (pid, 0) == 0) if (kill (pid, 0) == 0)
alive = true; alive = true;
} else { } else {
if (pidfile) { if (pidfile) {
/* The pidfile may not have been written yet - give it some time */ /* The pidfile may not have been
* written yet - give it some time */
if ((pid = get_pid(pidfile, true)) == -1) { if ((pid = get_pid(pidfile, true)) == -1) {
if (! nloopsp) if (! nloopsp)
eerrorx("%s: did not create a valid pid in `%s'", eerrorx("%s: did not "
"create a valid"
" pid in `%s'",
applet, pidfile); applet, pidfile);
alive = true; alive = true;
pid = 0; pid = 0;