亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? mmstatd.c

?? mmstatd包含一個 C庫和服務器
?? C
?? 第 1 頁 / 共 3 頁
字號:
/* $Id: mmstatd.c,v 1.5 2003/01/10 03:52:36 mmondor Exp $ *//* * Copyright (C) 2002-2003, Matthew Mondor * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *      This product includes software written by Matthew Mondor. * 4. The name of Matthew Mondor may not be used to endorse or promote *    products derived from this software without specific prior written *    permission. * * THIS SOFTWARE IS PROVIDED BY MATTHEW MONDOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL MATTHEW MONDOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *//* TODO * - Finish client packet uid credential checking, credentials have to be *   passed through the unix domain socket * - Have endian-independant logfile and database formats *//* HEADERS */#include <sys/types.h>#include <sys/stat.h>#include <sys/wait.h>#include <sys/socket.h>#include <sys/un.h>#include <sys/uio.h>#include <sys/file.h>#include <netinet/in.h>#include <arpa/inet.h>#include <arpa/nameser.h>#include <resolv.h>#include <poll.h>#include <syslog.h>#include <signal.h>#include <stddef.h>#include <unistd.h>#include <fcntl.h>#include <stdlib.h>#include <stdio.h>#include <time.h>#include <dirent.h>#include <pwd.h>#include <grp.h>#include <mmtypes.h>#include <mmlist.h>#include <mmstring.h>#include <mmstat.h>#include <mmstatd.h>#include <mmreadcfg.h>MMCOPYRIGHT("@(#) Copyright (c) 2002-2003\n\\tMatthew Mondor. All rights reserved.\n");MMRCSID("$Id: mmstatd.c,v 1.5 2003/01/10 03:52:36 mmondor Exp $");/* PROTOTYPES */static pid_t spawn_process(int (*)(void *), void *, bool);static void sighandler(int);static bool checklock(char *);static int unix_init(char *, gid_t, mode_t, int, bool, bool);static bool log_match(const char *, const char *);static bool writelogentries(int, struct log_entry *, int, int *, long *,       	off_t *);static bool readlogentry(int, struct log_entry *, int *, long *, off_t *);static int readlogentries(int, struct log_entry *, int, int *, long *, off_t *);static bool processlogentry(struct log_entry *, bool);static bool processlogentries(struct log_entry *, int, bool);/* static void debuglogentry(char, struct log_entry *); */static void load_db(long *, off_t *);static bool load_db_v0_0_1(FILE *, long *, long *);static bool load_db_v0_0_2(FILE *, long *, off_t *);static bool load_db_v0_0_3(FILE *, long *, off_t *);static void sync_db(long, off_t, bool);static void free_db(void);static void recover_db(void);static void writestats(int, char *);static void rotatestats(char *, char *);int main(int, char **);static int librarian_init(void *);static void librarian_main(int, int, int, long *, off_t *);static int logger_init(void *);static void logger_main(int, int, int, long *, off_t *);/* GLOBALS */static struct mmstat_config CONF;static pid_t librarian_pid = -1, logger_pid = -1;static list *key_list, *data_list;static int pipefds[2], syncbytes = 0;static bool run = TRUE, pipesend = TRUE, kdirection = TRUE, ddirection = TRUE;/* FUNCTIONS */static pid_tspawn_process(int (*function)(void *), void *params, bool leader){    pid_t pid = -1;    int fd;    /* Create new process */    if (!(pid = fork())) {	struct sigaction act;	/* Child */	if (leader) setsid();	chdir("/");	umask(0);	/* Make sure that stdin, stdout and stderr are safe */	if ((fd = open("/dev/null", O_RDWR)) != -1) {	    dup2(fd, 0);	    dup2(fd, 1);	    dup2(fd, 2);	    if (fd > 2)		close(fd);	}	/* Setup our break handler */	act.sa_handler = sighandler;	act.sa_flags = SA_NOCLDWAIT;	sigemptyset(&act.sa_mask);	sigaction(SIGTERM, &act, NULL);	sigaction(SIGSEGV, &act, NULL);	sigaction(SIGPIPE, &act, NULL);	/* Signals we want to ignore */	signal(SIGTTOU, SIG_IGN);	signal(SIGTTIN, SIG_IGN);	signal(SIGTSTP, SIG_IGN);	/* Simply call the wanted child function */	exit(function(params));    }    /* Parent */    return (pid);}static voidsighandler(int sig){    pid_t pid = getpid();    switch (sig) {    case SIGTERM:	syslog(LOG_NOTICE, "Received SIGTERM, cleaning up");	run = FALSE;	if (librarian_pid != -1 && librarian_pid != pid)	    kill(librarian_pid, SIGTERM);	if (logger_pid != -1 && logger_pid != pid)	    kill(logger_pid, SIGTERM);	break;    case SIGSEGV:	syslog(LOG_NOTICE, "Received SIGSEGV! Cleaning up");	kill(0, SIGTERM);	run = FALSE;	break;    case SIGPIPE:	pipesend = FALSE;	break;    default:	syslog(LOG_NOTICE, "Signal handler catched unexpected signal");	break;    }}/* This uses an fd which remains open in child processes, if they close it the * lock seems to be released automatically. */static boolchecklock(char *file){    int fd;    if ((fd = open(file, O_CREAT | O_TRUNC | O_WRONLY, 0600)) != -1) {	if (!(flock(fd, LOCK_EX | LOCK_NB))) return (TRUE);	close(fd);    }    return (FALSE);}static intunix_init(char *name, gid_t group, mode_t mode, int backlog, bool stream,	bool del){    int sock;    struct sockaddr_un sau;    if (del) unlink(name);    /* Open public UNIX domain socket */    if (stream) {	if ((sock = socket(AF_LOCAL, SOCK_STREAM, 0)) != -1) {	    mm_strncpy(sau.sun_path, name, 100);	    sau.sun_family = AF_UNIX;	    if (bind(sock, (struct sockaddr *)&sau, sizeof(struct sockaddr_un))		    != -1) {		if (!chmod(name, mode)) {		    chown(name, -1, group);		    if (!(listen(sock, backlog)))			return (sock);		    else			syslog(LOG_NOTICE, "unix_init() - listen()");		} else		    syslog(LOG_NOTICE, "unix_init() - chmod()");	    } else		syslog(LOG_NOTICE, "unix_init() - bind()");	    close(sock);	} else	    syslog(LOG_NOTICE, "unix_init() - socket()");    } else {	if ((sock = socket(AF_LOCAL, SOCK_DGRAM, 0)) != -1) {	    mm_strncpy(sau.sun_path, name, 100);	    sau.sun_family = AF_UNIX;	    if (bind(sock, (struct sockaddr *)&sau, sizeof(struct sockaddr_un))		    != -1) {		if (!chmod(name, mode)) {		    chown(name, -1, group);		    return (sock);		} else		    syslog(LOG_NOTICE, "unix_init() - chmod()");	    } else		syslog(LOG_NOTICE, "unix_init() - bind()");	    close(sock);	} else	    syslog(LOG_NOTICE, "unix_init() - socket()");    }    return (-1);}static boollog_match(const char *str, const char *pat){               for (; *pat != '*'; pat++, str++) {	if (!(*str)) {	    if (*pat) return (FALSE);	    else return (TRUE);	}	if(*str != *pat && *pat != '?') return (FALSE);    }    while (pat[1] == '*') pat++;    do	if (log_match(str, pat + 1)) return (TRUE);    while (*str++);    return (FALSE);}/* Writes requested log entries to specified fd, and if required automatically * perform logfile rotation, of course putting a mark at the end of the logfile * pointing to the next one continueing it. Files are rotated when reaching * approximately one megabyte in length. Returns TRUE on success or FALSE on * fatal error (eg: disk full). */static boolwritelogentries(int pfd, struct log_entry *entries, int len, int *fd,	long *lognum, off_t *logpos){    ssize_t l;    bool ok;    char filename[256], dat[MAX_TRANSACT];    ok = TRUE;    l = len * sizeof(struct log_entry);    /* First perform logfile rotation if required */    if (*logpos + l > CONF.max_logsize) {	struct log_entry newentry;	int newfd;	(*lognum)++;	if (*lognum > 99999999) *lognum = 0;	*logpos = 0;	snprintf(filename, 255, "%s/%08ld.log", CONF.ENV_DIR, *lognum);	if ((newfd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0600))		!= -1) {	    fsync(newfd);	    mm_memclr(&newentry, sizeof(struct log_entry));	    newentry.type = STAT_NEWFILE;	    newentry.un.newfile.lognum = *lognum;	    if ((write(*fd, &newentry, sizeof(struct log_entry))) !=		    sizeof(struct log_entry))		syslog(LOG_NOTICE,		       "writelogentry() - write(STAT_NEWFILE)");	    fsync(*fd);	    close(*fd);	    *fd = newfd;	    write(pfd, dat, 1);	} else {	    syslog(LOG_NOTICE, "writelogentry() - open()");	    ok = FALSE;	}    }    /* Write our new log entry */    if (ok) {	if (write(*fd, entries, l) == l) {	    *logpos += l;	    /* A trick to keep resonable physical disk sync rate */	    syncbytes += l;	    if (syncbytes >= CONF.SYNC_BYTES) {		syncbytes = 0;		fdatasync(*fd);	    }	    write(pfd, dat, len);	} else {	    syslog(LOG_NOTICE, "writelogentry() - write(STAT_*)");	    ok = FALSE;	}    }    return (ok);}/* This function attempts to read a log entry from specified fd, transparently * rotating to the new logfile when required, and updates fd and lognum via * provided pointers. If pfd is -1, we attempt to read an entry, and return * FALSE if none could be read. Otherwise we attempt to read for an entry * monitoring pfd for new data notification, until at least a full entry * could be read. We return TRUE if an entry could be read. */static boolreadlogentry(int pfd, struct log_entry *entry, int *fd, long *lognum,	off_t *logpos){    char filename[256], c;    int newfd;    bool ok, redo;    struct pollfd fds[] = {	{pfd, POLLIN, 0}    };    redo = TRUE;    while (redo) {	redo = FALSE;	ok = FALSE;	if (pfd == -1) {	    if ((read(*fd, entry, sizeof(struct log_entry))) ==		    sizeof(struct log_entry))		ok = TRUE;	} else {	    while (run) {		if ((poll(fds, 1, 5000)) > 0) {		    if (fds[0].revents & POLLIN) {			if ((read(pfd, &c, 1)) == 1) {			    if ((read(*fd, entry, sizeof(struct log_entry)))				    == sizeof(struct log_entry))				ok = TRUE;			    else				syslog(LOG_NOTICE,				       "readlogentry() - partial read");			    break;			}		    }		}	    }	}	if (ok) {	    /* debuglogentry('|', entry); */	    *logpos += sizeof(struct log_entry);	    /* If required switch to next logfile */	    if (entry->type == STAT_NEWFILE) {		snprintf(filename, 255, "%s/%08ld.log", CONF.ENV_DIR,			entry->un.newfile.lognum);		if ((newfd = open(filename, O_RDONLY)) != -1) {		    close(*fd);		    *fd = newfd;		    *logpos = 0;		    *lognum = entry->un.newfile.lognum;		    redo = TRUE;		} else {		    syslog(LOG_NOTICE, "* readlogentry() - open()");		    ok = FALSE;		}	    }	}    }    return (ok);}/* This function attempts to read at least one entry, but all entries of a * transaction if any is detected. If pfd is -1, we return FALSE if we * cannot read an entry or the whole transaction, otherwise we wait for * more data to be available using fdb with poll(). We only return TRUE * if a single entry or whole transaction could be read. * If STAT_NEWFILE entry is encoutered, auto rotation to the new logfile * is performed and fd,lognum,logpos are updated via the provided pointers, * transparently. * The STAT_TRANSACT header and footer entries are never put in the buffer, * this way their persistant flag is ignored. * IMPORTANT: Because of the way this function works to prevent additionnal * memory copy operations, the supplied buffer size should at least have one * additionnal entry than specified maximum size. */static intreadlogentries(int pfd, struct log_entry *entries, int max, int *fd,	long *lognum, off_t *logpos){    struct log_entry *ptr;    int len;    bool transact;    transact = FALSE;    ptr = entries;    len = 0;    if (readlogentry(pfd, entries, fd, lognum, logpos)) {	if (entries->type == STAT_TRANSACT) {	    if (entries->un.transact.begin) transact = TRUE;	    else {		/* Mismatch */		len = 0;		syslog(LOG_NOTICE,			"readlogentries() - Mismatched transaction start");	    }	} else	    len++;    }    /* If we fill the buffer of max entries or if we reach EOF before end of     * transaction marker can be found, we simply drop the whole transaction     * and return 0. That is where we need a read-ahead buffer, and require     * an additionnal entry.     */    while (transact) {	if (len > max) {	    len = 0;	    syslog(LOG_NOTICE, "readlogentries() - MAX_TRANSACT exceeded");	    break;	}	if (!readlogentry(pfd, ptr, fd, lognum, logpos)) {	    len = 1;	    break;	} else {	    if (ptr->type == STAT_TRANSACT) {		if (ptr->un.transact.begin) {		    /* Mismatch */		    len = 0;		    syslog(LOG_NOTICE,			   "readlogentries() - Mismatched transaction end");		}		break;	    } else {		ptr++;		len++;	    }	}    }    return (len);}/* Apply requested log entry to the live db. * STAT_NEWFILE or STAT_TRANSACT entries are never processed through this * function. */static boolprocesslogentry(struct log_entry *entry, bool tmp){    bool ok;    u_int64_t hash;    enum stat_type type;    /* debuglogentry(':', entry); */    ok = TRUE;    type = entry->type;    if (tmp || entry->persistant) {	register char *ptr;	/* Verify if we should perform wildcard matching and perform an atomic	 * operation on all matching keys	 */	for (ptr = entry->key; *ptr; ptr++)	    if (*ptr == '?' || *ptr == '*') break;	if (!(*ptr)) {	    register struct key_node *knod;	    /* Operating on a single key.	     * Locate corresponding key in db, if any	     */	    hash = mm_strhash64(entry->key);	    if (kdirection) {		for (knod = (struct key_node *)key_list->top; knod;			knod = (struct key_node *)knod->nod.next)		    if (knod->hash == hash) break;	    } else {

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91小视频在线| 国产亚洲综合色| 亚洲男人天堂一区| 91在线免费看| 一区在线观看视频| 一本久久综合亚洲鲁鲁五月天| www欧美成人18+| 国产精品一二三区在线| 亚洲日本在线天堂| 久久久久久免费网| 国产精品一区二区三区乱码| 欧美成人aa大片| 国产精品18久久久久久久久| 久久久久久亚洲综合| 成人性色生活片| 最新久久zyz资源站| 精品视频在线免费看| 美国毛片一区二区| 国产精品无圣光一区二区| 色综合久久综合网欧美综合网| 国产成人精品亚洲777人妖 | 亚洲一区二区三区在线| 另类小说一区二区三区| 中文字幕一区二区三区在线观看| 91网站黄www| 久久av资源网| 亚洲精品中文在线观看| 精品伦理精品一区| 在线精品视频一区二区三四| 免费在线观看精品| 亚洲色图在线看| 久久九九久久九九| 日韩一卡二卡三卡四卡| www.在线欧美| 国产在线视频一区二区| 有码一区二区三区| 国产欧美精品在线观看| 欧美不卡一区二区| 欧美电影影音先锋| 一道本成人在线| 99re热视频精品| 丁香另类激情小说| 韩国毛片一区二区三区| 9191成人精品久久| 欧美三片在线视频观看 | 亚洲男帅同性gay1069| 久久一区二区三区四区| 91精品国产色综合久久不卡电影| 在线免费观看日本一区| 亚洲成人一区二区| 亚洲欧美经典视频| 一区在线观看免费| 国产精品福利一区二区三区| 久久先锋影音av鲁色资源| 日韩久久久精品| wwww国产精品欧美| 国产午夜亚洲精品羞羞网站| 久久久久国产精品厨房| 精品91自产拍在线观看一区| 久久久国产午夜精品| 中文字幕中文乱码欧美一区二区| 中文字幕日本不卡| 夜夜亚洲天天久久| 国产日韩欧美亚洲| 欧洲一区二区三区在线| 欧洲人成人精品| 欧美妇女性影城| 久久久99精品免费观看| 亚洲私人黄色宅男| 日日夜夜精品视频天天综合网| 青青草精品视频| 成人av在线看| 精品免费日韩av| 亚洲永久免费视频| 国产原创一区二区三区| 99re热视频精品| 久久夜色精品一区| 中文字幕永久在线不卡| 美女视频一区二区三区| 麻豆精品在线看| 国产九九视频一区二区三区| 91美女蜜桃在线| 国产三级一区二区| 日韩精品色哟哟| 在线观看亚洲精品| 国产精品久久久久久久久久免费看| 亚洲.国产.中文慕字在线| 99久久精品一区| 欧美激情中文不卡| 久久99精品久久久久久国产越南| 在线视频一区二区三| 亚洲欧美视频一区| 成人高清视频免费观看| 国产无一区二区| 韩国av一区二区三区四区 | 亚洲色图.com| 国产精品亚洲人在线观看| 在线播放91灌醉迷j高跟美女| 亚洲人成网站在线| 91美女片黄在线| 亚洲精品国产第一综合99久久| 成人av电影免费在线播放| 国产欧美精品一区aⅴ影院| 国产成人精品免费视频网站| 欧美精品一区二区三区在线播放| 久久精品噜噜噜成人av农村| 日韩女优制服丝袜电影| 国产精品一区免费视频| 国产精品国产三级国产aⅴ原创| 99精品国产一区二区三区不卡| 中文字幕欧美激情| 91美女蜜桃在线| 日韩成人精品在线观看| 精品日韩一区二区三区免费视频| 精品写真视频在线观看| 国产精品亲子伦对白| 欧美视频一区二区在线观看| 麻豆国产精品官网| 日韩毛片精品高清免费| 欧美丰满少妇xxxxx高潮对白| 久久99国内精品| 亚洲精品va在线观看| 日韩欧美成人一区二区| 色域天天综合网| 精品亚洲porn| 亚洲欧洲日韩女同| 国产成人免费在线| 中文幕一区二区三区久久蜜桃| 欧美在线观看视频一区二区 | 欧美在线免费播放| 欧美在线一二三| 欧美精品久久99久久在免费线| 亚洲一区二区五区| 日本午夜一区二区| 国产成人在线观看| 91麻豆精品在线观看| 欧美三级韩国三级日本一级| 欧美精品aⅴ在线视频| 日韩一级免费一区| 国产精品乱人伦| 五月婷婷色综合| 国产精品综合一区二区| 色94色欧美sute亚洲13| 欧美日韩极品在线观看一区| 91精品国产综合久久精品图片| 精品国产sm最大网站| 中文字幕中文字幕中文字幕亚洲无线| 亚洲精品国产a| 国产高清无密码一区二区三区| 91麻豆6部合集magnet| 精品国产乱码久久久久久1区2区 | 亚洲一区二区三区美女| 56国语精品自产拍在线观看| 91一区二区三区在线播放| a级高清视频欧美日韩| 91精品国产乱| 亚洲黄色片在线观看| 高清不卡一区二区| 国产精品嫩草影院av蜜臀| 欧美一区二区精品在线| 国产精品久久久久天堂| 久久国产麻豆精品| 欧美日本一道本| 一区二区三区四区不卡在线| 成人成人成人在线视频| 久久夜色精品国产噜噜av| 免费视频一区二区| 欧美裸体一区二区三区| 亚洲一级二级在线| 色婷婷综合久久| 亚洲黄一区二区三区| 97se亚洲国产综合自在线不卡| 中文字幕精品一区二区精品绿巨人| 奇米影视一区二区三区小说| 欧美日韩中文字幕一区二区| 亚洲成国产人片在线观看| 欧美性xxxxxx少妇| 亚洲chinese男男1069| 欧美肥大bbwbbw高潮| 日本美女视频一区二区| 精品三级在线观看| 久久99精品视频| 国产欧美一区二区精品性| 成人精品国产福利| 亚洲欧美一区二区久久| 欧美日韩久久久久久| 麻豆精品久久精品色综合| 久久久一区二区| 色综合天天综合网天天看片| 亚洲综合激情网| 久久综合色综合88| 91美女片黄在线观看91美女| 亚洲国产精品久久久久秋霞影院| 欧美男人的天堂一二区| 国产精品一区二区三区乱码| 亚洲欧美日韩中文播放| 欧美放荡的少妇| 99久精品国产| 九色综合狠狠综合久久| 亚洲人吸女人奶水|