Beispiel #1
0
/* Cluster logging function */
void
cl_direct_log(int priority, const char* buf, gboolean use_priority_str,
	      const char* entity, int entity_pid, TIME_T ts)
{
	const char *	pristr;
	int	needprivs = !cl_have_full_privs();

	if (entity == NULL){
		entity =cl_log_entity;
	}
	
	pristr = use_priority_str ? prio2str(priority) : NULL;

	if (needprivs) {
		return_to_orig_privs();
	}
	
	if (syslog_enabled) {
		if (entity) {
			strncpy(common_log_entity, entity, MAXENTITY);
		} else {
			strncpy(common_log_entity, DFLT_ENTITY,MAXENTITY);
		}

		common_log_entity[MAXENTITY-1] = '\0';

		if (pristr) {
			syslog(priority, "[%d]: %s: %s%c",
			       entity_pid, pristr,  buf, 0);
		}else {
			syslog(priority, "[%d]: %s%c", entity_pid, buf, 0);
		}
	}

	if (debugfile_name != NULL) {
		append_log(debugfile_name,entity,entity_pid,ts,pristr,buf);
	}

	if (priority != LOG_DEBUG && logfile_name != NULL) {
		append_log(logfile_name,entity,entity_pid,ts,pristr,buf);
	}

	if (needprivs) {
		return_to_dropped_privs();
	}
	
	return;
}
int log_cgi(HttpState *state)
{
   auto int x;
   static far char buffer[512];
   auto int my_xpc;
   auto struct tm time;
   auto sockaddr sock_addr;

   #GLOBAL_INIT { count = 0; }

   _f_memset(buffer, 0, sizeof buffer);

   x = sizeof sock_addr;
   getpeername((sock_type *) &state->s, &sock_addr, &x);

   tm_rd(&time);
   sprintf(buffer, "%02d/%02d/%04d %02d:%02d:%02d - %d.%d.%d.%d<br>",
           tm_mon2month(time.tm_mon),
           time.tm_mday,
           time.tm_year + 1900,
           time.tm_hour,
           time.tm_min,
           time.tm_sec,
           *(((char *) &sock_addr.s_ip) + 3),
           *(((char *) &sock_addr.s_ip) + 2),
           *(((char *) &sock_addr.s_ip) + 1),
           *(((char *) &sock_addr.s_ip) + 0));

   x = append_log(buffer);
   ++count;
   return 1;
}
Beispiel #3
0
int log_cgi(HttpState* state)
{
	int x;
	char buffer[512];
	int my_xpc;
	struct tm time;
	sockaddr sock_addr;

	#GLOBAL_INIT {	count=0;	}

	memset(buffer,0,sizeof(buffer));

	x=sizeof(sock_addr);
	getpeername((sock_type*)&state->s,&sock_addr,&x);

	tm_rd(&time);
	sprintf(buffer, "%02d/%02d/%04d %02d:%02d:%02d - %d.%d.%d.%d<br>",
		time.tm_mon,
		time.tm_mday,
		time.tm_year+1900,
		time.tm_hour,
		time.tm_min,
		time.tm_sec,
		*(((char*)&sock_addr.s_ip)+3),
		*(((char*)&sock_addr.s_ip)+2),
		*(((char*)&sock_addr.s_ip)+1),
		*(((char*)&sock_addr.s_ip)+0));

	x = append_log(buffer);

	count++;

   return 1;
}
Beispiel #4
0
void runcmd(char *command){
	if (command /*&& !fork()*/) {
		FILE *forkd = popen(command, "r");
		if (forkd) {
			char line[128] = {0}; // f**k you and your long lines
			if (fgets(line, 128, forkd)) {
				append_log(line); // dont worry, it is memcpyd
			}
			fclose(forkd);
		}
//		exit(0);
	}
}
Beispiel #5
0
static void
process_rules(char *line)
{
	time_t tstamp;
	ListItem *item;
	struct pattern_rule *rule;
	regmatch_t parens[REGEX_PARENS_SIZE];
	long month, day, hour, minute, second;

	(void) convertSyslog(line, &month, &day, &hour, &minute, &second, NULL);
	convertToGmt(assumed_year, month, day, hour, minute, second, assumed_tz, &tstamp);

	for (item = pattern_rules.head; item != NULL; item = item->next) {
		rule = item->data;
		if (regexec(&rule->re, line, REGEX_PARENS_SIZE, parens, 0) == 0) {
			(void) append_log(line, rule, parens, tstamp);
			if (rule->limits[0] != NULL)
				check_limits(line, rule, parens, tstamp);
			if (first_match_only)
				break;
		}
	}
}
Beispiel #6
0
/*
 * This handles the game for each client.
 */
void *game_runner(void *client_data_pointer)
{
    /* Get client and details */
    client_nfo client = *(client_nfo*)client_data_pointer;
    int socket_id = client.socket_id;

    int status = 1, client_status = 1, move = 0, ai_move = 0, read_size;
    uint32_t move_nbo, ai_move_nbo;
    c4_t board;

    /* To ensure memory is freed at the end */
    pthread_detach(pthread_self());
    
    /* Set-up the game */
    srand(time(NULL));
    init_empty(board, NO_PRINT);

    /* log that client is connected */
    append_log(STATUS_CONNECTED, 0, &client, STATUS_CONNECTED, 0);

    /* Receive move from client */
    while((read_size = recv(socket_id, &move_nbo, sizeof(uint32_t), 0)) > 0)
    {
        if(status < 0) break;
        
        /* Get move from (client move in network byte order)*/
        move = ntohl(move_nbo);

        /* Make client move */
        status = human_play(board, move, NO_PRINT);
        client_status = status; /* needed for log */

        /* Make AI move if game is not over */
        if(status > 0)
        {
            ai_move = suggest_move(board, RED);
            status = ai_play(board, ai_move, NO_PRINT);
        }
        /* log the moves */
        append_log(status, ai_move, &client, client_status, move);

        /* If game is over, the old ai_move will be sent
           to client again but game will be terminated just after the
           client move is made in client program, so the ai move
           won't be made
        */

        /* Send the AI move to client */
        ai_move_nbo = htonl(ai_move);
        if(send(socket_id, &ai_move_nbo, sizeof(uint32_t), 0) < 0)
        {
            perror("send error");
            break;
        }
    }

    if(read_size == 0) {
        /* Client has been disconnected from server */
        if (status > 0) status = STATUS_ABNORMAL;
    }
    else if(read_size == -1)
    { 
        perror("recv error");
        if (status > 0) status = STATUS_ABNORMAL;
    }
    /* log any abnormal end of game */
    if(status == STATUS_ABNORMAL)
        append_log(STATUS_ABNORMAL, 0, &client, STATUS_ABNORMAL, 0);
    
    free(client_data_pointer);
    return 0;
}