diff options
Diffstat (limited to 'src/pies.c')
-rw-r--r-- | src/pies.c | 329 |
1 files changed, 52 insertions, 277 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* This file is part of GNU Pies. | 1 | /* This file is part of GNU Pies. |
2 | Copyright (C) 2008, 2009, 2010 Sergey Poznyakoff | 2 | Copyright (C) 2008, 2009, 2010, 2011 Sergey Poznyakoff |
3 | 3 | ||
4 | GNU Pies is free software; you can redistribute it and/or modify | 4 | GNU Pies is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 5 | it under the terms of the GNU General Public License as published by |
@@ -26,7 +26,18 @@ int log_facility = LOG_USER; | |||
26 | char *log_tag; | 26 | char *log_tag; |
27 | struct pies_privs pies_privs; | 27 | struct pies_privs pies_privs; |
28 | int foreground; | 28 | int foreground; |
29 | int command; | 29 | |
30 | enum pies_command { | ||
31 | COM_START, | ||
32 | COM_RESTART, | ||
33 | COM_RELOAD, | ||
34 | COM_STATUS, | ||
35 | COM_STOP, | ||
36 | COM_DUMP_PREREQ, | ||
37 | COM_DUMP_DEPMAP | ||
38 | }; | ||
39 | |||
40 | enum pies_command command; | ||
30 | char *statedir = DEFAULT_STATE_DIR; | 41 | char *statedir = DEFAULT_STATE_DIR; |
31 | char *instance; | 42 | char *instance; |
32 | char *pidfile; | 43 | char *pidfile; |
@@ -145,14 +156,11 @@ stderr_closed_p () | |||
145 | } | 156 | } |
146 | 157 | ||
147 | 158 | ||
148 | #define GRECS_VALUE_IS_EMPTY(val) \ | ||
149 | (!(val) || ((val)->type == GRECS_TYPE_STRING && !(val)->v.string)) | ||
150 | |||
151 | int | 159 | int |
152 | assert_grecs_value_type (grecs_locus_t *locus, | 160 | assert_grecs_value_type (grecs_locus_t *locus, |
153 | const grecs_value_t *value, int type) | 161 | const grecs_value_t *value, int type) |
154 | { | 162 | { |
155 | if (GRECS_VALUE_IS_EMPTY (value)) | 163 | if (GRECS_VALUE_EMPTY_P (value)) |
156 | { | 164 | { |
157 | grecs_error (locus, 0, _("expected %s"), | 165 | grecs_error (locus, 0, _("expected %s"), |
158 | grecs_data_type_string (type)); | 166 | grecs_data_type_string (type)); |
@@ -412,9 +420,9 @@ _get_array_arg (grecs_value_t *val, int num, grecs_locus_t *locus) | |||
412 | { | 420 | { |
413 | if (num < val->v.arg.c) | 421 | if (num < val->v.arg.c) |
414 | { | 422 | { |
415 | if (assert_grecs_value_type (locus, &val->v.arg.v[num], | 423 | if (assert_grecs_value_type (locus, val->v.arg.v[num], |
416 | GRECS_TYPE_STRING) == 0) | 424 | GRECS_TYPE_STRING) == 0) |
417 | return val->v.arg.v[num].v.string; | 425 | return val->v.arg.v[num]->v.string; |
418 | } | 426 | } |
419 | return NULL; | 427 | return NULL; |
420 | } | 428 | } |
@@ -422,7 +430,7 @@ _get_array_arg (grecs_value_t *val, int num, grecs_locus_t *locus) | |||
422 | const char * | 430 | const char * |
423 | _get_list_arg (grecs_value_t *val, int num, grecs_locus_t *locus) | 431 | _get_list_arg (grecs_value_t *val, int num, grecs_locus_t *locus) |
424 | { | 432 | { |
425 | grecs_value_t *elt = (grecs_value_t *) gl_list_get_at (val->v.list, num); | 433 | grecs_value_t *elt = (grecs_value_t *) grecs_list_index (val->v.list, num); |
426 | if (!elt) | 434 | if (!elt) |
427 | { | 435 | { |
428 | grecs_error (locus, 0, _("cannot get list item")); | 436 | grecs_error (locus, 0, _("cannot get list item")); |
@@ -445,7 +453,7 @@ return_code_section_parser (enum grecs_callback_command cmd, | |||
445 | switch (cmd) | 453 | switch (cmd) |
446 | { | 454 | { |
447 | case grecs_callback_section_begin: | 455 | case grecs_callback_section_begin: |
448 | if (GRECS_VALUE_IS_EMPTY (value)) | 456 | if (GRECS_VALUE_EMPTY_P (value)) |
449 | { | 457 | { |
450 | grecs_error (locus, 0, _("missing tag")); | 458 | grecs_error (locus, 0, _("missing tag")); |
451 | return 1; | 459 | return 1; |
@@ -463,7 +471,7 @@ return_code_section_parser (enum grecs_callback_command cmd, | |||
463 | break; | 471 | break; |
464 | 472 | ||
465 | case GRECS_TYPE_LIST: | 473 | case GRECS_TYPE_LIST: |
466 | count = gl_list_size (value->v.list); | 474 | count = grecs_list_size (value->v.list); |
467 | act = create_action (comp, locus, value, count, _get_list_arg); | 475 | act = create_action (comp, locus, value, count, _get_list_arg); |
468 | } | 476 | } |
469 | *(struct component **) cb_data = comp; | 477 | *(struct component **) cb_data = comp; |
@@ -497,9 +505,9 @@ config_array_to_argv (grecs_value_t *val, grecs_locus_t *locus, size_t *pargc) | |||
497 | argv = xcalloc (argc + 1, sizeof (argv[0])); | 505 | argv = xcalloc (argc + 1, sizeof (argv[0])); |
498 | for (i = j = 0; i < argc; i++) | 506 | for (i = j = 0; i < argc; i++) |
499 | { | 507 | { |
500 | if (assert_grecs_value_type (locus, &val->v.arg.v[i], GRECS_TYPE_STRING) | 508 | if (assert_grecs_value_type (locus, val->v.arg.v[i], GRECS_TYPE_STRING) |
501 | == 0) | 509 | == 0) |
502 | argv[j++] = xstrdup (val->v.arg.v[i].v.string); | 510 | argv[j++] = xstrdup (val->v.arg.v[i]->v.string); |
503 | } | 511 | } |
504 | argv[j] = NULL; | 512 | argv[j] = NULL; |
505 | if (pargc) | 513 | if (pargc) |
@@ -702,12 +710,12 @@ _cb_redir (enum grecs_callback_command cmd, | |||
702 | break; | 710 | break; |
703 | 711 | ||
704 | case GRECS_TYPE_ARRAY: | 712 | case GRECS_TYPE_ARRAY: |
705 | if (assert_grecs_value_type (locus, &value->v.arg.v[0], | 713 | if (assert_grecs_value_type (locus, value->v.arg.v[0], |
706 | GRECS_TYPE_STRING)) | 714 | GRECS_TYPE_STRING)) |
707 | return 0; | 715 | return 0; |
708 | if (strtotok (redirtab, value->v.arg.v[0].v.string, &res)) | 716 | if (strtotok (redirtab, value->v.arg.v[0]->v.string, &res)) |
709 | grecs_error (locus, 0, _("%s: unrecognised redirector type"), | 717 | grecs_error (locus, 0, _("%s: unrecognised redirector type"), |
710 | value->v.arg.v[0].v.string); | 718 | value->v.arg.v[0]->v.string); |
711 | else | 719 | else |
712 | { | 720 | { |
713 | if (res != redir_null) | 721 | if (res != redir_null) |
@@ -717,7 +725,7 @@ _cb_redir (enum grecs_callback_command cmd, | |||
717 | grecs_error (locus, 0, _("wrong number of arguments")); | 725 | grecs_error (locus, 0, _("wrong number of arguments")); |
718 | return 0; | 726 | return 0; |
719 | } | 727 | } |
720 | if (assert_grecs_value_type (locus, &value->v.arg.v[1], | 728 | if (assert_grecs_value_type (locus, value->v.arg.v[1], |
721 | GRECS_TYPE_STRING)) | 729 | GRECS_TYPE_STRING)) |
722 | return 0; | 730 | return 0; |
723 | 731 | ||
@@ -727,18 +735,18 @@ _cb_redir (enum grecs_callback_command cmd, | |||
727 | break; | 735 | break; |
728 | 736 | ||
729 | case redir_syslog: | 737 | case redir_syslog: |
730 | if (string_to_syslog_priority (value->v.arg.v[1].v.string, | 738 | if (string_to_syslog_priority (value->v.arg.v[1]->v.string, |
731 | &rp->v.prio)) | 739 | &rp->v.prio)) |
732 | { | 740 | { |
733 | grecs_error (locus, 0, | 741 | grecs_error (locus, 0, |
734 | _("unknown syslog priority `%s'"), | 742 | _("unknown syslog priority `%s'"), |
735 | value->v.arg.v[1].v.string); | 743 | value->v.arg.v[1]->v.string); |
736 | return 0; | 744 | return 0; |
737 | } | 745 | } |
738 | break; | 746 | break; |
739 | 747 | ||
740 | case redir_file: | 748 | case redir_file: |
741 | rp->v.file = xstrdup (value->v.arg.v[1].v.string); | 749 | rp->v.file = xstrdup (value->v.arg.v[1]->v.string); |
742 | break; | 750 | break; |
743 | } | 751 | } |
744 | } | 752 | } |
@@ -910,12 +918,11 @@ _cb_flags (enum grecs_callback_command cmd, | |||
910 | 918 | ||
911 | case GRECS_TYPE_LIST: | 919 | case GRECS_TYPE_LIST: |
912 | { | 920 | { |
913 | const void *p; | 921 | struct grecs_list_entry *ep; |
914 | gl_list_iterator_t itr = gl_list_iterator (value->v.list); | 922 | |
915 | 923 | for (ep = value->v.list->head; ep; ep = ep->next) | |
916 | while (gl_list_iterator_next (&itr, &p, NULL)) | ||
917 | { | 924 | { |
918 | const grecs_value_t *vp = p; | 925 | const grecs_value_t *vp = ep->data; |
919 | if (assert_grecs_value_type (locus, vp, GRECS_TYPE_STRING)) | 926 | if (assert_grecs_value_type (locus, vp, GRECS_TYPE_STRING)) |
920 | return 1; | 927 | return 1; |
921 | if (str_to_cf (vp->v.string, flags)) | 928 | if (str_to_cf (vp->v.string, flags)) |
@@ -1560,7 +1567,6 @@ struct grecs_keyword pies_keywords[] = { | |||
1560 | void | 1567 | void |
1561 | config_init () | 1568 | config_init () |
1562 | { | 1569 | { |
1563 | grecs_set_keywords (pies_keywords); | ||
1564 | grecs_include_path_setup (DEFAULT_VERSION_INCLUDE_DIR, | 1570 | grecs_include_path_setup (DEFAULT_VERSION_INCLUDE_DIR, |
1565 | DEFAULT_INCLUDE_DIR, NULL); | 1571 | DEFAULT_INCLUDE_DIR, NULL); |
1566 | grecs_log_to_stderr = log_to_stderr_only; | 1572 | grecs_log_to_stderr = log_to_stderr_only; |
@@ -1579,219 +1585,14 @@ config_help () | |||
1579 | /* TRANSLATORS: do not translate words between ` and ' */ | 1585 | /* TRANSLATORS: do not translate words between ` and ' */ |
1580 | N_("Configuration file structure for pies.\n" | 1586 | N_("Configuration file structure for pies.\n" |
1581 | "For more information, use `info pies configuration'."); | 1587 | "For more information, use `info pies configuration'."); |
1582 | grecs_format_docstring (stdout, docstring, 0); | 1588 | grecs_print_docstring (docstring, 0, stdout); |
1583 | grecs_format_statement_array (stdout, pies_keywords, 1, 0); | 1589 | grecs_print_statement_array (pies_keywords, 1, 0, stdout); |
1584 | } | 1590 | } |
1585 | 1591 | ||
1586 | |||
1587 | const char *program_version = "pies (" PACKAGE_STRING ")"; | ||
1588 | const char *argp_program_bug_address = "<" PACKAGE_BUGREPORT ">"; | ||
1589 | static char doc[] = N_("pies -- process invocation and execution supervisor"); | ||
1590 | static char args_doc[] = ""; | ||
1591 | |||
1592 | enum | ||
1593 | { | ||
1594 | OPT_FOREGROUND = 256, | ||
1595 | OPT_SYNTAX, | ||
1596 | OPT_SYSLOG, | ||
1597 | OPT_STDERR, | ||
1598 | OPT_DUMP_PREREQ, | ||
1599 | OPT_DUMP_DEPMAP, | ||
1600 | OPT_FORCE, | ||
1601 | OPT_CONFIG_HELP, | ||
1602 | OPT_SOURCE_INFO, | ||
1603 | OPT_RATE, | ||
1604 | OPT_INSTANCE | ||
1605 | }; | ||
1606 | |||
1607 | #define OPT_RESTART 'R' | ||
1608 | #define OPT_RELOAD 'r' | ||
1609 | #define OPT_STATUS 's' | ||
1610 | #define OPT_STOP 'S' | ||
1611 | |||
1612 | static struct argp_option options[] = { | ||
1613 | #define GRP 0 | ||
1614 | {NULL, 0, NULL, 0, N_("Operation Mode"), GRP}, | ||
1615 | {"foreground", OPT_FOREGROUND, 0, 0, N_("remain in foreground"), GRP + 1}, | ||
1616 | {"stderr", OPT_STDERR, NULL, 0, N_("log to stderr"),}, | ||
1617 | {"syslog", OPT_SYSLOG, NULL, 0, N_("log to syslog"),}, | ||
1618 | {"force", OPT_FORCE, NULL, 0, | ||
1619 | N_("force startup even if another instance may be running"), GRP + 1}, | ||
1620 | {"lint", 't', NULL, 0, | ||