Exemplo n.º 1
0
static void do_signalled(void) {
  sigprocmask(SIG_SETMASK, &ssblock, NULL);
  if (signalled & SIGNALLED_TERM) {
    if (fork_on_reload < 0) { /* this is a temp child; dump stats and exit */
      ipc_write_stats(1);
      if (flog && !flushlog)
        fflush(flog);
      _exit(0);
    }
    dslog(LOG_INFO, 0, "terminating");
#ifndef NO_STATS
    if (statsfile)
      dumpstats();
    logstats(0);
    if (statsfile)
      dumpstats_z();
#endif
    exit(0);
  }
#ifndef NO_STATS
  if (signalled & SIGNALLED_SSTATS && statsfile)
    dumpstats();
  if (signalled & SIGNALLED_LSTATS) {
    logstats(signalled & SIGNALLED_ZSTATS);
    if (signalled & SIGNALLED_ZSTATS && statsfile)
      dumpstats_z();
  }
#endif
  if (signalled & SIGNALLED_RELOG)
    reopenlog();
  if (signalled & SIGNALLED_RELOAD)
    do_reload(fork_on_reload);
  signalled = 0;
  sigprocmask(SIG_SETMASK, &ssempty, NULL);
}
Exemplo n.º 2
0
static void
shut_down( void )
    {
    int cnum;
    struct timeval tv;

    (void) gettimeofday( &tv, (struct timezone*) 0 );
    logstats( &tv );
    for ( cnum = 0; cnum < maxconnects; ++cnum )
	{
	if ( connects[cnum].conn_state != CNST_FREE )
	    httpd_close_conn( connects[cnum].hc, &tv );
	if ( connects[cnum].hc != (httpd_conn*) 0 )
	    {
	    httpd_destroy_conn( connects[cnum].hc );
	    free( (void*) connects[cnum].hc );
	    --httpd_conn_count;
	    connects[cnum].hc = (httpd_conn*) 0;
	    }
	}
    if ( hs != (httpd_server*) 0 )
	{
	httpd_server* ths = hs;
	hs = (httpd_server*) 0;
	httpd_terminate( ths );
	}
    mmc_destroy();
    tmr_destroy();
    free( (void*) connects );
    if ( throttles != (throttletab*) 0 )
	free( (void*) throttles );
    }
Exemplo n.º 3
0
int main(){

//logopen("loggertest.log");
logdup(1);

logtrace("%s", "Hello, LOG!!!!Hello, LOG!!!!Hello, LOG!!!!Hello, LOG!!!!Hello, LOG!!!!Hello, LOG!!!!Hello, LOG!!!!Hello, LOG!!!!Hello, LOG!!!!");
logerror("%s", "Hello, LOG!!!!");
logstats("%s", "Hello, LOG!!!!");

LOG("%s", "How about this macro?");

logclose();

return 0; }
Exemplo n.º 4
0
void tftp_server( void ) {
	int		cc;
	struct timeval	*tvp;
	time_t		last, hour6, min1;
	socklen_t	fromlen;
	struct sockaddr_in	from;
	struct timeval	tv;
	struct stat	tftp_stat;
	struct passwd	*pass_struct;
	char		*euid_pref, *tftp_dir, *dbhost_pref, *force_chroot;
	char		*tftp_high_load_c;
	int		tftp_high_load;
	fd_set		rfds;
	char		buf[SEGSIZE + 4];

	tftp_dir = my_GetTFTPdir();
	if ( stat( tftp_dir, &tftp_stat ) != 0 ) {
		fprintf(stderr,"Could not read tftp dir: %s", tftp_dir );
		exit(1);
	}
	chdir( tftp_dir );

	Init_TFTP_Socket();

	dbhost_pref = GetConfigVar( "mysql-host" );
	euid_pref = GetConfigVar( "effective-userid" );
	force_chroot = GetConfigVar( "force-localhost-chroot" );
	pass_struct = getpwnam( euid_pref );

	//if (strcmp(dbhost_pref,"localhost") || !strcmp(force_chroot, "yes")) {
		// We cannot chroot if connect to the DB via
		// a unix socket vs tcp
	//	chroot( tftp_dir );
	//}
	//if (pass_struct) {
	//	seteuid( pass_struct->pw_uid );
	//	setegid( pass_struct->pw_gid );
	//}

	tftp_high_load_c = GetConfigVar( "tftp-high-load" );
	if (*tftp_high_load_c == ' ') { tftp_high_load_c = "16"; }
	tftp_high_load = strtoul( tftp_high_load_c, NULL, 10 );
	if (tftp_high_load <= 4) { tftp_high_load = 4; }
	if (tftp_high_load >= 512) { tftp_high_load = 512; }
	my_Check_Load( tftp_high_load );

	InitSQLconnection();

	my_syslog( MLOG_TFTP, "docsis_server TFTP Version %s activated", VERSION );
	Clear_Remote_Commands();

	last = 0;
	hour6 = time(NULL);
	min1 = hour6;
	/* my_syslog( MLOG_TFTP, "tftp max num files %d", getdtablesize()); */

	while (tftpd_exit_flag) {
		// Update the PID file
		update_pid_file();

		FD_ZERO( &rfds );
		FD_SET( tftp_socket, &rfds );
		tv.tv_sec = 1;
		tv.tv_usec = 0;
		tvp = &tv;

		if (select(tftp_socket + 1, &rfds, NULL, NULL, &tv ) < 0) {
			/* Don't choke when we get ptraced */
			if (errno == EINTR) continue;
			my_syslog( MLOG_ERROR, "tftp select: %s", strerror(errno) );
			exit(1);
		}


		if (FD_ISSET( tftp_socket, &rfds ) ) {
			/* Process a packet */
			fromlen = sizeof(from);
			cc = recvfrom(tftp_socket, buf, sizeof(buf), 0,
			    (struct sockaddr *)&from, &fromlen);
			if (cc < 0) {
				my_syslog( MLOG_ERROR, "tftp recvfrom: %s", strerror(errno) );
				continue;
			}

			/* Update now */
			now = time(NULL);

			/* Process this packet */
			process(&from, (struct tftphdr *)buf, cc);
			my_Check_Load( tftp_high_load );
		} else {
			now = time(NULL);
		}

		/* Run the timer list, no more than once a second */
		if (clientlistcnt > 0) {
			if (last != now) {
				last = now;
				runtimer();
			}
		}

		if ( (now - min1) >= 120) {
			min1 = now;
			free_file_cache();

			// ping the MySQL server
			my_SQL_Ping();
		}

		/* run the log stats 4 times a day */
		if ( (now - hour6) >= 21600) {
			hour6 = now;
			logstats();
		}
		Check_Remote_Commands();
	}
}
Exemplo n.º 5
0
int main(int argc, char *argv[]) {

    if ( argc != 3 ) {
        fprintf( stderr, "%s version %s\n", argv[0], LINUX_FTOOLS_VERSION );
        fprintf( stderr, "SYNTAX: fallocate file length\n" );
        exit(1);
    }

    char* path = argv[1];

    printf( "Going to fallocate %s\n", path );

    int flags = O_RDWR;
    int fd = open( path, flags );

    if ( fd == -1 ) {
        perror( "Unable to open file" );
        exit(1);
    }

    logstats(fd);

    loff_t len = atol( argv[2] );

    printf( "Increasing file to: %ld\n", len );

    if ( len <= 0 ) {
        fprintf( stderr, "Unable to allocate size %ld\n", len );
        exit( 1 );
    }

    loff_t offset = 0;

    //TODO: make this a command line option.
    int mode = FALLOC_FL_KEEP_SIZE;

    long result = posix_fallocate( fd, mode, offset, len );

    if ( result != 0 ) {

        //TODO: rework this error handling
        if ( result != -1 ) {
            errno=result;
            perror( "Unable to fallocate" );
            exit( 1 );
        } else {
            char buff[100];
            sprintf( buff, "Unable to fallocate: %ld" , result );
            perror( buff );
            exit( 1 );
        }

        return 1;
    }

    logstats(fd);

    close( fd );
    return 0;

}
Exemplo n.º 6
0
static void
handle_usr2( int sig )
    {
    logstats( (struct timeval*) 0 );
    }
Exemplo n.º 7
0
static void
show_stats( ClientData client_data, struct timeval* nowP )
    {
    logstats( nowP );
    }