Esempio n. 1
0
static int generate_histdb_finalize(genhistdb_handle_type _handle)
{
	int i;
	void *par;
	int rc = -1;
	struct genhistdb_struct *handle = (struct genhistdb_struct *)_handle;
	if(!handle)
	      return -1;
	for(i = 0; i < handle->nr_threads; i++) {
		if(handle->error == 0)
			pthread_join(handle->threads[i], &par);
		list_purge(handle->per_thread_list[i]);
	}
	free(handle->per_thread_list);
	free(handle->threads);
	rc = 0;
	if(handle->error == 0) {
		if(handle->updated > 0) {
			if(write_histdb(handle->hist_list, handle->hist_len, handle->dbname)) {
				printf("Writing histdb failed\n");
				rc = -1;
			}
		} 
	} else {
		printf("There was an error. Not commiting to %s\n", handle->dbname);
		rc = -1;
	}
	if(handle->hist_list)
		free(handle->hist_list);
	pthread_mutex_destroy(&handle->hist_list_lock);
	pthread_barrier_destroy(&handle->barrier);
	free(handle);
	return rc;
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
	Node *head = NULL;
	Node *node;
	char *exts[] = {"mp3", "mp2", "ogg"};

	if(argc <= 1) {
		printf("USAGE: %s Dir\n",argv[0]);
		exit(-1);
	}

	node = head = find(head, argv[1], exts, 3);
	if(!head) {
		printf("Find failed\n");
	}

	while(node) {
		printf("%s\n", node->name);
		node = node->next;
	}

	list_purge(head);

	return 0;
	
}
Esempio n. 3
0
static int server_process(int sockfd)
{
    t_list *           serverlist_head;
    t_elem *           curr;
    t_server *         server;
    struct sockaddr_in cliaddr;
    t_psock_fd_set     rfds;
    struct timeval     tv;
    time_t             last;
    FILE *             outfile;
    psock_t_socklen    len;
    t_trackpacket      packet;
    
    if (!(serverlist_head = list_create()))
    {
	eventlog(eventlog_level_error,"server_process","could not create server list");
	return -1;
    }
    
    /* the main loop */
    last = time(NULL) - prefs.update;
    for (;;)
    {
	list_purge(serverlist_head);
	
	/* time to dump our list to disk and call the process command */
	/* (I'm making the assumption that this won't take very long.) */
	if (last+prefs.update<time(NULL))
	{
	    last = time(NULL);
	    
	    if (!(outfile = fopen(prefs.outfile,"w")))
	    {
		eventlog(eventlog_level_error,"server_process","unable to open file \"%s\" for writing (fopen: %s)",prefs.outfile,strerror(errno));
		continue;
	    }
	    
	    LIST_TRAVERSE(serverlist_head,curr)
	    {
		server = elem_get_data(curr);
		
		if (server->updated+prefs.expire<last)
		{
		    list_remove_elem(serverlist_head,curr);
		    free(server);
		}
		else
		{
		    fprintf(outfile,"%s\n##\n",inet_ntoa(server->address));
		    fprintf(outfile,"%hu\n##\n",(unsigned short)ntohs(server->info.port));
		    fprintf(outfile,"%s\n##\n",server->info.server_location);
		    fprintf(outfile,"%s\n##\n",server->info.software);
		    fprintf(outfile,"%s\n##\n",server->info.version);
		    fprintf(outfile,"%lu\n##\n",(unsigned long)ntohl(server->info.users));
		    fprintf(outfile,"%lu\n##\n",(unsigned long)ntohl(server->info.channels));
		    fprintf(outfile,"%lu\n##\n",(unsigned long)ntohl(server->info.games));
		    fprintf(outfile,"%s\n##\n",server->info.server_desc);
		    fprintf(outfile,"%s\n##\n",server->info.platform);
		    fprintf(outfile,"%s\n##\n",server->info.server_url);
		    fprintf(outfile,"%s\n##\n",server->info.contact_name);
		    fprintf(outfile,"%s\n##\n",server->info.contact_email);
		    fprintf(outfile,"%lu\n##\n",(unsigned long)ntohl(server->info.uptime));
		    fprintf(outfile,"%lu\n##\n",(unsigned long)ntohl(server->info.total_games));
		    fprintf(outfile,"%lu\n##\n",(unsigned long)ntohl(server->info.total_logins));
		    fprintf(outfile,"###\n");
		}
	    }
            if (fclose(outfile)<0)
                eventlog(eventlog_level_error,"main","could not close output file \"%s\" after writing (fclose: %s)",prefs.outfile,strerror(errno));
	    
	    if (prefs.process[0]!='\0')
		system(prefs.process);
	}