Exemple #1
0
void
skPDUSourceDestroy(
    skPDUSource_t      *source)
{
    RBLIST *iter;
    pdu_engine_info_t *engine_info;

    if (!source) {
        return;
    }
    if (!source->stopped) {
        skPDUSourceStop(source);
    }
    skUDPSourceDestroy(source->source);
    pthread_mutex_destroy(&source->stats_mutex);
    iter = rbopenlist(source->engine_info_tree);
    if (iter != NULL) {
        while ((engine_info = (pdu_engine_info_t *)rbreadlist(iter))) {
            free(engine_info);
        }
        rbcloselist(iter);
    }
    rbdestroy(source->engine_info_tree);
    free(source);
}
Exemple #2
0
static void RB_Purge (const struct rbtree *r)
{
	RBLIST *rblist;
	const void *val;
	void *data;
	void *ptr;

	if ((rblist=rbopenlist(rb)) != NULL)
	{
		while((val=rbreadlist(rblist)) != NULL)
		{
			data = rbfind (val, rb);
			ptr = *(void **)data;
			rbdelete (val, rb);

			if (ptr)
				Z_Free (ptr);
		}
	}

	rbcloselist(rblist);
	rbdestroy (rb);

	FS_InitCache();
}
Exemple #3
0
/*
 *  appTeardown()
 *
 *    Teardown all modules, close all files, and tidy up all
 *    application state.
 *
 *    This function is idempotent.
 */
static void
appTeardown(
    void)
{
    static int teardownFlag = 0;
    RBLIST *iter;
    transfer_t *sndr;

    if (teardownFlag) {
        return;
    }
    teardownFlag = 1;

    if (!daemonized) {
        rbdestroy(transfers);
        skDLListDestroy(duplicate_dirs);
        skDLListDestroy(open_file_list);
        skdaemonTeardown();
        skAppUnregister();
        return;
    }

    NOTICEMSG("Begin shutting down...");

    shuttingdown = 1;

    transferShutdown();
    transferTeardown();

    /* Destroy stuff */
    iter = rbopenlist(transfers);
    CHECK_ALLOC(iter);
    while ((sndr = (transfer_t *)rbreadlist(iter)) != NULL) {
        if (sndr->ident != NULL) {
            free(sndr->ident);
        }
        if (sndr->addr) {
            skSockaddrArrayDestroy(sndr->addr);
        }
        free(sndr);
    }
    rbcloselist(iter);
    rbdestroy(transfers);

    skDLListDestroy(duplicate_dirs);
    skDLListDestroy(open_file_list);

    NOTICEMSG("Finished shutting down.");

    skdaemonTeardown();
    skthread_teardown();
    skAppUnregister();
}
Exemple #4
0
void
upnp_entry_free (struct ushare_t *ut, struct upnp_entry_t *entry)
{
  if (!ut || !entry)
    return;

  /* Free all entries (i.e. children) */
  if (entry == ut->root_entry)
  {
    struct upnp_entry_t *entry_found = NULL;
    struct upnp_entry_lookup_t *lk = NULL;
    RBLIST *rblist;
    int i = 0;

    rblist = rbopenlist (ut->rb);
    lk = (struct upnp_entry_lookup_t *) rbreadlist (rblist);

    while (lk)
    {
      entry_found = lk->entry_ptr;
      if (entry_found)
      {
 	if (entry_found->fullpath)
 	  free (entry_found->fullpath);
 	if (entry_found->title)
 	  free (entry_found->title);
 	if (entry_found->url)
 	  free (entry_found->url);

	free (entry_found);
 	i++;
      }

      free (lk); /* delete the lookup */
      lk = (struct upnp_entry_lookup_t *) rbreadlist (rblist);
    }

    rbcloselist (rblist);
    rbdestroy (ut->rb);
    ut->rb = NULL;

    log_verbose ("Freed [%d] entries\n", i);
  }
  else
    _upnp_entry_free (entry);

  free (entry);
}
Exemple #5
0
int main()
{
	int i, *ptr;
	const void *val;
	struct rbtree *rb;
	RBLIST *rblist;

	if ((rb=rbinit(compare, NULL))==NULL)
	{
		fprintf(stderr, "insufficient memory from rbinit()\n");
		exit(1);
	}

	for (i = 200; i > 0; i--)
	{
		ptr = (int *)xmalloc(sizeof(int));
		*ptr = i;
		val = rbsearch((void *)ptr, rb);
		if(val == NULL)
		{
			fprintf(stderr, "insufficient memory from rbsearch()\n");
			exit(1);
		}
	}

	if ((rblist=rbopenlist(rb))==NULL)
	{
		fprintf(stderr, "insufficient memory from rbopenlist()\n");
		exit(1);
	}

	while((val=rbreadlist(rblist)))
	{
		printf("%6d\n", *(int *)val);
	}

	rbcloselist(rblist);

	rbdestroy(rb);
	
	return 0;
}
Exemple #6
0
int_dict_iter_t *
int_dict_open(
    int_dict_t         *dict)
{
    int_dict_iter_t *iter;

    assert(dict);

    iter = (int_dict_iter_t*)malloc(sizeof(int_dict_iter_t));
    if (iter == NULL) {
        return NULL;
    }
    iter->dict = dict;
    READ_LOCK(&dict->mutex);
    iter->list = rbopenlist(dict->tree);
    RW_MUTEX_UNLOCK(&dict->mutex);
    if (iter->list == NULL) {
        free(iter);
        return NULL;
    }
    return iter;
}
Exemple #7
0
int print_info() {
        unsigned int num_watches = 0;
        num_watches = inotifytools_get_num_watches();

	if ( !inotifytools_get_stat_total( 0 ) ) {
		fprintf( stderr, "No events occurred.\n" );
		return EXIT_SUCCESS;
	}

	// OK, go through the watches and print stats.
	printf("total  ");
	if ( (IN_ACCESS & events) &&
	     ( zero || inotifytools_get_stat_total( IN_ACCESS ) ) )
		printf("access  ");
	if ( ( IN_MODIFY & events) &&
	     ( zero || inotifytools_get_stat_total( IN_MODIFY ) ) )
		printf("modify  ");
	if ( ( IN_ATTRIB & events) &&
	     ( zero || inotifytools_get_stat_total( IN_ATTRIB ) ) )
		printf("attrib  ");
	if ( ( IN_CLOSE_WRITE & events) &&
	     ( zero || inotifytools_get_stat_total( IN_CLOSE_WRITE ) ) )
		printf("close_write  ");
	if ( ( IN_CLOSE_NOWRITE & events) &&
	     ( zero || inotifytools_get_stat_total( IN_CLOSE_NOWRITE ) ) )
		printf("close_nowrite  ");
	if ( ( IN_OPEN & events) &&
	     ( zero || inotifytools_get_stat_total( IN_OPEN ) ) )
		printf("open  ");
	if ( ( IN_MOVED_FROM & events) &&
	     ( zero || inotifytools_get_stat_total( IN_MOVED_FROM ) ) )
		printf("moved_from  ");
	if ( ( IN_MOVED_TO & events) &&
	     ( zero || inotifytools_get_stat_total( IN_MOVED_TO ) ) )
		printf("moved_to  ");
	if ( ( IN_MOVE_SELF & events) &&
	     ( zero || inotifytools_get_stat_total( IN_MOVE_SELF ) ) )
		printf("move_self  ");
	if ( ( IN_CREATE & events) &&
	     ( zero || inotifytools_get_stat_total( IN_CREATE ) ) )
		printf("create  ");
	if ( ( IN_DELETE & events) &&
	     ( zero || inotifytools_get_stat_total( IN_DELETE ) ) )
		printf("delete  ");
	if ( ( IN_DELETE_SELF & events) &&
	     ( zero || inotifytools_get_stat_total( IN_DELETE_SELF ) ) )
		printf("delete_self  ");
	if ( ( IN_UNMOUNT & events) &&
	     ( zero || inotifytools_get_stat_total( IN_UNMOUNT ) ) )
		printf("unmount  ");

	printf("filename\n");

	struct rbtree *tree = inotifytools_wd_sorted_by_event(sort);
	RBLIST *rblist = rbopenlist(tree);
	watch *w = (watch*)rbreadlist(rblist);

	while (w) {
		if ( !zero && !w->hit_total ) {
			w = (watch*)rbreadlist(rblist);
			continue;
		}
		printf("%-5u  ", w->hit_total );
		if ( ( IN_ACCESS & events) &&
		     ( zero || inotifytools_get_stat_total( IN_ACCESS ) ) )
			printf("%-6u  ", w->hit_access );
		if ( ( IN_MODIFY & events) &&
		     ( zero || inotifytools_get_stat_total( IN_MODIFY ) ) )
			printf("%-6u  ", w->hit_modify );
		if ( ( IN_ATTRIB & events) &&
		     ( zero || inotifytools_get_stat_total( IN_ATTRIB ) ) )
			printf("%-6u  ", w->hit_attrib );
		if ( ( IN_CLOSE_WRITE & events) &&
		     ( zero || inotifytools_get_stat_total( IN_CLOSE_WRITE ) ) )
			printf("%-11u  ",w->hit_close_write );
		if ( ( IN_CLOSE_NOWRITE & events) &&
		     ( zero || inotifytools_get_stat_total( IN_CLOSE_NOWRITE ) ) )
			printf("%-13u  ",w->hit_close_nowrite );
		if ( ( IN_OPEN & events) &&
		     ( zero || inotifytools_get_stat_total( IN_OPEN ) ) )
			printf("%-4u  ", w->hit_open );
		if ( ( IN_MOVED_FROM & events) &&
		     ( zero || inotifytools_get_stat_total( IN_MOVED_FROM ) ) )
			printf("%-10u  ", w->hit_moved_from );
		if ( ( IN_MOVED_TO & events) &&
		     ( zero || inotifytools_get_stat_total( IN_MOVED_TO ) ) )
			printf("%-8u  ", w->hit_moved_to );
		if ( ( IN_MOVE_SELF & events) &&
		     ( zero || inotifytools_get_stat_total( IN_MOVE_SELF ) ) )
			printf("%-9u  ", w->hit_move_self );
		if ( ( IN_CREATE & events) &&
		     ( zero || inotifytools_get_stat_total( IN_CREATE ) ) )
			printf("%-6u  ", w->hit_create );
		if ( ( IN_DELETE & events) &&
		     ( zero || inotifytools_get_stat_total( IN_DELETE ) ) )
			printf("%-6u  ", w->hit_delete );
		if ( ( IN_DELETE_SELF & events) &&
		     ( zero || inotifytools_get_stat_total( IN_DELETE_SELF ) ) )
			printf("%-11u  ",w->hit_delete_self );
		if ( ( IN_UNMOUNT & events) &&
		     ( zero || inotifytools_get_stat_total( IN_UNMOUNT ) ) )
			printf("%-7u  ", w->hit_unmount );

		printf("%s\n", w->filename );
		w = (watch*)rbreadlist(rblist);
	}
	rbcloselist(rblist);
	rbdestroy(tree);

	return EXIT_SUCCESS;
}