static void test_baddest(void) { QTestState *from, *to; QDict *rsp, *rsp_return; const char *status; bool failed; test_migrate_start(&from, &to, "tcp:0:0", true); migrate(from, "tcp:0:0"); do { rsp = wait_command(from, "{ 'execute': 'query-migrate' }"); rsp_return = qdict_get_qdict(rsp, "return"); status = qdict_get_str(rsp_return, "status"); g_assert(!strcmp(status, "setup") || !(strcmp(status, "failed"))); failed = !strcmp(status, "failed"); qobject_unref(rsp); } while (!failed); /* Is the machine currently running? */ rsp = wait_command(from, "{ 'execute': 'query-status' }"); g_assert(qdict_haskey(rsp, "return")); rsp_return = qdict_get_qdict(rsp, "return"); g_assert(qdict_haskey(rsp_return, "running")); g_assert(qdict_get_bool(rsp_return, "running")); qobject_unref(rsp); test_migrate_end(from, to, false); }
void mode8(void) { set_all_servo(ON); float first_pos[3] = {80, -40, 90}, last_pos[3] = {80, -40, 50}; add_straight_command(3, first_pos, last_pos, 500000, 10); // add_straight_command(4, first_pos, last_pos, 500000, 30); // add_straight_command(5, first_pos, last_pos, 500000, 30); exec_command(); wait_command(); add_straight_command(4, first_pos, last_pos, 500000, 100); // add_straight_command(4, first_pos, last_pos, 500000, 30); // add_straight_command(5, first_pos, last_pos, 500000, 30); exec_command(); wait_command(); }
static void migrate_start_postcopy(QTestState *who) { QDict *rsp; rsp = wait_command(who, "{ 'execute': 'migrate-start-postcopy' }"); g_assert(qdict_haskey(rsp, "return")); qobject_unref(rsp); }
/** * \brief Implementation of the set command */ int set_command(MountPtr mount, const RaDec& radec) { debug(LOG_DEBUG, DEBUG_LOG, 0, "ra = %s", radec.ra().hms().c_str()); debug(LOG_DEBUG, DEBUG_LOG, 0, "dec = %s", radec.dec().dms().c_str()); if (!dryrun) { mount->Goto(radec); return wait_command(mount, await_completion); } return get_command(mount); }
static void read_blocktime(QTestState *who) { QDict *rsp, *rsp_return; rsp = wait_command(who, "{ 'execute': 'query-migrate' }"); rsp_return = qdict_get_qdict(rsp, "return"); g_assert(qdict_haskey(rsp_return, "postcopy-blocktime")); qobject_unref(rsp); }
/*VARARGS4*/ int run_command(char *cmd, sigset_t *mask, int infd, int outfd, char *a0, char *a1, char *a2) { int pid; if ((pid = start_command(cmd, mask, infd, outfd, a0, a1, a2)) < 0) return (-1); return (wait_command(pid)); }
static void migrate_check_parameter(QTestState *who, const char *parameter, const char *value) { QDict *rsp, *rsp_return; char *result; rsp = wait_command(who, "{ 'execute': 'query-migrate-parameters' }"); rsp_return = qdict_get_qdict(rsp, "return"); result = g_strdup_printf("%" PRId64, qdict_get_try_int(rsp_return, parameter, -1)); g_assert_cmpstr(result, ==, value); g_free(result); qobject_unref(rsp); }
/* * Run a command without a shell, with optional arguments and splicing * of stdin and stdout. The command name can be a sequence of words. * Signals must be handled by the caller. * critical will mask interesting signals in the new process. * SIGINT is enabled if critical==0. */ int run_command(char* cmd, int critical, int infd, int outfd, char* a0, char* a1, char* a2) { int pid; int code; if ((pid = start_command(cmd, critical, infd, outfd, a0, a1, a2)) < 0) return -1; if (code = wait_command(pid)) { note(SYSTEM, "Fatal exit code %d from %s", code, cmd); return -1; } return 0; }
int main(int argc, char **argv) { int code = 42; initilization(); if (argc == 2) { open_file(argv[1],strlen(argv[1])); } if (argc > 2) { fprintf(stderr, "Неверное число параметров"); return 0; } while(1) { command = malloc(sizeof(char)); if (command == NULL) { exit_force(); return 0; } command[0] = '\0'; size_s_command = 1; code = wait_command(); free(command); if (code == 255) break; if (code == 0) fprintf(stderr, "Success\n"); if (eof_command == 1) { exit_force(); fprintf(stderr, "Closing\n"); break; } if (code == -12) fprintf(stderr, "You have unsaved changes\n"); if (code == -3) fprintf(stderr, "Error in function\n"); if ((code == -2) || (code == -1)) fprintf(stderr, "Wrong command\n"); } return 0; }
static uint64_t get_migration_pass(QTestState *who) { QDict *rsp, *rsp_return, *rsp_ram; uint64_t result; rsp = wait_command(who, "{ 'execute': 'query-migrate' }"); rsp_return = qdict_get_qdict(rsp, "return"); if (!qdict_haskey(rsp_return, "ram")) { /* Still in setup */ result = 0; } else { rsp_ram = qdict_get_qdict(rsp_return, "ram"); result = qdict_get_try_int(rsp_ram, "dirty-sync-count", 0); } qobject_unref(rsp); return result; }
static void wait_for_migration_complete(QTestState *who) { while (true) { QDict *rsp, *rsp_return; bool completed; const char *status; rsp = wait_command(who, "{ 'execute': 'query-migrate' }"); rsp_return = qdict_get_qdict(rsp, "return"); status = qdict_get_str(rsp_return, "status"); completed = strcmp(status, "completed") == 0; g_assert_cmpstr(status, !=, "failed"); qobject_unref(rsp); if (completed) { return; } usleep(1000); } }
int fileclose(FILE* fp) { int r; struct file* p; struct file** pp; if (fp == 0 || fp == stdin) return 0; if (fp == stdout || fp == stderr) return fflush(fp); r = 0; for (pp = &state.files;; pp = &p->link) { if (!(p = *pp)) { fclose(fp); return 0; } if (p->fp == fp) { r = p->pid; *pp = p->link; free(p); break; } } if (r) { holdsigs(); fclose(fp); signal(SIGPIPE, SIG_IGN); r = wait_command(r); signal(SIGPIPE, SIG_DFL); relsesigs(); } else r = fclose(fp); return r; }
/** * \brief Main method */ int main(int argc, char *argv[]) { debug(LOG_DEBUG, DEBUG_LOG, 0, "mount utility"); int c; int longindex; putenv((char *)"POSIXLY_CORRECT=1"); // cast to silence compiler while (EOF != (c = getopt_long(argc, argv, "c:dh", longopts, &longindex))) { switch (c) { case 'c': Configuration::set_default(std::string(optarg)); break; case 'd': debuglevel = LOG_DEBUG; break; case 'h': usage(argv[0]); return EXIT_SUCCESS; case 'n': dryrun = true; break; case 'f': decimal = true; break; case 'w': await_completion = true; break; case 1: switch (longindex) { } break; } } // next argument must be the command if (argc <= optind) { throw std::runtime_error("missing command argument"); } std::string command(argv[optind++]); // call the command specific functions if (command == "help") { return help_command(); } // the other commands need a repository astro::module::Repository repository; astro::module::Devices devices(repository); // list command if (command == "list") { return list_command(devices); } // other commands need a mount url if (argc <= optind) { throw std::runtime_error("missing mount URL"); } DeviceName mountname(argv[optind++]); if (!mountname.hasType(DeviceName::Mount)) { throw std::runtime_error("not a mount device name"); } debug(LOG_DEBUG, DEBUG_LOG, 0, "mount device name: %s", mountname.toString().c_str()); // use the Devices class to get the mount associated with this name MountPtr mount = devices.getMount(mountname); if (command == "get") { return get_command(mount); } if (command == "cancel") { return cancel_command(mount); } if (command == "wait") { return wait_command(mount, true); } if (command == "set") { if (argc < optind + 2) { throw std::runtime_error("two angle arguments missing"); } RaDec radec; radec.ra() = Angle::hms_to_angle(argv[optind++]); radec.dec() = Angle::dms_to_angle(argv[optind++]); return set_command(mount, radec); } throw std::runtime_error("unknown command"); }
/** * \brief Implementation of cancel command */ int cancel_command(MountPtr mount) { mount->cancel(); return wait_command(mount, await_completion); }
/* * Main thread of control. This worker thread will service requests * on a socket, read or writing to memory based on the command * dispatched from the main execution thread. */ void dmac_handler(void *v_void) { verinet_t *v = (verinet_t *)v_void; volatile int finished = 0; volatile uint32 dmaAddr, dmaData; rpc_cmd_t cmd; int sockfd = v->dmacFd; uint8 *byte_ptr; uint32 i; while (!finished){ debugk(DK_VERINET, "dmac_handler: wait...\n"); if (wait_command(sockfd, &cmd) < 0) { break; /* Error message already printed */ } debugk(DK_VERINET, "dmac_handler: request opcode 0x%x\n", cmd.opcode); switch(cmd.opcode){ case RPC_DMAC_READ_REQ: /* Read DMA memory ... */ dmaAddr = cmd.args[0]; /* Read data from shared memory at Addr */ dmaData = _dma_getw(dmaAddr); debugk(DK_VERINET, "**DMA_RD: 0x%x = 0x%x\n", dmaAddr, dmaData); /* Send back a response */ make_rpc_getmem_resp(&cmd, dmaData); write_command(sockfd, &cmd); break; case RPC_DMAC_WRITE_REQ: /* Write DMA memory ... */ dmaAddr = cmd.args[0]; /* Address */ dmaData = cmd.args[1]; /* Data */ /* Write the data to shared memory */ _dma_putw(dmaAddr, dmaData); debugk(DK_VERINET, "**DMA_WR: 0x%x = 0x%x\n", dmaAddr, dmaData); /* Send back a response */ make_rpc_setmem_resp(&cmd,dmaData); write_command(sockfd, &cmd); break; case RPC_DMAC_READ_BYTES_REQ: /* Read DMA memory as a string. Would be nice to use memcpy */ dmaAddr = cmd.args[0]; byte_ptr = (uint8 *)&cmd.args[1]; debugk(DK_VERINET, "**DMA_RD_B: 0x%x, %d bytes\n", dmaAddr, cmd.argcount); for (i = 0; i < cmd.argcount; i++) { byte_ptr[i] = _dma_getb(dmaAddr++); } /* Send back a response */ cmd.status = RPC_OK; cmd.opcode = RPC_DMAC_READ_BYTES_RESP; write_command(sockfd, &cmd); break; case RPC_DMAC_WRITE_BYTES_REQ: /* Write DMA memory as a string. Would be nice to use memcpy */ dmaAddr = cmd.args[0]; /* Address */ byte_ptr = (uint8 *)&cmd.args[1]; /* Data */ /* Write the data to shared memory */ debugk(DK_VERINET, "**DMA_WR_B: 0x%x, %d bytes\n", dmaAddr, cmd.argcount); for (i = 0; i < cmd.argcount; i++) { _dma_putb(dmaAddr++, byte_ptr[i]); } /* Send back a response */ cmd.status = RPC_OK; cmd.opcode = RPC_DMAC_WRITE_BYTES_RESP; write_command(sockfd, &cmd); break; case RPC_DISCONNECT: finished = 1; v->dmacWorkerExit++; printk("dma thread received disconnect\n"); exit(0); break; default: /* Unknown opcode */ break; } } printk("DMA controller shutdown.\n"); close(sockfd); sal_thread_exit(0); }
int main() { setlocale(LC_ALL,""); clit_config *config = malloc(sizeof(clit_config)); if(parse_config(config) == -1) { // first run int res = authorize(config); if(res == -1) { printf("Please retry.\n"); } else printf("Authorization finished. Run the program again.\n"); free(config); exit(0); } me = newuser(); me->screen_name = config->screen_name; me->id = config->user_id; init_oauth(config->key,config->secret); free(config); init_mutex(); raw_event_stream = new_raw_event_queue(); printf("Loading the timelines....\n"); if(init_timelines() == -1) { pthread_mutex_lock(&error_mutex); printf("Cannot load the timeline. Please check your network connection.\n"); pthread_mutex_unlock(&error_mutex); goto exit_twilc; } initscr(); curs_set(0); //if(has_colors() == FALSE) //goto exit_twilc; raw(); keypad(stdscr,TRUE); noecho(); start_color(); move(0,0); refresh(); if(init_ui() == -1) goto exit_twilc; start_userstream(); wait_command(tl_win); exit_twilc: destroy_ui(); curs_set(1); endwin(); destroy_mutex(); for(int i = 0; i < TIMELINE_COUNT; ++i) destroy_timeline(timelines[i]); stop_userstream(); pthread_mutex_lock(&event_buffer_mutex); destroy_raw_event_queue(raw_event_stream); raw_event_stream = NULL; pthread_mutex_unlock(&event_buffer_mutex); return 0; }