void handle_base_flags(int flag_char, /* IN */ const char *flag_arg, /* IN */ print_usage_f *print_usage, /* IN */ const char *appl, /* IN */ const char **default_outfilep) /* IN */ { switch(flag_char) { case 'o': *default_outfilep = flag_arg; break; case 'q': LOG_SET_LEVEL(LOG_BRIEF); break; case 'v': print_license(); exit(0); default: if (flagflag != '?') { LOG(LOG_ERROR, ("error, invalid option \"-%c\"", flagflag)); if (flagarg != NULL) { LOG(LOG_ERROR, (" with argument \"%s\"", flagarg)); } LOG(LOG_ERROR, ("\n")); } print_usage(appl, LOG_BRIEF, *default_outfilep); exit(0); } }
int main(int argc, char** argv) { LOG_SET_NAME("Slicer"); LOG_SET_LEVEL(Kernal::LOG_LEVEL_WRITE); //if( LOG_SET_FILE( "log.txt" ) ) // return 1; { LOG("MAIN"); LOG_WRITE("main"); TestMessageSender fp; TestMessageSender1 *tms1; TestMessageSender2 *tms2; TestMessageSender3 *tms3; TestMessageSender4 *tms4; Kernal::Watch::SleepSec(0.5f); LOG_WRITE("Running"); Kernal::Watch times; Kernal::Watch current; Kernal::Watch::SleepSec(0.5f); tms1 = new TestMessageSender1; tms2 = new TestMessageSender2; tms3 = new TestMessageSender3; tms4 = new TestMessageSender4; fp.Run(); while (Kernal::MyMessageHandlerServerRunning()) { Kernal::Watch::SleepSec(0.3f); if (times.GetSplit() > 1) { LOG_WRITE("Waiting here"); LOG_STACK; times.Reset(); } LOG_WRITE("No longer waiting here"); } LOG_WRITE("IM OUTSIDE AGAIN!!!"); Kernal::CloseMyMessageHandlerServer(); LOG_WRITE("Deleting"); delete tms1; delete tms2; delete tms3; LOG_WRITE("Close.."); delete tms4; LOG_WRITE("Closed"); } CLOSE_LOG; return 0; }
int main( int argc, char *argv[] ) { int pid; /* read the arguments */ td.connect = 1; td.logfile = NULL; LOG_INIT(NULL);//"/tmp/vlhttp-debug.log"); LOG_SET_LEVEL(LOG_LEVEL_DBG); char opt; while((opt = getopt(argc, argv, "p:i:m:r:A:S:f")) != -1) { switch(opt) { case 'A': encode_base64(optarg, strlen(optarg), (unsigned char**)(&proxy_auth)); DBG("proxy_auth: %s", proxy_auth); break; case 'S': encode_base64(optarg, strlen(optarg), (unsigned char**)(&sys_auth)); DBG("sys_auth: %s", sys_auth); break; case 'r': strncpy(proxy_realm, optarg, sizeof(proxy_realm)); break; case 'p': proxy_port = atoi(optarg); break; case 'i': td.auth_ip = inet_addr(optarg); break; case 'm': td.netmask = inet_addr(optarg); break; case 'f': DBG("turn off daemon", 0); foreground_mode = 1; break; } } td.auth_ip &= td.netmask; td.client_ip = 0; DBG("========================================================================================================", 0); /* is inetd mode enabled ? */ if( proxy_port == 0 ) { int r; td.client_fd = 0; /* stdin */ DBG("start",0); r = proxy_thread( &td ); DBG("exit with %d code", r); return( r ); } /* fork into background */ if (!foreground_mode) { if ( (pid = fork() ) < 0 ) { ERR("fork() fail", 0); return -1; } if (pid) return ( 0 ); } if (!init_proxy()) { return -1; } while( 1 ) { int n = sizeof( client_addr ); /* wait for inboud connections */ if( ( td.client_fd = accept( proxy_fd, (struct sockaddr *) &client_addr, (socklen_t*)&n ) ) < 0 ) { ERR("accept() fail", 0); return -1; } td.client_ip = client_addr.sin_addr.s_addr; /* verify that the client is authorized */ if ( (td.client_ip & td.netmask) != td.auth_ip ) { close( td.client_fd ); continue; } /* fork a child to handle the connection */ if ( (pid = fork()) < 0 ) { close( td.client_fd ); continue; } if (pid) { /* in father; wait for the child to terminate */ close( td.client_fd ); waitpid( pid, NULL, 0 ); continue; } /* in child; fork & exit so that father becomes init */ if ((pid = fork()) < 0 ) { ERR("fork() fail", 0); return -1; } if (pid) return 0; return( proxy_thread( &td ) ); } /* not reached */ return -1; }