static void test(void *stack_pointer) { mps_arena_t arena; mps_pool_t pool; mps_addr_t block[ITERATIONS]; unsigned i; MPS_ARGS_BEGIN(args) { MPS_ARGS_ADD(args, MPS_KEY_ARENA_SIZE, CHUNKSIZE); die(mps_arena_create_k(&arena, mps_arena_class_vm(), args), "arena_create"); } MPS_ARGS_END(args); MPS_ARGS_BEGIN(args) { MPS_ARGS_ADD(args, MPS_KEY_SPARE, 0); die(mps_pool_create_k(&pool, arena, mps_class_mvff(), args), "pool_create"); } MPS_ARGS_END(args); check_chunks(arena, 1); for (i = 0; i < ITERATIONS; ++i) { die(mps_alloc(&block[i], pool, CHUNKSIZE), "mps_alloc"); check_chunks(arena, i + 2); } for (i = ITERATIONS; i > 0; --i) { mps_free(pool, block[i - 1], CHUNKSIZE); mps_arena_collect(arena); /* ensure ArenaCompact is called */ check_chunks(arena, i); } mps_pool_destroy(pool); mps_arena_destroy(arena); }
void mrbig(void) { char *p; time_t t, lastrun; int sleeptime, i; char hostname[256]; DWORD hostsize; /* * install exception logging/stacktrace handler. * We need to resolve the symbol at run time because windows 2000 * does not have it. */ do { HMODULE dll; PVOID (*ptr) (ULONG First,PVECTORED_EXCEPTION_HANDLER Handler) = NULL; dll = LoadLibraryEx("kernel32.dll", NULL, 0); if (dll == NULL) break; ptr = (typeof(ptr))GetProcAddress(dll, "AddVectoredExceptionHandler"); if (ptr == NULL) break; ptr(1, VectoredExceptionHandler); mrlog("VectoredExceptionHandler handler has been installed"); } while(0); if (debug) { mrlog("mrbig()"); } for (i = 0; _environ[i]; i++) { startup_log("%s", _environ[i]); } for (;;) { if (debug) mrlog("main loop"); read_cfg("mrbig", cfgfile); readcfg(); t = time(NULL); strlcpy(now, ctime(&t), sizeof now); p = strchr(now, '\n'); if (p) *p = '\0'; hostsize = sizeof hostname; if (GetComputerName(hostname, &hostsize)) { for (i = 0; hostname[i]; i++) hostname[i] = tolower(hostname[i]); snprcat(now, sizeof now, " [%s]", hostname); } cpu(); check_chunks("after cpu test"); disk(); check_chunks("after disk test"); memory(); check_chunks("after memory test"); msgs(); check_chunks("after msgs test"); procs(); check_chunks("after procs test"); svcs(); check_chunks("after svcs test"); wmi(); check_chunks("after wmi test"); if (pickupdir[0]) ext_tests(); lastrun = t; t = time(NULL); if (t < lastrun) { mrlog("mainloop: timewarp detected, sleep for %d", mrloop); sleeptime = mrloop; } else { sleeptime = mrloop-(t-lastrun); } if (sleeptime < SLEEP_MIN) sleeptime = SLEEP_MIN; if (debug) mrlog("started at %d, finished at %d, sleep for %d", (int)lastrun, (int)t, sleeptime); clear_cfg(); if (debug) { dump_chunks(); check_chunks("after main loop"); } Sleep(sleeptime*1000); } }
int main(int argc, char **argv) { int i; char *p; startup_log("main()"); dirsep = '\\'; GetModuleFileName(NULL, cfgdir, sizeof cfgdir); startup_log("cfgdir = '%s'", cfgdir); p = strrchr(cfgdir, dirsep); if (p) *p = '\0'; cfgfile[0] = '\0'; snprcat(cfgfile, sizeof cfgfile, "%s%c%s", cfgdir, dirsep, "mrbig.cfg"); startup_log("cfgfile = '%s'", cfgfile); startup_log("SystemRoot = '%s'", getenv("SystemRoot")); for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-c")) { i++; if (argv[i] == NULL) { fprintf(stderr, "No cfg file\n"); return EXIT_FAILURE; } } else if (!strcmp(argv[i], "-d")) { debug++; } else if (!strcmp(argv[i], "-m")) { debug_memory = 1; } else if (!strncmp(argv[i], "-i", 2)) { if (argv[i][2] == '\0') { install_service("MrBig", "Mr Big Monitoring Agent"); } else { install_service(argv[i]+2, argv[i]+2); } return 0; } else if (!strncmp(argv[i], "-u", 2)) { if (argv[i][2] == '\0') { delete_service("MrBig"); } else { delete_service(argv[i]+2); } return 0; } else if (!strcmp(argv[i], "-t")) { standalone = 1; } else { fprintf(stderr, "Bogus option '%s'\n", argv[i]); usage(); } } if (standalone) { mrbig(); return 0; } startup_log("We want to become a service"); service_main(argc, argv); dump_chunks(); check_chunks("just before exit"); dump_files(); return 0; }