Ejemplo n.º 1
0
int server_init(server_t *server)
{
    assert(server!= NULL);

	pthread_mutex_init(&server->send_pending_lock, NULL);
	pthread_cond_init(&server->send_pending_cond, NULL);

    UNUSED int r;

    get_instance_parent_full_path(server->root_dir, NAME_MAX);

    sprintf(server->storage.storage_dir, "%s/data/storage", server->root_dir);
    if ( mkdir_if_not_exist(server->storage.storage_dir) != 0 ){
        error_log("mkdir %s failed.", server->storage.storage_dir);
        return -1;
    }

    char log_dir[NAME_MAX];
    sprintf(log_dir, "%s/data/log", server->root_dir);
    if ( mkdir_if_not_exist(log_dir) != 0 ) {
        error_log("mkdir %s failed.", log_dir);
        return -1;
    }

    /*r = storage_init(&server->storage);*/
    int i;
    for ( i = 0 ; i < VNODES ; i++ ){
        vnode_t *vnode = vnode_new(server->storage.storage_dir, i);
        if ( vnode == NULL ){
            error_log("vnode_init() failed. id:%d", i);
            return -1;
        }
        server->vnodes[i] = vnode;
    }

    /* logfile */
    for ( i = 0 ; i < LOGFILES ; i++ ) {
        char logfile_name[NAME_MAX];
        sprintf(logfile_name, "%s/%02d.log", log_dir, i);

        logfile_t *logfile = logfile_new(i, logfile_name);

        if ( logfile_open(logfile, 1) != 0 ) {
            error_log("logfile_open(%d) failed.", i);
            return -1;
        }

        server->logfiles[i] = logfile;
    }

    /* FIXME */
    r = init_server_work_queue(server);
    if ( r != 0 ){
        error_log("init_server_work_queue() failed.");
        return -1;
    }

    return 0;
}
Ejemplo n.º 2
0
void
LogfileList_init(void)
{
    Logfile *curr, *next;
    CfgLogItor *li;
    const CfgLog *cl;

    /* if already initialized, first free the previous list */
    if (firstLog) LogfileList_done();

    /* determine pattern for recognizing own log entries */
    snprintf(ignorepattern, 128, "%s[%d]:", Daemon_name(), getpid());

    curr = NULL;

    /* iterate over Logfile config sections, create objects */
    li = Config_cfgLogItor();
    while (cfgLogItor_moveNext(li))
    {
	cl = cfgLogItor_current(li);
	next = logfile_new(cl);
	if (next)
	{
	    if (curr)
	    {
		curr->next = next;
		curr = next;
	    }
	    else
	    {
		curr = next;
		firstLog = next;
	    }
	}
    }
    cfgLogItor_free(li);
}