int main (int argc, const char * argv[]) { struct settings *settings = local_config(); settings->hash_power = 0; settings->prealloc = true; settings->evict_opt = EVICT_LRU; settings->maxbytes = 200 * 1024 * 1024; settings->slab_size = 1024 * 1024; settings->use_freeq = true; settings->use_lruq = true; settings->profile_last_id = 12; int i = 0, j = 0, n = 0; for (i = 1; i < 13; i++) { settings->profile[i] = 100 * i; } bool result = local_start(); if (result) printf("cache started\n"); else { printf("cache started fail\n"); return 1; } char *key = (char*)malloc(8); char *value = (char*)malloc(900); for (i = 0; i < 10000; i++) { for (j = 0; j < 10000; j++) { int *ptr = (int*)key; *ptr = i; *(ptr++) = j; n = i + j; n = (n % 9) * 100 + 50; ptr = (int*)value; *ptr = i; *(ptr + n - 4) = j; result = local_put(key, 8, 10, value, n); if (!result) { printf("cache put item fail\n"); printf("%d %d\n", i, j); return 1; } struct item *res = local_get(key, 8); if (res == NULL || res->nbyte != n) { printf("cache get item fail\n"); printf("%d %d\n", i, j); return 1; } char *data = item_data(res); if (*((int*)data) != i) { printf("cache get value fail\n"); printf("%d %d\n", i, j); return 1; } } } return 0; }
/** void WINAPI OssecServiceStart (DWORD argc, LPTSTR *argv) * Starts OSSEC service */ void WINAPI OssecServiceStart (DWORD argc, LPTSTR *argv) { ossecServiceStatus.dwServiceType = SERVICE_WIN32; ossecServiceStatus.dwCurrentState = SERVICE_START_PENDING; ossecServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP; ossecServiceStatus.dwWin32ExitCode = 0; ossecServiceStatus.dwServiceSpecificExitCode= 0; ossecServiceStatus.dwCheckPoint = 0; ossecServiceStatus.dwWaitHint = 0; ossecServiceStatusHandle = RegisterServiceCtrlHandler(g_lpszServiceName, OssecServiceCtrlHandler); if (ossecServiceStatusHandle == (SERVICE_STATUS_HANDLE)0) { merror("%s: RegisterServiceCtrlHandler failed.", ARGV0); return; } ossecServiceStatus.dwCurrentState = SERVICE_RUNNING; ossecServiceStatus.dwCheckPoint = 0; ossecServiceStatus.dwWaitHint = 0; if (!SetServiceStatus(ossecServiceStatusHandle, &ossecServiceStatus)) { merror("%s: SetServiceStatus error.", ARGV0); return; } #ifdef OSSECHIDS /* Starting process */ local_start(); #endif }
/** main(int argc, char **argv) * .. */ int main(int argc, char **argv) { char *tmpstr; char mypath[OS_MAXSTR +1]; char myfinalpath[OS_MAXSTR +1]; char myfile[OS_MAXSTR +1]; /* Setting the name */ OS_SetName(ARGV0); /* Find where I'm */ mypath[OS_MAXSTR] = '\0'; myfinalpath[OS_MAXSTR] = '\0'; myfile[OS_MAXSTR] = '\0'; /* mypath is going to be the whole path of the file */ strncpy(mypath, argv[0], OS_MAXSTR); tmpstr = strrchr(mypath, '\\'); if(tmpstr) { /* tmpstr is now the file name */ *tmpstr = '\0'; tmpstr++; strncpy(myfile, tmpstr, OS_MAXSTR); } else { strncpy(myfile, argv[0], OS_MAXSTR); mypath[0] = '.'; mypath[1] = '\0'; } chdir(mypath); getcwd(mypath, OS_MAXSTR -1); snprintf(myfinalpath, OS_MAXSTR, "\"%s\\%s\"", mypath, myfile); if(argc > 1) { if(strcmp(argv[1], "install-service") == 0) { return(InstallService(myfinalpath)); } else if(strcmp(argv[1], "uninstall-service") == 0) { return(UninstallService()); } else if(strcmp(argv[1], "start") == 0) { return(local_start()); } else if(strcmp(argv[1], "-h") == 0) { agent_help(); } else if(strcmp(argv[1], "help") == 0) { agent_help(); } else { merror("%s: Unknown option: %s", ARGV0, argv[1]); exit(1); } } /* Start it */ if(!os_WinMain(argc, argv)) { ErrorExit("%s: Unable to start WinMain.", ARGV0); } return(0); }