/common/home/bel/bella/lnx/exports/build/current/all/op-services/consmngr/srvr/consmngr.h

Go to the documentation of this file.
00001 #ifndef CONSMNGR_H
00002 #define CONSMNGR_H
00003 
00058 #include <stdio.h>
00059 #include <stdlib.h>
00060 #include <unistd.h>
00061 #include <string.h>
00062 #include <time.h>
00063 #include <libgen.h>
00064 #include <sys/socket.h>
00065 #include <sys/types.h>
00066 #include <sys/stat.h>
00067 #include <sys/inotify.h>
00068 #include <fcntl.h>
00069 #include <netinet/in.h>
00070 #include <arpa/inet.h>
00071 #include <errno.h>
00072 #include <signal.h>
00073 #include <wait.h>
00074 #include "ix_tools.h"
00075 #include "isintf.h"
00076 #include "rsintf.h"
00077 #include "consintf.h"
00078 #include "xcons.h"
00079 #include "uv.h"
00080 #include "xvalue.h"
00081 #include "xfreader.h"
00082 #include "ixf.h"
00083 #include "vmssys.h"
00084 #include "version.h"
00085 
00086 #define IX_V_INIT 0x02
00087 #define IX_V_CMD 0x04
00088 #define IX_V_WATCH 0x08
00089 #define IX_V_NOTIFY 0x20
00090 #define IX_V_XFER 0x40
00091 #define IX_V_TIMER 0x80
00092 #define IX_V_MSG 0x100
00093 #define IX_V_RUNLEVEL 0x200
00094 #define IX_V_DEBUG 0x400
00095 
00096 #define MAX_SERVICES 8
00097 #define CMD_MAX 256
00098 #define PROC_MAX 256
00099 #define LISTENER_MAX 32
00100 #define CMD_LEN_MAX 4096
00101 
00102 #define CONS_GUI "consgui"
00103 #define CONS_PROG "KONS.sh"
00104 #define BEAMLINEID "beamlineid"
00105 #define BEAMLINEKEY "BEAMLINE_KEY"
00106 #define CONS_USER "opcons"
00107 
00108 #define CONS_WAIT_PROC "zdisup"
00109 
00110 // default path for consoles logfile
00111 #define CONS_PATH "/common/usr/develop/operating/log"
00112 
00113 // configuration environment
00114 #define CONFIG_ENV "BELA_CONFIGDIR"
00115 
00116 typedef enum
00117 {
00118   EXEC_START,
00119   EXEC_REMOVE
00120 } cons_type_e;
00121 
00122 /*
00123  * info and state of a process
00124  */
00125 typedef struct
00126 {
00127   char proc  [CMD_LEN_MAX];  // process name
00128   char cmdstr[CMD_LEN_MAX];  // command str from client
00129   int opt;                   // how the process is spawned
00130   int id;                    // id of command
00131   xf_t *pxf;                 // the associated client stream connection
00132   int result;                // result of command execution (exit code)
00133   pid_t pid;                 // process id of command, > 0: running
00134   pid_t pgid;                // process group id of command, 
00135                              // > 0: it is a group leader
00136   time_t term_time;           // the time process was terminated
00137   cons_type_e type;          // 
00138   int status;                // status of execution
00139   int runlevel;              // runlevel for group start command
00140   int fd[3];                 // stdin, stdout, stderr for process
00141 
00142 } cmd_t;
00143 
00144 // common message 
00145 typedef struct
00146 {
00147   xf_instance_t *pinst;
00148   xf_t *pxf;
00149 } msg_t;
00150 
00151 // listener for process list changes
00152 typedef struct
00153 {
00154   int lifetime;
00155   int minrunlevel;
00156   int maxrunlevel;
00157   xf_t *pxf;
00158 } listener_t;
00159 
00160 typedef struct
00161 {
00162   int min;
00163   int max;
00164   int active;
00165   int level;
00166   int start;
00167 } runlevel_t;
00168 
00169 typedef struct
00170 {
00171   char console[256];
00172   char options[256];
00173 } console_t;
00174 
00175 typedef struct
00176 {
00177   char *myproc;
00178   char *consname;
00179   char *logpath;
00180   char logfn[PATH_MAX];
00181   int logfd;
00182   int log;
00183   int myudpport;
00184   int mytcpport;
00185   int mqevid;
00186   int daemon;
00187   int gui;
00188   char *guiprog;
00189   int zd;
00190   char *zdfn;
00191   int master;
00192   int test;
00193   int set;
00194   int undecor;
00195 
00196   int wait;
00197   int wait_time;
00198   char *wait_proc;
00199 
00200   ix_list_t *pcmd_list;
00201   ix_list_t *pproc_list;
00202   ix_list_t *plistener_list;
00203   ix_cs_t *pcs;
00204   int verbose;
00205   ix_msg_queue_t *pmq;
00206   ix_msg_queue_t *pdelayedmq;
00207   xf_refl_t *service_l[MAX_SERVICES];
00208   xf_refl_t *pcons_refl;
00209 
00210   ix_event_t *ptev;
00211   ix_event_t *prltev;
00212   ix_event_t *pmsgev;
00213   ix_event_t *pdelayedmsgev;
00214   ix_event_t *pdelayevent;
00215   ix_event_t *pkillevent;
00216   ix_event_t *psigev;
00217   ix_event_t *prunningev;
00218 
00219   ix_timer_t *pt;
00220   ix_timer_t *pdelaytimer;
00221   ix_timer_t *pkilltimer;
00222   ix_timer_t *prlt;
00223   rs_reg_t rs;
00224 
00225   int trun_f;
00226   int delay_f;
00227   int kill_f;
00228 
00229   char *user;
00230   char userhost[PATH_MAX];
00231 
00232   ix_thread_t *pstart;
00233   runlevel_t runlevel;
00234   int rl_timeout;
00235   int delay_timer;
00236   int kill_timer;
00237   int beamlineid;
00238   char beamkey[256];
00239   char hostname[512];
00240   char **environ;
00241 } gl_data;
00242 
00243 
00244 /***************************
00245  * main.c
00246  **************************/
00247 cmd_t *cmd_new_proc( char *proc, char *cmdstr, int opt, int type, 
00248     int runlevel, int fd[3] );
00249 cmd_t *cmd_new_xms( xcons_cmd_t *pc,  xf_t *pxf, int type );
00250 void cmd_free( cmd_t * p);
00251 int kick_update_listener(void);
00252 int cancel_runlevel_timer(void);
00253 int kick_handle_runlevel(void);
00254 int kick_kill_timer(void);
00255 int init_set( xcons_init_t *pinit );
00256 int set_proc_env( char *proc );
00257 int restart_proc( cmd_t *pcmd );
00258 int add_uv_proc( cmd_t *proc );
00259 int rm_uv_proc( cmd_t *proc );
00260 int set_uv_proc( cmd_t *proc );
00261 
00262 
00263 
00264 /***************************
00265  * proc.c 
00266  **************************/
00267 /*
00268  * 0 ok
00269  * !0 error
00270  */
00271 int add_proc( cmd_t *proc, int update_flag );
00272 int exec_proc( cmd_t *proc );
00273 int start_proc( char *proc );
00274 int kill_proc( char *proc );
00275 int rm_proc( char *proc );
00276 int runlevel_proc( int min, int max );
00277 int running_proc( char *proc );
00278 void handle_runlevel(int timeout_f );
00279 int quit_proc( int mode );
00280 int is_inlist_proc( char *proc );
00281 int _kill_proc( cmd_t *proc, int signal );
00282 
00283 /*
00284  * <0: not known
00285  * 0: known, not running
00286  * >0: known running
00287  */
00288 int check_proc( char *proc );
00289 int check_proc_list(void);
00290 int check_kill_list(void);
00291 
00292 /***************************
00293  * db.c 
00294  ***************************/
00295 int init_proc_list( xcons_init_t *pdef );
00296 
00297 /****************************
00298  * xmsg.c 
00299  ****************************/
00300 int update_listener(void);
00301 int rm_listener( xf_t *pxf);
00302 int add_listener( xcons_subscribe_t *psub, xf_t *pxf);
00303 int proc_request( xcons_request_t *preq, xf_t *pxf );
00304 
00305 
00306 #endif

Generated on 4 Mar 2014 for consmngr by  doxygen 1.4.7