#include <sys/types.h>
#include <sys/param.h>
#include <sys/procctl.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <sys/un.h>
#include <sys/ttycom.h>
#include <sys/devfs.h>
#include <sys/mount.h>
#include <sys/jail.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stddef.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <dirent.h>
#include <assert.h>
#include <errno.h>
#include <ctype.h>
#include <pwd.h>
#include <grp.h>
#include <pthread.h>
typedef struct SvcCommand {
int mountdev : 1;
int cmdline : 1;
int foreground : 1;
int restart_some : 1;
int restart_all : 1;
int exit_mode : 1;
int sync_mode : 1;
int tail_mode : 3;
int jail_clean : 1;
int uid_mode : 1;
int gid_mode : 1;
int manual_stop : 1;
int empty_label : 1;
int commanded : 1;
int force_remove_files : 1;
FILE *fp;
char *piddir;
char *rootdir;
char *jaildir;
char *logfile;
char *proctitle;
char *directive;
char *label;
char **ext_av;
int ext_ac;
char **orig_av;
int orig_ac;
int restart_timo;
int termkill_timo;
int debug;
int restart_per;
int restart_count;
struct passwd pwent;
struct group grent;
gid_t groups[NGROUPS];
int ngroups;
pthread_cond_t logcond;
char logbuf[8192];
int logwindex;
int logcount;
int logfds[2];
int logfd;
} command_t;
typedef enum {
RS_STOPPED,
RS_STARTED,
RS_STOPPING1,
RS_STOPPING2,
RS_STOPPING3,
} runstate_t;
#define LOGCHUNK 1024
extern pthread_mutex_t serial_mtx;
int process_cmd(command_t *cmd, FILE *fp, int ac, char **av);
int execute_cmd(command_t *cmd);
void free_cmd(command_t *cmd);
void sfree(char **strp);
void sreplace(char **strp, const char *orig);
void sdup(char **strp);
void afree(char ***aryp);
void adup(char ***aryp);
int setup_pid_and_socket(command_t *cmd, int *lfdp, int *pfdp);
void remove_pid_and_socket(command_t *cmd, const char *label);
void remote_execute(command_t *cmd, const char *label);
void remote_listener(command_t *cmd, int lfd);
int remote_wait(void);
int execute_init(command_t *cmd);
int execute_start(command_t *cmd);
int execute_stop(command_t *cmd);
int execute_restart(command_t *cmd);
int execute_exit(command_t *cmd);
int execute_list(command_t *cmd);
int execute_status(command_t *cmd);
int execute_log(command_t *cmd);
int execute_logfile(command_t *cmd);
int execute_help(command_t *cmd);