rotate_state.c (2406B) download
1#include "defs.h"
2#include "util.h"
3
4#include <errno.h>
5#include <string.h>
6#include <unistd.h>
7
8state_t get_rotated_state(void) {
9 bool depends = !access("depends", R_OK),
10 setup = !access("setup", X_OK),
11 start = !access("start", X_OK),
12 run = !access("run", X_OK),
13 pid = !access("pid", X_OK),
14 stop = !access("stop", X_OK),
15 finish = !access("finish", X_OK);
16
17 switch (service.state) {
18 case STATE_INACTIVE:
19 return depends ? STATE_DEPENDENCY
20 : setup ? STATE_SETUP
21 : start ? STATE_STARTING
22 : run ? STATE_ACTIVE_FOREGROUND
23 : STATE_ACTIVE_DUMMY;
24 case STATE_DEPENDENCY:
25 return setup ? STATE_SETUP
26 : start ? STATE_STARTING
27 : run ? STATE_ACTIVE_FOREGROUND
28 : STATE_ACTIVE_DUMMY;
29 case STATE_SETUP:
30 return start ? STATE_STARTING
31 : run ? STATE_ACTIVE_FOREGROUND
32 : STATE_ACTIVE_DUMMY;
33 case STATE_STARTING:
34 return pid ? STATE_ACTIVE_PID
35 : STATE_ACTIVE_BACKGROUND;
36 case STATE_ACTIVE_FOREGROUND:
37 return finish ? STATE_FINISHING
38 : STATE_INACTIVE;
39 case STATE_ACTIVE_BACKGROUND:
40 case STATE_ACTIVE_PID:
41 return stop ? STATE_STOPPING
42 : finish ? STATE_FINISHING
43 : !need_restart() ? STATE_INACTIVE
44 : setup ? STATE_SETUP
45 : start ? STATE_STARTING
46 : run ? STATE_ACTIVE_FOREGROUND
47 : STATE_ACTIVE_DUMMY;
48 case STATE_ACTIVE_DUMMY:
49 return finish ? STATE_FINISHING
50 : !need_restart() ? STATE_INACTIVE
51 : setup ? STATE_SETUP
52 : start ? STATE_STARTING
53 : run ? STATE_ACTIVE_FOREGROUND
54 : STATE_ACTIVE_DUMMY;
55 case STATE_STOPPING:
56 return finish ? STATE_FINISHING
57 : !need_restart() ? STATE_INACTIVE
58 : setup ? STATE_SETUP
59 : start ? STATE_STARTING
60 : run ? STATE_ACTIVE_FOREGROUND
61 : STATE_ACTIVE_DUMMY;
62 case STATE_FINISHING:
63 return !need_restart() ? STATE_INACTIVE
64 : setup ? STATE_SETUP
65 : start ? STATE_STARTING
66 : run ? STATE_ACTIVE_FOREGROUND
67 : STATE_ACTIVE_DUMMY;
68 }
69 return -1;
70}
71
72int rotate_state(bool now) {
73}