亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
欧美一级高清大全免费观看| 成人激情文学综合网| 欧美一区二区三级| 男男视频亚洲欧美| 欧美在线观看一区二区| 国产女人水真多18毛片18精品视频| 韩国av一区二区| 中文在线一区二区| 日本二三区不卡| 午夜精品成人在线| 337p亚洲精品色噜噜| 国产日韩欧美不卡| 裸体在线国模精品偷拍| 久久久精品影视| 99久久精品国产一区二区三区| 亚洲综合图片区| 欧美一级欧美三级| 黄网站免费久久| 亚洲欧洲日韩在线| 欧美日韩一区二区三区不卡| 老司机精品视频在线| 欧美激情一区在线观看| 在线观看日韩电影| 日本成人在线网站| 国产欧美日韩久久| 91福利视频在线| 国产精品日韩成人| 欧美亚洲日本国产| 久久99精品久久久久久动态图 | 成人av影院在线| 一区二区三区加勒比av| 日韩午夜在线观看视频| 成av人片一区二区| 午夜精品福利一区二区蜜股av| 日韩av电影天堂| 欧美日韩国产在线观看| 国产精品羞羞答答xxdd| 亚洲日本中文字幕区| 欧美一级专区免费大片| 成人黄色网址在线观看| 亚洲成人av在线电影| 久久精品夜夜夜夜久久| 在线精品国精品国产尤物884a| 狂野欧美性猛交blacked| 亚洲色欲色欲www在线观看| 日韩亚洲欧美成人一区| 99re这里只有精品首页| 免费久久精品视频| 中文字幕人成不卡一区| 日韩一区二区精品| 91免费在线看| 国产在线精品一区二区三区不卡| 一区二区三区国产| 久久久精品tv| 欧美日韩高清一区二区不卡| 成人综合婷婷国产精品久久免费| 五月天国产精品| 国产女人18水真多18精品一级做 | 8x8x8国产精品| a级精品国产片在线观看| 蜜臀久久99精品久久久久宅男 | 久久综合色鬼综合色| 欧美亚洲综合网| 成人国产精品免费观看| 精品一区二区三区免费毛片爱 | 亚洲码国产岛国毛片在线| 欧美videos中文字幕| 欧美性色欧美a在线播放| 成人自拍视频在线| 久久99精品久久久久婷婷| 亚洲国产精品久久久久婷婷884 | 亚洲欧美日韩精品久久久久| 26uuu精品一区二区三区四区在线| 欧美日韩视频专区在线播放| 大胆欧美人体老妇| 韩国一区二区三区| 奇米精品一区二区三区在线观看一| 亚洲蜜臀av乱码久久精品| 国产精品美女久久久久aⅴ国产馆 国产精品美女久久久久av爽李琼 国产精品美女久久久久高潮 | 欧美大度的电影原声| 欧美性一二三区| 91丝袜美腿高跟国产极品老师| 国产一区二区0| 久久精品久久综合| 日韩在线观看一区二区| 亚洲国产三级在线| 亚洲欧美国产三级| 国产精品久久久久一区| 国产色91在线| 久久人人97超碰com| 欧美成人猛片aaaaaaa| 久久精品人人做| 欧美老人xxxx18| 欧美亚洲精品一区| 色婷婷av久久久久久久| 成人高清免费观看| 成人一区二区三区在线观看 | 日本成人中文字幕| 日韩在线a电影| 丝袜美腿高跟呻吟高潮一区| 亚洲主播在线观看| 一区二区三区中文字幕精品精品 | 国产老女人精品毛片久久| 麻豆成人综合网| 日本v片在线高清不卡在线观看| 亚洲成人av资源| 日韩精品三区四区| 日本欧美一区二区| 青青草97国产精品免费观看 | 播五月开心婷婷综合| 成人在线一区二区三区| 成人av午夜影院| 91毛片在线观看| 91成人免费网站| 欧美日韩在线三级| 6080午夜不卡| 欧美大片在线观看| 久久伊人蜜桃av一区二区| 国产夜色精品一区二区av| 国产视频一区二区在线观看| 国产精品麻豆视频| 亚洲男人的天堂一区二区| 一区二区三区免费| 亚洲电影欧美电影有声小说| 日日摸夜夜添夜夜添精品视频 | 日韩天堂在线观看| 欧美一区午夜精品| 欧美va亚洲va香蕉在线| 久久久精品综合| 一色屋精品亚洲香蕉网站| 亚洲综合激情另类小说区| 亚洲成av人片在线| 麻豆91在线播放免费| 激情欧美一区二区| 成人激情免费网站| 91黄色在线观看| 91精品国产综合久久福利 | 精品国精品国产尤物美女| 久久久久久影视| 国产精品天美传媒| 夜夜操天天操亚洲| 麻豆国产精品视频| 岛国av在线一区| 在线观看视频欧美| 日韩三级视频在线看| 国产丝袜欧美中文另类| 亚洲一区二区三区四区五区中文| 日韩电影在线观看网站| 国产露脸91国语对白| 色婷婷久久99综合精品jk白丝| 欧美伦理视频网站| 国产日韩欧美高清| 亚洲尤物视频在线| 精品一区二区三区欧美| 91亚洲国产成人精品一区二区三| 欧美日韩国产在线观看| 国产婷婷色一区二区三区| 亚洲综合无码一区二区| 韩国v欧美v日本v亚洲v| 91视频在线观看| 91精品国产欧美一区二区成人| 国产日韩欧美a| 亚洲大型综合色站| 国产高清不卡一区| 中文字幕一区二区三区视频| 日本一区二区三区四区在线视频| 亚洲一区二区偷拍精品| 国产精品一色哟哟哟| 在线观看一区日韩| 久久女同互慰一区二区三区| 一区二区日韩av| 理论电影国产精品| 色香蕉久久蜜桃| 久久综合九色综合97婷婷女人| 一区二区三区在线播放| 国内精品国产成人国产三级粉色 | 成人黄色片在线观看| 欧美丰满少妇xxxbbb| 国产精品三级av在线播放| 日韩国产精品久久久久久亚洲| 成人av动漫在线| 日韩欧美美女一区二区三区| 亚洲欧美一区二区久久| 精品一区二区三区的国产在线播放| thepron国产精品| 精品人伦一区二区色婷婷| 一区二区三区影院| 国产精品资源在线| 7777精品伊人久久久大香线蕉 | 国产精品水嫩水嫩| 日韩av不卡在线观看| 91性感美女视频| 久久久精品免费免费| 琪琪久久久久日韩精品| 91浏览器打开| 亚洲国产精品精华液ab| 久久国产精品区| 欧美日韩一区二区三区在线| 亚洲一区二区三区四区在线免费观看 | 成人免费看视频|