int main(int argc, char ** argv) { int sock; struct sockaddr_in addr; int rc; sock = socket(AF_INET, SOCK_STREAM , 0); if (sock < 0) { perror("socket"); return EXIT_FAILURE; } addr.sin_family = AF_INET; addr.sin_port = htons(5679); addr.sin_addr.s_addr = inet_addr("127.0.0.1"); rc = connect(sock, (const struct sockaddr *)&addr, sizeof(addr)); if (rc < 0) { perror("connect"); return EXIT_FAILURE; } if (argc == 1) { exec_listener(sock); } else { exec_write(sock, atoi(argv[1])); } close(sock); return EXIT_SUCCESS; }
void show_photos(const struct user_attribute *attrs, int count,PKT_public_key *pk,PKT_secret_key *sk, PKT_user_id *uid) { #ifndef DISABLE_PHOTO_VIEWER int i; struct expando_args args; u32 len; u32 kid[2]={0,0}; memset(&args,0,sizeof(args)); args.pk=pk; args.sk=sk; args.validity_info=get_validity_info(pk,uid); args.validity_string=get_validity_string(pk,uid); if(pk) keyid_from_pk(pk,kid); else if(sk) keyid_from_sk(sk,kid); for(i=0;i<count;i++) if(attrs[i].type==ATTRIB_IMAGE && parse_image_header(&attrs[i],&args.imagetype,&len)) { char *command,*name; struct exec_info *spawn; int offset=attrs[i].len-len; #ifdef FIXED_PHOTO_VIEWER opt.photo_viewer=FIXED_PHOTO_VIEWER; #else if(!opt.photo_viewer) opt.photo_viewer=get_default_photo_command(); #endif /* make command grow */ command=pct_expando(opt.photo_viewer,&args); if(!command) goto fail; name=xmalloc(16+strlen(EXTSEP_S)+ strlen(image_type_to_string(args.imagetype,0))+1); /* Make the filename. Notice we are not using the image encoding type for more than cosmetics. Most external image viewers can handle a multitude of types, and even if one cannot understand a particular type, we have no way to know which. The spec permits this, by the way. -dms */ #ifdef USE_ONLY_8DOT3 sprintf(name,"%08lX" EXTSEP_S "%s",(ulong)kid[1], image_type_to_string(args.imagetype,0)); #else sprintf(name,"%08lX%08lX" EXTSEP_S "%s",(ulong)kid[0],(ulong)kid[1], image_type_to_string(args.imagetype,0)); #endif if(exec_write(&spawn,NULL,command,name,1,1)!=0) { xfree(name); goto fail; } #ifdef __riscos__ riscos_set_filetype_by_mimetype(spawn->tempfile_in, image_type_to_string(args.imagetype,2)); #endif xfree(name); fwrite(&attrs[i].data[offset],attrs[i].len-offset,1,spawn->tochild); if(exec_read(spawn)!=0) { exec_finish(spawn); goto fail; } if(exec_finish(spawn)!=0) goto fail; } return; fail: log_error(_("unable to display photo ID!\n")); #endif }
void exec(Pystat stat){ Arg arg0 = stat->args[0]; Arg arg1 = stat->args[1]; switch(stat->op){ case Y_PUSH: { exec_push(arg0.ival, pc+1); // num_objects break; } case Y_GOTO: { exec_goto(arg0.ival); // absolute line break; } case Y_POP: { exec_pop(); break; } case Y_NEW: { exec_new(arg0.ival); // obj size break; } case Y_NEWS: { exec_news(arg0.ival); // obj size break; } case Y_LDC: { exec_ldc(arg0.ival); break; } case Y_LDI: { exec_ldi(arg0.ival); break; } case Y_LDR: { exec_ldr(arg0.rval); break; } case Y_LDS: { exec_lds(arg0.sval); break; } case Y_LOD: { exec_lod(arg0.ival); // oid break; } case Y_GLOD: { exec_glod(arg0.ival); // oid break; } case Y_CAT: { exec_cat(arg0.ival, arg1.ival); // num fields, record/array size break; } case Y_LDA: { exec_lda(arg0.ival); // oid break; } case Y_GLDA: { exec_glda(arg0.ival); // oid break; } case Y_FDA: { exec_fda(arg0.ival); // field offset break; } case Y_EIL: { exec_eil(arg0.ival); // field size, embedded break; } case Y_SIL: { exec_sil(arg0.ival); // field size, on stack break; } case Y_IXA: { exec_ixa(arg0.ival); // elem size break; } case Y_STO: { exec_sto(arg0.ival); // oid break; } case Y_GSTO: { exec_gsto(arg0.ival); // oid break; } case Y_IST: { exec_ist(); // indirect store break; } case Y_JMF: { exec_jmf(arg0.ival); // offset break; } case Y_JMP: { exec_jmp(arg0.ival); // offset break; } case Y_EQU: { exec_equ(); // for all types of objects break; } case Y_NEQ: { exec_neq(); // for all types of objects break; } case Y_IGT: { exec_igt(); break; } case Y_IGE: { exec_ige(); break; } case Y_ILT: { exec_ilt(); break; } case Y_ILE: { exec_ile(); break; } case Y_RGT: { exec_rgt(); break; } case Y_RGE: { exec_rge(); break; } case Y_RLT: { exec_rlt(); break; } case Y_RLE: { exec_rle(); break; } case Y_SGT: { exec_sgt(); break; } case Y_SGE: { exec_sge(); break; } case Y_SLT: { exec_slt(); break; } case Y_SLE: { exec_sle(); break; } case Y_IPLUS: { exec_iplus(); break; } case Y_IMINUS: { exec_iminus(); break; } case Y_ITIMES: { exec_itimes(); break; } case Y_IDIV: { exec_idiv(); break; } case Y_RPLUS: { exec_rplus(); break; } case Y_RMINUS: { exec_rminus(); break; } case Y_RTIMES: { exec_rtimes(); break; } case Y_RDIV: { exec_rdiv(); break; } case Y_IUMI: { exec_iumi(); break; } case Y_RUMI: { exec_rumi(); break; } case Y_NEG: { exec_neg(); break; } case Y_WR: { exec_wr(arg0.sval, 1, stdout); // schema break; } case Y_FWR: { exec_fwr(arg0.sval); // schema break; } case Y_RD: { exec_rd(arg0.sval, 1, stdin); // schema break; } case Y_FRD: { exec_frd(arg0.sval); // schema break; } case Y_TOINT: { exec_toint(); break; } case Y_TOINTUP: { exec_tointup(); break; } case Y_TOREAL: { exec_toreal(); break; } case Y_READ: { exec_read(arg0.ival, arg1.sval, 1, stdin); // oid, schema break; } case Y_GREAD: { exec_gread(arg0.ival, arg1.sval, 1, stdin); // oid, schema break; } case Y_FREAD: { exec_fread(arg0.ival, arg1.sval); // oid, schema break; } case Y_GFREAD: { exec_gfread(arg0.ival, arg1.sval); // oid, schema break; } case Y_WRITE: { exec_write(arg0.sval); // schema break; } case Y_FWRITE: { exec_fwrite(arg0.sval); // schema break; } case Y_TDUP: { exec_tdup(); break; } case Y_TPOP: { exec_tpop(arg0.ival); // num objects break; } case Y_MODULE: { // nothing to do here, the instruction is useless break; } case Y_RETURN: { exec_return(); break; } default: { machine_error("Unknown instruction."); break; } } }
void *volstd_exec(void *arg) { struct volume *vol; struct volume_standard *volstd; struct volume_cmd *cmd = NULL; vol = (struct volume *)arg; ASSERT(vol != NULL, "vol == NULL\n"); ASSERT(vol->type == VOLTYPE_STANDARD, "vol->type(%d) != VOLTYPE_STANDARD(%d)\n", vol->type, VOLTYPE_STANDARD); volstd = (struct volume_standard *)vol->ext; log_dbg3("lock\n"); LOCK_LIST_CMD(vol); { loop: cmd = vol_dequeue_cmd(vol); log_dbg3("cmd=%p\n", cmd); if (cmd == NULL) { log_dbg3("sleep...\n"); // wait for enqueue notification pthread_cond_wait(&(volstd->cond_cmdq), &(vol->lock_list_cmd)); // dequeue log_dbg3("wakeup.\n"); goto loop; } } UNLOCK_LIST_CMD(vol); log_dbg3("unlock\n"); #ifdef __DEBUG vol_dump_cmd(cmd); #endif // __DEBUG int rv = 0; vol_record_start_time(vol, cmd); switch (cmd->opcode) { case VOLUME_OP_READ: rv = exec_read(volstd, cmd); break; case VOLUME_OP_WRITE: rv = exec_write(volstd, cmd); break; default: ASSERT(0, "NOT IMPLEMENTED YET\n"); abort(); } vol_record_finish_time(vol, cmd); vol_dump_iotrace(vol, cmd); if (rv) { goto failure; } rv = vol_send_cmd_completion(cmd, VOLCMD_RESULT_SUCCESS); if (rv) { goto failure; } goto loop; failure: return NULL; } // volstd_exec
int exec_command(int fd, LPS331AP_COMMAND cmd, uint8_t write_val, uint32_t *read_val) { uint8_t buf[2]; uint32_t value; memset(buf, 0, sizeof(buf)); switch (cmd) { case CMD_WHO_AM_I: exec_read(fd, REG_WHO_AM_I, buf, ARRAY_SIZE_OF(buf)); if (buf[0] != 0xBB) { fprintf(stderr, "ERROR: invalid value\n"); exit(EXIT_FAILURE); } break; case CMD_CTRL1: exec_write(fd, REG_CTRL_REG1, write_val); break; case CMD_CTRL2: exec_write(fd, REG_CTRL_REG2, write_val); break; case CMD_WAIT_BOTH: for (uint8_t i = 0; i < WAIT_COUNT; i++) { exec_read(fd, REG_STATUS, buf, ARRAY_SIZE_OF(buf)); if ((buf[0] & 0x3) == 0x3) { break; } usleep(100000); // wait 100ms } if ((buf[0] & 0x3) != 0x3) { fprintf(stderr, "ERROR: data not ready\n"); // something is wrong, so power down exec_write(fd, REG_CTRL_REG1, PD_DOWN); exit(EXIT_FAILURE); } break; case CMD_PRESS_OUT: value = 0; exec_read(fd, REG_PRESS_OUT_XL, buf, ARRAY_SIZE_OF(buf)); value = buf[0] << 0 | value; exec_read(fd, REG_PRESS_OUT_L, buf, ARRAY_SIZE_OF(buf)); value = buf[0] << 8 | value; exec_read(fd, REG_PRESS_OUT_H, buf, ARRAY_SIZE_OF(buf)); value = buf[0] << 16 | value; *read_val = value; break; case CMD_TEMP_OUT: value = 0; exec_read(fd, REG_TEMP_OUT_L, buf, ARRAY_SIZE_OF(buf)); value = buf[0] << 0 | value; exec_read(fd, REG_TEMP_OUT_H, buf, ARRAY_SIZE_OF(buf)); value = buf[0] << 8 | value; *read_val = value; break; } usleep(10000); // wait 10ms return 0; }