#include "rc_lib.h" #include #include #include int accept_receive_rc (int , int * , unsigned long ); static int n_branches = 0; static int n_eor_ok = 0; #define NONBLOCKING 1 FILE *error_ptr = NULL; #define TLTRC_LOG "tltrc_error.log" char TIME_STAMP[32] = "11:59:59"; char lastmsg[256]; int script_time; pid_t childpid; int CHILD_FLAG = 0; int SCRIPT_FLAG = 0; int ABORT_FLAG = 0; /*===========================================================================================*/ /* dummy and short functions */ /*===========================================================================================*/ #define ZMP_SUCCESS 1 // success #define SRVCLI_SUCCESS 1 /* success */ #define SRVCLI_ERROR 0 /* error */ #define SRVCLI_SUICIDE 2 /* end job status request */ #define SRVCLI_TALK_NORMAL 1 #define SRVCLI_TALK_LOUD 2 //extern int status; //int SRVCLI_FAILURE(status) { if (status != SRVCLI_SUCCESS) return 1; else return 0; } //int ZMP_FAILURE(status) { if (status != ZMP_SUCCESS) return 1; else return 0; } //int ZMP_STREQ(char*s1,char*s2) { if (strcmp(s1,s2)) return 0; else return 1; } void close_exit_handler(int flag) { printf(" !!!!!!!! close_exit_handler CALLED \n"); } /*===========================================================================================*/ int local = 0; const char *hello = {"here I am"}; /* enter log system message */ const char *byebye = {"byebye"}; /* exit log system message */ const char *s_idle = "IDLE"; const char *s_init = "INIT"; const char *s_ready = "READY"; const char *s_setup = "SETUP"; const char *s_activate= "ACTIVATE"; const char *s_active = "ACTIVE"; const char *s_pause = "PAUSE"; const char *s_paused = "PAUSED"; const char *s_resume = "RESUME"; const char *s_end = "END"; const char *s_abort = "ABORT"; const char *s_exit = "EXIT"; const char *s_wayout = "WAYOUT"; const char *s_undef = "UNDEF"; /* state on exit */ const char *s_givests = "GIVE_STATUS"; const char *s_goaway = "GO_AWAY"; const char *s_set = "SET"; const char *s_err = "ERROR"; const char *s_sts = "STS"; /* status reply */ const char *s_war = "WAR"; /* WAR reply */ const char *s_inf = "INF"; const char *s_on = "ONLINE"; const char *s_off = "OFFLINE"; const char *s_new = "NEWCONTROL"; /* new control message */ const char *s_map = "MAPCONTROL"; /* free control and remap */ const char *s_cmd = "CMD:"; /* the rest of the command send down */ const char *s_nst = "NEW_STATE"; /* goto to the new state */ const char *s_unk = "Unknown command"; /* message if command unknown */ const char *s_trn = "TRANS"; const char *s_blank = " "; /* blank used in strtok() */ const char *s_comma = ","; /* comma used in strtok() */ const char *s_brkop = "<"; /* comma used in strtok() */ const char *s_brkcl = ">"; /* comma used in strtok() */ int DEBUG=1; /******************************************************************************** void process_msg (char *buf, char **tk, int *ntk) This new version uses strsep instead of strtok that can't deal correctly with empty strings. ********************************************************************************/ void process_msg_0 (char *buf, char **tk, int *ntk ) { int n = 0; for ( n = 0 ; n < MAX_TOKENS ; n++ ) { tk[n] = NULL; tk[n] = strsep(&buf, " \t\n"); if ( tk[n] == NULL ) break; // if (DEBUG>0) // printf("p_m: tk[%d] = %s\n",n, tk[n]); } *ntk = n; } /********************************************************************************/ void process_msg (char *buf, char **tk, int *ntk) { int i,n = 0, len; char *ptr; *ntk=0; ptr=buf; len=strlen(buf); for (i=0;i0 && len>=i && ptr[i]==0x20 && ptr[i-1]==0x20) { //printf(" m:%d:%d:%d \n",i,len,len-i); memcpy(&ptr[i-1],&ptr[i],len-i); ptr[len-1]=0; len--; goto loop; } //printf(" %2d=%02x ",i,ptr[i]); }; if (ptr[len-1]==0x20) ptr[len-1]=0; len=strlen(buf); // printf("new BUF LEN=%d \n",len); for ( n = 0 ; n < MAX_TOKENS ; n++ ) { tk[n] = NULL; tk[n] = strsep(&buf, " \t\n\r"); if ( tk[n] == NULL ) break; // printf("p_m: tk[%d] = %s\n",n, tk[n]); } *ntk = n; //for (int i=0;isin_family = AF_INET; hp = gethostbyname(host); if( hp == NULL ) { printf("%s: unknown host\n", host); return -1; } memcpy( &addr->sin_addr, hp->h_addr, hp->h_length); addr->sin_port = htons(port); return 0; } /******************************************************************************** void copy_lastmsg(char *message) ********************************************************************************/ void copy_lastmsg(char *message) { int sizem = 0; memset(lastmsg, 0, sizeof(lastmsg)); if ( (message == NULL) || (strlen(message) == 0) ) return; if ( strlen(message) < sizeof(lastmsg) ) sizem = strlen(message); else sizem = sizeof(lastmsg); strncpy(lastmsg, message, sizem); } /******************************************************************************** get_current_time(void) ********************************************************************************/ void get_current_time(void) { time_t t1; time(&t1); memset(TIME_STAMP, 0, sizeof(TIME_STAMP)); strcpy(TIME_STAMP, ctime(&t1)); TIME_STAMP[strlen(TIME_STAMP)-1] = 0; } /******************************************************************************** static void child_exit(int signo) ********************************************************************************/ void child_exit(int signo) { pid_t child; int status = 0; char ss[256]; /********************************** * we call the blocking wait * cause we know there is a child * reporting its exit status **********************************/ child = wait(&status); printf("TLT_RC: waited for %d, got %d\n",(int)childpid, (int)child); }