int check_zoo_options(struct zoodis *zoodis) { if(zoodis->zoo_host != NULL || zoodis->zoo_path != NULL || zoodis->zoo_nodename != NULL) { if(zoodis->zoo_host == NULL || zoodis->zoo_path == NULL || zoodis->zoo_nodename == NULL) { log_err("--zoo-host, --zoo-path and --zoo-nodename are mandatory for using zookeeper server."); exit_proc(-1); } } if(zoodis->zoo_nodedata != NULL) { if(zoodis->zoo_host == NULL || zoodis->zoo_path == NULL || zoodis->zoo_nodename == NULL) { log_err("--zoo-host, --zoo-path and --zoo-nodename are mandatory for using zookeeper server."); exit_proc(-1); } } if(zoodis->zoo_host == NULL || zoodis->zoo_path == NULL || zoodis->zoo_nodename == NULL) { return 0; } return 1; }
int main(int argc, char **argv) { char *config_xml; if (argc != 2) { printf("Usage: %s config.xml \n", argv[0]); return (EXIT_SUCCESS); } // GET Ctrl+C signal; signal(SIGINT, exit_proc); /** Read configure file */ config_xml = argv[1]; parse_doc(config_xml); /** Initialize NFQUEUE forwarding process, logging files e.t.c */ if(!nfqp_init() || !glb_init() || !stats_init() /* MYSQL , */){ exit_proc(); } nfqp_analyzer_function(); return(EXIT_SUCCESS); }
void exec_redis() { pid_t pid; pid = fork(); if(pid < 0) { log_err("Redis: Failed forming process, %s", strerror(errno)); exit_proc(-1); } if(pid == 0) { if(execl(zoodis.redis_bin->data, zoodis.redis_bin->data, zoodis.redis_conf->data, NULL) < 0) { log_err("Redis: failed to execute redis daemon. %s", strerror(errno)); } }else { zoodis.redis_pid = pid; zoodis.redis_stat = REDIS_STAT_EXECUTED; log_info("Redis: started redis daemon."); sleep(DEFAULT_REDIS_SLEEP_AFTER_EXEC); redis_health(); } return; }
/*===========================================================================* * do_exit * *===========================================================================*/ PUBLIC int do_exit() { /* Perform the exit(status) system call. The real work is done by exit_proc(), * which is also called when a process is killed by a signal. */ exit_proc(mp, m_in.status, FALSE /*dump_core*/); return(SUSPEND); /* can't communicate from beyond the grave */ }
struct mstr* check_redis_conf(char *optarg) { struct stat stat_bin; int res; if(strlen(optarg) == 0) { log_err("path of redis-conf option must not be empty."); exit_proc(-1); } res = lstat(optarg, &stat_bin); // check stat readable if(res < 0) { log_err("%s, %s", strerror(errno), optarg); exit_proc(-1); } // check regular file if(!S_ISREG(stat_bin.st_mode)) { log_err("%s is not a regular file.", optarg); exit_proc(-1); } // check executable or not if( stat_bin.st_mode & S_IROTH || (getgid() == stat_bin.st_gid && stat_bin.st_mode & S_IRGRP) || (getuid() == stat_bin.st_uid && stat_bin.st_mode & S_IRUSR )) { return mstr_alloc_dup(optarg, strlen(optarg)); }else { log_err("%s is not an readable.", optarg); exit_proc(-1); return NULL; } }
const char* check_pid_file(const char *pid_file) { int fd, res; pid_t pid = getpid(); struct flock flock; zoodis.pid_fp = fopen(pid_file, "r+"); if(zoodis.pid_fp == NULL) { zoodis.pid_fp = fopen(pid_file, "w"); if(zoodis.pid_fp == NULL) { log_err("Cannot open pid file %s, %s", pid_file, strerror(errno)); exit_proc(-1); } } fd = fileno(zoodis.pid_fp); memset(&flock, 0x00, sizeof(struct flock)); flock.l_type = F_WRLCK; res = fcntl(fd, F_SETLK, &flock); if(res < 0) { log_err("Another zoodis process is running. PID:%s", pid_file); fclose(zoodis.pid_fp); exit_proc(-1); } log_info("PID file %s", pid_file); fseek(zoodis.pid_fp, 0L, SEEK_SET); res = fprintf(zoodis.pid_fp, "%d", pid); res = ftruncate(fd, (off_t)ftell(zoodis.pid_fp)); fflush(zoodis.pid_fp); return pid_file; }
void signal_sigint(int sig) { signal(SIGCHLD, SIG_IGN); log_debug("Signal: Received shutdown singal, NO:%d", sig); log_info("Suspending zoodis,", sig); zoodis.keepalive = 0; if(zoodis.redis_stat == REDIS_STAT_EXECUTED || zoodis.redis_stat == REDIS_STAT_OK || zoodis.redis_stat == REDIS_STAT_ABNORMAL) { redis_kill(); } exit_proc(0); }
/*===========================================================================* * do_exit * *===========================================================================*/ PUBLIC int do_exit() { /* Perform the exit(status) system call. The real work is done by exit_proc(), * which is also called when a process is killed by a signal. System processes * do not use PM's exit() to terminate. If they try to, we warn the user * and send a SIGKILL signal to the system process. */ if(mp->mp_flags & PRIV_PROC) { printf("PM: system process %d (%s) tries to exit(), sending SIGKILL\n", mp->mp_endpoint, mp->mp_name); sys_kill(mp->mp_endpoint, SIGKILL); } else { exit_proc(mp, m_in.status, FALSE /*dump_core*/); } return(SUSPEND); /* can't communicate from beyond the grave */ }
int check_redis_options(struct zoodis *zoodis) { if(zoodis->redis_bin == NULL || zoodis->redis_conf == NULL) { log_err("--redis-bin, --redis-conf are mandatory."); exit_proc(-1); } if(zoodis->redis_port == 0) zoodis->redis_port = DEFAULT_REDIS_PORT; memset(&zoodis->redis_addr, 0, sizeof(struct sockaddr_in)); zoodis->redis_addr.sin_family = AF_INET; zoodis->redis_addr.sin_port = htons(zoodis->redis_port); zoodis->redis_addr.sin_addr.s_addr= inet_addr(DEFAULT_REDIS_IP); return 1; }
int main(int argc, char **argv) { char *binary = "binary"; char binary_buf[64]; Obj_Entry *objp; func_ptr_type exit_proc; int fd = open(binary, O_RDONLY); /* find file name of file descriptor */ if (!find_binary_name(fd, binary_buf, sizeof(binary_buf))) binary = binary_buf; /* build dummy stack */ void *sp = setup_stack(binary, (long)fd); /* DEBUGGING printf("Starting ldso ...\n"); */ /* this is usually '_start' */ func_ptr_type main_func = _rtld(sp, &exit_proc, &objp); /* DEBUGGING char **p; for(p = environ; *p; p++) printf("env: %s\n", *p); printf("Starting application ... environ: %p\n", lx_environ); */ /* start loaded application */ call_main(main_func); exit_proc(); printf("Exiting ldso\n"); return 0; }
static int set_mode ( int mode, int w, int h, int depth, int scanline_size, int num_pages, int refresh_rate, int palette, int font, int flags, float aspect, int text_w, int text_h ) { const GFXDRIVER *driver = NULL; FB_GFXCTX *context; int i, j, try_count; char *c, *driver_name; unsigned char *dest; /* normalize flags */ if ((flags >= 0) && (flags & DRIVER_SHAPED_WINDOW)) flags |= DRIVER_SHAPED_WINDOW | DRIVER_NO_FRAME | DRIVER_NO_SWITCH; release_gfx_mem(); if( (mode == 0) || (w == 0) ) { memset(&__fb_ctx.hooks, 0, sizeof(__fb_ctx.hooks)); if (flags != SCREEN_EXIT) { /* set and clear text screen mode or the width and line_len will be wrong */ fb_Width( 80, 25 ); fb_Cls( 0 ); } /* reset viewport to console dimensions */ fb_ConsoleSetTopBotRows(-1, -1); } else { __fb_ctx.hooks.inkeyproc = fb_GfxInkey; __fb_ctx.hooks.getkeyproc = fb_GfxGetkey; __fb_ctx.hooks.keyhitproc = fb_GfxKeyHit; __fb_ctx.hooks.clsproc = fb_GfxClear; __fb_ctx.hooks.colorproc = fb_GfxColor; __fb_ctx.hooks.locateproc = fb_GfxLocate; __fb_ctx.hooks.widthproc = fb_GfxWidth; __fb_ctx.hooks.getxproc = fb_GfxGetX; __fb_ctx.hooks.getyproc = fb_GfxGetY; __fb_ctx.hooks.getxyproc = fb_GfxGetXY; __fb_ctx.hooks.getsizeproc = fb_GfxGetSize; __fb_ctx.hooks.printbuffproc = fb_GfxPrintBufferEx; __fb_ctx.hooks.printbuffwproc = fb_GfxPrintBufferWstrEx; __fb_ctx.hooks.readstrproc = fb_GfxReadStr; __fb_ctx.hooks.multikeyproc = fb_GfxMultikey; __fb_ctx.hooks.getmouseproc = fb_GfxGetMouse; __fb_ctx.hooks.setmouseproc = fb_GfxSetMouse; __fb_ctx.hooks.inproc = fb_GfxIn; __fb_ctx.hooks.outproc = fb_GfxOut; __fb_ctx.hooks.viewupdateproc = fb_GfxViewUpdate; __fb_ctx.hooks.lineinputproc = fb_GfxLineInput; __fb_ctx.hooks.lineinputwproc = fb_GfxLineInputWstr; __fb_ctx.hooks.readxyproc = fb_GfxReadXY; __fb_ctx.hooks.sleepproc = fb_GfxSleep; __fb_ctx.hooks.isredirproc = fb_GfxIsRedir; __fb_ctx.hooks.pagecopyproc = fb_GfxPageCopy; __fb_ctx.hooks.pagesetproc = fb_GfxPageSet; __fb_gfx = (FBGFX *)calloc(1, sizeof(FBGFX)); } if (__fb_gfx) { __fb_gfx->id = screen_id++; __fb_gfx->mode_num = mode; __fb_gfx->w = w; __fb_gfx->h = h; __fb_gfx->depth = depth; if ((flags >= 0) && (flags & DRIVER_OPENGL)) __fb_gfx->depth = MAX(16, __fb_gfx->depth); __fb_gfx->default_palette = (palette >= 0) ? &__fb_palette[palette] : NULL; __fb_gfx->scanline_size = scanline_size; __fb_gfx->font = (font >= 0) ? &__fb_font[font] : NULL; if( aspect != 0.0f ) __fb_gfx->aspect = aspect; else __fb_gfx->aspect = (4.0 / 3.0) * ((float)__fb_gfx->h / (float)__fb_gfx->w); switch (__fb_gfx->depth) { case 15: case 16: __fb_gfx->color_mask = 0xFFFF; __fb_gfx->depth = 16; break; case 24: case 32: __fb_gfx->color_mask = 0xFFFFFFFF; __fb_gfx->depth = 32; break; default: __fb_gfx->color_mask = (1 << __fb_gfx->depth) - 1; } __fb_gfx->bpp = BYTES_PER_PIXEL(__fb_gfx->depth); __fb_gfx->pitch = __fb_gfx->w * __fb_gfx->bpp; __fb_gfx->page = (unsigned char **)malloc(sizeof(unsigned char *) * num_pages); for (i = 0; i < num_pages; i++) { /* 0xF for the para alignment, p_size is sizeof(void *) rounded up to % 16 for the storage for the original pointer */ int p_size = (sizeof(void *) + 0xF) & 0xF; void *tmp = malloc((__fb_gfx->pitch * __fb_gfx->h) + p_size + 0xF); __fb_gfx->page[i] = (unsigned char *)(((intptr_t)tmp + p_size + 0xF) & ~0xF); ((void **)(__fb_gfx->page[i]))[-1] = tmp; } __fb_gfx->num_pages = num_pages; __fb_gfx->framebuffer = __fb_gfx->page[0]; /* dirty lines array may be bigger than needed; this is to please the gfx driver which is not aware of the scanline size */ __fb_gfx->dirty = (char *)calloc(1, __fb_gfx->h * __fb_gfx->scanline_size); __fb_gfx->device_palette = (unsigned int *)calloc(1, sizeof(int) * 256); __fb_gfx->palette = (unsigned int *)calloc(1, sizeof(int) * 256); __fb_gfx->color_association = (unsigned char *)malloc(16); __fb_gfx->key = (char *)calloc(1, 128); __fb_gfx->event_queue = (EVENT *)malloc(sizeof(EVENT) * MAX_EVENTS); __fb_gfx->event_mutex = fb_MutexCreate(); __fb_color_conv_16to32 = (unsigned int *)malloc(sizeof(int) * 512); if (flags != DRIVER_NULL) { if (flags & DRIVER_ALPHA_PRIMITIVES) __fb_gfx->flags |= ALPHA_PRIMITIVES; if (flags & DRIVER_OPENGL) __fb_gfx->flags |= OPENGL_SUPPORT; if (flags & DRIVER_HIGH_PRIORITY) __fb_gfx->flags |= HIGH_PRIORITY; } fb_hSetupFuncs(__fb_gfx->bpp); fb_hSetupData(); if (!__fb_window_title) { __fb_window_title = fb_hGetExeName( window_title_buff, WINDOW_TITLE_SIZE - 1 ); if ((c = strrchr(__fb_window_title, '.'))) *c = '\0'; } driver_name = __fb_gfx_driver_name; if (!driver_name) driver_name = getenv("FBGFX"); if ((flags == DRIVER_NULL) || ((driver_name) && (!strcasecmp(driver_name, "null")))) driver = &__fb_gfxDriverNull; else { for (try_count = (driver_name ? 4 : 2); try_count; try_count--) { for (i = 0; __fb_gfx_drivers_list[i >> 1]; i++) { driver = __fb_gfx_drivers_list[i >> 1]; if ((driver_name) && !(try_count & 0x1) && (strcasecmp(driver_name, driver->name))) { driver = NULL; continue; } if (!driver->init(__fb_window_title, __fb_gfx->w, __fb_gfx->h * __fb_gfx->scanline_size, __fb_gfx->depth, (i & 0x1) ? 0 : refresh_rate, flags)) break; driver->exit(); driver = NULL; } if (driver) break; if (driver_name) { if (try_count == 3) flags ^= DRIVER_FULLSCREEN; } else flags ^= DRIVER_FULLSCREEN; } } if (!driver) { exit_proc(); return fb_ErrorSetNum(FB_RTERROR_ILLEGALFUNCTIONCALL); } __fb_gfx->driver = driver; fb_GfxPalette(-1, 0, 0, 0); __fb_gfx->text_w = text_w; __fb_gfx->text_h = text_h; context = fb_hGetContext(); fb_hResetCharCells(context, TRUE); for (i = 0; i < num_pages; i++) { dest = __fb_gfx->page[i]; for (j = 0; j < __fb_gfx->h; j++) { context->pixel_set(dest, context->bg_color, context->view_w); dest += __fb_gfx->pitch; } } if( !exit_proc_set ) { exit_proc_set = TRUE; atexit(exit_proc); } } if( flags!=SCREEN_EXIT ) { /* Reset VIEW PRINT * * Normally, resetting VIEW PRINT should also result in setting the cursor * position to Y,X = 1,1 but this doesn't seem to be suitable (at least * on Win32 platforms). I don't believe that this is a problem because * on DOS, the cursor position will automatically be reset when the screen * mode changes and not changing the console cursor position on Win32 * and Linux seem to be more "natural". */ fb_ConsoleViewEx( 0, 0, __fb_gfx!=NULL ); } return fb_ErrorSetNum( FB_RTERROR_OK ); }
/*===========================================================================* * do_trace * *===========================================================================*/ PUBLIC int do_trace() { register struct mproc *child; struct ptrace_range pr; int i, r, seg, req; req = m_in.request; /* The T_OK call is made by the child fork of the debugger before it execs * the process to be traced. The T_ATTACH call is made by the debugger itself * to attach to an existing process. */ switch (req) { case T_OK: /* enable tracing by parent for this proc */ if (mp->mp_tracer != NO_TRACER) return(EBUSY); mp->mp_tracer = mp->mp_parent; mp->mp_reply.reply_trace = 0; return(OK); case T_ATTACH: /* attach to an existing process */ if ((child = find_proc(m_in.pid)) == NULL) return(ESRCH); if (child->mp_flags & EXITING) return(ESRCH); /* For non-root processes, user and group ID must match. */ if (mp->mp_effuid != SUPER_USER && (mp->mp_effuid != child->mp_effuid || mp->mp_effgid != child->mp_effgid || child->mp_effuid != child->mp_realuid || child->mp_effgid != child->mp_realgid)) return(EPERM); /* Only root may trace system servers. */ if (mp->mp_effuid != SUPER_USER && (child->mp_flags & PRIV_PROC)) return(EPERM); /* System servers may not trace anyone. They can use sys_trace(). */ if (mp->mp_flags & PRIV_PROC) return(EPERM); /* Can't trace self, PM or VM. */ if (child == mp || child->mp_endpoint == PM_PROC_NR || child->mp_endpoint == VM_PROC_NR) return(EPERM); /* Can't trace a process that is already being traced. */ if (child->mp_tracer != NO_TRACER) return(EBUSY); child->mp_tracer = who_p; child->mp_trace_flags = TO_NOEXEC; sig_proc(child, SIGSTOP, TRUE /*trace*/, FALSE /* ksig */); mp->mp_reply.reply_trace = 0; return(OK); case T_STOP: /* stop the process */ /* This call is not exposed to user programs, because its effect can be * achieved better by sending the traced process a signal with kill(2). */ return(EINVAL); case T_READB_INS: /* special hack for reading text segments */ if (mp->mp_effuid != SUPER_USER) return(EPERM); if ((child = find_proc(m_in.pid)) == NULL) return(ESRCH); if (child->mp_flags & EXITING) return(ESRCH); r = sys_trace(req, child->mp_endpoint, m_in.PMTRACE_ADDR, &m_in.data); if (r != OK) return(r); mp->mp_reply.reply_trace = m_in.data; return(OK); case T_WRITEB_INS: /* special hack for patching text segments */ if (mp->mp_effuid != SUPER_USER) return(EPERM); if ((child = find_proc(m_in.pid)) == NULL) return(ESRCH); if (child->mp_flags & EXITING) return(ESRCH); #if 0 /* Should check for shared text */ /* Make sure the text segment is not used as a source for shared * text. */ child->mp_ino = 0; child->mp_dev = 0; child->mp_ctime = 0; #endif r = sys_trace(req, child->mp_endpoint, m_in.PMTRACE_ADDR, &m_in.data); if (r != OK) return(r); mp->mp_reply.reply_trace = m_in.data; return(OK); } /* All the other calls are made by the tracing process to control execution * of the child. For all these calls, the child must be stopped. */ if ((child = find_proc(m_in.pid)) == NULL) return(ESRCH); if (child->mp_flags & EXITING) return(ESRCH); if (child->mp_tracer != who_p) return(ESRCH); if (!(child->mp_flags & STOPPED)) return(EBUSY); switch (req) { case T_EXIT: /* exit */ child->mp_flags |= TRACE_EXIT; /* Defer the exit if the traced process has an VFS call pending. */ if (child->mp_flags & VFS_CALL) child->mp_exitstatus = (int) m_in.data; /* save for later */ else exit_proc(child, (int) m_in.data, FALSE /*dump_core*/); /* Do not reply to the caller until VFS has processed the exit * request. */ return(SUSPEND); case T_SETOPT: /* set trace options */ child->mp_trace_flags = m_in.data; mp->mp_reply.reply_trace = 0; return(OK); case T_GETRANGE: case T_SETRANGE: /* get/set range of values */ r = sys_datacopy(who_e, (vir_bytes) m_in.PMTRACE_ADDR, SELF, (vir_bytes) &pr, (phys_bytes) sizeof(pr)); if (r != OK) return(r); if (pr.pr_space != TS_INS && pr.pr_space != TS_DATA) return(EINVAL); if (pr.pr_size == 0 || pr.pr_size > LONG_MAX) return(EINVAL); seg = (pr.pr_space == TS_INS) ? T : D; if (req == T_GETRANGE) r = sys_vircopy(child->mp_endpoint, seg, (vir_bytes) pr.pr_addr, who_e, D, (vir_bytes) pr.pr_ptr, (phys_bytes) pr.pr_size); else r = sys_vircopy(who_e, D, (vir_bytes) pr.pr_ptr, child->mp_endpoint, seg, (vir_bytes) pr.pr_addr, (phys_bytes) pr.pr_size); if (r != OK) return(r); mp->mp_reply.reply_trace = 0; return(OK); case T_DETACH: /* detach from traced process */ if (m_in.data < 0 || m_in.data >= _NSIG) return(EINVAL); child->mp_tracer = NO_TRACER; /* Let all tracer-pending signals through the filter. */ for (i = 1; i < _NSIG; i++) { if (sigismember(&child->mp_sigtrace, i)) { (void) sigdelset(&child->mp_sigtrace, i); check_sig(child->mp_pid, i, FALSE /* ksig */); } } if (m_in.data > 0) { /* issue signal */ sig_proc(child, (int) m_in.data, TRUE /*trace*/, FALSE /* ksig */); } /* Resume the child as if nothing ever happened. */ child->mp_flags &= ~STOPPED; child->mp_trace_flags = 0; check_pending(child); break; case T_RESUME: case T_STEP: case T_SYSCALL: /* resume execution */ if (m_in.data < 0 || m_in.data >= _NSIG) return(EINVAL); if (m_in.data > 0) { /* issue signal */ sig_proc(child, (int) m_in.data, FALSE /*trace*/, FALSE /* ksig */); } /* If there are any other signals waiting to be delivered, * feign a successful resumption. */ for (i = 1; i < _NSIG; i++) { if (sigismember(&child->mp_sigtrace, i)) { mp->mp_reply.reply_trace = 0; return(OK); } } child->mp_flags &= ~STOPPED; check_pending(child); break; } r = sys_trace(req, child->mp_endpoint, m_in.PMTRACE_ADDR, &m_in.data); if (r != OK) return(r); mp->mp_reply.reply_trace = m_in.data; return(OK); }
int main(int argc, char **argv) { //----信号处理 int i = 0; for (i = 1; i <= NSIG; i++) { signal(i, SIG_IGN); } signal(SIGINT, sigINT); signal(SIGPIPE, sigPIPE); signal(SIGQUIT,sigQUIT); signal(SIGKILL,sigQUIT); signal(SIGTERM,sigQUIT); //----数据初始化 for (int i=0;i<THREADS_ARRAY_NUM;i++) { threads_array[i] = 0; memset(&Results_History[i],0,sizeof(TResult)); memset(&Results_Now[i],0,sizeof(TResult)); pthread_mutex_init(&Results_NowLock[i],NULL); } pthread_mutex_init(&m_mutex_threadid,NULL); pthread_mutex_init(&m_mutex_thread_user,NULL); memset(&g_Config,0,sizeof(g_Config)); //获取参数 if (argc == 1) { TLib_Cfg_GetConfig(CFGFILE, "Host", CFG_STRING, g_Config.m_szDestIp, "",sizeof(g_Config.m_szDestIp), "Port", CFG_INT, &(g_Config.m_iDestPort),0, "ThreadNum", CFG_INT, &(g_Config.m_iThreadNum), 30, "ThreadSleepMs", CFG_INT, &(g_Config.m_iThreadSleepMs), 0, "RunMins", CFG_INT, &(g_Config.m_iRunMins), 0, "SampleSecs", CFG_INT, &(g_Config.m_iSampleSecs), 5, "RspTimeLevel1", CFG_INT, &(g_Config.m_iTimeLevel1), 10000, "RspTimeLevel2", CFG_INT, &(g_Config.m_iTimeLevel2), 100000, "RspTimeLevel3", CFG_INT, &(g_Config.m_iTimeLevel3), 1000000, NULL); } else if (argc == 6) { strcpy(g_Config.m_szDestIp,argv[1]); g_Config.m_iDestPort = atoi(argv[2]); g_Config.m_iThreadNum = atoi(argv[3]); if(argv[4]) g_Config.m_iRunMins = atoi(argv[4]); if(argv[5]) g_Config.m_iSampleSecs = atoi(argv[5]); if(argv[6]) g_Config.m_iTimeLevel1 = atoi(argv[6]); if(argv[7]) g_Config.m_iTimeLevel2 = atoi(argv[7]); if(argv[8]) g_Config.m_iTimeLevel3 = atoi(argv[8]); } else { printf("presscall [ip] [port] [th_num] \n"); printf("presscall [ip] [port] [th_num] [run_min] [sample_sec] [time_l1] [time_l2] [time_l3]\n"); printf("example:\n"); printf("presscall 192.168.1.1 8080\n"); exit(0); } //创建线程 for( int i = 0; i<g_Config.m_iThreadNum; i++) { int ret = pthread_create(&threads_array[i],NULL,thread_func,NULL); //&tattr if (ret != 0) { printf("create thread failed :%d\n",ret); exit(1); } } printf("\nOK,running... %s:%d %dthreads %dmins time level(us):%d,%d,%d\n\n", g_Config.m_szDestIp, g_Config.m_iDestPort, g_Config.m_iThreadNum, g_Config.m_iRunMins, g_Config.m_iTimeLevel1, g_Config.m_iTimeLevel2, g_Config.m_iTimeLevel3 ); printf("TIME OK/NO/BAD/ALL=PERCENT TIPS AvgTime(ms) MaxTime(ms) L1(%d) L2(%d) L3(%d)\n", g_Config.m_iTimeLevel1,g_Config.m_iTimeLevel2,g_Config.m_iTimeLevel3); #ifdef FORTMAT_OUTPUT char pcFormatBuf[CELL_LEN_SHORT]; #endif //持续运行 if (g_Config.m_iRunMins == 0) { iSecRuned = 0; while(1) { sleep(g_Config.m_iSampleSecs); iSecRuned += g_Config.m_iSampleSecs; #ifdef FORTMAT_OUTPUT sprintf(pcFormatBuf,"%d",iSecRuned); for ( int i=strlen(pcFormatBuf); i<sizeof(pcFormatBuf);i++) { pcFormatBuf[i] = ' '; } pcFormatBuf[sizeof(pcFormatBuf)-1] = '\0'; printf("%s",pcFormatBuf); #else printf("%d ",iSecRuned); #endif if (isTimeEnd) { break; } calculate(); } } else { iSecLeft = g_Config.m_iRunMins * 60; iSecRuned = 0; while(iSecLeft>g_Config.m_iSampleSecs) { sleep(g_Config.m_iSampleSecs); iSecRuned += g_Config.m_iSampleSecs; iSecLeft -= g_Config.m_iSampleSecs; #ifdef FORTMAT_OUTPUT sprintf(pcFormatBuf,"%d",iSecLeft); for ( int i=strlen(pcFormatBuf); i<sizeof(pcFormatBuf);i++) { pcFormatBuf[i] = ' '; } pcFormatBuf[sizeof(pcFormatBuf)-1] = '\0'; printf("%s",pcFormatBuf); #else printf("%d ",iSecLeft); #endif if (isTimeEnd) { break; } calculate(); } if (!isTimeEnd && iSecLeft > 0) { sleep(iSecLeft); iSecRuned += iSecLeft; iSecLeft = 0; } } //通知线程结束 isTimeEnd = 1; exit_proc(); }
int main(int argc, char *argv[]) { signal(SIGCHLD, signal_sigchld); signal(SIGINT, signal_sigint); signal(SIGPIPE, signal_sigint); signal(SIGTERM, signal_sigint); signal(SIGTSTP, signal_sigint); signal(SIGHUP, signal_sigint); log_level(_LOG_DEBUG); log_msg("Start zoodis."); zoodis.keepalive_interval = DEFAULT_KEEPALIVE_INTERVAL; zoodis.zoo_stat = ZOO_STAT_NOT_CONNECTED; zoodis.zoo_timeout = DEFAULT_ZOO_TIMEOUT; zoodis.zoo_connect_wait_interval = DEFAULT_ZOO_CONNECT_WAIT_INTERVAL; zoodis.redis_port = DEFAULT_REDIS_PORT; zoodis.redis_ping_interval = DEFAULT_REDIS_PING_INTERVAL; zoodis.redis_pong_timeout_sec = DEFAULT_REDIS_PONG_TIMEOUT_SEC; zoodis.redis_pong_timeout_usec = DEFAULT_REDIS_PONG_TIMEOUT_USEC; zoodis.redis_max_fail_count = DEFAULT_REDIS_MAX_FAIL_COUNT; zoodis.pid_file = NULL; zoodis.redis_stat = REDIS_STAT_NONE; static struct option long_options[] = { {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'v'}, {"log-level", required_argument, 0, 'l'}, {"pid-file", required_argument, 0, 'f'}, {"keepalive", no_argument, 0, 'k'}, {"keepalive-interval", required_argument, 0, 'i'}, {"redis-bin", required_argument, 0, 'b'}, {"redis-conf", required_argument, 0, 'c'}, {"redis-port", required_argument, 0, 'r'}, {"redis-ping-interval", required_argument, 0, 's'}, {"zoo-host", required_argument, 0, 'z'}, {"zoo-path", required_argument, 0, 'p'}, {"zoo-nodename", required_argument, 0, 'n'}, {"zoo-nodedata", required_argument, 0, 'd'}, {"zoo-timeout", required_argument, 0, 't'}, {0, 0, 0, 0} }; enum zoo_res zres; if(argc < 3) print_help(argv); while (1) { /* getopt_long stores the option index here. */ int option_index = 0; int opt; opt = getopt_long_only(argc, argv, "", long_options, &option_index); /* Detect the end of the options. */ if (opt == -1) break; switch (opt) { case 'h': print_help(argv); break; case 'v': print_version(argv); break; case 'l': set_logging(optarg); break; case 'k': zoodis.keepalive = 1; break; case 'f': zoodis.pid_file = check_pid_file(optarg); case 'i': zoodis.keepalive_interval = check_option_int(optarg, DEFAULT_KEEPALIVE_INTERVAL); break; case 'b': zoodis.redis_bin = check_redis_bin(optarg); break; case 'c': zoodis.redis_conf = check_redis_conf(optarg); break; case 'r': zoodis.redis_port = check_option_int(optarg, DEFAULT_REDIS_PORT); break; case 's': zoodis.redis_ping_interval = check_option_int(optarg, DEFAULT_REDIS_PING_INTERVAL); break; case 'z': zoodis.zoo_host = check_zoo_host(optarg); break; case 'p': zoodis.zoo_path = check_zoo_path(optarg); break; case 'n': zoodis.zoo_nodename = check_zoo_nodename(optarg); break; case 'd': zoodis.zoo_nodedata = check_zoo_nodedata(optarg); break; case 't': zoodis.zoo_timeout = check_option_int(optarg, DEFAULT_ZOO_TIMEOUT); break; default: exit_proc(-1); } } zoodis.zookeeper = check_zoo_options(&zoodis); if(zoodis.zoo_nodedata == NULL) zoodis.zoo_nodedata = mstr_alloc_dup(DEFAULT_ZOO_NODEDATA, strlen(DEFAULT_ZOO_NODEDATA)); check_redis_options(&zoodis); if(zoodis.zookeeper) { zoodis.zoo_nodepath = mstr_concat(3, zoodis.zoo_path->data, "/", zoodis.zoo_nodename->data); zu_set_log_level(log_level(0)); zu_set_log_stream(log_fd(stdout)); zres = zu_connect(&zoodis); if(zres != ZOO_RES_OK) { exit_proc(-1); } } // sleep(1); // while(zoodis.zoo_stat != ZOO_STAT_CONNECTED) // if(zoodis.zoo_stat != ZOO_STAT_CONNECTED) // { // log_warn("Zookeeper: is not connected yet."); // sleep(zoodis.zoo_connect_wait_interval); // } exec_redis(); redis_health(); return 0; }