aboutsummaryrefslogtreecommitdiff
path: root/src/pies.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pies.c')
-rw-r--r--src/pies.c329
1 files changed, 52 insertions, 277 deletions
diff --git a/src/pies.c b/src/pies.c
index 112bfb6..cc2c26b 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -1,3 +1,3 @@
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
@@ -28,3 +28,14 @@ struct pies_privs pies_privs;
28int foreground; 28int foreground;
29int command; 29
30enum 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
40enum pies_command command;
30char *statedir = DEFAULT_STATE_DIR; 41char *statedir = DEFAULT_STATE_DIR;
@@ -147,5 +158,2 @@ stderr_closed_p ()
147 158
148#define GRECS_VALUE_IS_EMPTY(val) \
149 (!(val) || ((val)->type == GRECS_TYPE_STRING && !(val)->v.string))
150
151int 159int
@@ -154,3 +162,3 @@ assert_grecs_value_type (grecs_locus_t *locus,
154{ 162{
155 if (GRECS_VALUE_IS_EMPTY (value)) 163 if (GRECS_VALUE_EMPTY_P (value))
156 { 164 {
@@ -414,5 +422,5 @@ _get_array_arg (grecs_value_t *val, int num, grecs_locus_t *locus)
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 }
@@ -424,3 +432,3 @@ _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)
@@ -447,3 +455,3 @@ return_code_section_parser (enum grecs_callback_command cmd,
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 {
@@ -465,3 +473,3 @@ return_code_section_parser (enum grecs_callback_command cmd,
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);
@@ -499,5 +507,5 @@ config_array_to_argv (grecs_value_t *val, grecs_locus_t *locus, size_t *pargc)
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 }
@@ -704,8 +712,8 @@ _cb_redir (enum grecs_callback_command cmd,
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
@@ -719,3 +727,3 @@ _cb_redir (enum grecs_callback_command cmd,
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))
@@ -729,3 +737,3 @@ _cb_redir (enum grecs_callback_command cmd,
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))
@@ -734,3 +742,3 @@ _cb_redir (enum grecs_callback_command cmd,
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;
@@ -740,3 +748,3 @@ _cb_redir (enum grecs_callback_command cmd,
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;
@@ -912,8 +920,7 @@ _cb_flags (enum grecs_callback_command cmd,
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))
@@ -1562,3 +1569,2 @@ 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,
@@ -1581,215 +1587,10 @@ config_help ()
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
1587const char *program_version = "pies (" PACKAGE_STRING ")";
1588const char *argp_program_bug_address = "<" PACKAGE_BUGREPORT ">";
1589static char doc[] = N_("pies -- process invocation and execution supervisor");
1590static char args_doc[] = "";
1591
1592enum
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
1612static 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,
1621 N_("parse configuration file and exit"), GRP + 1},
1622 {NULL, 'E', NULL, 0,
1623 N_("preprocess config and exit"), GRP + 1},
1624 {"inetd", 'i', NULL, 0,
1625 N_("run in inetd mode"), GRP + 1},
1626 {"config-file", 'c', N_("FILE"), 0,
1627 N_("use FILE instead of the default configuration"), GRP + 1},
1628 {"config-help", OPT_CONFIG_HELP, NULL, 0,
1629 N_("show configuration file summary"), GRP + 1},
1630 {"syntax", OPT_SYNTAX, "{pies|inetd|meta1}", 0,
1631 N_("expect configuration files in the given syntax"), GRP+1 },
1632 {"rate", OPT_RATE, N_("NUMBER"), 0,
1633 N_("set default maximum rate for inetd-style components"),
1634 GRP + 1},
1635 {"instance", OPT_INSTANCE, N_("NAME"), 0,
1636 N_("set instance name"),
1637 GRP + 1},
1638#undef GRP
1639
1640#define GRP 5
1641 {NULL, 0, NULL, 0, N_("Preprocessor"), GRP},
1642 {"define", 'D', N_("NAME[=VALUE]"), 0,
1643 N_("define a preprocessor symbol NAME as having VALUE, or empty"), GRP+1 },
1644 {"undefine", 'U', N_("NAME"), 0,
1645 N_("undefine a preprocessor symbol NAME"), GRP+1 },
1646#undef GRP
1647
1648#define GRP 10
1649 {NULL, 0, NULL, 0, N_("Component Management"), GRP},
1650 {"restart-component", OPT_RESTART, NULL, 0,
1651 N_("restart components named in the command line"), GRP + 1},
1652 {"reload", OPT_RELOAD, NULL, 0,
1653 N_("reload the running instance of pies "), GRP + 1},
1654 {"hup", 0, NULL, OPTION_ALIAS},
1655 {"status", OPT_STATUS, NULL, 0,
1656 N_("display info about the running instance "), GRP + 1},
1657 {"stop", OPT_STOP, NULL, 0,
1658 N_("stop the running instance "), GRP + 1},
1659#undef GRP
1660
1661#define GRP 20
1662 {NULL, 0, NULL, 0, N_("Debugging and Additional Diagnostics"), GRP},
1663 {"debug", 'x', N_("LEVEL"), 0,
1664 N_("set debug verbosity level"), GRP + 1},
1665 {"source-info", OPT_SOURCE_INFO, NULL, 0,
1666 N_("show source info with debugging messages"), GRP + 1},
1667 {"dump-prereq", OPT_DUMP_PREREQ, NULL, 0,
1668 N_("dump prerequisite charts"), GRP + 1},
1669 {"dump-depmap", OPT_DUMP_DEPMAP, NULL, 0,
1670 N_("dump dependency map"), GRP + 1},
1671#undef GRP
1672 {NULL}
1673};
1674
1675static enum config_syntax current_syntax = CONF_PIES; 1592static enum config_syntax current_syntax = CONF_PIES;
1676 1593
1677static error_t 1594#include "cmdline.h"
1678parse_opt (int key, char *arg, struct argp_state *state)
1679{
1680 char *p;
1681
1682 switch (key)
1683 {
1684 case 'c':
1685 add_config (current_syntax, arg);
1686 break;
1687
1688 case 'D':
1689 add_pp_option ("-D", arg);
1690 break;
1691
1692 case 'U':
1693 add_pp_option ("-U", arg);
1694 break;
1695
1696 case 'E':
1697 preprocess_only = 1;
1698 break;
1699
1700 case 'i':
1701 if (!instance)
1702 instance = "inetd";
1703 current_syntax = CONF_INETD;
1704 inetd_mod