int main(int argc, char *argv[]) { bool chook = false; int client = false; int dinx; int disable; int ferr; int inx; char lname[10]; bool mq = false; int oid; void *res; bool rnd = false; int sleept; int snid; int spid; int status; TAD zargs[] = { { "-chook", TA_Bool, TA_NOMAX, &chook }, { "-client", TA_Bool, TA_NOMAX, &client }, { "-dloop", TA_Int, MAX_OUT, &gdloop }, { "-dsize", TA_Int, TA_NOMAX, &gdsize }, { "-ksleep", TA_Int, TA_NOMAX, &gksleep }, { "-loop", TA_Int, TA_NOMAX, &gloop }, { "-maxc", TA_Int, MAX_THR, &gmaxc }, { "-maxs", TA_Int, MAX_THR, &gmaxs }, { "-mq", TA_Bool, TA_NOMAX, &mq }, { "-nodecycle", TA_Bool, TA_NOMAX, &gnodecycle }, { "-rnd", TA_Bool, TA_NOMAX, &rnd }, { "-server", TA_Ign, TA_NOMAX, NULL }, { "-v", TA_Bool, TA_NOMAX, &gverbose }, { "-vpp", TA_Bool, TA_NOMAX, &gverbosepp }, { "", TA_End, TA_NOMAX, NULL } }; arg_proc_args(zargs, false, argc, argv); if (client && chook) test_debug_hook("c", "c"); msfs_util_init(&argc, &argv, msg_debug_hook); util_test_start(client); if (!client) setup_sig(); ferr = msg_mon_process_startup(true); // system messages TEST_CHK_FEOK(ferr); gargc = argc; // after msg_init - it removes args gargp = argv; sprintf(gprog, "%s/%s", getenv("PWD"), argv[0]); gvirtual = (getenv("SQ_VIRTUAL_NODES") != NULL); ferr = msg_mon_get_my_process_name(gname, sizeof(gname)); assert(ferr == XZFIL_ERR_OK); if (client) { msg_mon_enable_mon_messages(true); // get mon messages ferr = msg_mon_get_process_info(NULL, &gcnid, NULL); assert(ferr == XZFIL_ERR_OK); ferr = XCONTROLMESSAGESYSTEM(XCTLMSGSYS_SETSENDLIMIT, (short) (gmaxc * gdloop)); assert(ferr == XZFIL_ERR_OK); srand(1); sleept = 1000; start_server(argc, argv); sleep(1); ferr = msg_mon_open_process((char *) "$srv", // name TPT_REF(gphandle), &oid); TEST_CHK_FEOK(ferr); ferr = XPROCESSHANDLE_DECOMPOSE_(TPT_REF(gphandle), &snid, &spid); TEST_CHK_FEOK(ferr); for (inx = 0; inx < gloop; inx++) { if (mq) printf("client: inx=%d\n", inx); for (dinx = 0; dinx < gmaxc; dinx++) { sprintf(lname, "c%d", dinx); gthrc[dinx] = new MyThread(client_thr, lname, dinx); } disable = msg_test_assert_disable(); for (dinx = 0; dinx < gmaxc; dinx++) gthrc[dinx]->start(); if (rnd) sleept = (int) ((float) gksleep * (rand_r(&gseed) / (RAND_MAX + 1.0))); usleep(sleept); for (dinx = 0; dinx < gmaxc; dinx++) { status = gthrc[dinx]->join(&res); TEST_CHK_STATUSOK(status); if (gverbose) printf("joined with client %d\n", dinx); } for (dinx = 0; dinx < gmaxc; dinx++) delete gthrc[dinx]; msg_test_assert_enable(disable); } } else { msg_mon_enable_mon_messages(true); // get mon messages ferr = XCONTROLMESSAGESYSTEM(XCTLMSGSYS_SETRECVLIMIT, XMAX_SETTABLE_RECVLIMIT); assert(ferr == XZFIL_ERR_OK); pp_init(); if (!gshutdown) { for (dinx = 0; dinx < gmaxs; dinx++) { char lname[10]; sprintf(lname, "s%d", dinx); gthrs[dinx] = new SB_Thread::Thread(server_thr, lname); } for (dinx = 0; dinx < gmaxs; dinx++) gthrs[dinx]->start(); for (dinx = 0; dinx < gmaxs; dinx++) { status = gthrs[dinx]->join(&res); TEST_CHK_STATUSOK(status); if (gverbose) printf("joined with server %d\n", dinx); } } if (gverbosepp) pp_printf("exit pid=%d\n", getpid()); } if (client) { sleep(1); ferr = msg_mon_close_process(TPT_REF(gphandle)); TEST_CHK_FEOK(ferr); } ferr = msg_mon_process_shutdown(); TEST_CHK_FEOK(ferr); util_test_finish(client); return 0; }
static int gen_init(void) { struct rlimit reslimit; struct sigaction n_hand; /* * Really needed to handle large archives. We can run out of memory for * internal tables really fast when we have a whole lot of files... */ if (getrlimit(RLIMIT_DATA , &reslimit) == 0){ reslimit.rlim_cur = reslimit.rlim_max; (void)setrlimit(RLIMIT_DATA , &reslimit); } /* * should file size limits be waived? if the os limits us, this is * needed if we want to write a large archive */ if (getrlimit(RLIMIT_FSIZE , &reslimit) == 0){ reslimit.rlim_cur = reslimit.rlim_max; (void)setrlimit(RLIMIT_FSIZE , &reslimit); } /* * increase the size the stack can grow to */ if (getrlimit(RLIMIT_STACK , &reslimit) == 0){ reslimit.rlim_cur = reslimit.rlim_max; (void)setrlimit(RLIMIT_STACK , &reslimit); } /* * not really needed, but doesn't hurt */ if (getrlimit(RLIMIT_RSS , &reslimit) == 0){ reslimit.rlim_cur = reslimit.rlim_max; (void)setrlimit(RLIMIT_RSS , &reslimit); } /* * signal handling to reset stored directory times and modes. Since * we deal with broken pipes via failed writes we ignore it. We also * deal with any file size limit thorough failed writes. Cpu time * limits are caught and a cleanup is forced. */ if ((sigemptyset(&s_mask) < 0) || (sigaddset(&s_mask, SIGTERM) < 0) || (sigaddset(&s_mask,SIGINT) < 0)||(sigaddset(&s_mask,SIGHUP) < 0) || (sigaddset(&s_mask,SIGPIPE) < 0)||(sigaddset(&s_mask,SIGQUIT)<0) || (sigaddset(&s_mask,SIGXCPU) < 0)||(sigaddset(&s_mask,SIGXFSZ)<0)) { paxwarn(1, "Unable to set up signal mask"); return(-1); } memset(&n_hand, 0, sizeof n_hand); n_hand.sa_mask = s_mask; n_hand.sa_flags = 0; n_hand.sa_handler = sig_cleanup; if (setup_sig(SIGHUP, &n_hand) || setup_sig(SIGTERM, &n_hand) || setup_sig(SIGINT, &n_hand) || setup_sig(SIGQUIT, &n_hand) || setup_sig(SIGXCPU, &n_hand)) goto out; n_hand.sa_handler = SIG_IGN; if ((sigaction(SIGPIPE, &n_hand, NULL) < 0) || (sigaction(SIGXFSZ, &n_hand, NULL) < 0)) goto out; return(0); out: syswarn(1, errno, "Unable to set up signal handler"); return(-1); }