From 1bfa33ac7c167cd863b88a5cac7690d511851e6e Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Sun, 6 Jan 2013 17:04:28 +0200 Subject: Fix runlevel transition algorithm, implement SysV-style fifo interface. * src/prog.h: New file. * src/Makefile.am: Add new file. * src/cmdline.opt: New option --telinit (-T). * src/diag.c (vlogmsg): In sysvin it mode, write directly to the console. Close it when finished. * src/pies.c (_cb_initdefault, _cb_runlevels): Use is_valid_runlevel to check if the specified runlevels are ok. (main): In sysvinit mode, reset action to ACTION_CONT. * src/pies.h (progman_filter): New proto. (progman_accept,register_socket): Change signature. (deregister_socket): New proto. (register_program_socket): New proto. * src/progman.c: Move constant and adatatype definitions to prog.h (prog_stop): Remove static qualifier. (console_open): Likewise. (progman_accept): Use new socket API. (progman_stop): Correctly handle timeouts. (progman_foreach): New function. * src/socket.c: Register all sockets along with their handlers in a doubly-linked list. (sockinst): New struct. (register_socket,deregister_socket): New functions. (register_program_socket): New function. (pies_pause): Traverse the list to find which fd has changed. Use its registered handler to handle the event. * src/sysvinit.c: Include prog.h (is_valid_runlevel): New function. (sysvinit_fifo_handler,check_fifo): New static functions. (inittrans): Fix transition algorithm. (telinit): New function. --- src/prog.h | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/prog.h (limited to 'src/prog.h') diff --git a/src/prog.h b/src/prog.h new file mode 100644 index 0000000..2fd4c47 --- /dev/null +++ b/src/prog.h @@ -0,0 +1,85 @@ +/* This file is part of GNU Pies. + Copyright (C) 2008, 2009, 2010, 2011 Sergey Poznyakoff + + GNU Pies 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. + + GNU Pies 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 GNU Pies. If not, see . */ + +enum prog_type + { + TYPE_COMPONENT, + TYPE_REDIRECTOR, + TYPE_COMMAND + }; + +enum prog_status + { + status_enabled, /* Component enabled. prog->pid!=0 shows if it is + actually running */ + status_disabled, /* Component is disabled. */ + status_listener, /* Component is an inetd listener */ + status_sleeping, /* Component is sleeping. An attempt to start it will + be made at prog->v.p.timestamp + SLEEPTIME */ + status_stopping, /* Component is being stopped */ + status_finished, /* A "once" component has finished */ + }; + +struct conn_class +{ + const char *tag; + union pies_sockaddr_storage sa_storage; + size_t sa_len; + size_t count; +}; + +struct prog +{ + struct prog *next, *prev; + enum prog_type type; + pid_t pid; /* PID */ + char *tag; /* Entry tag (for diagnostics purposes) */ + char **prereq; + int facility; + union + { + struct + { + struct component *comp; + size_t idx; /* Numeric identifier */ + int socket; + struct prog *redir[2]; /* Pointers to redirectors */ + time_t timestamp; /* Time of last startup */ + size_t failcount; /* Number of failed starts since timestamp */ + enum prog_status status; /* Current component status */ + char *runlevels; + /* If status == status_listener: */ + size_t num_instances; /* Number of running instances */ + /* If comp->type == pies_comp_inetd && status == status_enabled */ + struct prog *listener; + union pies_sockaddr_storage sa_storage; + size_t sa_len; + struct conn_class *cclass; + } p; + + struct + { + struct prog *master; + } r; + + struct + { + char *command; + } c; + } v; +}; + +void progman_foreach (int (*filter) (struct prog *, void *data), void *data); -- cgit v1.2.1