/* Utility to start or stop system services. Requests are sent to the * reincarnation server that does the actual work. * * Changes: * Nov 22, 2009: added basic live update support (Cristiano Giuffrida) * Jul 22, 2005: Created (Jorrit N. Herder) */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "kernel/proc.h" #include "config.h" #include "proto.h" /* This array defines all known requests. */ static char *known_requests[] = { "up", "down", "refresh", "restart", "shutdown", "update", "clone", "edit", "catch for illegal requests" }; #define ILLEGAL_REQUEST sizeof(known_requests)/sizeof(char *) /* Global error number set for failed system calls. */ #define OK 0 #define RUN_CMD "run" #define RUN_SCRIPT "/etc/rs.single" /* Default script for 'run' */ #define SELF_BINARY "self" #define SELF_REQ_PATH "/dev/null" #define PATH_CONFIG _PATH_SYSTEM_CONF /* Default config file */ #define DEFAULT_LU_STATE SEF_LU_STATE_WORK_FREE /* Default lu state */ #define DEFAULT_LU_MAXTIME 0 /* Default lu max time */ /* Define names for options provided to this utility. */ #define OPT_COPY "-c" /* copy executable image */ #define OPT_REUSE "-r" /* reuse executable image */ #define OPT_NOBLOCK "-n" /* unblock caller immediately */ #define OPT_REPLICA "-p" /* create replica for the service */ /* Define names for arguments provided to this utility. The first few * arguments are required and have a known index. Thereafter, some optional * argument pairs like "-args arglist" follow. */ #define ARG_NAME 0 /* own application name */ /* The following are relative to optind */ #define ARG_REQUEST 0 /* request to perform */ #define ARG_PATH 1 /* system service */ #define ARG_LABEL 1 /* name of system service */ #define MIN_ARG_COUNT 1 /* require an action */ #define ARG_ARGS "-args" /* list of arguments to be passed */ #define ARG_DEV "-dev" /* major device number for drivers */ #define ARG_MAJOR "-major" /* major number */ #define ARG_PERIOD "-period" /* heartbeat period in ticks */ #define ARG_SCRIPT "-script" /* name of the script to restart a * system service */ #define ARG_LABELNAME "-label" /* custom label name */ #define ARG_CONFIG "-config" /* name of the file with the resource * configuration */ #define ARG_LU_STATE "-state" /* the live update state required */ #define ARG_LU_MAXTIME "-maxtime" /* max time to prepare for the update */ #define ARG_DEVMANID "-devid" /* the id of the devman device this driver should be able to access */ /* The function parse_arguments() verifies and parses the command line * parameters passed to this utility. Request parameters that are needed * are stored globally in the following variables: */ static int req_type; static int do_run= 0; /* 'run' command instead of 'up' */ static char *req_label = NULL; static char *req_path = NULL; static char *req_path_self = SELF_REQ_PATH; static char *req_args = ""; static int req_major = 0; static int devman_id = 0; static long req_period = 0; static char *req_script = NULL; static char *req_config = PATH_CONFIG; static int custom_config_file = 0; static int req_lu_state = DEFAULT_LU_STATE; static int req_lu_maxtime = DEFAULT_LU_MAXTIME; /* Buffer to build "/command arg1 arg2 ..." string to pass to RS server. */ static char command[4096]; /* An error occurred. Report the problem, print the usage, and exit. */ static void print_usage(char *app_name, char *problem) { fprintf(stderr, "Warning, %s\n", problem); fprintf(stderr, "Usage:\n"); fprintf(stderr, " %s [%s %s %s %s] (up|run|edit|update) [%s ] [%s ] [%s ] [%s ] [%s ] [%s ] [%s ] [%s ] [%s ] [%s