diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2016-01-21 08:31:31 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2016-01-21 08:31:31 +0200 |
commit | 0c930fc6d3fde82e800c685ec1df92ddfa23fe09 (patch) | |
tree | 1494ff68c9006d3e1a9d6ab5b3b2a5e2f66a47ca /src/pies.h | |
parent | 2040ea870ae411472a73d0bee49fb7c4a774ad93 (diff) | |
download | pies-0c930fc6d3fde82e800c685ec1df92ddfa23fe09.tar.gz pies-0c930fc6d3fde82e800c685ec1df92ddfa23fe09.tar.bz2 |
Cleanup: redo configuration file handling and dependency tracking.
Implement clean configuration reload on SIGHUP.
Use SIGUSR1 to restart the program (previously initiated by SIGHUP).
* src/Makefile.am (pies_SOURCES): Add comp.c
* src/comp.c: New file.
* src/acl.c (pies_acl_free): Don't coredump on NULL arg.
(_parse_from): Set cmp function for the sockaddr list.
(_acl_common_section_parser): Set cmp function for the ACL
(pies_acl_cmp): New function.
* src/acl.h (pies_acl_cmp): New proto.
* src/cmdline.opt: Remove option --dump-prereq. Add options
--trace-prereq and --trace-depend.
* src/ctl.c: Use prog_tag to access tag of struct prog.
* src/depmap.c (depmap_clear)
(depmap_clear_all): New functions.
* src/inetd.c (inetd_conf_file): Don't register prog right
away. This is done later in component_config_commit.
(inetd_parse_conf): Rename to inetd_config_parse.
* src/limits.c (limits_cmp): New function.
* src/pies.c (config_file): Replace with struct config_syntax.
(str_to_config_syntax): Return a pointer to struct config_syntax.
(add_config): Rename to config_file_add.
(config_file_add_type): New function.
(return_code_keywords, create_action): Change handling of actions.
(return_code_section_parser): Likewise.
(component_verify, component_create)
(component_free, component_finish): Move to comp.c
(config_parse): Remove.
(pies_config_parse): New function.
(pies_read_config,pies_reload): New function.
(pies_reload): Rename to request_reload.
(pies_status): Rename to request_status.
(pies_stop): Rename to request_stop.
(main): Change configuration file handling.
SIGHUP reloads configuration, instead of restarting the program.
(default_sigv,sig_handler): Handle SIGUSR1.
* src/pies.h (component): New members: prev, next, listidx, arridx,
ref_count, prog.
Remove act_head, act_tail, act_temp.
Add new prototypes.
* src/prog.h (prog): Remove tag and prereq.
* src/progman.c (prog_tag): New function.
(destroy_prog): Update component reference count.
(register_redir): Likewise.
(register_prog0): Take one argument.
Update component reference count.
(register_prog): Update comp->prog
(prog_rebuild_prerequisites): Remove.
(component_fixup_depend): Remove.
(fixup_prerequisites,rebuild_prerequisites)
(print_dep,progman_dump_prereq)
(progman_dump_depmap,progman_build_depmap): Remove.
(prog_start_prerequisites): Scan depmap to find prerequisites.
(prog_stop_dependents): Likewise.
(progman_wait): Remove.
(progman_wait_until): New function.
(progman_stop): Rewrite using progman_wait_until.
(react): Rewrite using grecs_list
* src/sysvinit.c: Use prog_tag when needed.
* src/userprivs.c (pies_privs_cmp, pies_privs_free): New functions.
* grecs: Update.
* lib/safe_strcmp.c: New file.
* lib/Makefile.am: Add safe_strcmp.c
* lib/libpies.h (safe_strcmp): New proto.
Diffstat (limited to 'src/pies.h')
-rw-r--r-- | src/pies.h | 57 |
1 files changed, 46 insertions, 11 deletions
@@ -98,7 +98,6 @@ enum return_action | |||
98 | 98 | ||
99 | struct action | 99 | struct action |
100 | { | 100 | { |
101 | struct action *next; | ||
102 | size_t nstat; | 101 | size_t nstat; |
103 | unsigned *status; | 102 | unsigned *status; |
104 | enum return_action act; /* Action to take when the component terminates */ | 103 | enum return_action act; /* Action to take when the component terminates */ |
@@ -202,8 +201,16 @@ enum pies_comp_mode | |||
202 | 201 | ||
203 | #define ISCF_TCPMUX(f) ((f) & (CF_TCPMUX | CF_TCPMUXPLUS)) | 202 | #define ISCF_TCPMUX(f) ((f) & (CF_TCPMUX | CF_TCPMUXPLUS)) |
204 | 203 | ||
204 | struct prog; | ||
205 | |||
205 | struct component | 206 | struct component |
206 | { | 207 | { |
208 | struct component *prev, *next; /* Components form doubly-linked list. */ | ||
209 | int listidx; /* Index of the list. */ | ||
210 | size_t arridx; /* Index of this component. */ | ||
211 | size_t ref_count; /* Reference count. */ | ||
212 | struct prog *prog; /* Prog associated with this component. */ | ||
213 | |||
207 | enum pies_comp_mode mode; | 214 | enum pies_comp_mode mode; |
208 | char *tag; /* Entry tag (for diagnostics purposes) */ | 215 | char *tag; /* Entry tag (for diagnostics purposes) */ |
209 | char *program; /* Program name */ | 216 | char *program; /* Program name */ |
@@ -217,7 +224,7 @@ struct component | |||
217 | size_t max_instances; /* Maximum number of simultaneously running | 224 | size_t max_instances; /* Maximum number of simultaneously running |
218 | instances */ | 225 | instances */ |
219 | char *rmfile; /* Try to remove this file before starting */ | 226 | char *rmfile; /* Try to remove this file before starting */ |
220 | struct pies_privs privs; /* UID/GIDS+groups to run under */ | 227 | struct pies_privs privs; /* UID/GIDS+groups to run as */ |
221 | mode_t umask; /* Umask to install before starting */ | 228 | mode_t umask; /* Umask to install before starting */ |
222 | limits_record_t limits; /* System limits */ | 229 | limits_record_t limits; /* System limits */ |
223 | 230 | ||
@@ -249,8 +256,7 @@ struct component | |||
249 | int facility; /* Syslog facility. */ | 256 | int facility; /* Syslog facility. */ |
250 | struct redirector redir[2]; /* Repeaters for stdout and stderr */ | 257 | struct redirector redir[2]; /* Repeaters for stdout and stderr */ |
251 | /* Actions to execute on various exit codes: */ | 258 | /* Actions to execute on various exit codes: */ |
252 | struct action *act_head, *act_tail; | 259 | struct grecs_list *act_list; |
253 | struct action act_temp; /* Auxiliary object used during configuration */ | ||
254 | /* ACLs for control interface */ | 260 | /* ACLs for control interface */ |
255 | pies_acl_t list_acl; /* List access control list */ | 261 | pies_acl_t list_acl; /* List access control list */ |
256 | pies_acl_t adm_acl; /* Administrative ACL (stop, start, etc.) */ | 262 | pies_acl_t adm_acl; /* Administrative ACL (stop, start, etc.) */ |
@@ -262,6 +268,7 @@ enum pies_action { | |||
262 | ACTION_CONT, | 268 | ACTION_CONT, |
263 | ACTION_STOP, | 269 | ACTION_STOP, |
264 | ACTION_RESTART, | 270 | ACTION_RESTART, |
271 | ACTION_RELOAD, | ||
265 | ACTION_CTRLALTDEL, | 272 | ACTION_CTRLALTDEL, |
266 | ACTION_KBREQUEST | 273 | ACTION_KBREQUEST |
267 | }; | 274 | }; |
@@ -289,7 +296,7 @@ extern size_t pies_master_argc; | |||
289 | extern char **pies_master_argv; | 296 | extern char **pies_master_argv; |
290 | extern char *default_control_url[2]; | 297 | extern char *default_control_url[2]; |
291 | 298 | ||
292 | enum config_syntax | 299 | enum config_syntax_type |
293 | { | 300 | { |
294 | CONF_PIES, | 301 | CONF_PIES, |
295 | CONF_META1, | 302 | CONF_META1, |
@@ -297,12 +304,16 @@ enum config_syntax | |||
297 | CONF_INITTAB | 304 | CONF_INITTAB |
298 | }; | 305 | }; |
299 | 306 | ||
300 | int str_to_config_syntax (const char *str, enum config_syntax *psynt); | 307 | struct config_syntax; |
301 | void add_config (enum config_syntax syntax, const char *name); | 308 | |
309 | struct config_syntax *str_to_config_syntax (const char *str); | ||
310 | void config_file_add (struct config_syntax *syntax, const char *name); | ||
311 | void config_file_add_type (enum config_syntax_type syntax, const char *name); | ||
302 | 312 | ||
303 | void free_redirector (struct redirector *rp); | 313 | void free_redirector (struct redirector *rp); |
304 | 314 | ||
305 | void pies_schedule_action (int act); | 315 | void pies_schedule_action (int act); |
316 | void free_action (struct action *act); | ||
306 | 317 | ||
307 | void register_prog (struct component *comp); | 318 | void register_prog (struct component *comp); |
308 | int progman_running_p (void); | 319 | int progman_running_p (void); |
@@ -313,11 +324,10 @@ void progman_stop (void); | |||
313 | void progman_cleanup (int expect_term); | 324 | void progman_cleanup (int expect_term); |
314 | void progman_filter (int (*filter) (struct component *, void *data), | 325 | void progman_filter (int (*filter) (struct component *, void *data), |
315 | void *data); | 326 | void *data); |
327 | int progman_wait_until (int (*cond) (void *), void *data); | ||
316 | void progman_stop_tag (const char *name); | 328 | void progman_stop_tag (const char *name); |
317 | void progman_dump_prereq (void); | ||
318 | void progman_dump_depmap (void); | ||
319 | int progman_accept (int socket, void *data); | 329 | int progman_accept (int socket, void *data); |
320 | int progman_build_depmap (void); | 330 | |
321 | void progman_create_sockets (void); | 331 | void progman_create_sockets (void); |
322 | struct component *progman_lookup_component (const char *tag); | 332 | struct component *progman_lookup_component (const char *tag); |
323 | struct component *progman_lookup_tcpmux (const char *service, | 333 | struct component *progman_lookup_tcpmux (const char *service, |
@@ -351,6 +361,11 @@ pies_depmap_t depmap_alloc (size_t count); | |||
351 | pies_depmap_t depmap_copy (pies_depmap_t dpm); | 361 | pies_depmap_t depmap_copy (pies_depmap_t dpm); |
352 | void depmap_set (pies_depmap_t dmap, size_t row, size_t col); | 362 | void depmap_set (pies_depmap_t dmap, size_t row, size_t col); |
353 | int depmap_isset (pies_depmap_t dmap, size_t row, size_t col); | 363 | int depmap_isset (pies_depmap_t dmap, size_t row, size_t col); |
364 | void depmap_clear (pies_depmap_t dmap, size_t row, size_t col); | ||
365 | |||
366 | void depmap_clear_all (pies_depmap_t dmap, enum pies_depmap_direction dir, | ||
367 | size_t coord); | ||
368 | |||
354 | void depmap_tc (pies_depmap_t dmap); | 369 | void depmap_tc (pies_depmap_t dmap); |
355 | size_t depmap_first (pies_depmap_t dmap, enum pies_depmap_direction dir, | 370 | size_t depmap_first (pies_depmap_t dmap, enum pies_depmap_direction dir, |
356 | size_t coord, pies_depmap_pos_t *ppos); | 371 | size_t coord, pies_depmap_pos_t *ppos); |
@@ -365,10 +380,25 @@ int socket_type_to_str (int socket_type, const char **pres); | |||
365 | 380 | ||
366 | struct component *component_create (const char *name); | 381 | struct component *component_create (const char *name); |
367 | void component_free (struct component *comp); | 382 | void component_free (struct component *comp); |
383 | void component_ref_incr (struct component *comp); | ||
384 | void component_ref_decr (struct component *comp); | ||
385 | |||
386 | void component_config_begin (void); | ||
387 | void component_config_rollback (void); | ||
388 | void component_config_commit (void); | ||
389 | |||
390 | int component_is_active (struct component *comp); | ||
368 | 391 | ||
369 | void component_finish (struct component *comp, grecs_locus_t *locus); | 392 | void component_finish (struct component *comp, grecs_locus_t *locus); |
370 | struct grecs_keyword *find_component_keyword (const char *ident); | 393 | struct grecs_keyword *find_component_keyword (const char *ident); |
371 | 394 | ||
395 | void components_dump_depmap (void); | ||
396 | void components_trace (char **argv, enum pies_depmap_direction dir); | ||
397 | |||
398 | struct component *component_depmap_first (enum pies_depmap_direction dir, | ||
399 | size_t idx, pies_depmap_pos_t *ppos); | ||
400 | struct component *component_depmap_next (pies_depmap_pos_t pos); | ||
401 | |||
372 | 402 | ||
373 | 403 | ||
374 | void pies_pause (void); | 404 | void pies_pause (void); |
@@ -401,6 +431,7 @@ void enable_socket (int fd); | |||
401 | int parse_limits (limits_record_t *plrec, char *str, char **endp); | 431 | int parse_limits (limits_record_t *plrec, char *str, char **endp); |
402 | int set_limits (const char *name, limits_record_t lrec); | 432 | int set_limits (const char *name, limits_record_t lrec); |
403 | void free_limits (limits_record_t rec); | 433 | void free_limits (limits_record_t rec); |
434 | int limits_cmp (limits_record_t a, limits_record_t b); | ||
404 | 435 | ||
405 | 436 | ||
406 | void meta1_parser_set_debug (void); | 437 | void meta1_parser_set_debug (void); |
@@ -451,9 +482,13 @@ int switch_to_privs (uid_t uid, gid_t gid, struct grecs_list *retain_groups); | |||
451 | 482 | ||
452 | void pies_priv_setup (struct pies_privs *); | 483 | void pies_priv_setup (struct pies_privs *); |
453 | void pies_epriv_setup (struct pies_privs *); | 484 | void pies_epriv_setup (struct pies_privs *); |
485 | |||
486 | int pies_privs_cmp (struct pies_privs const *a, struct pies_privs const *b); | ||
487 | void pies_privs_free (struct pies_privs *p); | ||
488 | |||
454 | 489 | ||
455 | /* inetd.c */ | 490 | /* inetd.c */ |
456 | int inetd_parse_conf (const char *file); | 491 | int inetd_config_parse (const char *file); |
457 | 492 | ||
458 | /* inetd-bi.c */ | 493 | /* inetd-bi.c */ |
459 | struct inetd_builtin | 494 | struct inetd_builtin |