summaryrefslogtreecommitdiffstats
path: root/urunlevel/runlevel/start_daemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'urunlevel/runlevel/start_daemon.c')
-rw-r--r--urunlevel/runlevel/start_daemon.c168
1 files changed, 81 insertions, 87 deletions
diff --git a/urunlevel/runlevel/start_daemon.c b/urunlevel/runlevel/start_daemon.c
index ba922fa..6bd0b2f 100644
--- a/urunlevel/runlevel/start_daemon.c
+++ b/urunlevel/runlevel/start_daemon.c
@@ -3,6 +3,9 @@
3 * 3 *
4 * Copyright (C) 2005 by David Seikel won_fang@yahoo.com.au 4 * Copyright (C) 2005 by David Seikel won_fang@yahoo.com.au
5 * 5 *
6 * Clean room implementation of LSB init.d specs.
7 * I didn't steal any of this, honest B-).
8 *
6 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or 11 * the Free Software Foundation; either version 2 of the License, or
@@ -31,40 +34,39 @@
31#include "lib_init_d.h" 34#include "lib_init_d.h"
32 35
33 36
34int start_daemon(int force, int nice_level, char *pidfile, char *pathname, char *args) 37int start_daemon(int force, int nice_level, char *pidfile, char *pathname,
38 char *args)
35{ 39{
36 int status = 0; 40 int status = pidofproc(pidfile, pathname, NULL);
37 status = pidofproc(pidfile, pathname, NULL); 41
38 42 if ((status != INIT_D_STATUS_OK) || (force)) {
39 if ((status != INIT_D_STATUS_OK) || (force)) 43 char *pids = NULL;
40 { 44 char *strtok_temp;
41 char *pids = NULL; 45
42 char *strtok_temp; 46 doit(DAEMON, "start-stop-daemon -Sbmp %s -x %s -- %s", pidfile,
43 47 pathname, args);
44 doit(DAEMON, "start-stop-daemon -Sbmp %s -x %s -- %s", pidfile, pathname, args); 48// Should poll /proc/pid/... instead
45sleep(1); 49 sleep(1);
46 status = pidofproc(pidfile, pathname, &pids); 50 status = pidofproc(pidfile, pathname, &pids);
47 if ((status == INIT_D_STATUS_OK) && (nice_level)) 51 if ((status == INIT_D_STATUS_OK) && (nice_level)) {
48 { 52 int i;
49 int i; 53 char *pid;
50 char *pid; 54
51 55 pid = strtok_r(pids, " ", &strtok_temp);
52 pid = strtok_r(pids, " ", &strtok_temp); 56 for (i = 0; pid != NULL; i++) {
53 for (i = 0; pid != NULL; i++) 57 int ps = atoi(pid);
54 { 58 int oldp;
55 int ps = atoi(pid); 59
56 int oldp; 60 errno = 0;
57 61 oldp = getpriority(PRIO_PROCESS, ps);
58 errno = 0; 62 if (errno == 0)
59 oldp = getpriority(PRIO_PROCESS, ps); 63 setpriority(PRIO_PROCESS, ps, oldp + nice_level);
60 if (errno == 0) 64 pid = strtok_r(NULL, " ", &strtok_temp);
61 setpriority(PRIO_PROCESS, ps, oldp + nice_level); 65 }
62 pid = strtok_r(NULL, " ", &strtok_temp); 66 }
63 }
64 } 67 }
65 }
66 68
67 return status; 69 return status;
68} 70}
69 71
70 72
@@ -83,71 +85,63 @@ start_daemon [-f] [-n nicelevel] [-p pidfile] pathname [args]
83*/ 85*/
84 86
85 87
88 /* getopt not used, because I don't think it can handle [args] */
86int start_daemon_main(int argc, char **argv) 89int start_daemon_main(int argc, char **argv)
87{ 90{
88 int result = EXIT_FAILURE; 91 int result = EXIT_FAILURE;
89 int force = 0; 92 int force = 0;
90 int nice_level = 0; 93 int nice_level = 0;
91 char *pidfile = NULL; 94 char *pidfile = NULL;
92 char *pathname = NULL; 95 char *pathname = NULL;
93 char *args = NULL; 96 char *args = NULL;
94 int i; 97 int i;
95 98
96 for (i = 1; i < argc; i++) 99 for (i = 1; i < argc; i++) {
97 { 100 char *p = argv[i];
98 char *p = argv[i]; 101
99 102 if (*p == '-') {
100 if (*p == '-') 103 while (*(++p)) {
101 { 104 switch (*p) {
102 while (*(++p)) 105 case 'f':
103 { 106 force = 1;
104 switch (*p) 107 break;
105 { 108
106 case 'f' : 109 case 'n':
107 force = 1; 110 if ((++i) < argc)
108 break; 111 nice_level = atoi(argv[i]);
109 112 else
110 case 'n' : 113 bb_show_usage();
111 if ((++i) < argc) 114 break;
112 nice_level = atoi(argv[i]); 115
113 else 116 case 'p':
114 bb_show_usage(); 117 if ((++i) < argc)
115 break; 118 pidfile = argv[i];
116 119 else
117 case 'p' : 120 bb_show_usage();
118 if ((++i) < argc) 121 break;
119 pidfile = argv[i]; 122
120 else 123 default:
121 bb_show_usage(); 124 bb_show_usage();
125 }
126 }
127 } else if (pathname == NULL) {
128 pathname = p;
122 break; 129 break;
123 130 } else
124 default:
125 bb_show_usage(); 131 bb_show_usage();
126 }
127 }
128 }
129 else if (pathname == NULL)
130 {
131 pathname = p;
132 break;
133 } 132 }
134 else
135 bb_show_usage();
136 }
137 133
138 if (pathname == NULL) 134 if (pathname == NULL)
139 bb_show_usage(); 135 bb_show_usage();
140 136
141 if (i < argc) 137 if (i < argc)
142 args = argv_cat(argc - i, &argv[i]); 138 args = argv_cat(argc - i, &argv[i]);
143 139
144//bb_printf("ARGS - |%s|%s|%d|%d|%s\n", pidfile, pathname, force, nice_level, args); 140//bb_printf("ARGS - |%s|%s|%d|%d|%s\n", pidfile, pathname, force, nice_level, args);
145 result = start_daemon(force, nice_level, pidfile, pathname, args); 141 result = start_daemon(force, nice_level, pidfile, pathname, args);
146 142
147 if (args != NULL) 143 if (args != NULL)
148 free(args); 144 free(args);
149 145
150 return result; 146 return result;
151} 147}
152
153