/* 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 #include "config.h" #include "proto.h" /* This array defines all known requests. */ static char *known_requests[] = { "up", "down", "refresh", "restart", "shutdown", "update", "clone", "unclone", "edit", "sysctl", "catch for illegal requests" }; static int known_request_types[] = { RS_UP, RS_DOWN, RS_REFRESH, RS_RESTART, RS_SHUTDOWN, RS_UPDATE, RS_CLONE, RS_UNCLONE, RS_EDIT, RS_SYSCTL, 0 }; #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 OPT_NO_BIN_EXP "-b" /* no binary exponential backoff */ #define OPT_BATCH "-q" /* batch mode */ #define OPT_ASR_LU "-a" /* asr update */ #define OPT_PREPARE_ONLY_LU "-o" /* prepare-only update */ #define OPT_FORCE_SELF_LU "-s" /* force self update */ #define OPT_FORCE_INIT_CRASH "-x" /* force init crash (for debugging) */ #define OPT_FORCE_INIT_FAIL "-y" /* force init failure (for debugging) */ #define OPT_FORCE_INIT_TIMEOUT "-z" /* force init timeout (for debugging) */ #define OPT_FORCE_INIT_DEFCB "-d" /* force init default callback */ #define OPT_UNSAFE_LU "-u" /* allow unsafe update */ #define OPT_NOMMAP_LU "-m" /* don't inherit mmaped regions */ #define OPT_DETACH "-e" /* detach on update/restart */ #define OPT_NORESTART "-f" /* don't restart */ #define OPT_FORCE_INIT_ST "-t" /* force init state transfer */ /* 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 ARG_SYSCTL_TYPE 1 /* sysctl action type */ #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 */ #define ARG_HEAP_PREALLOC "-heap-prealloc" /* preallocate heap regions */ #define ARG_MAP_PREALLOC "-map-prealloc" /* preallocate mmapped regions */ #define ARG_TRG_LABELNAME "-trg-label" /* target label name */ #define ARG_LU_IPC_BL "-ipc_bl" /* IPC blacklist filter */ #define ARG_LU_IPC_WL "-ipc_wl" /* IPC whitelist filter */ #define ARG_RESTARTS "-restarts" /* number of restarts */ /* 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_trg_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; static int req_restarts = 0; static long req_heap_prealloc = 0; static long req_map_prealloc = 0; static int req_sysctl_type = 0; static struct rs_ipc_filter_el rs_ipc_filter_els[RS_MAX_IPC_FILTERS][IPCF_MAX_ELEMENTS]; static int num_ipc_filters = 0; static char *req_state_eval = NULL; /* 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 %s %s %s %s %s %s %s %s %s %s %s %s %s %s] (up|run|edit|update) [%s ] [%s ] [%s ] [%s ] [%s ] [%s ] [%s ] [%s ] [%s ] [%s