[Netadm-devel] gwc/gwcklogd gwcklogd.c,1.1,1.2
Status: Beta
Brought to you by:
linuxpark
From: linuxpark <lin...@us...> - 2006-05-09 00:57:21
|
Update of /cvsroot/netadm/gwc/gwcklogd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28605/gwcklogd Modified Files: gwcklogd.c Log Message: ADD1: sysklog.ko, gwcklogd. MOD1: make deactivate gwcguid. MOD2: scripts/gwc, scripts/install.sh according to ADD1 and MOD1. FIX1: fix select maxfd from klogcmdtab[MAXSYSIDX] to klogcmdtab [MAXSYSIDX -1]. DEL1: remove debug code. ADD2: CHANGES according to ADD1, MOD1 MOD3: change syslog.conf to be able to handling gwcklogd log to local1 (gwc.log). OTHERS: comment and my email address. Index: gwcklogd.c =================================================================== RCS file: /cvsroot/netadm/gwc/gwcklogd/gwcklogd.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** gwcklogd.c 6 May 2006 15:48:47 -0000 1.1 --- gwcklogd.c 6 May 2006 17:33:33 -0000 1.2 *************** *** 41,46 **** static int terminate = 0; static int caught_TSTP = 0; - static int one_shot = 0; - static int no_fork = 0; #ifdef RUNWITH_SYSLOGD /* i dont need to run with syslogd --LP (linuxpark, Jeho Park )*/ static char log_buffer[LOG_BUFFER_SIZE]; --- 41,44 ---- *************** *** 281,285 **** closelogsrc(); ! Syslog(LOG_INFO, "Kernel log daemon terminating."); if ( output_file != (FILE *) 0 ) { --- 279,283 ---- closelogsrc(); ! Syslog(LOG_INFO, "gwcklogd: gwc Kernel log daemon terminating."); if ( output_file != (FILE *) 0 ) { *************** *** 410,416 **** fflush(output_file); - if (!one_shot) - fsync(fileno(output_file)); - return; } --- 408,411 ---- *************** *** 626,632 **** int main( int argc, char ** argv) { int ch; - int use_output = 0; char *log_level = NULL; - char *output = NULL; fd_set sock_set; struct timeval tv; --- 621,625 ---- *************** *** 642,646 **** chdir ("/"); /* Parse the command-line. */ ! while ((ch = getopt(argc, argv, "c:df:iIk:nopsvx")) != EOF) { switch((char)ch) { --- 635,639 ---- chdir ("/"); /* Parse the command-line. */ ! while ((ch = getopt(argc, argv, "c:d:iIk:psvx")) != EOF) { switch((char)ch) { *************** *** 654,662 **** break; - case 'f': /* Define an output file. */ - output = optarg; - use_output++; - break; - case 'i': /* Reload module symbols. */ signaldaemon(SIGUSR1); --- 647,650 ---- *************** *** 667,678 **** return(0); - case 'n': /* don't fork */ - no_fork++; - break; - - case 'o': /* One-shot mode. */ - one_shot = 1; - break; - case 'v': printf("gwcklogd %s.%s\n", VERSION, PATCHLEVEL); --- 655,658 ---- *************** *** 694,733 **** * The following code allows klogd to auto-background itself. */ ! if ( (!one_shot) && (!no_fork) ) { ! ! if (!check_pid(PidFile)) { ! ! if ( fork() == 0 ) { ! int fl; ! int num_fds = getdtablesize(); ! /* This is the child closing its file descriptors. */ ! for (fl= 0; fl <= num_fds; ++fl) { ! ! if ( fileno(stdout) == fl && use_output ) ! if ( strcmp(output, "stdout") == 0 ) ! continue; ! ! close(fl); ! } ! setsid(); ! ! } else { ! /* bye son */ ! exit(0); } ! ! } else { ! out ("klogd: Already running.\n"); ! exit(1); } } /* tuck my process id away */ if (!check_pid(PidFile)) { ! if (!write_pid(PidFile)) exitprog(); } else { ! out ("klogd: Already running.\n"); exitprog(); } --- 674,710 ---- * The following code allows klogd to auto-background itself. */ ! if (!check_pid(PidFile)) { ! if ( fork() == 0 ) { ! int fl; ! int num_fds = getdtablesize(); ! /* This is the child closing its file descriptors. */ ! for (fl= 2; fl <= num_fds; ++fl) { ! #if 0 ! if ( fileno(stdout) == fl && use_output ) ! if ( strcmp(output, "stdout") == 0 ) ! continue; ! #endif ! close(fl); } ! setsid(); ! ! } else { ! /* bye son */ ! exit(0); } + } else { + out ("Some other gwcklogd Already running.\n"); + exit(1); } /* tuck my process id away */ if (!check_pid(PidFile)) { ! if (!write_pid(PidFile)) { ! out ("Failed to write pid, exit ...\n"); exitprog(); + } } else { ! out ("Some other gwcklogd Already running.\n"); exitprog(); } *************** *** 745,749 **** --- 722,728 ---- signal(SIGCONT, restart); + out ("1.\n"); /* Open outputs. */ + #if 0 if ( strcmp(output, "-") == 0 ) { output_file = stdout; *************** *** 752,756 **** return 1; } ! /* Determine where kernel logging information is to come from. */ for (i = 0; i < MAXSYSIDX; i++) { --- 731,736 ---- return 1; } ! #endif ! out ("2.\n"); /* Determine where kernel logging information is to come from. */ for (i = 0; i < MAXSYSIDX; i++) { *************** *** 761,766 **** if (klogcmdtab[i].fd < 0 ) { ! out ("Failed to open fd[%d] {%s}: %s\n", ! i, klogcmdtab[i].devname, strerror(errno)); goto exit; --- 741,746 ---- if (klogcmdtab[i].fd < 0 ) { ! out ("Failed to open idx [%d] {%s}: %s\n", ! i, path, strerror(errno)); goto exit; *************** *** 774,777 **** --- 754,766 ---- } + for (i = 0; i < MAXSYSIDX; i++) { + out ("idx: %d, fd: %d, logfd: %d, devname: %s, log_file: %s\n", + klogcmdtab[i].idx, + klogcmdtab[i].fd, + klogcmdtab[i].log_fd, + klogcmdtab[i].devname, + klogcmdtab[i].log_file); + } + out ("gwcklogd: Starting ...\n"); /* The main loop. */ while (1) { *************** *** 779,793 **** FD_ZERO(&sock_set); for (i = 0; i < MAXSYSIDX; i++) { FD_SET( klogcmdtab[i].fd, &sock_set); } ! ! if ( change_state ) changelog(); ! tv.tv_sec = GWC_KLOGD_TIMEOUT * 60L; tv.tv_usec = 0; ptv = &tv; ! ret = select(klogcmdtab [MAXSYSIDX].fd + 1, &sock_set, NULL, NULL, ptv); if ((ret < 0 ) && (errno != EAGAIN)) { --- 768,788 ---- FD_ZERO(&sock_set); for (i = 0; i < MAXSYSIDX; i++) { + if (klogcmdtab[i].fd <= 0 ) + break; + FD_SET( klogcmdtab[i].fd, &sock_set); } ! #if 0 ! if ( change_state ) { ! out ("Changelog.\n"); changelog(); ! } ! #endif tv.tv_sec = GWC_KLOGD_TIMEOUT * 60L; tv.tv_usec = 0; ptv = &tv; ! out ("select ...\n"); ! ret = select(klogcmdtab [MAXSYSIDX -1 ].fd + 1, &sock_set, NULL, NULL, ptv); if ((ret < 0 ) && (errno != EAGAIN)) { *************** *** 801,809 **** } else { ! for (i = 0; i < MAXSYSIDX; i++) { if( FD_ISSET(klogcmdtab[i].fd, &sock_set) ) { ret = klogcmdtab[i].func (NULL); if (ret < 0 ) { --- 796,806 ---- } else { ! ! out ("receive kernel log\n"); for (i = 0; i < MAXSYSIDX; i++) { if( FD_ISSET(klogcmdtab[i].fd, &sock_set) ) { + out ("find idx [%d]\n", i); ret = klogcmdtab[i].func (NULL); if (ret < 0 ) { *************** *** 815,818 **** --- 812,817 ---- klogcmdtab[i].log_file ); + } else { + out ("success to handling kernel log\n"); } break; |