int main( int argc, char *argv[] ) { long int sleep_time; int server_port; char server_ip[] = "000.000.000.000"; LOG_OPEN(); if (argc != 5) { print_help(); exit(EXIT_SUCCESS); } else { // to do: user input validation! sensor_id = atoi(argv[1]); sleep_time = atoi(argv[2]); strncpy(server_ip, argv[3],strlen(server_ip)); server_port = atoi(argv[4]); //printf("%d %ld %s %d\n", sensor_id, sleep_time, server_ip, server_port); } srand48( time(NULL) ); // open TCP connection to the server; server is listening to SERVER_IP and PORT client = tcp_active_open( server_port, server_ip ); int i=LOOPS; signal(SIGINT, my_handler); while(running) { temperature = temperature + TEMP_DEV * ((drand48() - 0.5)/10); time(×tamp); // send data to server in this order (!!): <sensor_id><temperature><timestamp> // remark: don't send as a struct! tcp_send( client, (void *)&sensor_id, sizeof(sensor_id)); tcp_send( client, (void *)&temperature, sizeof(temperature)); tcp_send( client, (void *)×tamp, sizeof(timestamp)); LOG_PRINTF(sensor_id,temperature,timestamp); sleep(sleep_time); UPDATE(i); } i = 0; tcp_close( &client ); LOG_CLOSE(); exit(EXIT_SUCCESS); }
EXTIO_HERMES_API bool __stdcall InitHW(char *name, char *model, int & extio_type) { LOG_OPEN ("hermes"); LOG (("opened in InitHW(): %d\n", GetInstanceNumber() )) ; static bool first = true; EXTIO_BASE_TYPE extio_type_; Ethernet::Device *pDev = 0; extio_type = extio_type_.value; if (first) { if ( GetInstanceNumber() == 1 ) { first = false; ExtioCallback = NULL; pGui = new Gui (EXTIO_DEFAULT_SAMPLE_RATE); if (pHermesEth == 0) { // placement new used, in order to share it among all instances pHermes = new (bufHR) ExtioHermesRadio < EXTIO_BASE_TYPE > (EXTIO_NS); if (pHermes != 0) { pGui->setRadio (pHermes); pHermes->setSampleRate (EXTIO_DEFAULT_SAMPLE_RATE); } Flow *pFlow = new Flow (pHermes); pHermesEth = new HermesEthernet (pGui, pFlow); } Ethernet::scan_devices (); pDev = pHermesEth->found(); //rc = HermesInit (DEFAULT_SAMPLE_RATE, pHermes); // TextModeEthernet *pEth = new TextModeEthernet (pFlow); if (pDev != 0) { LOG (("HARDWARE FOUND !\n")); pGui->HermesSetHwAddressGUI (pDev); } else { LOG (("HARDWARE NOT FOUND !\n")); pGui->HermesSetHwAddressGUI (0); } } else { pHermesEth = (HermesEthernet *) bufHE; pDev = pHermesEth->found(); // point local hermes radio object pointer to shared buffer pHermes = (ExtioHermesRadio < EXTIO_BASE_TYPE > *) bufHR; } } if (pDev != 0) { LOG(("Radio in use: %s %s %1.1f\n", pDev->ip_address, pDev->mac_address, ((float)pDev->code_version)/10.0f )); strcpy(name, "HPSDR"); strcpy(model, "Hermes"); } else { strcpy(name, "HARDWARE NOT OPERATING !!!"); strcpy(model, "N/A"); } LOG (("INSTANCE: %d Name: [%s] Model: [%s]\n", GetInstanceNumber(), name, model)); return (pDev != 0); }
void PhaseTest :: end (){ LOG_OPEN(LOG_INFO); LOG_TEXT("Test I/O finished with "); LOG_NUMBER(nbError); LOG_TEXT(" error(s) in "); LOG_NUMBER(myM.length()+1); LOG_TEXT(" test(s)."); LOG_CLOSE(); }
int main() { ScUuid * uuid1 = NULL; ScUuid * uuid2 = NULL; ScUuid * uuid3 = NULL; //char p1[SC_UUID_LEN] = { 0 }; //char p2[SC_UUID_LEN] = { 0 }; //char p3[SC_UUID_LEN] = { 0 }; LOG_OPEN(NULL); uuid1 = ScUuid_New(); ScUuid_GenerateRandom(uuid1); LOG_I("test", "UUID 1: %s", ScUuid_ToString(uuid1, true)); uuid2 = ScUuid_New(); ScUuid_GenerateRandom(uuid2); LOG_I("test", "UUID 2: %s", ScUuid_ToString(uuid2, true)); LOG_I("test", "UUID 2: %s", ScUuid_ToString(uuid2, false)); LOG_I("test", "UUID1 and UUID2 is %s", ScUuid_Equal(uuid1, uuid2) ? "equal" : "not equal"); ScUuid_Clear(uuid1); LOG_I("test", "UUID1 clear, UUID1 : %s", ScUuid_IsNull(uuid1) ? "is NULL" : "is Not NULL"); LOG_I("test", "UUID1 and UUID2 is %s", ScUuid_Equal(uuid1, uuid2) ? "equal" : "not equal"); uuid3 = ScUuid_New(); ScUuid_Copy(uuid3, uuid2); LOG_I("test", "clone from UUID2, UUID3: %s", ScUuid_ToString(uuid3, true)); LOG_I("test", "UUID2 and UUID3 is %s", ScUuid_Equal(uuid2, uuid3) ? "equal" : "not equal"); test_uuid("4A5BFD77-D452-4492-B973-69198200339", false); test_uuid("84949cc5-4701-4a84-895b-354c584a981b", true); test_uuid("84949SC5-4701-4A84-895B-354C584A981B", true); test_uuid("84949cc5-4701-4a84-895b-354c584a981bc", false); test_uuid("84949cc5-4701-4a84-895b-354c584a981", false); test_uuid("84949cc5x4701-4a84-895b-354c584a981b", false); test_uuid("84949cc504701-4a84-895b-354c584a981b", false); test_uuid("84949cc5-470104a84-895b-354c584a981b", false); test_uuid("84949cc5-4701-4a840895b-354c584a981b", false); test_uuid("84949cc5-4701-4a84-895b0354c584a981b", false); test_uuid("g4949cc5-4701-4a84-895b-354c584a981b", false); test_uuid("84949cc5-4701-4a84-895b-354c584a981g", false); ScUuid_Delete(uuid1); ScUuid_Delete(uuid2); ScUuid_Delete(uuid3); LOG_CLOSE(); return 0; }
int main(int argc, char *argv[]) { SetConsoleTitle("YTDYDRYDDYFT2TXDDFFCOL"); if(settings.m_bEnableLog) LOG_OPEN(); if (argc > 1) { printf("argc=%d\n", argc); UINT8 i; for ( i= 1; i < argc; i++) { if (argv[i]!=NULL) printf("arg%d\t%s\n", i, argv[i]); } char ext[4]; i = strlen(argv[1]); ext[0] = argv[1][i - 3]; ext[1] = argv[1][i - 2]; ext[2] = argv[1][i - 1]; ext[3] = 0; //strcpy(ext, argv[1]+strlen(argv[1]) - 3); if (strcmp(ext,"ydr")==0) { ConvertYDR(argv[1]); } } else{ LOGL("No arguments. Searching file.."); LOGL("Searching for ytd..."); SearchFiles("*.ytd", (LPSEARCHFUNC)ConvertYTD); LOGL("Searching for ydr..."); SearchFiles("*.ydr", (LPSEARCHFUNC)ConvertYDR); LOGL("Searching for ydd..."); SearchFiles("*.ydd", (LPSEARCHFUNC)ConvertYDD); LOGL("Searching for yft..."); SearchFiles("*.yft", (LPSEARCHFUNC)ConvertYFT); } LOG_CLOSE(); printf("\nConversion finished."); getchar(); return 1; }
asmlinkage long our_sys_open(const char* file, int flags, int mode) { long fd = 0; long uid, gid; struct log_path *p; struct passwd_entry *pe = NULL; struct process_ids *pids; struct task_struct *ptask; int is_log; int type; type = SYSCALL_OPEN; is_log = is_log_file(file); //if (is_relevant_file(file, &uid, &gid) == 1) if(is_log == 0) { if((flags & O_CREAT) > 0) { flags -= O_CREAT; fd = original_sys_open_call(file, flags, mode); flags += O_CREAT; if(fd < 0) { type = SYSCALL_CREAT; fd = original_sys_open_call(file, flags, mode); if(fd < 0) return fd; //Error opening file } } else { fd = original_sys_open_call(file, flags, mode); if(fd < 0) return fd; //Error opening file } pids = get_process_ids(); pe = get_passwd_entry(pids->uid); p = find_path(); ptask = find_task_by_vpid(pids->pid); LOG_OPEN(type, pe->username, pids->pid, pids->ppid, pids->audit, pids->paudit, ptask->comm, file, p->name, flags, mode, fd); kfree(p); kfree(pids); } else { //TODO: check process if for rsyslog fd = original_sys_open_call(file, flags, mode); } return fd; }
/* * daemonize * * Performs the steps necessary to become a daemon. */ static void daemonize(void) { int pid; int status; signal(SIGTERM, &parent_exit_handler); pid = fork(); if (pid < 0) { LOG_ERROR("Unable to fork()"); exit(EXIT_FAILURE); } if (pid) { /* Parent waits here for child to get going */ while (!waitpid(pid, &status, WNOHANG) && !exit_now); if (exit_now) exit(EXIT_SUCCESS); switch (WEXITSTATUS(status)) { case EXIT_LOCKFILE: LOG_ERROR("Failed to create lockfile"); LOG_ERROR("Process already running?"); break; case EXIT_KERNEL_SOCKET: LOG_ERROR("Unable to create netlink socket"); break; case EXIT_KERNEL_BIND: LOG_ERROR("Unable to bind to netlink socket"); break; case EXIT_KERNEL_SETSOCKOPT: LOG_ERROR("Unable to setsockopt on netlink socket"); break; case EXIT_CLUSTER_CKPT_INIT: LOG_ERROR("Unable to initialize checkpoint service"); LOG_ERROR("Has the cluster infrastructure been started?"); break; case EXIT_FAILURE: LOG_ERROR("Failed to start: Generic error"); break; default: LOG_ERROR("Failed to start: Unknown error"); break; } exit(EXIT_FAILURE); } setsid(); chdir("/"); umask(0); close(0); close(1); close(2); open("/dev/null", O_RDONLY); /* reopen stdin */ open("/dev/null", O_WRONLY); /* reopen stdout */ open("/dev/null", O_WRONLY); /* reopen stderr */ LOG_OPEN("cmirrord", LOG_PID, LOG_DAEMON); if (create_lockfile(CMIRRORD_PIDFILE)) exit(EXIT_LOCKFILE); signal(SIGINT, &sig_handler); signal(SIGQUIT, &sig_handler); signal(SIGTERM, &sig_handler); signal(SIGHUP, &sig_handler); signal(SIGPIPE, SIG_IGN); signal(SIGUSR1, &sig_handler); signal(SIGUSR2, &sig_handler); sigemptyset(&signal_mask); signal_received = 0; }
int main(int argc, char **argv) { /* open log */ if (0 != LOG_OPEN("./center", LOG_LEVEL_DEBUG, -1)) { fprintf(stderr, "open center log failed!\n"); return 1; } if (0 != check_cmd()) { return 1; } /* protobuf verify version */ GOOGLE_PROTOBUF_VERIFY_VERSION; struct event_base *main_base = event_base_new(); if (NULL == main_base) { mfatal("main_base = event_base_new() failed!"); return 1; } conn_init(); /* thread */ pthread_t worker[WORKER_NUM]; thread_init(main_base, WORKER_NUM, worker); /* signal */ struct event *signal_event; signal_event = evsignal_new(main_base, SIGINT, signal_cb, (void *)main_base); if (NULL == signal_event || 0 != event_add(signal_event, NULL)) { mfatal("create/add a signal event failed!"); return 1; } /* listener for gate */ struct sockaddr_in sa; bzero(&sa, sizeof(sa)); sa.sin_family = AF_INET; sa.sin_addr.s_addr = htonl(INADDR_ANY); sa.sin_port = htons(44000); listener *lg = listener_new(main_base, (struct sockaddr *)&sa, sizeof(sa), gate_cb); if (NULL == lg) { mfatal("create client listener failed!"); return 1; } /* connector to center */ struct sockaddr_in csa; bzero(&csa, sizeof(csa)); csa.sin_family = AF_INET; csa.sin_addr.s_addr = inet_addr("127.0.0.1"); csa.sin_port = htons(43001); connector *ce = connector_new((struct sockaddr *)&csa, sizeof(csa), center_cb); if (NULL == ce) { mfatal("create center connector failed!"); return 1; } event_base_dispatch(main_base); for (int i = 0; i < WORKER_NUM; i++) pthread_join(worker[i], NULL); connector_free(ce); listener_free(lg); event_free(signal_event); event_base_free(main_base); /* shutdown protobuf */ google::protobuf::ShutdownProtobufLibrary(); /* close log */ LOG_CLOSE(); return 0; }