int main(int argc, char *argv[]) { int sockfd , clisockfd; unsigned int clilen; int childpid; struct sockaddr_in serv_addr,cli_addr; int err_select;//JY1113 #ifdef LPR_with_ASUS//JY1112 int LPRflag = 0; fd_set rfds, afds; int nfds; int sockfd_ASUS; unsigned int clilen_ASUS; int childpid_ASUS; struct sockaddr_in serv_addr_ASUS,cli_addr_ASUS; #endif #ifdef Raw_Printing_with_ASUS //Lisa int netfd, fd, clientlen, one = 1; struct sockaddr_in netaddr, client; #endif int lock; int pid = 0; FILE *fp; fp = fopen("/var/run/lpdparent.pid", "r"); if (fp) { fscanf(fp, "%d", &pid); fclose(fp); } if ((pid > 1) && (kill(pid, 0) == 0 || errno != ESRCH)) { syslog(LOGOPTS, "another lpd daemon exists!!\n"); exit(0); } update_pidfile(); //Initial the server the not busy lptstatus.busy = FALSE; sigset_t sigs_to_catch; sigemptyset(&sigs_to_catch); sigaddset(&sigs_to_catch, SIGCLD); sigaddset(&sigs_to_catch, SIGINT); sigaddset(&sigs_to_catch, SIGQUIT); sigaddset(&sigs_to_catch, SIGKILL); sigaddset(&sigs_to_catch, SIGUSR2); sigprocmask(SIG_UNBLOCK, &sigs_to_catch, NULL); //Setup the signal handler signal(SIGCLD, sig_child); signal(SIGINT, sig_cleanup); signal(SIGQUIT, sig_cleanup); signal(SIGKILL, sig_cleanup); signal(SIGUSR2, sig_remove);//JY1110 if((sockfd = socket(AF_INET,SOCK_STREAM,0)) < 0 ) { syslog(LOGOPTS, "can't open stream socket: %m"); exit(0); } bzero((char *)&serv_addr , sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); serv_addr.sin_port = htons(PNT_SVR_PORT_LPR); if(bind(sockfd,(struct sockaddr *)&serv_addr , sizeof(serv_addr)) < 0 ) { syslog(LOGOPTS, "can't bind socket with port %d: %m", PNT_SVR_PORT_LPR); exit(0); } /*JY1111*/ int windowsize=2920; setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, (char *)&windowsize, sizeof(windowsize)); int no_delay=1; setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, &no_delay, sizeof(no_delay)); // by Jiahao. 20080808. listen(sockfd , 15); #ifdef Raw_Printing_with_ASUS //Lisa if ((netfd = socket(AF_INET, SOCK_STREAM, IPPROTO_IP)) < 0) { syslog(LOGOPTS, "cannot open stream socket for raw printing: %m\n"); exit(1); } if (setsockopt(netfd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) < 0) { syslog(LOGOPTS, "cannot setsocketopt for raw printing: %m\n"); exit(1); } netaddr.sin_family = AF_INET; netaddr.sin_port = htons(BASEPORT); netaddr.sin_addr.s_addr = htonl(INADDR_ANY); memset(netaddr.sin_zero, 0, sizeof(netaddr.sin_zero)); if (bind(netfd, (struct sockaddr*) &netaddr, sizeof(netaddr)) < 0) { syslog(LOGOPTS, "cannot bind socket with port %d for raw printing: %m\n", BASEPORT); exit(1); } if (listen(netfd, 5) < 0) { syslog(LOGOPTS, "cannot listen socket for raw printing: %m\n"); exit(1); } //clientlen = sizeof(client); //memset(&client, 0, sizeof(client)); #endif #ifdef LPR_with_ASUS//JY1112 if((sockfd_ASUS = socket(AF_INET,SOCK_STREAM,0)) < 0 ) { syslog(LOG_ERR, "can't open stream socket for LPR: %m"); exit(0); } bzero((char *)&serv_addr_ASUS , sizeof(serv_addr_ASUS)); serv_addr_ASUS.sin_family = AF_INET; serv_addr_ASUS.sin_addr.s_addr = htonl(INADDR_ANY); serv_addr_ASUS.sin_port = htons(PNT_SVR_PORT_ASUS); if(bind(sockfd_ASUS,(struct sockaddr *)&serv_addr_ASUS , sizeof(serv_addr_ASUS)) < 0 ) { syslog(LOG_ERR, "can't bind socket for LPR: %m"); exit(0); } setsockopt(sockfd_ASUS, SOL_SOCKET, SO_RCVBUF, (char *)&windowsize, sizeof(windowsize)); listen(sockfd_ASUS , 15); /*set the fds*/ nfds=MAX(sockfd, sockfd_ASUS); FD_ZERO(&afds); #endif while(TRUE) { //if (busy) syslog(LOG_NOTICE, "busying %d %d\n", lptstatus.busy, busy); lock = file_lock("printer"); // by Jiahao for U2EC. 20080808. if (lptstatus.busy==FALSE && nvram_invmatch("MFP_busy", "2")) { busy=FALSE; nvram_set_int_temp("MFP_busy", 0); nvram_set_temp("u2ec_busyip", ""); } file_unlock(lock); #ifdef Raw_Printing_with_ASUS //Lisa FD_SET(netfd, &afds); #endif #ifdef LPR_with_ASUS//JY1112 FD_SET(sockfd, &afds); FD_SET(sockfd_ASUS, &afds); memcpy(&rfds, &afds, sizeof(rfds)); if((err_select=select(nfds+1, &rfds, (fd_set *)0, (fd_set *)0, (struct timeval *)0 )) < 0) { //JY1120 printf("select error on sockfd: error=%d\n", errno); /**/ // printf("sockfd_FD_ISSET=%d\n", FD_ISSET(sockfd, &rfds)); //JY1120 printf("sockfd_ASUS FD_ISSET=%d\n", FD_ISSET(sockfd_ASUS, &rfds)); /**/ // if(errno != 4)//JY1113: delete //syslog(LOG_NOTICE, "select error %d\n", err_select); continue; } #endif clilen = sizeof(cli_addr); if(FD_ISSET(sockfd_ASUS, &rfds)) { LPRflag = 0; clisockfd = accept(sockfd_ASUS,(struct sockaddr *)&cli_addr, &clilen); } #ifdef LPR_with_ASUS//JY1112 else if(FD_ISSET(sockfd, &rfds)) { LPRflag = 1; clisockfd = accept(sockfd,(struct sockaddr *)&cli_addr, &clilen); } #endif #ifdef Raw_Printing_with_ASUS //Lisa // else if(FD_ISSET(netfd, &rfds) && busy==FALSE) else if(FD_ISSET(netfd, &rfds)) { lock = file_lock("printer"); // by Jiahao for U2EC. 20080808. if (nvram_match("MFP_busy", "0")) { file_unlock(lock); LPRflag = 2; clisockfd = accept(netfd, (struct sockaddr*) &cli_addr, &clilen); } else { file_unlock(lock); sleep(2); continue; } } #endif else { //syslog(LOG_NOTICE, "No select\n"); sleep(2); continue; } strcpy(clientaddr , inet_ntoa(cli_addr.sin_addr)); if(clisockfd < 0) { //syslog(LOG_NOTICE, "LPD error: No clisockfd %d\n", LPRflag); continue; } lock = file_lock("printer"); // if (busy!=FALSE) /* 2004/09/10 by Joey, process nack in parent for LPR and Remote Prot */ if (nvram_invmatch("MFP_busy", "0")) // by Jiahao for U2EC. 20080808. { file_unlock(lock); //syslog(LOG_NOTICE, "Printing others 1 %d %d\n", LPRflag, clisockfd); if (LPRflag==0) processReq(clisockfd); else if (LPRflag==1) processReq_LPR(clisockfd, 0); //syslog(LOG_NOTICE, "Printing others %d %d\n", LPRflag, clisockfd); close(clisockfd); // For Raw printing, don't resonse to client while busy sleep(5); continue; } nvram_set_int_temp("MFP_busy", 1); if (nvram_match("lan_ipaddr_t", "")) nvram_set_temp("u2ec_busyip", nvram_safe_get("lan_ipaddr")); else nvram_set_temp("u2ec_busyip", nvram_safe_get("lan_ipaddr_t")); file_unlock(lock); if( (childpid = fork() ) < 0) { } else if(childpid == 0) { //syslog(LOG_NOTICE, "Printing %d\n", LPRflag); if(LPRflag==0) processReq(clisockfd); #ifdef LPR_with_ASUS//JY1114 else if(LPRflag==1) processReq_LPR(clisockfd, 1); #endif #ifdef Raw_Printing_with_ASUS //Lisa else if(LPRflag == 2) processReq_Raw(clisockfd); #endif close(sockfd); close(sockfd_ASUS); #ifdef Raw_Printing_with_ASUS close(netfd); #endif exit(0); } //syslog(0, "Printing Process %d %d %d\n", busy, lptstatus.busy, childpid); //parents process goes on here //remark PRINT("fork -- childpid %d\n",childpid); if(lptstatus.busy == FALSE) { lptstatus.busy = TRUE; // busy = TRUE; // remarked by Jiahao for U2EC. 20080808. strcpy(lptstatus.addr , inet_ntoa(cli_addr.sin_addr)); lptstatus.pid = childpid; } close(clisockfd); } }
int main(int argc , char* argv[]) { int sockfd; struct sockaddr_in serv_addr,cli_addr; int broadcast = 1; int count = 0; struct timeval tv; if (argc < 2) { printf("not enough parameters for infosvr\n"); printf("infosvr netif...\n"); exit(0); } // Write PID file if (!set_pid(getpid())) // Add by Joey { printf("can not set process id\n"); exit(0); } // Load system related static parameter load_sysparam(); #ifdef PRNINFO //JYWeng: 20030325 for WL500g/WL500b // Signal for reading Printer Information signal(SIGALRM, sig_usr1); // Add by Joey signal(SIGUSR1 , sig_usr1); alarm(2); // Get ID for the first time 2 seconds later #endif /* signal(SIGUSR1, sig_do_nothing); */ signal(SIGUSR2, sig_do_nothing); g_intfCount = argc - 1; while (count < g_intfCount) { g_intf[count] = argv[count+1]; count ++; } if ((sockfd = socket(AF_INET,SOCK_DGRAM,0)) < 0) { PRINT("can't open datagram socket\n"); perror("socket:"); exit(0); } if (setsockopt(sockfd , SOL_SOCKET , SO_BROADCAST ,(char *)&broadcast,sizeof(broadcast)) == -1) { perror("setsockopt:"); } bzero((char *)&cli_addr , sizeof(cli_addr)); cli_addr.sin_family = AF_INET; cli_addr.sin_addr.s_addr = inet_addr("255.255.255.255"); cli_addr.sin_port = htons(SRV_PORT); bzero((char *)&serv_addr , sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); serv_addr.sin_port = htons(SRV_PORT); int flag=1; setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&flag, sizeof(flag)); if (bind(sockfd,(struct sockaddr *)&serv_addr , sizeof(serv_addr)) < 0) { PRINT("can't bind\n"); perror("ERR:"); exit(0); } while (TRUE) { int res; fd_set fdvar; FD_ZERO(&fdvar); FD_SET(sockfd, &fdvar); tv.tv_sec = 2; tv.tv_usec = 0; res = select( sockfd + 1 , &fdvar , NULL , NULL , &tv); if (res == 1) { // printf("got packet\n"); processReq(sockfd); } } }
int main( int argc, char * argv[] ) { int ret; int bindFd; char * php_ini_path = NULL; char * php_bind = NULL; int n; int climode = 0; struct timeval tv_req_begin; struct timeval tv_req_end; int slow_script_msec = 0; char time_buf[40]; #ifdef HAVE_SIGNAL_H #if defined(SIGPIPE) && defined(SIG_IGN) signal(SIGPIPE, SIG_IGN); #endif #endif #ifdef ZTS tsrm_startup(1, 1, 0, NULL); #endif zend_signal_startup(); if (argc > 1 ) { if ( parse_opt( argc, argv, &climode, &php_ini_path, &php_bind ) == -1 ) { return 1; } } if ( climode ) { lsapi_sapi_module.phpinfo_as_text = 1; } else { setArgv0(argc, argv ); } sapi_startup(&lsapi_sapi_module); #ifdef ZTS compiler_globals = ts_resource(compiler_globals_id); executor_globals = ts_resource(executor_globals_id); core_globals = ts_resource(core_globals_id); sapi_globals = ts_resource(sapi_globals_id); tsrm_ls = ts_resource(0); SG(request_info).path_translated = NULL; #endif lsapi_sapi_module.executable_location = argv[0]; /* Initialize from environment variables before processing command-line * options: the latter override the former. */ init_sapi_from_env(&lsapi_sapi_module); if ( ignore_php_ini ) lsapi_sapi_module.php_ini_ignore = 1; if ( php_ini_path ) { lsapi_sapi_module.php_ini_path_override = php_ini_path; } lsapi_sapi_module.ini_defaults = sapi_lsapi_ini_defaults; if (php_module_startup(&lsapi_sapi_module, &litespeed_module_entry, 1) == FAILURE) { #ifdef ZTS tsrm_shutdown(); #endif return FAILURE; } if ( climode ) { return cli_main(argc, argv); } if ( php_bind ) { bindFd = LSAPI_CreateListenSock( php_bind, 10 ); if ( bindFd == -1 ) { fprintf( stderr, "Failed to bind socket [%s]: %s\n", php_bind, strerror( errno ) ); exit( 2 ); } if ( bindFd != 0 ) { dup2( bindFd, 0 ); close( bindFd ); } } LSAPI_Init(); LSAPI_Init_Env_Parameters( NULL ); lsapi_mode = 1; slow_script_msec = LSAPI_Get_Slow_Req_Msecs(); if ( php_bind ) { LSAPI_No_Check_ppid(); free( php_bind ); php_bind = NULL; } while( LSAPI_Prefork_Accept_r( &g_req ) >= 0 ) { if ( slow_script_msec ) { gettimeofday( &tv_req_begin, NULL ); } ret = processReq(); if ( slow_script_msec ) { gettimeofday( &tv_req_end, NULL ); n = ((long) tv_req_end.tv_sec - tv_req_begin.tv_sec ) * 1000 + (tv_req_end.tv_usec - tv_req_begin.tv_usec) / 1000; if ( n > slow_script_msec ) { strftime( time_buf, 30, "%d/%b/%Y:%H:%M:%S", localtime( &tv_req_end.tv_sec ) ); fprintf( stderr, "[%s] Slow PHP script: %d ms\n URL: %s %s\n Query String: %s\n Script: %s\n", time_buf, n, LSAPI_GetRequestMethod(), LSAPI_GetScriptName(), LSAPI_GetQueryString(), LSAPI_GetScriptFileName() ); } } LSAPI_Finish(); if ( ret ) { break; } } php_module_shutdown(); #ifdef ZTS tsrm_shutdown(); #endif return ret; }
main() { int sockfd , clisockfd; unsigned int clilen; int childpid; struct sockaddr_in serv_addr,cli_addr; #ifdef LPR_with_ASUS//JY1112 int LPRflag = 0; fd_set rfds, afds; int nfds,nfds1; int sockfd_ASUS; unsigned int clilen_ASUS; int childpid_ASUS; struct sockaddr_in serv_addr_ASUS,cli_addr_ASUS; #endif #ifdef Raw_Printing_with_ASUS //Lisa int netfd, fd, clientlen, one = 1; struct sockaddr_in netaddr, client; #endif //Initial the server the not busy lptstatus.busy = FALSE; //Setup the signal handler signal(SIGCLD, sig_child); signal(SIGINT, sig_cleanup); signal(SIGQUIT, sig_cleanup); signal(SIGKILL, sig_cleanup); signal(SIGUSR2, sig_remove);//JY1110 if((sockfd = socket(AF_INET,SOCK_STREAM,0)) < 0 ) { perror("can't open stream socket:"); exit(0); } bzero((char *)&serv_addr , sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); serv_addr.sin_port = htons(PNT_SVR_PORT_LPR); if(bind(sockfd,(struct sockaddr *)&serv_addr , sizeof(serv_addr)) < 0 ) { perror("can't bind:"); exit(0); } /*JY1111*/ int windowsize=2920; setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, (char *)&windowsize, sizeof(windowsize)); #if 1 int currentpid=getpid(); FILE *pidfileread; if((pidfileread=fopen("/var/run/lpdparent.pid", "r")) == NULL) { pidfileread=fopen("/var/run/lpdparent.pid", "w"); fprintf(pidfileread, "%d", currentpid); fclose(pidfileread); } else { printf("another lpd daemon exists!!\n"); fclose(pidfileread); exit(0); } #endif /*JY1110 int testusb = 0; testusb = check_par_usb_prn(); if(testusb){ printf("USB\n");//JY1112delete fd_print=open("/dev/usb/lp0", O_RDWR); } else{ printf("PARALLEL\n");//JY1112delete fd_print=open("/dev/lp0", O_RDWR); } checkstatus_usb_par(); close(fd_print); 111111*/ listen(sockfd , 15); #ifdef Raw_Printing_with_ASUS //Lisa if ((netfd = socket(AF_INET, SOCK_STREAM, IPPROTO_IP)) < 0) { // syslog(LOGOPTS, "socket: %m\n"); exit(1); } if (setsockopt(netfd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) < 0) { // syslog(LOGOPTS, "setsocketopt: %m\n"); exit(1); } netaddr.sin_port = htons(BASEPORT); netaddr.sin_addr.s_addr = htonl(INADDR_ANY); memset(netaddr.sin_zero, 0, sizeof(netaddr.sin_zero)); if (bind(netfd, (struct sockaddr*) &netaddr, sizeof(netaddr)) < 0) { // syslog(LOGOPTS, "bind: %m\n"); exit(1); } if (listen(netfd, 5) < 0) { // syslog(LOGOPTS, "listen: %m\n"); exit(1); } //clientlen = sizeof(client); //memset(&client, 0, sizeof(client)); #endif #ifdef LPR_with_ASUS//JY1112 if((sockfd_ASUS = socket(AF_INET,SOCK_STREAM,0)) < 0 ) { perror("can't open stream socket:"); exit(0); } bzero((char *)&serv_addr_ASUS , sizeof(serv_addr_ASUS)); serv_addr_ASUS.sin_family = AF_INET; serv_addr_ASUS.sin_addr.s_addr = htonl(INADDR_ANY); serv_addr_ASUS.sin_port = htons(PNT_SVR_PORT_ASUS); if(bind(sockfd_ASUS,(struct sockaddr *)&serv_addr_ASUS , sizeof(serv_addr_ASUS)) < 0 ) { perror("can't bind:"); exit(0); } setsockopt(sockfd_ASUS, SOL_SOCKET, SO_RCVBUF, (char *)&windowsize, sizeof(windowsize)); listen(sockfd_ASUS , 15); /*set the fds*/ nfds1=MAX(sockfd, sockfd_ASUS); #ifdef Raw_Printing_with_ASUS //Lisa nfds=MAX(nfds1, netfd); #endif FD_ZERO(&afds); #endif while(TRUE) { #ifdef Raw_Printing_with_ASUS //Lisa FD_SET(netfd, &afds); #endif #ifdef LPR_with_ASUS//JY1112 FD_SET(sockfd, &afds); FD_SET(sockfd_ASUS, &afds); int err_select;//JY1113 memcpy(&rfds, &afds, sizeof(rfds)); if((err_select=select(nfds+1, &rfds, (fd_set *)0, (fd_set *)0, (struct timeval *)0 )) < 0) { //JY1120 printf("select error on sockfd: error=%d\n", errno); /**/ // printf("sockfd_FD_ISSET=%d\n", FD_ISSET(sockfd, &rfds)); //JY1120 printf("sockfd_ASUS FD_ISSET=%d\n", FD_ISSET(sockfd_ASUS, &rfds)); /**/ // if(errno != 4)//JY1113: delete continue; } #endif clilen = sizeof(cli_addr); if (busy == FALSE) //Add by Lisa { busy = TRUE; // Add by Lisa #ifdef LPR_with_ASUS//JY1112 if(FD_ISSET(sockfd, &rfds)) { LPRflag = 1; clisockfd = accept(sockfd,(struct sockaddr *)&cli_addr, &clilen); //JY1120 printf("LPR sock received...\n");//JY1114: delete } else if(FD_ISSET(sockfd_ASUS, &rfds)) { LPRflag = 0; clisockfd = accept(sockfd_ASUS,(struct sockaddr *)&cli_addr, &clilen); //JY1120 printf("ASUSRemote port sock receved...\n");//JY1114: delete } #ifdef Raw_Printing_with_ASUS //Lisa else if(FD_ISSET(netfd, &rfds)) { LPRflag = 2; clisockfd = accept(netfd, (struct sockaddr*) &cli_addr, &clilen); printf("Raw Printing sock received...\n"); } #endif else { perror("lpr: no data received..."); continue; } #else clisockfd = accept(sockfd,(struct sockaddr *)&cli_addr, &clilen); #endif strcpy(clientaddr , inet_ntoa(cli_addr.sin_addr)); if(clisockfd < 0) { perror("accept error:"); continue; } //remark PRINT("Accept OK ,client address -- %s\n",inet_ntoa(cli_addr.sin_addr)); if( (childpid = fork() ) < 0) { perror("fork error:"); } else if(childpid == 0) { printf("child start\n"); //child process starts here //#ifdef LPR_SUPPORT //JY1120 printf("LPR process....\n"); #ifdef LPR_with_ASUS//JY1114 //JY1120 printf("lptstatus.busy=%s\n", lptstatus.busy);//JY1114 //JY1120 printf("lptstatus.pid=%d\n", lptstatus.pid);//JY1114 if(LPRflag == 1) { printf("LPRflag_remote=%d \n",LPRflag); processReq_LPR(clisockfd); } #ifdef Raw_Printing_with_ASUS //Lisa else if (LPRflag == 2) { printf("LPRflag_raw=%d \n",LPRflag); processReq_Raw(clisockfd); } #endif else #endif { printf("LPRflag_LPR=%d \n",LPRflag); processReq(clisockfd); } //#else // processReq(clisockfd); //#endif //PRINT("client exit\n"); if(LPRflag == 1) printf("LPR client exit\n");//JY1113delete else if (LPRflag == 2) printf("Raw Printing client exit\n"); else printf("ASUS Remote client exit\n");//JY1113delete // check_prn_status(ONLINE, ""); close(sockfd);// close(sockfd_ASUS);// exit(0); } //parents process goes on here //remark PRINT("fork -- childpid %d\n",childpid); if(lptstatus.busy == FALSE) { //someone is using the printer now //lptstatus.busy = TRUE; //record the infomation of the client process strcpy(lptstatus.addr , inet_ntoa(cli_addr.sin_addr)); lptstatus.pid = childpid; } } //PRINT("lptstatus.addr %s\n",lptstatus.addr); close(clisockfd); } }