/*
This file is part of GNUnet.
(C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors)
GNUnet 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.
GNUnet 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 GNUnet; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/**
* @file arm/gnunet-service-arm.c
* @brief the automated restart manager service
* @author Christian Grothoff
*/
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_arm_service.h"
#include "gnunet_protocols.h"
#include "arm.h"
/**
* List of our services.
*/
struct ServiceList;
/**
* Record with information about a listen socket we have open.
*/
struct ServiceListeningInfo
{
/**
* This is a linked list.
*/
struct ServiceListeningInfo *next;
/**
* This is a linked list.
*/
struct ServiceListeningInfo *prev;
/**
* Address this socket is listening on.
*/
struct sockaddr *service_addr;
/**
* Service this listen socket is for.
*/
struct ServiceList *sl;
/**
* Number of bytes in 'service_addr'
*/
socklen_t service_addr_len;
/**
* Our listening socket.
*/
struct GNUNET_NETWORK_Handle *listen_socket;
/**
* Task doing the accepting.
*/
GNUNET_SCHEDULER_TaskIdentifier accept_task;
};
/**
* List of our services.
*/
struct ServiceList
{
/**
* This is a doubly-linked list.
*/
struct ServiceList *next;
/**
* This is a doubly-linked list.
*/
struct ServiceList *prev;
/**
* Linked list of listen sockets associated with this service.
*/
struct ServiceListeningInfo *listen_head;
/**
* Linked list of listen sockets associated with this service.
*/
struct ServiceListeningInfo *listen_tail;
/**
* Name of the service.
*/
char *name;
/**
* Name of the binary used.
*/
char *binary;
/**
* Name of the configuration file used.
*/
char *config;
/**
* Client to notify upon kill completion (waitpid), NULL
* if we should simply restart the process.
*/
struct GNUNET_SERVER_Client *killing_client;
/**
* Process structure pointer of the child.
*/
struct GNUNET_OS_Process *proc;
/**
* Process exponential backoff time
*/
struct GNUNET_TIME_Relative backoff;
/**
* Absolute time at which the process is scheduled to restart in case of death
*/
struct GNUNET_TIME_Absolute restart_at;
/**
* Time we asked the service to shut down (used to calculate time it took
* the service to terminate).
*/
struct GNUNET_TIME_Absolute killed_at;
/**
* Is this service to be started by default (or did a client tell us explicitly
* to start it)? GNUNET_NO if the service is started only upon 'accept' on a
* listen socket or possibly explicitly by a client changing the value.
*/
int is_default;
/**
* Should we use pipes to signal this process? (YES for Java binaries and if we
* are on Windoze).
*/
int pipe_control;
};
/**
* List of running services.
*/
static struct ServiceList *running_head;
/**
* List of running services.
*/
static struct ServiceList *running_tail;
/**
* Our configuration
*/
static const struct GNUNET_CONFIGURATION_Handle *cfg;
/**
* Command to prepend to each actual command.
*/
static char *prefix_command;
/**
* Option to append to each actual command.
*/
static char *final_option;
/**
* ID of task called whenever we get a SIGCHILD.
*/
static GNUNET_SCHEDULER_TaskIdentifier child_death_task;
/**
* ID of task called whenever the timeout for restart