示例#1
0
int init_watch_hashtables()
{
    int result=0;
    unsigned int error=0;

    result=initialize_group(&group_watches_inode, inode_hashfunction, 256, &error);

    if (result<0) goto out;

    result=initialize_group(&group_watches_ctr, ctr_hashfunction, 256, &error);

    out:

    return result;

}
示例#2
0
/* setup and create a groups threads */
int create_group(struct group_parameters *group)
{
	int status;
	pthread_attr_t thread_attr;
	cpu_set_t mask;

	/* initialize group structure */
	status = initialize_group(group);
	if (status) {
		error("initializing group %d\n", group->id);
		return FAILURE;
	}

	CPU_ZERO(&mask);
	CPU_SET(group->cpu, &mask);

	debug("group %d bound to cpu %ld\n", group->id, group->cpu);

	/* start the low priority thread */
	debug("creating low priority thread\n");
	if (setup_thread_attr(&thread_attr, LOW_PRIO(), &mask, policy))
		return FAILURE;
	status = pthread_create(&group->low_tid,
				&thread_attr, low_priority, group);
	if (status != 0) {
		error("creating low_priority thread: %s\n", strerror(status));
		return FAILURE;
	}

	/* create the medium priority thread */
	debug("creating medium priority thread\n");
	if (setup_thread_attr(&thread_attr, MED_PRIO(), &mask, policy))
		return FAILURE;
	status = pthread_create(&group->med_tid,
				&thread_attr, med_priority, group);
	if (status != 0) {
		error("creating med_priority thread: %s\n", strerror(status));
		return FAILURE;
	}

	/* create the high priority thread */
	debug("creating high priority thread\n");
	if (setup_thread_attr(&thread_attr, HIGH_PRIO(), &mask, policy))
		return FAILURE;
	status = pthread_create(&group->high_tid,
				&thread_attr, high_priority, group);
	if (status != 0) {
		error("creating high_priority thread: %s\n", strerror(status));
		set_shutdown_flag();
		return FAILURE;
	}
	return SUCCESS;
}
示例#3
0
static struct resource_struct *get_next_ftp_noname(struct resource_struct *p, unsigned char type, void **index, unsigned char (*select_fn)(struct resource_struct *p, struct resource_struct *r, char *name, unsigned char type))
{
    struct resource_struct *r=NULL;

    if (type==FTP_TYPE_NETWORK) {

	/* there is one ftp network resource for all net workspaces/users */

	r=&ftp_network_resource;

    } else if (type==FTP_TYPE_SERVER) {
	int hashvalue=0;

	while(hashvalue<server_list.len && ! r) {

	    /* lookup in workgroup list */

	    r=get_next_element(&server_list, index, hashvalue);

	    while(r) {

		if (select_fn(p, r, NULL, type)==1) break;
		r=get_next_element(&server_list, index, hashvalue);

	    }

	    if (!r) {

		/* jump to the next hash */

		*index=NULL;
		hashvalue++;

	    } else {

		break;

	    }

	}

    }

    return r;


struct resource_struct *get_next_ftp(struct resource_struct *p, char *name, unsigned char type, void **index, unsigned char (*select_fn)(struct resource_struct *p, struct resource_struct *r, char *name, unsigned char type))
{
    struct resource_struct *r=NULL;

    if (! select_fn) select_fn=default_select_fn;

    if (! name) {

	r=get_next_ftp_noname(p, type, index, select_fn);
	goto out;

    }

    if (type==FTP_TYPE_NETWORK) {

	/* there is one smb network resource for all net workspaces/users */

	r=&ftp_network_resource;

    } else if (type==FTP_TYPE_SERVER) {
	int hashvalue;

	hashvalue=calculate_ftp_hash(name);

	/* lookup in server list */

	r=get_next_element(server_list, &index, hashvalue);

	while(r) {

	    if (select_fn(p, r, name, type)==1) break;
	    r=get_next_element(server_list, index, hashvalue);

	}

    }

    out:

    return r;

}

int ftp_groupadd(struct resource_struct *resource)
{

    if (resource->type==FTP_TYPE_SERVER) {

	/* add resource to servers */

	add_element_to_group(&server_list, (void *) resource);

    }

    return 0;

}

int smb_groupremove(struct resource_struct *resource)
{

     if (resource->type==FTP_TYPE_SERVER) {

	/* remove resource from servers */

	remove_element_from_group(&server_list, (void *) resource);

    }

    return 0;

}

static struct group_calls_struct ftp_group_calls={
	.find_role		= find_role_ftp,
	.readrecord		= NULL,
	.init			= NULL,
	.add			= NULL,
	.change			= NULL,
	.remove			= NULL,
	.close			= NULL,
	.get_next		= get_next_ftp,
	.groupadd		= ftp_groupadd,
	.groupremove		= ftp_groupremove,
	.lock			= NULL,
	.unlock			= NULL,
};

void add_group_ftp()
{
    int res=0;

    init_resource_group(&ftp_resource_group);
    add_resource_group(RESOURCE_GROUP_FTP, &ftp_resource_group, &ftp_group_calls);

    create_ftp_network_resource();

    res=initialize_group(server_list, server_hashfunction, 256);

    /* read the config */

    read_ftp_config();

    /* init ftp network role */

    snprintf(ftp_network_role.name, 128, "remote.net.ftp.network");

    ftp_network_role.directory_file=NULL;

    ftp_network_role.group=RESOURCE_GROUP_FTP;
    ftp_network_role.type=FTP_TYPE_NETWORK;

    add_role_simple(&ftp_network_role);

    /* init ftp server role */

    snprintf(ftp_server_role.name, 128, "remote.net.ftp.server");

    ftp_server_role.directory_file=NULL;

    ftp_server_role.group=RESOURCE_GROUP_FTP;
    ftp_server_role.type=FTP_TYPE_SERVER;

    add_role_simple(&ftp_server_role);

}
void initialize_inotify(unsigned int *error)
{
    struct bevent_xdata_struct *xdata=NULL;
    int result=0, fd=0;

    /* create the inotify instance */

    fd=inotify_init();

    if (fd==-1) {

	*error=errno;
        logoutput("initialize_inotify: error creating inotify fd: %i.", errno);
        goto error;

    }

    /*
	add inotify to the main eventloop
    */

    xdata=add_to_beventloop(fd, EPOLLIN | EPOLLPRI, &handle_inotify_fd, NULL, &xdata_inotify, NULL);

    if ( ! xdata ) {

        logoutput("initialize_inotify: error adding inotify fd to eventloop.");
        goto error;

    } else {

        logoutput("initialize_inotify: inotify fd %i added to eventloop", fd);
	add_xdata_to_list(xdata);

    }

    result=initialize_group(&group_watches_inotify, wd_hashfunction, 256, error);

    if (result<0) {

	*error=abs(result);
    	logoutput("initialize_inotify: error %i adding inotify fd to eventloop", *error);
	goto error;

    }

    return;

    error:

    if (fd>0) {

	close(fd);
	fd=0;

    }

    if (xdata) {

	remove_xdata_from_beventloop(xdata);
	xdata=NULL;

    }

    free_group(&group_watches_inotify, free_inotify_watch);

}