From 989a5bbb74c3620abaa2191ce2c4f8d5968dbf0a Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Tue, 15 Sep 2009 10:40:29 +0300 Subject: Branch off from the Mailfromd project into a separate repository. --- src/pies.h | 205 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 205 insertions(+) create mode 100644 src/pies.h (limited to 'src/pies.h') diff --git a/src/pies.h b/src/pies.h new file mode 100644 index 0000000..add175c --- /dev/null +++ b/src/pies.h @@ -0,0 +1,205 @@ +/* This file is part of Mailfromd. + Copyright (C) 2008, 2009 Sergey Poznyakoff + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifdef HAVE_CONFIG_H +# include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "inttostr.h" +#include "c-ctype.h" +#include "xalloc.h" +#include "libpies.h" + +#define TESTTIME 2*60 +#define SLEEPTIME 5*60 +#define MAXSPAWN 10 + +#define RETR_OUT 0 +#define RETR_ERR 1 + +enum redir_type +{ + redir_null, + redir_syslog, + redir_file +}; + +struct redirector +{ + enum redir_type type; + union + { + int prio; + char *file; + } v; +}; + +typedef struct limits_rec *limits_record_t; + +enum return_action +{ + action_restart, + action_disable, +}; + +#define STATUS_SIG_BIT 0x80000000 +#define STATUS_CODE(c) ((c) & ~STATUS_SIG_BIT) + +struct action +{ + struct action *next; + size_t nstat; + unsigned *status; + enum return_action act; /* Action to take when the component terminates */ + mu_address_t addr; /* Addresses to notify about it. */ + char *message; /* Notification mail. */ + char *command; /* Execute this command */ +}; + +enum pies_comp_mode + { + /* Execute the component, no sockets are opened. This is the default + Pies mode. */ + pies_comp_exec, + /* Open a socket and start a component with stdin/stdout bound to that + socket. Corresponds to MeTA1 notion of `start_action = accept'. + */ + pies_comp_accept, + /* Inetd mode: like above, but start the component only when an + incoming connection is requested. Corresponds to + `start_action = nostartaccept' in MeTA1. + */ + pies_comp_inetd, + /* Open a socket, start a component, and pass the socket fd to the + component via the UNIX domain socket. Corresponds to + `start_action = pass' in MeTA1. */ + pies_comp_pass_fd + }; + +struct component +{ + enum pies_comp_mode mode; + char *tag; /* Entry tag (for diagnostics purposes) */ + char *program; /* Program name */ + char **argv; /* Program command line */ + char **env; /* Program environment */ + char *dir; /* Working directory */ + mu_list_t prereq; /* Prerequisites */ + mu_list_t depend; /* Dependency targets */ + unsigned settle_timeout; /* Time needed for started prerequisites to + settle */ + /* FIXME: disabled and precious can be encoded as bits in mode */ + int disabled; /* The componenet is disabled */ + int precious; /* The component is precious (cannot be disabled) */ + char *rmfile; /* Try to remove this file before starting */ + struct mf_privs privs; /* UID/GIDS+groups to run under */ + mode_t umask; /* Umask to install before starting */ + limits_record_t limits; /* System limits */ + mu_url_t socket_url; /* Socket to listen on + (if mode != pies_comp_exec) */ + char *pass_fd_socket; /* Socket to pass fd on + (if mode == pies_comp_pass_fd) */ + mu_acl_t acl; + /* Retranslators: */ + int facility; /* Syslog facility. */ + struct redirector redir[2]; /* Repeaters for stdout and stderr */ + /* Actions to execute on various exit codes: */ + struct action *act_head, *act_tail; + struct action act_temp; /* Auxiliary object used during configuration */ +}; + +extern char *syslog_tag; +extern unsigned long shutdown_timeout; +extern struct component default_component; +extern mu_acl_t pies_acl; +extern mu_debug_t pies_debug; +extern limits_record_t pies_limits; + +void register_prog (struct component *comp); +size_t progman_running_count (void); +void progman_start (void); +void progman_wake_sleeping (void); +void progman_stop (void); +void progman_cleanup (int expect_term); +void progman_stop_component (const char *name); +void progman_dump_stats (const char *filename); +void progman_dump_prereq (void); +void progman_dump_depmap (void); +int progman_accept (int socket); +int progman_build_depmap (void); +void progman_create_sockets (void); +struct component *progman_lookup_component (const char *tag); + +void log_setup (int want_stderr); +void signal_setup (RETSIGTYPE (*sf)(int)); + +typedef struct pies_depmap *pies_depmap_t; +typedef struct pies_depmap_pos *pies_depmap_pos_t; +enum pies_depmap_direction + { + depmap_row = 0, + depmap_col = !depmap_row + }; + +pies_depmap_t depmap_alloc (unsigned count); +pies_depmap_t depmap_copy (pies_depmap_t dpm); +void depmap_set (pies_depmap_t dmap, unsigned row, unsigned col); +int depmap_isset (pies_depmap_t dmap, unsigned row, unsigned col); +void depmap_tc (pies_depmap_t dmap); +unsigned depmap_first (pies_depmap_t dmap, enum pies_depmap_direction dir, + unsigned coord, pies_depmap_pos_t *ppos); +unsigned depmap_next (pies_depmap_t dmap, pies_depmap_pos_t pos); + + +void pies_pause (void); +int register_listener (int fd); +int pass_fd (const char *socket, int fd); +int create_socket (mu_url_t url, const char *user, mode_t umask); + + +int parse_limits (limits_record_t *plrec, char *str, char **endp); +int set_limits (const char *name, limits_record_t lrec); + + +void meta1_parser_set_debug (void); +int meta1lex (void); +int meta1error (char *s); +int meta1parse (void); + -- cgit v1.2.1