예제 #1
0
파일: cache.c 프로젝트: foxfair/formosa
/*******************************************************************
 *	alloc shm for cache file
 *******************************************************************/
void init_cache()
{

	file_shm = attach_shm(FILE_SHM_KEY, FS_SIZE*NUM_CACHE_FILE);
	html_shm = attach_shm(HTML_SHM_KEY, HS_SIZE*NUM_CACHE_HTML);

}
예제 #2
0
파일: utmp.c 프로젝트: wyat/kbs
void resolve_utmp()
{
    int iscreate;

    if (utmpshm == NULL) {
        utmpshm = (struct UTMPFILE *) attach_shm("UTMP_SHMKEY", 3699, sizeof(*utmpshm), &iscreate);     /*attach user tmp cache */
        if (iscreate) {
            int i, utmpfd;
            utmphead = (struct UTMPHEAD *) attach_shm("UTMPHEAD_SHMKEY", 3698, sizeof(struct UTMPHEAD), &iscreate);     /*attach user tmp cache */
            utmpfd = utmp_lock();
            bzero(utmpshm, sizeof(struct UTMPFILE));
            bzero(utmphead, sizeof(struct UTMPHEAD));
            utmphead->number = 0;
            utmphead->hashhead[0] = 1;
            for (i = 0; i < USHM_SIZE - 1; i++)
                utmphead->next[i] = i + 2;
            utmphead->next[USHM_SIZE - 1] = 0;
            /*
                     utmphead->listhead=0;
            */
            utmp_unlock(utmpfd);
        } else
            utmphead = (struct UTMPHEAD *) attach_shm1("UTMPHEAD_SHMKEY", 3698, sizeof(struct UTMPHEAD), &iscreate, 0, NULL);   /*attach user tmp head */
    }
}
예제 #3
0
void resolve_utmp()
{
    if (utmpshm == NULL)
    {
        utmpshm = attach_shm("UTMP_SHMKEY", 3699, sizeof(*utmpshm));
    }
}
예제 #4
0
파일: ucache.c 프로젝트: phoenixgao/fdubbs
// If 'utmpshm' == NULL, gets shared memory for online users
// and puts its starting address in utmpshm.
void resolve_utmp(void)
{
	if (utmpshm == NULL) {
		utmpshm = attach_shm("UTMP_SHMKEY", 3699, sizeof(*utmpshm));
		if (utmpshm == NULL)
			exit(1); // TODO: leave to callers.
	}
}
예제 #5
0
파일: Shm.cpp 프로젝트: jackaudio/jack2
 int Shm::resize_shm (jack_shm_info_t* si, jack_shmsize_t size) {
     jack_shm_id_t id;
     
     /* The underlying type of `id' differs for SYSV and POSIX */
     memcpy (&id, &jack_shm_registry[si->index].id, sizeof (id));
     
     release_shm (si);
     destroy_shm (si);
     
     if (shmalloc ((char *) id, size, si)) {
         return -1;
     }
     return attach_shm (si);
 }
예제 #6
0
void resolve_ucache()
{
    struct stat st;
    int     ftime;
    if (uidshm == NULL)
    {
        uidshm = attach_shm("UCACHE_SHMKEY", 3696, sizeof(*uidshm));
    }
    if (stat(FLUSH, &st) < 0)
    {
        ftime = time(0) - 86400;
    }
    else
        ftime = st.st_mtime;
    if (uidshm->uptime < ftime||forceresolve)
    {
        log_usies("CACHE", "reload ucache");
        /* uidshm->uptime = ftime; */
        usernumber = 0;
        apply_record(PASSFILE, fillucache, sizeof(struct userec));
        uidshm->number = usernumber;
        uidshm->uptime = ftime;
    }
}
예제 #7
0
void resolve_boards()
{
    struct stat st;
    time_t  now;
    if (brdshm == NULL)
    {
        brdshm = attach_shm("BCACHE_SHMKEY", 3693, sizeof(*brdshm));
    }
    numboards = brdshm->number;
    bcache = brdshm->bcache;
    now = time(0);
    if (stat(BOARDS, &st) < 0)
    {
        st.st_mtime = now - 3600;
    }
    if (brdshm->uptime < st.st_mtime || brdshm->uptime < now - 3600)
    {
        log_usies("CACHE", "reload bcache");
        numboards = 0;
        apply_record(BOARDS, fillbcache, sizeof(struct boardheader));
        brdshm->number = numboards;
        brdshm->uptime = now;
    }
}
예제 #8
0
파일: menu.c 프로젝트: wtj/formosa
static void
menu_title()
{
	title_func(cmenus[n_cmenus - 1].chelp, BBSTITLE);

#ifdef USE_MENUSHOW
	if (redraw && !(curuser.flags[0] & PICTURE_FLAG))
	{
		if (msshm == NULL)
			msshm = (struct MenuShowShm *) attach_shm(MENUSHOW_KEY, sizeof(struct MenuShowShm));
		if (msshm && msshm->number)
		{
			int j;
			char *p1, *p2;
			unsigned char chs;
			static long randomseed = 1;

			/*  
			 * This is a simple linear congruential random number
			 * generator.  Hence, it is a bad random number
			 * generator, but good enough for most randomized
			 * geometric algorithms. modify by lthuang
			 */
			randomseed = (randomseed * 1366l + 150889l) % 714025l;
			pict_no = randomseed / (714025l / msshm->number + 1);

/*
 * j = n_cmenus + 2;
 * if (j < 13)
 * j = 13;
 */
			move(10, 69 - strlen(msshm->list[pict_no].owner));
			prints("《提供》%s ", msshm->list[pict_no].owner);
			j = 2;
			move(j, 0);
/*                      
 * prints("《作者》%35.35s  《標題》%27.27s",
 * msshm->list[pict_no].owner, msshm->list[pict_no].title);
 */
			p1 = msshm->list[pict_no].body;

/*
 * while (j++ < b_line)
 */
			while (++j < 11)
			{
				if ((p2 = strchr(p1, '\n')) != NULL)
					p1 = ++p2;
				else
					break;
			}
			/* 
			 * Direct output the content in shared memory,
			 * for better performance. by lthuang
			 */
			j = p1 - msshm->list[pict_no].body;
			p1 = msshm->list[pict_no].body;
			while (j-- > 0 && (chs = *p1++) != '\0')
				outc(chs);
			outs("");

			redraw = FALSE;
		}
/*              
 * move(b_line, 0); 
 */
	}
#endif /* USE_MENUSHOW */
}
예제 #9
0
void resolve_boards()
{
    int boardfd=-1;
    int iscreate = 0;
    char errbuf[STRLEN];

    if (bcache == NULL) {
        if ((boardfd = open(BOARDS, O_RDWR | O_CREAT, 0644)) == -1) {
            bbslog("3system", "Can't open " BOARDS "file %s", strerror_r(errno, errbuf, STRLEN));
            exit(-1);
        }
        bcache = (struct boardheader *) mmap(NULL, MAXBOARD * sizeof(struct boardheader), PROT_READ, MAP_SHARED, boardfd, 0);
        if (bcache == (struct boardheader *) -1) {
            bbslog("4system", "Can't map " BOARDS "file %s", strerror_r(errno, errbuf, STRLEN));
            close(boardfd);
            exit(-1);
        }
    }
    if (brdshm == NULL) {
        brdshm = attach_shm("BCACHE_SHMKEY", 3693, sizeof(*brdshm), &iscreate); /* attach board share memory */
        if (iscreate) {
            int i, maxi = -1;
            int fd;

            bbslog("3system", "reload bcache!");
            fd = bcache_lock();
            for (i = 0; i < MAXBOARD; i++)
                if (bcache[i].filename[0]) {
                    int count;
                    char filename[MAXPATH];
                    struct fileheader lastfh;
                    getlastpost(bcache[i].filename, &brdshm->bstatus[i].lastpost, &brdshm->bstatus[i].total);
                    /* ulock: get nowid from the last fileheader and idseq*/
                    setbfile(filename,bcache[i].filename,DOT_DIR);
                    count=get_num_records(filename,sizeof(struct fileheader));
                    if (count > 0) {
                        get_record(filename, &lastfh, sizeof(struct fileheader), count-1);
                        brdshm->bstatus[i].nowid=lastfh.id+1;
                        if (bcache[i].idseq>lastfh.id+1)
                            brdshm->bstatus[i].nowid=bcache[i].idseq;
                        else
                            brdshm->bstatus[i].nowid=lastfh.id+1;
                    } else
                        brdshm->bstatus[i].nowid=bcache[i].idseq;
                    /* update top title */
                    board_update_toptitle(i+1,false);
#ifdef RECORDMAXONLINE
                    /* load board max online record */
                    brdshm->bstatus[i].maxonline = bcache[i].maxonline;
                    brdshm->bstatus[i].maxtime = bcache[i].maxtime;
#endif
#ifdef TITLEKEYWORD
                    load_title_key(1, i+1, bcache[i].filename);
#endif

                    maxi = i;
                }
            if (maxi != -1)
                brdshm->numboards = maxi + 1;
            bcache_unlock(fd);
        }
    }
    if (bdirshm == NULL) {
        bdirshm = attach_shm("BDIRCACHE_SHMKEY", 3697, sizeof(*bdirshm), &iscreate); /* attach board share memory */
        if (iscreate) {
            bbslog("3system", "reload bdircache!");
            load_allboard(bdirshm->allbrd_list, &bdirshm->allbrd_list_t);
            load_wwwboard(bdirshm->wwwbrd_list, &bdirshm->wwwbrd_list_t);
        }
    }
    if (boardfd!=-1)
        close(boardfd);
}
예제 #10
0
파일: Shm.cpp 프로젝트: jackaudio/jack2
 int Shm::attach_lib_shm (jack_shm_info_t* si) {
     int res = attach_shm(si);
     if (res == 0)
         si->size = jack_shm_registry[si->index].size; // Keep size in si struct
     return res;
 }
예제 #11
0
CK_RV
ST_Initialize(void *FunctionList,
	CK_SLOT_ID SlotNumber,
	unsigned char *Correlator)
{
	CK_RV  rc = CKR_OK;
	struct ST_FCN_LIST *flist = (struct ST_FCN_LIST *)FunctionList;
	TSS_HCONTEXT hContext = 0;

	stlogterm();
	stloginit();

	if (st_Initialized() == TRUE) {
		return (CKR_OK);
	}
	// assume that the upper API prevents multiple calls of initialize
	// since that only happens on C_Initialize and that is the
	// resonsibility of the upper layer..
	initialized = FALSE;

	// check for other completing this before creating mutexes...
	// make sure that the same process tried to to the init...
	// thread issues should be caught up above...
	if (st_Initialized() == TRUE) {
		goto done;
	}

	Fork_Initializer();

	(void) pthread_mutex_init(&pkcs_mutex, NULL);
	(void) pthread_mutex_init(&obj_list_mutex, NULL);
	(void) pthread_rwlock_init(&obj_list_rw_mutex, NULL);

	(void) pthread_mutex_init(&sess_list_mutex, NULL);
	(void) pthread_mutex_init(&login_mutex, NULL);

	if (st_Initialized() == FALSE) {
		if ((rc = attach_shm()) != CKR_OK)
			goto done;

		nv_token_data = &global_shm->nv_token_data;

		initialized = TRUE;
		initedpid = getpid();
		SC_SetFunctionList();

		if (flist != NULL)
			(*flist) = function_list;

		/* Always call the token_specific_init function.... */
		rc = token_specific.t_init((char *)Correlator, SlotNumber,
		    &hContext);
		if (rc != 0) {
			/*
			 * The token could not be initialized, return OK, but
			 * present no slots.
			 */
			rc = CKR_OK;
			goto done;
		} else {
			/* Mark the token as available */
			global_shm->token_available = TRUE;
		}
	}

	rc = load_token_data(hContext, nv_token_data);

	if (rc != CKR_OK) {
		goto done;
	}

	rc = load_public_token_objects();
	if (rc != CKR_OK)
		goto done;

	(void) XProcLock(xproclock);
	global_shm->publ_loaded = TRUE;
	(void) XProcUnLock(xproclock);

	init_slot_info(nv_token_data);

done:
	if (hContext)
		Tspi_Context_Close(hContext);
	return (rc);
}