summaryrefslogtreecommitdiff
path: root/src/librc.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2007-10-09 21:13:08 +0000
committerRoy Marples <roy@marples.name>2007-10-09 21:13:08 +0000
commit2613316686a95986f88d5b8521ef82baa7617088 (patch)
treef6f6d794c08787b3e6ff223115f3f4258f630f60 /src/librc.c
parent31c6cacb0a92d4fc8d024ca51eb83058398bb6b5 (diff)
downloadopenrc-2613316686a95986f88d5b8521ef82baa7617088.tar.gz
openrc-2613316686a95986f88d5b8521ef82baa7617088.tar.bz2
openrc-2613316686a95986f88d5b8521ef82baa7617088.tar.xz
Fix failed services a little, and make timeout more sane
Diffstat (limited to 'src/librc.c')
-rw-r--r--src/librc.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/librc.c b/src/librc.c
index 43809e2..0995d3d 100644
--- a/src/librc.c
+++ b/src/librc.c
@@ -10,8 +10,10 @@
/* usecs to wait while we poll the fifo */
#define WAIT_INTERVAL 20000000
-/* max nsecs to wait until a service comes up */
-#define WAIT_MAX 60000000000
+/* max secs to wait until a service comes up */
+#define WAIT_MAX 300
+
+#define ONE_SECOND 1000000000
#define SOFTLEVEL RC_SVCDIR "/softlevel"
@@ -393,7 +395,7 @@ bool rc_service_mark (const char *service, const rc_service_state_t state)
skip_state = state;
}
- if (state == RC_SERVICE_COLDPLUGGED) {
+ if (state == RC_SERVICE_COLDPLUGGED || state == RC_SERVICE_FAILED) {
free (init);
free (svc);
return (true);
@@ -604,7 +606,12 @@ static pid_t _exec_service (const char *service, const char *arg)
pid_t rc_service_stop (const char *service)
{
- if (rc_service_state (service) & RC_SERVICE_STOPPED)
+ rc_service_state_t state = rc_service_state (service);
+
+ if (state & RC_SERVICE_FAILED)
+ return (-1);
+
+ if (state & RC_SERVICE_STOPPED)
return (0);
return (_exec_service (service, "stop"));
@@ -613,7 +620,12 @@ librc_hidden_def(rc_service_stop)
pid_t rc_service_start (const char *service)
{
- if (! rc_service_state (service) & RC_SERVICE_STOPPED)
+ rc_service_state_t state = rc_service_state (service);
+
+ if (state & RC_SERVICE_FAILED)
+ return (-1);
+
+ if (! state & RC_SERVICE_STOPPED)
return (0);
return (_exec_service (service, "start"));
@@ -676,7 +688,7 @@ bool rc_service_wait (const char *service)
char *base;
char *fifo;
struct timespec ts;
- int nloops = WAIT_MAX / WAIT_INTERVAL;
+ int nloops = WAIT_MAX * (ONE_SECOND / WAIT_INTERVAL);
bool retval = false;
bool forever = false;
@@ -710,6 +722,8 @@ bool rc_service_wait (const char *service)
nloops --;
}
+ if (! exists (fifo))
+ retval = true;
free (fifo);
return (retval);
}