int main(int argc, char **argv) { int n; /* Poll array: * 0 - server_fd * 1 - pipein_fd * 2 - client_fd (if any) */ struct pollfd fds[3]; int nfds = 3; sigset_t sigmask; sigset_t sigmask_orig; struct sigaction act; int c; while ((c = getopt(argc, argv, "v:")) != -1) { switch (c) { case 'v': verbose = atoi(optarg); break; default: fprintf(stderr, "%s [-v 0-3]\n", argv[0]); return 1; } } /* Termination signal handler. */ memset(&act, 0, sizeof(act)); act.sa_handler = signal_handler; if (sigaction(SIGHUP, &act, 0) < 0 || sigaction(SIGINT, &act, 0) < 0 || sigaction(SIGTERM, &act, 0) < 0) { syserror("sigaction error."); return 2; } /* Ignore SIGPIPE in all cases: it may happen, since we write to pipes, but * it is not fatal. */ sigemptyset(&sigmask); sigaddset(&sigmask, SIGPIPE); if (sigprocmask(SIG_BLOCK, &sigmask, NULL) < 0) { syserror("sigprocmask error."); return 2; } /* Ignore terminating signals, except when ppoll is running. Save current * mask in sigmask_orig. */ sigemptyset(&sigmask); sigaddset(&sigmask, SIGHUP); sigaddset(&sigmask, SIGINT); sigaddset(&sigmask, SIGTERM); if (sigprocmask(SIG_BLOCK, &sigmask, &sigmask_orig) < 0) { syserror("sigprocmask error."); return 2; } /* Prepare pollfd structure. */ memset(fds, 0, sizeof(fds)); fds[0].events = POLLIN; fds[1].events = POLLIN; fds[2].events = POLLIN; /* Initialise pipe and WebSocket server */ socket_server_init(PORT); pipe_init(); while (!terminate) { /* Make sure fds is up to date. */ fds[0].fd = server_fd; fds[1].fd = pipein_fd; fds[2].fd = client_fd; /* Only handle signals in ppoll: this makes sure we complete processing * the current request before bailing out. */ n = ppoll(fds, nfds, NULL, &sigmask_orig); log(3, "poll ret=%d (%d, %d, %d)\n", n, fds[0].revents, fds[1].revents, fds[2].revents); if (n < 0) { /* Do not print error when ppoll is interupted by a signal. */ if (errno != EINTR || verbose >= 1) syserror("ppoll error."); break; } if (fds[0].revents & POLLIN) { log(1, "WebSocket accept."); socket_server_accept(VERSION); n--; } if (fds[1].revents & POLLIN) { log(2, "Pipe fd ready."); pipein_read(); n--; } if (fds[2].revents & POLLIN) { log(2, "Client fd ready."); socket_client_read(); n--; } if (n > 0) { /* Some events were not handled, this is a problem */ error("Some poll events could not be handled: " "ret=%d (%d, %d, %d).", n, fds[0].revents, fds[1].revents, fds[2].revents); break; } } log(1, "Terminating..."); if (client_fd) socket_client_close(1); return 0; }
int main(int argc, char *argv[]) { int ii; FILE *tr_file; char tr_filename[1024]; char cmd_string[256]; if(argc < 1) { die_message("Must Provide a Trace File"); } //-------------------------------------------------------------------- // -- Get params from command line //-------------------------------------------------------------------- for ( ii = 1; ii < argc; ii++) { if (argv[ii][0] == '-') { if (!strcmp(argv[ii], "-h") || !strcmp(argv[ii], "-help")) { die_usage(); } else if (!strcmp(argv[ii], "-pipewidth")) { if (ii < argc - 1) { PIPE_WIDTH = atoi(argv[ii+1]); ii += 1; } } else if (!strcmp(argv[ii], "-schedpolicy")) { if (ii < argc - 1) { SCHED_POLICY = atoi(argv[ii+1]); ii += 1; } } else if (!strcmp(argv[ii], "-loadlatency")) { if (ii < argc - 1) { LOAD_EXE_CYCLES = atoi(argv[ii+1]); ii += 1; } } } else { strcpy(tr_filename, argv[ii]); } } // ------- Open Trace File ------------------------------------------- sprintf(cmd_string,"gunzip -c %s", tr_filename); if ((tr_file = popen(cmd_string, "r")) == NULL){ printf("Command string is %s\n", cmd_string); die_message("Unable to open the trace file with gzip option \n") ; } else { printf("Opened file with command: %s \n", cmd_string); } // ------- Pipeline Initialization & Execution ---------------------- pipeline = pipe_init(tr_file); printf("\n%48s", ""); while(!pipeline->halt) { pipe_cycle(pipeline); check_heartbeat(); } // ------- Print Statistics------------------------------------------ print_stats(); fclose(tr_file); return 0; }
int readcfg(void) { char ports[BUFSIZ], *p; int port; pipe_s *pipe; cfg_s local; serialinfo_s sinfo; char *parity; /* Read the global config settings */ cfg_fromfile(&cfg, cfgfile); /* Read the comm port list */ if (cfg_readbuf(cfgfile, "comm_ports", ports, sizeof(ports)) == NULL) errend("Couldn't find 'comm_ports' entry in config file '%s'", cfgfile); vlist_clear(&pipes); /* Parse the comm ports list */ p = strtok(ports, ","); while (p) { if (sscanf(p, "%d", &port) > 0) { pipe = malloc(sizeof(pipe_s)); //pipe_init(pipe); if (pipe == NULL) perrend("malloc(pipe_s)"); cfg_init(&local, port); /* Copy global settings to those for current pipe */ cfg_assign(&local, &cfg); /* Set the comm port */ local.ints[CFG_IPORT].val = port; /* Load this pipe's config */ cfg_fromfile(&local, cfgfile); /* Try initializing the pipe */ if (pipe_init(pipe, local.ints[CFG_INETPORT].val)) perrend("pipe_init"); /* Copy over the rest of the pipe's config */ pipe->timeout = local.ints[CFG_ITIMEOUT].val; sinfo.port = port; sinfo.baud = local.ints[CFG_IBAUD].val; sinfo.stopbits = local.ints[CFG_ISTOP].val; sinfo.databits = local.ints[CFG_IDATA].val; parity = local.strs[CFG_SPARITY].val; if (strcmp(parity, "none") == 0) { sinfo.parity = SIO_PARITY_NONE; } else if (strcmp(parity, "even") == 0) { sinfo.parity = SIO_PARITY_EVEN; } else if (strcmp(parity, "odd") == 0) { sinfo.parity = SIO_PARITY_ODD; } else { errend("Unknown parity string '%s'", parity); } if (sio_setinfo(&pipe->sio, &sinfo)) errend("Unable to configure comm port %d", port); /* Finally add the pipe to the pipes list */ vlist_add(&pipes, pipes.tail, pipe); cfg_cleanup(&local); } p = strtok(NULL, ","); } /* Clean up local cfg struct */ cfg_cleanup(&local); return 0; }
int main() { pipe_init("\\\\.\\PIPE\\cuckoo", 0); hook_init(GetModuleHandle(NULL)); mem_init(); assert(native_init() == 0); dnq_t d1, d2, d3; uint32_t val1[] = { 1, 6, 4, 8, 13337, 42, 89, 9001, 90, }; uint32_t val1_sorted[] = { 1, 4, 6, 8, 42, 89, 90, 9001, 13337, }; dnq_init(&d1, val1, sizeof(uint32_t), sizeof(val1) / sizeof(uint32_t)); assert(memcmp(d1.list, val1_sorted, sizeof(val1_sorted)) == 0); assert(dnq_has32(&d1, 4) == 1); assert(dnq_has32(&d1, 0) == 0); assert(dnq_has32(&d1, 1) == 1); assert(dnq_has32(&d1, 2) == 0); assert(dnq_has32(&d1, 43) == 0); assert(dnq_has32(&d1, 91) == 0); assert(dnq_has32(&d1, 90) == 1); assert(dnq_has32(&d1, 9002) == 0); assert(dnq_has32(&d1, 9000) == 0); assert(dnq_has32(&d1, 13337) == 1); assert(dnq_has32(&d1, 13338) == 0); assert(dnq_has32(&d1, 13336) == 0); assert(dnq_has32(&d1, 88) == 0); assert(dnq_has32(&d1, 41) == 0); assert(dnq_has32(&d1, 42) == 1); uint64_t val2[] = { 1, 6, 4, 8, 13337, 42, 89, 9001, 90, }; uint64_t val2_sorted[] = { 1, 4, 6, 8, 42, 89, 90, 9001, 13337, }; dnq_init(&d2, val2, sizeof(uint64_t), sizeof(val2) / sizeof(uint64_t)); assert(memcmp(d2.list, val2_sorted, sizeof(val2_sorted)) == 0); assert(dnq_has64(&d2, 4) == 1); assert(dnq_has64(&d2, 0) == 0); assert(dnq_has64(&d2, 1) == 1); assert(dnq_has64(&d2, 2) == 0); assert(dnq_has64(&d2, 43) == 0); assert(dnq_has64(&d2, 91) == 0); assert(dnq_has64(&d2, 90) == 1); assert(dnq_has64(&d2, 9002) == 0); assert(dnq_has64(&d2, 9000) == 0); assert(dnq_has64(&d2, 13337) == 1); assert(dnq_has64(&d2, 13338) == 0); assert(dnq_has64(&d2, 13336) == 0); assert(dnq_has64(&d2, 88) == 0); assert(dnq_has64(&d2, 41) == 0); assert(dnq_has64(&d2, 42) == 1); uintptr_t val3[] = { 1, 6, 4, 8, 13337, 42, 89, 9001, 90, }; uintptr_t val3_sorted[] = { 1, 4, 6, 8, 42, 89, 90, 9001, 13337, }; dnq_init(&d3, val3, sizeof(uintptr_t), sizeof(val3) / sizeof(uintptr_t)); assert(memcmp(d3.list, val3_sorted, sizeof(val3_sorted)) == 0); assert(dnq_hasptr(&d3, 4) == 1); assert(dnq_hasptr(&d3, 0) == 0); assert(dnq_hasptr(&d3, 1) == 1); assert(dnq_hasptr(&d3, 2) == 0); assert(dnq_hasptr(&d3, 43) == 0); assert(dnq_hasptr(&d3, 91) == 0); assert(dnq_hasptr(&d3, 90) == 1); assert(dnq_hasptr(&d3, 9002) == 0); assert(dnq_hasptr(&d3, 9000) == 0); assert(dnq_hasptr(&d3, 13337) == 1); assert(dnq_hasptr(&d3, 13338) == 0); assert(dnq_hasptr(&d3, 13336) == 0); assert(dnq_hasptr(&d3, 88) == 0); assert(dnq_hasptr(&d3, 41) == 0); assert(dnq_hasptr(&d3, 42) == 1); assert(dnq_iter32(&d1)[4] == 42); assert(dnq_iter64(&d2)[4] == 42); assert(dnq_iterptr(&d3)[4] == 42); pipe("INFO:Test finished!"); return 0; }
void fs_init(void) { vfs_init(); dev_init(); pipe_init(); }
static void ubjson_set_up(void) { ringbuffer_init(&pipe_rb, pipe_buffer, sizeof(pipe_buffer)); pipe_init(&communication_pipe, &pipe_rb, NULL); }
int32_t main(int argc, char **argv) { int32_t i = 0; pthread_t vPollcmd; pthread_t vPipecmd; _gCurrentState=STATE_INIT; for(i = 0; i < argc; i++) { if(0 == memcmp("-d", argv[i], 2)) { if(i+1 < argc) { _gDebugFlagMask = strtol(argv[i+1], NULL, 0); i++; } else { _gDebugFlagMask=0xFF; } printf("enable debug, mask = 0x%04X\n", _gDebugFlagMask); _gDebugFlag=1; } else if(0 == memcmp("-t", argv[i], 2)) { _gTestMode=1; } } _gQuitHandler = signal( SIGQUIT, exit_handler ); _gKillHandler = signal( SIGKILL, exit_handler ); _gTermHandler = signal( SIGTERM, exit_handler ); _gTermHandler = signal( SIGINT, exit_handler ); #if(_DEBUG_ == 1 && _DEBUG_TO_FILE_ == 1) if(gDebugToFile == 1) util_debug_file_init(); #endif pipe_init(); if(0 != i2c_init()) return -1; #ifdef STATUS_LED LED_init(); #endif #ifdef PUBLIC_GPIO GPIO_init(); #endif Flags_init(); sysinfo_update_init(); menu_init(); signal( SIG_PROC_CMD, cmd_queue_handler ); signal( SIG_PROC_MENU, menu_queue_handler ); sigemptyset(&_gSigMask); pthread_create(&vPollcmd, NULL, timer_main, NULL); pthread_create(&vPipecmd, NULL, pipecmd, NULL); pthread_join( vPollcmd, NULL); pthread_join( vPipecmd, NULL); return (0); }
int Y_PipeInit() { pipe_t *pipe = pipe_init(); return pipe->id; }