Ejemplo n.º 1
0
void unregister_net_interface(net_interface_t *interface) {
    uint32_t flags;
    spin_lock_irqsave(&interface_lock, &flags);

    list_rm(&interface->list);

    spin_unlock_irqstore(&interface_lock, flags);
}
Ejemplo n.º 2
0
void multirom_ui_tab_rom_set_empty(void *data, int empty)
{
    assert(empty == 0 || empty == 1);

    tab_data_roms *t = (tab_data_roms*)data;
    int width = cur_theme->get_tab_width(themes_info->data);

    static const char *str[] = { "Select ROM to boot:", "No ROMs in this location!" };
    t->title_text->head.x = center_x(t->list->x, width, SIZE_BIG, str[empty]);
    t->title_text->text = realloc(t->title_text->text, strlen(str[empty])+1);
    strcpy(t->title_text->text, str[empty]);

    if(t->boot_btn)
        button_enable(t->boot_btn, !empty);

    if(empty && !t->usb_text)
    {
        const int line_len = 37;
        static const char *txt = "This list is refreshed automagically,\njust plug in the USB drive and  wait.";
        int x = t->list->x + (width/2 - (line_len*ISO_CHAR_WIDTH*SIZE_NORMAL)/2);
        int y = center_y(t->list->y, t->list->h, SIZE_NORMAL);
        t->usb_text = fb_add_text(x, y, WHITE, SIZE_NORMAL, txt);
        list_add(t->usb_text, &t->ui_elements);

        x = t->list->x + ((width/2) - (PROGDOTS_W/2));
        t->usb_prog = progdots_create(x, y+100*DPI_MUL);
    }
    else if(!empty && t->usb_text)
    {
        progdots_destroy(t->usb_prog);
        t->usb_prog = NULL;

        list_rm(t->usb_text, &t->ui_elements, &fb_remove_item);
        t->usb_text = NULL;
    }
}
Ejemplo n.º 3
0
int main(void)
{
    List *l1 = list_prepend(NULL, "one");
    if (l1 == NULL ||
        l1->next != NULL ||
        l1->prev != NULL ||
        str_cmp(l1->elem, "one") != 0)
        fail();

    List *l2 = list_prepend(l1, "two");
    if (l1->prev != l2)
        fail();

    if (l2 == NULL ||
        l2->next != l1 ||
        l2->prev != NULL ||
        str_cmp(l2->elem, "two") != 0)
        fail();

    List *l3 = list_prepend(l2, "three");
    if (l2->prev != l3)
        fail();

    if (l3 == NULL ||
        l3->next != l2 ||
        l3->prev != NULL ||
        str_cmp(l3->elem, "three") != 0)
        fail();

    List *x = list_next(l2);
    if (x != l1 ||
        x->next != NULL ||
        x->prev != l3 ||
        str_cmp(x->elem, "one") != 0)
        fail();

    l2 = list_prepend(x, "++two++");
    if (l2 == NULL ||
        l2->prev != l3 ||
        l2->prev->next != l2 ||
        l2->next != l1 ||
        l2->next->prev != l2 ||
        str_cmp(l2->elem, "++two++"))
        fail();

    List *y = list_prev(l2);
    if (y != l3 ||
        y->next != l1 ||
        y->next->prev != l3 ||
        y->prev != NULL ||
        str_cmp(y->elem, "three"))
        fail();

    l2 = list_prepend(x, "--two--");
    if (l2 == NULL ||
        l2->prev != l3 ||
        l2->prev->next != l2 ||
        l2->next != l1 ||
        l2->next->prev != l2 ||
        str_cmp(l2->elem, "--two--"))
        fail();

    List *h1 = list_rm(l3, "--two--", rm_given);
    if (h1 != l3 ||
        h1->next != l1 ||
        h1->next->prev != l3 ||
        h1->prev != NULL ||
        str_cmp(h1->elem, "three") != 0 ||
        str_cmp(h1->next->elem, "one") != 0)
        fail();

    List *h2 = list_rm(l3, NULL, rm_none);
    if (h1 != l3 ||
        h1->next != l1 ||
        h1->next->prev != l3 ||
        h1->prev != NULL ||
        str_cmp(h1->elem, "three") != 0 ||
        str_cmp(h1->next->elem, "one") != 0)
        fail();

    List *h3 = list_rm(l3, NULL, rm_all);
    if (h3 != NULL)
        fail();

    return 0;
}
Ejemplo n.º 4
0
/**
 * Main daemon routine
 */
int main( int argc, char **argv )
{
    int            c, option_index = 0;
    char          *bin = basename( argv[0] );

    char           config_file[MAX_OPT_LEN] = "";

    enum { ACTION_NONE, ACTION_LIST, ACTION_RESTORE } action = ACTION_NONE;
    int            force_log_level = FALSE;
    int            log_level = 0;

    int            rc;
    char           err_msg[4096];
    robinhood_config_t config;
    int chgd = 0;
    char    badcfg[RBH_PATH_MAX];

    /* parse command line options */
    while ( ( c = getopt_long( argc, argv, SHORT_OPT_STRING, option_tab,
                               &option_index ) ) != -1 )
    {
        switch ( c )
        {
        case 'L':
            if ( (action != ACTION_NONE) && (action != ACTION_LIST) )
                fprintf( stderr, "WARNING: only a single action (--list or --restore) is expected\n"
                                 "on command line. '--restore' will be ignored.\n" );
            action = ACTION_LIST;
            break;
        case 'R':
            if ( (action != ACTION_NONE) && (action != ACTION_RESTORE) )
                fprintf( stderr, "WARNING: only a single action (--list or --restore) is expected\n"
                                 "on command line. '--list' will be ignored.\n" );
            action = ACTION_RESTORE;
            break;
        case 'f':
            strncpy( config_file, optarg, MAX_OPT_LEN );
            break;
        case 'l':
            force_log_level = TRUE;
            log_level = str2debuglevel( optarg );
            if ( log_level == -1 )
            {
                fprintf( stderr,
                         "Unsupported log level '%s'. CRIT, MAJOR, EVENT, VERB, DEBUG or FULL expected.\n",
                         optarg );
                exit( 1 );
            }
            break;
        case 'h':
            display_help( bin );
            exit( 0 );
            break;
        case 'V':
            display_version( bin );
            exit( 0 );
            break;
        case ':':
        case '?':
        default:
            display_help( bin );
            exit( 1 );
            break;
        }
    }

    /* 1 expected argument: path */
    if ( optind != argc - 1 )
    {
        fprintf( stderr, "Error: missing mandatory argument on command line: <path|fid>\n" );
        exit( 1 );
    }
    strncpy( path_filter, argv[optind], RBH_PATH_MAX );

    /* get default config file, if not specified */
    if ( SearchConfig( config_file, config_file, &chgd, badcfg ) != 0 )
    {
        fprintf(stderr, "No config file found matching %s\n", badcfg);
        exit(2);
    }
    else if (chgd)
    {
        fprintf(stderr, "Using config file '%s'.\n", config_file );
    }

    /* only read ListMgr config */
    if ( ReadRobinhoodConfig( 0, config_file, err_msg, &config, FALSE ) )
    {
        fprintf( stderr, "Error reading configuration file '%s': %s\n", config_file, err_msg );
        exit( 1 );
    }
    process_config_file = config_file;

    /* set global configuration */
    global_config = config.global_config;

    /* set policies info */
    policies = config.policies;

    if ( force_log_level )
        config.log_config.debug_level = log_level;

    /* XXX HOOK: Set logging to stderr */
    strcpy( config.log_config.log_file, "stderr" );
    strcpy( config.log_config.report_file, "stderr" );
    strcpy( config.log_config.alert_file, "stderr" );

    /* Initialize logging */
    rc = InitializeLogs( bin, &config.log_config );
    if ( rc )
    {
        fprintf( stderr, "Error opening log files: rc=%d, errno=%d: %s\n",
                 rc, errno, strerror( errno ) );
        exit( rc );
    }

    /* Initialize Filesystem access */
    rc = InitFS();
    if (rc)
        exit(rc);

    /* Initialize list manager */
    rc = ListMgr_Init( &config.lmgr_config, FALSE );
    if ( rc )
    {
        DisplayLog( LVL_CRIT, LOGTAG, "Error %d initializing list manager", rc );
        exit( rc );
    }
    else
        DisplayLog( LVL_DEBUG, LOGTAG, "ListManager successfully initialized" );

    if ( CheckLastFS(  ) != 0 )
        exit( 1 );

    /* Create database access */
    rc = ListMgr_InitAccess( &lmgr );
    if ( rc )
    {
        DisplayLog( LVL_CRIT, LOGTAG, "Error %d: cannot connect to database", rc );
        exit( rc );
    }

#ifdef _HSM_LITE
    rc = Backend_Start( &config.backend_config, 0 );
    if ( rc )
    {
        DisplayLog( LVL_CRIT, LOGTAG, "Error initializing backend" );
        exit( 1 );
    }
#endif

    /* perform the action */
    switch( action )
    {
        case ACTION_LIST:
            rc= list_rm();
            break;
        case ACTION_RESTORE:
            rc = undo_rm();
            break;
        case ACTION_NONE:
            display_help( bin );
            rc = 1;
            break;
        default:
            fprintf(stderr, "Unexpected action (action code=%#x)\n", action );
            display_help( bin );
            rc = EINVAL;
            break;
    }

    ListMgr_CloseAccess( &lmgr );

    return rc;

}
Ejemplo n.º 5
0
Archivo: rm.c Proyecto: Zabrane/SPOCP
int
element_rm(junc_t * jp, element_t * ep, ruleinst_t * rt)
{
	branch_t       *bp;
	int             r = 0, n;

	bp = ARRFIND(jp, ep->type);

	if (bp == 0) {		/* Ooops, how did that happen, can't delete
				 * something that isn't there */
		DEBUG(SPOCP_DSTORE)
		    traceLog(LOG_DEBUG,"missing branch where there shold be one");
		return -2;
	}

	bp->count--;

	DEBUG(SPOCP_DSTORE) traceLog(LOG_DEBUG,"Branch: [%d]", bp->count);

	if (bp->count == 0) {
		DEBUG(SPOCP_DSTORE)
		    traceLog(LOG_DEBUG,"element_rm; branch counter down to zero");
		branch_free(bp);

		/*
		 * have to do the junction handling here since the type is
		 * unknown further up 
		 */

		jp->item[ep->type] = 0;

		return 1;
	}

	/*
	 * type dependent part 
	 */
	switch (ep->type) {
	case SPOC_ATOM:
		r = atom_rm(bp, ep, rt);
		break;


	case SPOC_PREFIX:
		r = prefix_rm(bp, ep, rt);
		break;

	case SPOC_SUFFIX:
		r = suffix_rm(bp, ep, rt);
		break;

	case SPOC_RANGE:
		break;

	case SPOC_LIST:
		r = list_rm(bp, ep, rt);
		break;

	case SPOC_SET:
		break;

	}

	if (r == 0) {
		/*
		 * that branch is gone 
		 */
		DEBUG(SPOCP_DSTORE)
		    traceLog(LOG_DEBUG,"rm element; no type %d branch anymore",
			     ep->type);

		jp->item[ep->type] = 0;

		n = junction_index(jp);
		DEBUG(SPOCP_DSTORE)
			traceLog(LOG_DEBUG,"rm element; junction index %d", n);
		if (n == 0)
			junc_free(jp);
	}

	return 1;
}
Ejemplo n.º 6
0
int queue_rm(shmQueue *queue, QueueElement *element)
{
	return list_rm(queue, element);
}
Ejemplo n.º 7
0
Archivo: list.c Proyecto: e7/analysis
int main(int argc, char *argv[])
{
#if 0
    intptr_t list = 0;
    data_t data[8];
    int i = 0;
    intptr_t iter = 0;

    for (i = 0; i < ARRAY_COUNT(data); ++i) {
        data[i].__x__ = i;
        list_add(&list, &data[i].__node__);
    }

    assert(0 == list_rm(&list, 0));
    assert(0 == list_rm(&list, 7));

    iter = list;
    while (0 != iter) {
        data_t *data = CONTAINER_OF((intptr_t *)iter, data_t, __node__);

        (void)fprintf(stderr, "%d\n", data->__x__);
        iter = *(intptr_t *)iter;
    }

    return 0;
#endif

#if 0
    intptr_t head = 0;
    intptr_t node = 0;

    (void)fprintf(stderr, "&head: %p, &node: %p\n", &head, &node);
    list_add(&head, &node);
    (void)fprintf(stderr, "head: %x, node: %x\n", head, node);
    list_remove(&head);
    (void)fprintf(stderr, "head: %x, node: %x\n", head, node);

    return 0;
#endif

#if 0
    intptr_t i = 0;
    data_t data[8];

    print_data((data_t){9, 0, {0, 0}});
    memset(data, 0, SIZE_OF(data));
    arraylist_add(&data[0].__node__, &data[2].__node__, 2);
    arraylist_add(&data[2].__node__, &data[3].__node__, 3);
    arraylist_add(&data[3].__node__, &data[7].__node__, 7);
    arraylist_del(&data[0].__node__, &data[2].__node__);
    for (i = 0; i < (intptr_t)ARRAY_COUNT(data); ++i) {
        (void)fprintf(stderr, "data[%d] : %d\n", i, data[i].__node__);
    }

    memset(data, 0, SIZE_OF(data));
    arraydlist_add(&data[0].__dnode__,
                   &data[0].__dnode__,
                   &data[0].__dnode__,
                   0);
    arraydlist_add(&data[0].__dnode__,
                   &data[0].__dnode__,
                   &data[2].__dnode__,
                   2);
    arraydlist_add(&data[0].__dnode__,
                   &data[2].__dnode__,
                   &data[3].__dnode__,
                   3);
    arraydlist_add(&data[3].__dnode__,
                   &data[2].__dnode__,
                   &data[7].__dnode__,
                   7);
    /* that's NOT right, broke the dlist
    arraydlist_add(&data[2].__dnode__,
                   &data[3].__dnode__,
                   &data[7].__dnode__,
                   7);*/

    /*arraydlist_del(&data[3].__dnode__,
                   &data[2].__dnode__,
                   &data[7].__dnode__);*/

    for (i = 0; i < (intptr_t)ARRAY_COUNT(data); ++i) {
        (void)fprintf(stderr,
                      "data[%d] : (%d, %d)\n",
                      i,
                      data[i].__dnode__.__prev__,
                      data[i].__dnode__.__next__);
    }

    return 0;
#endif

#if 1
    typedef struct {
        intptr_t a;
        intptr_t b;
    } mydata_t;

    dlist_t dlist;
    mydata_t x1 = {1, 2};
    mydata_t x2 = {3, 4};
    mydata_t x3 = {5, 6};

    (void)init_dlist(&dlist, SIZE_OF(mydata_t));
    dlist_insert(&dlist, &x2);
    dlist_insert(&dlist, &x3);
    dlist_insert(&dlist, &x1);
    for (intptr_t iter = dlist.__head__->__next__;
         iter != 0;
         iter = dlist_next(&dlist, iter))
    {
        // mydata_t *d = CONTAINER_OF(iter, mydata_t, __dnode__);
        intptr_t shell_size = dlist.__obj_size__ + SIZE_OF(arraydlist_t);

        mydata_t *d = (mydata_t *)(dlist.__cache__ + shell_size * iter);

        fprintf(stderr, "%d, %d\n", d->a, d->b);
    }
    exit_dlist(&dlist);

    return 0;
#endif
}