static int init_glog() { char *logname = myconfig_get_value("log_main_logname"); if (!logname) logname = "./main_log.log"; char *cloglevel = myconfig_get_value("log_main_loglevel"); int loglevel = LOG_NORMAL; if (cloglevel) loglevel = getloglevel(cloglevel); int logsize = myconfig_get_intval("log_main_logsize", 100); int logintval = myconfig_get_intval("log_main_logtime", 3600); int lognum = myconfig_get_intval("log_main_lognum", 10); glogfd = registerlog(logname, loglevel, logsize, logintval, lognum); return glogfd; }
int init_pfs_time_stamp() { char *datadir = myconfig_get_value("pfs_path"); if (datadir == NULL) datadir = "../data"; char tmpfile[256] = {0x0}; snprintf(tmpfile, sizeof(tmpfile), "%s/pfs_time_stamp", datadir); struct stat filestat; if (stat(tmpfile, &filestat)) LOG(glogfd, LOG_ERROR, "%s not exit init it!\n", tmpfile); fd_time_stamp = open(tmpfile, O_CREAT | O_RDWR | O_LARGEFILE, 0644); if (fd_time_stamp < 0) { LOG(glogfd, LOG_ERROR, "open %s err %m\n", tmpfile); return -1; } if (ftruncate(fd_time_stamp, sizeof(t_time_stamp) * DIR1 * DIR2)) { LOG(glogfd, LOG_ERROR, "ftruncate %s err %m\n", tmpfile); return -1; } t_pfs_timer pfs_timer; memset(&pfs_timer, 0, sizeof(pfs_timer)); pfs_timer.span_time = 600; pfs_timer.cb = sync_fd; pfs_timer.loop = 1; if (add_to_delay_task(&pfs_timer)) LOG(glogfd, LOG_ERROR, "add delay task err %m\n"); return 0; }
int get_localdir(char *hostname, char *srcfile, char *dstfile) { char tmpfile[256] = {0x0}; snprintf(tmpfile, sizeof(tmpfile), "%s", srcfile); char *p = basename(tmpfile); sprintf(dstfile, "%s/%s/%s", myconfig_get_value("vfs_dst_datadir"), hostname, p); return 0; }
static int init_redis() { char *ip = myconfig_get_value("redis_server"); if (ip == NULL) { LOG(vfs_http_log, LOG_ERROR, "config have not redis_server!\n"); return -1; } return redis_connect(ip, myconfig_get_intval("redis_port", 16379)); }
static int active_connect() { char *ip = myconfig_get_value("iplist_serverip"); int port = g_config.sig_port; int fd = createsocket(ip, port); if (fd < 0) { LOG(vfs_sig_log, LOG_ERROR, "connect %s:%d err %m\n", ip, port); return -1; } if (svc_initconn(fd)) { LOG(vfs_sig_log, LOG_ERROR, "svc_initconn err %m\n"); close(fd); return -1; } add_fd_2_efd(fd); LOG(vfs_sig_log, LOG_NORMAL, "fd [%d] connect %s:%d\n", fd, ip, port); return fd; }
static void start_inotify_thread(void * arg) { #ifndef PR_SET_NAME #define PR_SET_NAME 15 #endif memset(watch_dirs, 0, sizeof(watch_dirs)); prctl(PR_SET_NAME, "fcs_inotify", 0, 0, 0); pthread_detach(pthread_self()); inotify_fd = inotify_init(); if(inotify_fd < 0) { stop = 1; LOG(vfs_sig_log, LOG_ERROR, "inotify thread init error!\n"); return ; } char *flvdir = myconfig_get_value("vfs_src_datadir"); if(!flvdir) { flvdir = "/flvdata"; } FD_ZERO(&fds); FD_SET(inotify_fd, &fds); int ret = add_watch(inotify_fd, flvdir, mask); if(ret != 0) { stop = 1; LOG(vfs_sig_log, LOG_ERROR, "inotify add watch dir error!\n"); return ; } LOG(vfs_sig_log, LOG_DEBUG, "start to inotify watch dir\n"); struct timeval tv; //Ñ»·¼ì²éʼþ while(1) { tv.tv_sec = 20; tv.tv_usec = 0; if (select(inotify_fd + 1, &fds, NULL, NULL, &tv) > 0) { while (1) { int len, index = 0; unsigned char buf[1024] = {0}; len = read(inotify_fd, &buf, sizeof(buf)); if (len <= 0) break; while (index < len) { struct inotify_event *event = (struct inotify_event *)(buf + index); inotify_event_handler(event); index += sizeof(struct inotify_event) + event->len; } } } FD_ZERO(&fds); FD_SET(inotify_fd, &fds); } }
int init_para(t_path_info * path) { char *v = myconfig_get_value("log_logname"); if (v == NULL) { fprintf(stderr, "config have not logname!\n"); return -1; } char *logfile = v; int loglevel = getloglevel(myconfig_get_value("log_loglevel")); int logsize = myconfig_get_intval("log_logsize", 100); int logtime = myconfig_get_intval("log_logtime", 3600); int logcount = myconfig_get_intval("log_logcount", 10); if (init_log()) { fprintf(stderr, "init log error %m\n"); return -1; } fplog = registerlog(logfile, loglevel, logsize, logtime, logcount); if (fplog < 0) { fprintf(stderr, "registerlog %s %m\n", logfile); return -1; } v = myconfig_get_value("path_workdir"); if (v == NULL) { LOG(fplog, LOG_ERROR, "config have not path_workdir!\n"); return -1; } snprintf(path->workdir, sizeof(path->workdir), "%s", v); v = myconfig_get_value("path_indir"); if (v == NULL) { LOG(fplog, LOG_ERROR, "config have not path_indir!\n"); return -1; } snprintf(path->indir, sizeof(path->indir), "%s", v); v = myconfig_get_value("path_outdir"); if (v == NULL) { LOG(fplog, LOG_ERROR, "config have not path_outdir!\n"); return -1; } snprintf(path->outdir, sizeof(path->outdir), "%s", v); v = myconfig_get_value("path_bkdir"); if (v == NULL) { LOG(fplog, LOG_ERROR, "config have not path_bkdir!\n"); return -1; } snprintf(path->bkdir, sizeof(path->bkdir), "%s", v); v = myconfig_get_value("path_fulldir"); if (v == NULL) { LOG(fplog, LOG_ERROR, "config have not path_fulldir!\n"); return -1; } snprintf(path->fulldir, sizeof(path->fulldir), "%s", v); v = myconfig_get_value("path_tmpdir"); if (v == NULL) { LOG(fplog, LOG_ERROR, "config have not path_tmpdir!\n"); return -1; } snprintf(path->tmpdir, sizeof(path->tmpdir), "%s", v); memset(taskfile_prefix, 0, sizeof(taskfile_prefix)); v = myconfig_get_value("path_taskfile_prefix"); if (v == NULL) snprintf(taskfile_prefix, sizeof(taskfile_prefix), "%s", "/home/webadm/"); else snprintf(taskfile_prefix, sizeof(taskfile_prefix), "%s", v); prefix_len = strlen(taskfile_prefix); return 0; }