diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-01-28 22:07:31 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-01-28 22:07:31 +0000 |
commit | df4a2a61ce0cde5190def22309e9807cb5a56ab0 (patch) | |
tree | 364eb6562f6bd41eb3fe0ca15e497a2a76a4b57c /jabberd/progman.c | |
parent | 5f392fc3cf8e94112ed7b15b2038e51f1b2b3800 (diff) | |
download | gsc-df4a2a61ce0cde5190def22309e9807cb5a56ab0.tar.gz gsc-df4a2a61ce0cde5190def22309e9807cb5a56ab0.tar.bz2 |
Remove jabberd
git-svn-id: file:///svnroot/gsc/trunk@339 d2de0444-eb31-0410-8365-af798a554d48
Diffstat (limited to 'jabberd/progman.c')
-rw-r--r-- | jabberd/progman.c | 647 |
1 files changed, 0 insertions, 647 deletions
diff --git a/jabberd/progman.c b/jabberd/progman.c deleted file mode 100644 index 3dfe3ba..0000000 --- a/jabberd/progman.c +++ /dev/null | |||
@@ -1,647 +0,0 @@ | |||
1 | /* jabberd - a dispatcher program for jabber 2.x | ||
2 | Copyright (C) 2007 Sergey Poznyakoff | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU General Public License as published by the | ||
6 | Free Software Foundation; either version 3 of the License, or (at your | ||
7 | option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License along | ||
15 | with this program. If not, see <http://www.gnu.org/licenses/>. */ | ||
16 | |||
17 | #include "jabberd.h" | ||
18 | #include <sys/stat.h> | ||
19 | #include <fcntl.h> | ||
20 | |||
21 | #define TYPE_CORE 0 | ||
22 | #define TYPE_TRANSPORT 1 | ||
23 | #define TYPE_RETR 2 | ||
24 | |||
25 | struct prog | ||
26 | { | ||
27 | struct prog *next; /* Next program in the list */ | ||
28 | int type; | ||
29 | pid_t pid; /* PID */ | ||
30 | char *tag; /* Entry tag (for diagnostics purposes) */ | ||
31 | char **depend; | ||
32 | union | ||
33 | { | ||
34 | struct | ||
35 | { | ||
36 | int argc; | ||
37 | char **argv; /* Command line arguments */ | ||
38 | int retr[2]; | ||
39 | char *pidfile; /* Pidfile location */ | ||
40 | time_t timestamp; /* Time of last startup */ | ||
41 | size_t count; /* Number of failed starts since timestamp */ | ||
42 | int disabled; /* 1 if this entry is disabled */ | ||
43 | } p; | ||
44 | |||
45 | struct | ||
46 | { | ||
47 | struct prog *master; | ||
48 | } r; | ||
49 | } v; | ||
50 | }; | ||
51 | |||
52 | |||
53 | #define IS_PROG(p) ((p)->type == TYPE_CORE || (p)->type == TYPE_TRANSPORT) | ||
54 | |||
55 | static struct prog *proghead, *progtail; | ||
56 | static size_t prognum; | ||
57 | |||
58 | static void prog_stop (struct prog *prog, int sig); | ||
59 | |||
60 | void | ||
61 | link_prog (struct prog *pp, int prepend) | ||
62 | { | ||
63 | if (prepend) | ||
64 | { | ||
65 | pp->next = proghead; | ||
66 | proghead = pp; | ||
67 | if (!progtail) | ||
68 | progtail = pp; | ||
69 | } | ||
70 | else | ||
71 | { | ||
72 | pp->next = NULL; | ||
73 | if (progtail) | ||
74 | progtail->next = pp; | ||
75 | else | ||
76 | proghead = pp; | ||
77 | progtail = pp; | ||
78 | } | ||
79 | } | ||
80 | |||
81 | void | ||
82 | register_retr (int type, struct prog *master, pid_t pid) | ||
83 | { | ||
84 | struct prog *pp; | ||
85 | static char *retrstr[2] = { "stdout", "stderr" }; | ||
86 | size_t taglen = strlen (master->tag) + 1 + strlen (retrstr[type]); | ||
87 | char *tag = emalloc (taglen + 1); | ||
88 | |||
89 | strcpy (tag, master->tag); | ||
90 | strcat (tag, "/"); | ||
91 | strcat (tag, retrstr[type]); | ||
92 | |||
93 | for (pp = proghead; pp; pp = pp->next) | ||
94 | if (pp->type == TYPE_RETR && pp->v.r.master == master | ||
95 | && strcmp (pp->tag, tag) == 0) | ||
96 | { | ||
97 | free (tag); | ||
98 | prog_stop (pp, SIGKILL); | ||
99 | break; | ||
100 | } | ||
101 | |||
102 | if (!pp) | ||
103 | { | ||
104 | pp = emalloc (sizeof(*pp) + taglen + 1); | ||
105 | memset (pp, 0, sizeof(*pp)); | ||
106 | pp->type = TYPE_RETR; | ||
107 | pp->tag = (char *) (pp + 1); | ||
108 | strcpy (pp->tag, tag); | ||
109 | free (tag); | ||
110 | pp->v.r.master = master; | ||
111 | link_prog (pp, 1); | ||
112 | } | ||
113 | |||
114 | pp->pid = pid; | ||
115 | } | ||
116 | |||
117 | void | ||
118 | register_prog (int type, char *tag, char **argv, int retr[2], char **depv, | ||
119 | char *pidfile) | ||
120 | { | ||
121 | struct prog *p, *newp; | ||
122 | char *pstr; | ||
123 | int i; | ||
124 | size_t size = 0; | ||
125 | int dep_all = 0; | ||
126 | int depc = 0; | ||
127 | |||
128 | if (depv) | ||
129 | { | ||
130 | if (depv[0] && depv[1] == NULL) | ||
131 | { | ||
132 | if (strcmp (depv[0], "all") == 0) | ||
133 | { | ||
134 | dep_all = 1; | ||
135 | for (p = proghead; p; p = p->next) | ||
136 | if (p->type == TYPE_CORE) | ||
137 | { | ||
138 | depc++; | ||
139 | size += strlen (p->tag) + 1; | ||
140 | } | ||
141 | } | ||
142 | else if (strcmp (depv[0], "none") == 0) | ||
143 | depv = NULL; | ||
144 | } | ||
145 | |||
146 | if (depc == 0) | ||
147 | for (depc = 0; depv[depc]; depc++) | ||
148 | ; | ||
149 | size += sizeof (depv[0]) * (depc + 1); | ||
150 | } | ||
151 | |||
152 | for (i = 0; argv[i]; i++) | ||
153 | size += strlen (argv[i]); | ||
154 | size += i + sizeof (argv[0]) * (i + 1) + sizeof (*newp) | ||
155 | + (tag ? (strlen (tag) + 1) : 0); | ||
156 | if (pidfile) | ||
157 | size += strlen (pidfile) + 1; | ||
158 | |||
159 | newp = emalloc (size); | ||
160 | memset (newp, 0, sizeof(*newp)); | ||
161 | newp->type = type; | ||
162 | newp->pid = 0; | ||
163 | newp->v.p.argc = i; | ||
164 | newp->v.p.argv = (char **) (newp + 1); | ||
165 | pstr = (char*) (newp->v.p.argv + i + 1); | ||
166 | |||
167 | for (i = 0; argv[i]; i++) | ||
168 | { | ||
169 | strcpy (pstr, argv[i]); | ||
170 | newp->v.p.argv[i] = pstr; | ||
171 | pstr += strlen (pstr) + 1; | ||
172 | } | ||
173 | newp->v.p.argv[i] = NULL; | ||
174 | |||
175 | if (tag) | ||
176 | { | ||
177 | newp->tag = strcpy (pstr, tag); | ||
178 | pstr += strlen (pstr) + 1; | ||
179 | } | ||
180 | else | ||
181 | newp->tag = newp->v.p.argv[0]; | ||
182 | |||
183 | if (pidfile) | ||
184 | { | ||
185 | newp->v.p.pidfile = strcpy (pstr, pidfile); | ||
186 | pstr += strlen (pstr) + 1; | ||
187 | } | ||
188 | else | ||
189 | newp->v.p.pidfile = NULL; | ||
190 | |||
191 | if (depv) | ||
192 | { | ||
193 | newp->depend = (char**) pstr; | ||
194 | pstr = (char*) (newp->depend + depc + 1); | ||
195 | if (dep_all) | ||
196 | { | ||
197 | depc = 0; | ||
198 | for (p = proghead; p; p = p->next) | ||
199 | if (p->type == TYPE_CORE) | ||
200 | { | ||
201 | newp->depend[depc++] = pstr; | ||
202 | strcpy (pstr, p->tag); | ||
203 | pstr += strlen (pstr) + 1; | ||
204 | } | ||
205 | } | ||
206 | else | ||
207 | { | ||
208 | for (depc = 0; depv[depc]; depc++) | ||
209 | { | ||
210 | newp->depend[depc] = pstr; | ||
211 | strcpy (pstr, p->tag); | ||
212 | pstr += strlen (pstr) + 1; | ||
213 | } | ||
214 | } | ||
215 | depv[depc] = NULL; | ||
216 | } | ||
217 | else | ||
218 | newp->depend = NULL; | ||
219 | |||
220 | newp->v.p.retr[0] = retr[0]; | ||
221 | newp->v.p.retr[1] = retr[1]; | ||
222 | |||
223 | link_prog (newp, 0); | ||
224 | } | ||
225 | |||
226 | void | ||
227 | register_transport (char *tag, char **argv, int retr[2], char **depv, | ||
228 | char *pidfile) | ||
229 | { | ||
230 | static char *std_dep[] = { "all", NULL }; | ||
231 | if (!depv) | ||
232 | depv = std_dep; | ||
233 | register_prog (TYPE_TRANSPORT, tag, argv, retr, depv, pidfile); | ||
234 | } | ||
235 | |||
236 | void | ||
237 | register_jabber_process (char *cmd, char *cfg) | ||
238 | { | ||
239 | int retr[2] = { -1, -1 }; | ||
240 | char *argv[5]; | ||
241 | int argc = 0; | ||
242 | |||
243 | argv[argc++] = cmd; | ||
244 | if (cfg) | ||
245 | { | ||
246 | argv[argc++] = "-c"; | ||
247 | argv[argc++] = cfg; |