int cmd_setattr(int argc, char **argv) { int ret; char opt; char *path = NULL; dpl_dict_t *metadata = NULL; var_set("status", "1", VAR_CMD_SET, NULL); optind = 0; while ((opt = getopt(argc, argv, usage_getoptstr(setattr_usage))) != -1) switch (opt) { case 'm': metadata = dpl_parse_metadata(optarg); if (NULL == metadata) { fprintf(stderr, "error parsing metadata\n"); return SHELL_CONT; } break ; case '?': default: usage_help(&setattr_cmd); return SHELL_CONT; } argc -= optind; argv += optind; if (1 != argc) { usage_help(&setattr_cmd); return SHELL_CONT; } path = argv[0]; ret = dpl_setattr(ctx, path, metadata); if (DPL_SUCCESS != ret) { fprintf(stderr, "status: %s (%d)\n", dpl_status_str(ret), ret); goto end; } var_set("status", "0", VAR_CMD_SET, NULL); end: if (NULL != metadata) dpl_dict_free(metadata); return SHELL_CONT; }
static int exec_help(int argc, char **argv) { char *manpage; if ((argc != 2) || (strcmp("help", argv[1]) == 0)) { usage_help(); return(EX_USAGE); } for (unsigned int i = 0; i < cmd_len; i++) { if (strcmp(cmd[i].name, argv[1]) == 0) { if (asprintf(&manpage, "/usr/bin/man pkg-%s", cmd[i].name) == -1) errx(1, "cannot allocate memory"); system(manpage); free(manpage); return (0); } } /* Command name not found */ warnx("'%s' is not a valid command.\n", argv[1]); fprintf(stderr, "See 'pkg help' for more information on the commands.\n"); return (EX_USAGE); }
static void usage(FILE* out) { usage_lead_reset(); usage_help(out); usage_led(out, NULL); putchar('\n'); printf("om-led provides the same functionality as \"om led\" but as a separate executable\n" "so that it can be made suid-root. No proper security audit has been done so\n" "you should only do this at your own risk.\n\n"); usage_options(out); }
int cmd_mv(int argc, char **argv) { int ret; char opt; char *src_path = NULL; char *dst_path = NULL; dpl_sysmd_t sysmd; var_set("status", "1", VAR_CMD_SET, NULL); optind = 0; while ((opt = linux_getopt(argc, argv, usage_getoptstr(mv_usage))) != -1) switch (opt) { case '?': default: usage_help(&mv_cmd); return SHELL_CONT; } argc -= optind; argv += optind; if (2 != argc) { usage_help(&mv_cmd); goto end; } src_path = argv[0]; dst_path = argv[1]; if (!strcmp(dst_path, ".")) { char *p; p = rindex(src_path, '/'); if (NULL != p) { p++; dst_path = p; } else { dst_path = src_path; } } if (! strcmp("s3", (char *) dpl_get_backend_name(ctx))) { if (-1 == path_contains_valid_bucketname(ctx, src_path) || -1 == path_contains_valid_bucketname(ctx, dst_path)) { fprintf(stderr, "You need to set a bucket to use 'mv' " "(use 'la' to list the buckets)\n"); goto end; } } ret = dpl_getattr(ctx, src_path, NULL, &sysmd); if (DPL_SUCCESS != ret) { fprintf(stderr, "dpl_getattr status: %s (%d)\n", dpl_status_str(ret), ret); goto end; } ret = dpl_rename(ctx, src_path, dst_path, sysmd.ftype); if (DPL_SUCCESS != ret) { fprintf(stderr, "dpl_rename status: %s (%d)\n", dpl_status_str(ret), ret); goto end; } var_set("status", "0", VAR_CMD_SET, NULL); end: return SHELL_CONT; }
int cmd_ls(int argc, char **argv) { char opt; int ret; int lflag = 0; int aflag = 0; int Rflag = 0; size_t total_size = 0; char *path; struct ls_data ls_data; var_set("status", "1", VAR_CMD_SET, NULL); optind = 0; while ((opt = getopt(argc, argv, usage_getoptstr(ls_usage))) != -1) switch (opt) { case 'R': Rflag = 1; break ; case 'a': break ; case 'A': aflag = 1; break ; case 'l': lflag = 1; break ; case '?': default: usage_help(&ls_cmd); return SHELL_CONT; } argc -= optind; argv += optind; if (0 == argc) path = "."; else if (1 == argc) path = argv[0]; else { usage_help(&ls_cmd); return SHELL_CONT; } memset(&ls_data, 0, sizeof (ls_data)); ls_data.ctx = ctx; ls_data.lflag = lflag; ls_data.Rflag = Rflag; ls_data.aflag = aflag; ret = ls_recurse(&ls_data, path, 0); if (DPL_SUCCESS != ret) { fprintf(stderr, "ls failure %s (%d)\n", dpl_status_str(ret), ret); goto end; } total_size = ls_data.total_size; if (1 == lflag) { if (NULL != ctx->pricing) printf("Total %s Price %s\n", dpl_size_str(total_size), dpl_price_storage_str(ctx, total_size)); } var_set("status", "0", VAR_CMD_SET, NULL); end: return SHELL_CONT; }
void parseoptions(int argc,char *argv[]) { int done=0; opterr=0; do switch(getopt(argc,argv,"A:BeF:hlmnNsSt:")) { case 'A': /* stopafter */ stopafter=atoi(optarg); if(stopafter<0) stopafter=0; if(stopafter>10*60) stopafter=10*60; break; case 'B': /* ABC stereo (not ACB) */ sound_stereo_ay_abc=1; break; case 'e': /* eight-bit-only */ sixteenbit=0; break; case 'F': /* fadetime */ fadetime=atoi(optarg); if(fadetime<1) fadetime=1; if(fadetime>20) fadetime=20; break; case 'h': usage_help(); exit(0); case 'l': /* list tracks etc. rather than playing */ list_only=1; break; case 'm': /* mono */ sound_stereo=0; break; case 'N': /* narrow stereo separation */ sound_stereo_ay_narrow=1; break; case 'n': /* no UI (effective in non-X ver only) */ use_ui=0; break; case 'S': /* pseudostereo (for beeper) */ sound_stereo_beeper=1; break; case 's': /* play to stdout */ use_ui=0; /* implied */ play_to_stdout=1; break; case 't': if (!(play_one_track_only=atoi(optarg))) { fprintf(stderr, "%s: error parsing an argument.\n This should be " "a numerical value betwen 1 and num_tracks.\n", progname); exit(1); } break; case '?': switch(optopt) { case 'A': fprintf(stderr,"%s: " "the `-A' option requires a stop-after time (in seconds).\n", progname); break; case 'F': fprintf(stderr,"%s: " "the `-F' option requires a fade-out time (in seconds).\n", progname); break; case 't': fprintf(stderr,"%s: the -t option requires a track number to " "play.\n",progname); break; default: fprintf(stderr,"%s: " "option `%c' not recognised.\n", progname,optopt); } exit(1); case -1: done=1; } while(!done); if(optind>=argc) /* if no filenames given... */ { fprintf(stderr,"%s: you must specify the file(s) to %s.\n", progname,list_only?"list":"play"); exit(1); } ay_filenames=argv+optind; ay_num_files=argc-optind; }
static int usage_check(int argc, char *argv[]) { int c; while (1) { int option_index = 0; static struct option long_options[] = { {"quiet", 0, 0, 'q'}, {"verbose", 0, 0, 'v'}, #if (EVMLOG_MODULE_TRACE != 0) {"trace", 0, 0, 't'}, #endif #if (EVMLOG_MODULE_DEBUG != 0) {"debug", 0, 0, 'g'}, #endif {"no-header", 0, 0, 'n'}, {"syslog", 0, 0, 's'}, {"help", 0, 0, 'h'}, {0, 0, 0, 0} }; #if (EVMLOG_MODULE_TRACE != 0) && (EVMLOG_MODULE_DEBUG != 0) c = getopt_long(argc, argv, "qvtgnsh", long_options, &option_index); #elif (EVMLOG_MODULE_TRACE == 0) && (EVMLOG_MODULE_DEBUG != 0) c = getopt_long(argc, argv, "qvgnsh", long_options, &option_index); #elif (EVMLOG_MODULE_TRACE != 0) && (EVMLOG_MODULE_DEBUG == 0) c = getopt_long(argc, argv, "qvtnsh", long_options, &option_index); #else c = getopt_long(argc, argv, "qvnsh", long_options, &option_index); #endif if (c == -1) break; switch (c) { case 'q': evmlog_normal = 0; break; case 'v': evmlog_verbose = 1; break; #if (EVMLOG_MODULE_TRACE != 0) case 't': evmlog_trace = 1; break; #endif #if (EVMLOG_MODULE_DEBUG != 0) case 'g': evmlog_debug = 1; break; #endif case 'n': evmlog_add_header = 0; break; case 's': evmlog_use_syslog = 1; break; case 'h': usage_help(argv); exit(EXIT_SUCCESS); case '?': exit(EXIT_FAILURE); break; default: printf("?? getopt returned character code 0%o ??\n", c); exit(EXIT_FAILURE); } } if (optind < argc) { char *param = argv[optind]; if ((num_additional_threads = atoi(param)) >= 0) optind++; } if (optind < argc) { printf("non-option ARGV-elements: "); while (optind < argc) printf("%s ", argv[optind++]); printf("\n"); exit(EXIT_FAILURE); } return 0; }
int main P2C(int,argc,string*,argv) #line 104 "./ctie.w" { #line 38 "./ctie-k.ch" /*5:*/ #line 84 "./ctie-k.ch" kpse_set_program_name(argv[0],"ctie"); /*:5*/ #line 38 "./ctie-k.ch" ; /*19:*/ #line 300 "./ctie.w" actual_input= 0; out_mode= normal; /*:19*/ #line 39 "./ctie-k.ch" ; #line 106 "./ctie.w" /*63:*/ #line 1135 "./ctie.w" { if(argc> max_file_index+5-1)usage_error(); no_ch= -1; while(--argc> 0){ argv++; if(strcmp("-help",*argv)==0||strcmp("--help",*argv)==0) /*66:*/ #line 1202 "./ctie.w" usage_help(); /*:66*/ #line 1142 "./ctie.w" ; if(strcmp("-version",*argv)==0||strcmp("--version",*argv)==0) /*67:*/ #line 1208 "./ctie.w" { print_version_and_exit("CTIE",version_number); } /*:67*/ #line 1144 "./ctie.w" ; if(**argv=='-')/*64:*/ #line 1158 "./ctie.w" if(prod_chf!=unknown)usage_error(); else switch(*(*argv+1)){ case'c':case'C':prod_chf= chf;break; case'm':case'M':prod_chf= master;break; default:usage_error(); } /*:64*/ #line 1145 "./ctie.w" else/*65:*/ #line 1172 "./ctie.w" { if(no_ch==(-1)){ out_name= *argv; }else{ register input_description*inp_desc; inp_desc= (input_description*)malloc(sizeof(input_description)); if(inp_desc==NULL) fatal_error(-1,"! No memory for input descriptor",""); inp_desc->mode= search; inp_desc->line= 0; inp_desc->type_of_file= chf; inp_desc->limit= inp_desc->buffer; inp_desc->buffer[0]= ' '; inp_desc->loc= inp_desc->buffer+1; inp_desc->buffer_end= inp_desc->buffer+buf_size-2; inp_desc->file_name= *argv; inp_desc->current_include= NULL; input_organisation[no_ch]= inp_desc; } no_ch++; } /*:65*/ #line 1146 "./ctie.w" } if(no_ch<=0||prod_chf==unknown)usage_error(); } /*:63*/ #line 106 "./ctie.w" /*62:*/ #line 1118 "./ctie.w" #line 382 "./ctie-k.ch" { extern KPSEDLL string kpathsea_version_string; printf("%s (%s)\n",banner,kpathsea_version_string); } #line 1120 "./ctie.w" printf("%s\n",copyright); /*:62*/ #line 107 "./ctie.w" ; /*42:*/ #line 277 "./ctie-k.ch" { string fullname; fullname= kpse_find_cweb(input_organisation[0]->file_name); if(fullname) input_organisation[0]->the_file= fopen(fullname,"r"); if(fullname==NULL||input_organisation[0]->the_file==NULL){ if(fullname){ pfatal_error("! Cannot open master file ", input_organisation[0]->file_name); }else{ fatal_error(-1,"! Cannot find master file ", input_organisation[0]->file_name); } } else free(fullname); #line 759 "./ctie.w" printf("(%s)\n",input_organisation[0]->file_name); input_organisation[0]->type_of_file= master; get_line(0,true); } /*:42*/ #line 108 "./ctie.w" /*43:*/ #line 313 "./ctie-k.ch" { file_index i; string fullname; i= 1; while(i<no_ch){ fullname= kpse_find_cweb(input_organisation[i]->file_name); if(fullname) input_organisation[i]->the_file= fopen(fullname,"r"); if(fullname==NULL||input_organisation[i]->the_file==NULL){ if(fullname){ pfatal_error("! Cannot open change file ", input_organisation[i]->file_name); }else{ fatal_error(-1,"! Cannot find change file ", input_organisation[i]->file_name); } } else free(fullname); #line 780 "./ctie.w" printf("(%s)\n",input_organisation[i]->file_name); init_change_file(i); i++; } } /*:43*/ #line 109 "./ctie.w" /*40:*/ #line 729 "./ctie.w" { out_file= fopen(out_name,"w"); if(out_file==NULL){ pfatal_error("! Cannot open/create output file",""); } } /*:40*/ #line 110 "./ctie.w" /*59:*/ #line 1074 "./ctie.w" actual_input= 0; input_has_ended= false; while(input_has_ended==false||actual_input!=0) /*51:*/ #line 917 "./ctie.w" { file_index test_file; /*52:*/ #line 934 "./ctie.w" { register input_description*inp_desc; while(actual_input> 0&&e_of_ch_module(actual_input)){ inp_desc= input_organisation[actual_input]; if(inp_desc->type_of_file==master){ fatal_error(-1,"! This can't happen: change file is master file",""); } inp_desc->mode= search; init_change_file(actual_input); while((input_organisation[actual_input]->mode!=reading &&actual_input> 0)) actual_input--; } } /*:52*/ #line 921 "./ctie.w" if(input_has_ended&&actual_input==0)break; /*53:*/ #line 960 "./ctie.w" test_input= none; test_file= actual_input; while(test_input==none&&test_file<no_ch-1){ test_file++; switch(input_organisation[test_file]->mode){ case search: if(lines_dont_match(actual_input,test_file)==false){ input_organisation[test_file]->mode= test; test_input= test_file; } break; case test: if(lines_dont_match(actual_input,test_file)){ input_organisation[test_file]->dont_match++; } test_input= test_file; break; case reading: break; case ignore: break; } } /*:53*/ #line 923 "./ctie.w" /*54:*/ #line 993 "./ctie.w" if(prod_chf==chf){ while(1){ /*55:*/ #line 1007 "./ctie.w" if(out_mode==normal){ if(test_input!=none){ fprintf(out_file,"@x\n"); out_mode= pre; }else break; } /*:55*/ #line 996 "./ctie.w" /*56:*/ #line 1021 "./ctie.w" if(out_mode==pre){ if(test_input==none){ fprintf(out_file,"@y\n"); out_mode= post; }else{ if(input_organisation[actual_input]->type_of_file==master) put_line(actual_input); break; } } /*:56*/ #line 997 "./ctie.w" /*57:*/ #line 1040 "./ctie.w" if(out_mode==post){ if(input_organisation[actual_input]->type_of_file==chf){ if(test_input==none)put_line(actual_input); break; }else{ fprintf(out_file,"@z\n\n"); out_mode= normal; } } /*:57*/ #line 998 "./ctie.w" } }else if(test_input==none)put_line(actual_input); /*:54*/ #line 924 "./ctie.w" /*58:*/ #line 1055 "./ctie.w" get_line(actual_input,true); if(test_input!=none){ get_line(test_input,true); if(e_of_ch_preamble(test_input)==true){ get_line(test_input,true); input_organisation[test_input]->mode= reading; actual_input= test_input; test_input= none; } } /*:58*/ #line 925 "./ctie.w" } /*:51*/ #line 1078 "./ctie.w" if(out_mode==post) fprintf(out_file,"@z\n"); /*:59*/ #line 111 "./ctie.w" /*60:*/ #line 1087 "./ctie.w" { file_index i; for(i= 1;i<no_ch;i++){ if(input_organisation[i]->mode!=ignore){ input_organisation[i]->loc= input_organisation[i]->buffer; err_print(i,"! Change file entry did not match"); } } } /*:60*/ #line 112 "./ctie.w" exit(wrap_up()); }
int main(int argc, char **argv) { INIT_GLB_VARS(); SET_PROCESS_ROLE(PROCESS_ROLE_MASTER); SET_CHILD_PROCESS(PROCESS_ROLE_MASTER, getpid()); /* 此处注册清理函数, 以便主进程由于某些原因退出时, kill掉 * 启动的所有子进程. 但man atexit可知, 通过fork的子进程会 * 继承atexit的注册链, 而exec后将抛弃此注册链. * <NOTE> 此处不考虑fork子进程也执行此函数带来的影响 */ (void)atexit(kill_child_all); if (log_init() == RET_ERR) { SDNS_LOG_ERR("LOG init failed"); exit(EXIT_FAILURE); } if (zone_init() == RET_ERR) { SDNS_LOG_ERR("ZONE init failed"); exit(EXIT_FAILURE); } if (get_options(argc, argv) == RET_ERR) { SDNS_LOG_ERR("parse cmdline failed"); usage_help(); exit(EXIT_FAILURE); } if (IS_PROCESS_ROLE(PROCESS_ROLE_SIGNALLER)) { process_option_signal(); exit(EXIT_SUCCESS); } if (IS_PROCESS_ROLE(PROCESS_ROLE_HELPER)) { usage_help(); exit(EXIT_SUCCESS); } if (start_monitor() == RET_ERR) { exit(EXIT_FAILURE); } if (parse_conf() == RET_ERR) { exit(EXIT_FAILURE); } if (IS_PROCESS_ROLE(PROCESS_ROLE_TESTER)) { SDNS_LOG_DEBUG("配置文件测试OK"); print_parse_res(); exit(EXIT_SUCCESS); } if (pkt_engine_init() == RET_ERR) { SDNS_LOG_ERR("engine init failed"); exit(EXIT_FAILURE); } if (set_required_signal() == RET_ERR || block_required_signal() == RET_ERR) { SDNS_LOG_ERR("signal init failed"); exit(EXIT_FAILURE); } if (sort_init() == RET_ERR) { SDNS_LOG_ERR("sort init failed"); exit(EXIT_FAILURE); } start_worker(); if (start_pkt_engine() == RET_ERR) { SDNS_LOG_ERR("start engine failed"); exit(EXIT_FAILURE); } for(;;) { (void)wait_required_signal(); (void)process_signals(); } exit(EXIT_SUCCESS); }
int cmd_mkdent(int argc, char **argv) { char opt; int ret; char *id = NULL; char *path = NULL; dpl_ftype_t ftype = DPL_FTYPE_REG; var_set("status", "1", VAR_CMD_SET, NULL); optind = 0; while ((opt = linux_getopt(argc, argv, "t:l")) != -1) switch (opt) { case 'l': list_object_types(); return SHELL_CONT; break ; case 't': if (!strcasecmp(optarg, "reg")) ftype = DPL_FTYPE_REG; else if (!strcasecmp(optarg, "chrdev")) ftype = DPL_FTYPE_CHRDEV; else if (!strcasecmp(optarg, "blkdev")) ftype = DPL_FTYPE_BLKDEV; else if (!strcasecmp(optarg, "fifo")) ftype = DPL_FTYPE_FIFO; else if (!strcasecmp(optarg, "socket")) ftype = DPL_FTYPE_SOCKET; else if (!strcasecmp(optarg, "symlink")) ftype = DPL_FTYPE_SYMLINK; else { fprintf(stderr, "not supported\n"); return SHELL_CONT; } break ; case '?': default: usage_help(&mkdent_cmd); return SHELL_CONT; } argc -= optind; argv += optind; if (2 != argc) { usage_help(&mkdent_cmd); return SHELL_CONT; } id = argv[0]; path = argv[1]; ret = dpl_mkdent(ctx, id, path, ftype); if (DPL_SUCCESS != ret) { fprintf(stderr, "status %s (%d)\n", dpl_status_str(ret), ret); goto end; } var_set("status", "0", VAR_CMD_SET, NULL); end: return SHELL_CONT; }
int cmd_get(int argc, char **argv) { int ret; char opt; char *path = NULL; dpl_dict_t *metadata = NULL; struct get_data get_data; int do_stdout = 0; int kflag = 0; char *local_file = NULL; int start = -1; int start_inited = 0; int end = -1; int end_inited = 0; int mflag = 0; memset(&get_data, 0, sizeof (get_data)); get_data.fd = -1; var_set("status", "1", VAR_CMD_SET, NULL); optind = 0; while ((opt = getopt(argc, argv, usage_getoptstr(get_usage))) != -1) switch (opt) { case 'm': mflag = 1; break ; case 's': start = strtol(optarg, NULL, 0); start_inited = 1; break ; case 'e': end = strtol(optarg, NULL, 0); end_inited = 1; break ; case 'k': kflag = 1; break ; case '?': default: usage_help(&get_cmd); return SHELL_CONT; } argc -= optind; argv += optind; if (start_inited != end_inited) { fprintf(stderr, "please provide -s and -e\n"); return SHELL_CONT; } if (2 == argc) { path = argv[0]; local_file = argv[1]; } else if (1 == argc) { path = argv[0]; local_file = rindex(path, '/'); if (NULL != local_file) local_file++; else local_file = path; } else { usage_help(&get_cmd); return SHELL_CONT; } if (!strcmp(local_file, "-")) { get_data.fd = 1; do_stdout = 1; } else if ('|' == local_file[0]) { get_data.pipe = popen(local_file + 1, "w"); if (NULL == get_data.pipe) { fprintf(stderr, "pipe failed\n"); goto end; } } else { ret = access(local_file, F_OK); if (0 == ret) { if (1 == ask_for_confirmation("file already exists, overwrite?")) return SHELL_CONT; } get_data.fd = open(local_file, O_WRONLY|O_CREAT, 0600); if (-1 == get_data.fd) { perror("open"); goto end; } } if (1 == start_inited && 1 == end_inited) { char *data_buf; u_int data_len; ret = dpl_openread_range(ctx, path, (1 == kflag ? DPL_VFILE_FLAG_ENCRYPT : 0u), NULL, start, end, &data_buf, &data_len, &metadata); if (DPL_SUCCESS != ret) { fprintf(stderr, "status: %s (%d)\n", dpl_status_str(ret), ret); goto end; } ret = write_all(get_data.fd, data_buf, data_len); free(data_buf); if (0 != ret) { fprintf(stderr, "short write\n"); goto end; } if (1 == mflag) dpl_dict_iterate(metadata, cb_print_metadata, NULL); } else { ret = dpl_openread(ctx, path, (1 == kflag ? DPL_VFILE_FLAG_ENCRYPT : 0u), NULL, cb_get_buffered, &get_data, &metadata); if (DPL_SUCCESS != ret) { fprintf(stderr, "status: %s (%d)\n", dpl_status_str(ret), ret); goto end; } if (1 == mflag) dpl_dict_iterate(metadata, cb_print_metadata, NULL); } var_set("status", "0", VAR_CMD_SET, NULL); end: if (NULL != metadata) dpl_dict_free(metadata); if (0 == do_stdout) { if (-1 != get_data.fd) close(get_data.fd); if (NULL != get_data.pipe) pclose(get_data.pipe); } return SHELL_CONT; }
int cmd_mb(int argc, char **argv) { int ret; char opt; char *bucket; char *resource; dpl_canned_acl_t canned_acl = DPL_CANNED_ACL_PRIVATE; int Aflag = 0; int i; dpl_location_constraint_t location_constraint = DPL_LOCATION_CONSTRAINT_US_STANDARD; int Lflag = 0; var_set("status", "1", VAR_CMD_SET, NULL); optind = 0; while ((opt = getopt(argc, argv, usage_getoptstr(mb_usage))) != -1) switch (opt) { case 'l': location_constraint = dpl_location_constraint(optarg); if (-1 == location_constraint) { fprintf(stderr, "bad location constraint '%s'\n", optarg); return SHELL_CONT; } break ; case 'L': Lflag = 1; break ; case 'a': canned_acl = dpl_canned_acl(optarg); if (-1 == canned_acl) { fprintf(stderr, "bad canned acl '%s'\n", optarg); return SHELL_CONT; } break ; case 'A': Aflag = 1; break ; case '?': default: usage_help(&mb_cmd); return SHELL_CONT; } argc -= optind; argv += optind; if (1 == Aflag) { for (i = 0;i < DPL_N_CANNED_ACL;i++) printf("%s\n", dpl_canned_acl_str(i)); return SHELL_CONT; } if (1 == Lflag) { for (i = 0;i < DPL_N_LOCATION_CONSTRAINT;i++) printf("%s\n", dpl_location_constraint_str(i)); return SHELL_CONT; } if (1 != argc) { usage_help(&mb_cmd); return SHELL_CONT; } bucket = argv[0]; resource = "/"; ret = dpl_make_bucket(ctx, bucket, location_constraint, canned_acl); if (DPL_SUCCESS != ret) { fprintf(stderr, "status: %s (%d)\n", dpl_status_str(ret), ret); return SHELL_CONT; } var_set("status", "0", VAR_CMD_SET, NULL); return SHELL_CONT; }
int cmd_mknod(int argc, char **argv) { char opt; int ret; char *id = NULL; char *path = NULL; dpl_ftype_t ftype = DPL_FTYPE_REG; var_set("status", "1", VAR_CMD_SET, NULL); optind = 0; while ((opt = linux_getopt(argc, argv, "t:l")) != -1) switch (opt) { case 'l': list_object_types(); return SHELL_CONT; break ; case 't': if (!strcasecmp(optarg, "reg")) ftype = DPL_FTYPE_REG; else if (!strcasecmp(optarg, "chrdev")) ftype = DPL_FTYPE_CHRDEV; else if (!strcasecmp(optarg, "blkdev")) ftype = DPL_FTYPE_BLKDEV; else if (!strcasecmp(optarg, "fifo")) ftype = DPL_FTYPE_FIFO; else if (!strcasecmp(optarg, "socket")) ftype = DPL_FTYPE_SOCKET; else if (!strcasecmp(optarg, "symlink")) ftype = DPL_FTYPE_SYMLINK; else { fprintf(stderr, "not supported\n"); return SHELL_CONT; } break ; case '?': default: usage_help(&mknod_cmd); return SHELL_CONT; } argc -= optind; argv += optind; if (1 != argc) { usage_help(&mknod_cmd); return SHELL_CONT; } path = argv[0]; if (! strcmp("s3", (char *) dpl_get_backend_name(ctx))) { if (-1 == path_contains_valid_bucketname(ctx, path)) { fprintf(stderr, "You need to set a bucket to use 'mknod' " "(use 'la' to list the buckets)\n"); goto end; } } ret = dpl_mknod(ctx, path, ftype, NULL, NULL); if (DPL_SUCCESS != ret) { fprintf(stderr, "status %s (%d)\n", dpl_status_str(ret), ret); goto end; } var_set("status", "0", VAR_CMD_SET, NULL); end: return SHELL_CONT; }
int cmd_put(int argc, char **argv) { int ret; char opt; dpl_canned_acl_t canned_acl = DPL_CANNED_ACL_PRIVATE; int Aflag = 0; int i; int fd = -1; dpl_dict_t *metadata = NULL; char *local_file = NULL; char *remote_file = NULL; dpl_vfile_t *vfile = NULL; size_t block_size = 64*1024; ssize_t cc; struct stat st; int kflag = 0; char *buf; var_set("status", "1", VAR_CMD_SET, NULL); optind = 0; while ((opt = getopt(argc, argv, usage_getoptstr(put_usage))) != -1) switch (opt) { case 'k': kflag = 1; break ; case 'm': metadata = dpl_parse_metadata(optarg); if (NULL == metadata) { fprintf(stderr, "error parsing metadata\n"); return SHELL_CONT; } break ; case 'a': canned_acl = dpl_canned_acl(optarg); if (-1 == canned_acl) { fprintf(stderr, "bad canned acl '%s'\n", optarg); return SHELL_CONT; } break ; case 'A': Aflag = 1; break ; case '?': default: usage_help(&put_cmd); return SHELL_CONT; } argc -= optind; argv += optind; if (1 == Aflag) { for (i = 0;i < DPL_N_CANNED_ACL;i++) printf("%s\n", dpl_canned_acl_str(i)); return SHELL_CONT; } if (2 == argc) { char *p, *p2; local_file = argv[0]; remote_file = argv[1]; p = index(remote_file, ':'); if (NULL != p) { p++; if (!strcmp(p, "")) { p2 = rindex(local_file, '/'); if (NULL != p2) { p2++; strcat(remote_file, p2); } else { strcat(remote_file, local_file); } } } } else if (1 == argc) { local_file = argv[0]; remote_file = rindex(local_file, '/'); if (NULL != remote_file) remote_file++; else remote_file = local_file; } else { usage_help(&put_cmd); return SHELL_CONT; } fd = open(local_file, O_RDONLY); if (-1 == fd) { perror("open"); goto end; } buf = alloca(block_size); ret = fstat(fd, &st); if (-1 == ret) { perror("fstat"); return SHELL_CONT; } ret = dpl_openwrite(ctx, remote_file, DPL_VFILE_FLAG_CREAT | (1 == kflag ? DPL_VFILE_FLAG_ENCRYPT : DPL_VFILE_FLAG_MD5), metadata, canned_acl, st.st_size, &vfile); if (DPL_SUCCESS != ret) { fprintf(stderr, "status: %s (%d)\n", dpl_status_str(ret), ret); return SHELL_CONT; } while (1) { cc = read(fd, buf, block_size); if (-1 == cc) { perror("read"); return -1; } if (0 == cc) { break ; } ret = dpl_write(vfile, buf, cc); if (DPL_SUCCESS != ret) { fprintf(stderr, "write failed\n"); return SHELL_CONT; } if (1 == hash) { fprintf(stderr, "#"); fflush(stderr); } } ret = dpl_close(vfile); if (DPL_SUCCESS != ret) { fprintf(stderr, "close failed %s (%d)\n", dpl_status_str(ret), ret); return SHELL_CONT; } vfile = NULL; var_set("status", "0", VAR_CMD_SET, NULL); end: if (-1 != fd) close(fd); if (NULL != metadata) dpl_dict_free(metadata); if (NULL != vfile) dpl_close(vfile); return SHELL_CONT; }
int main(int argc, char **argv) { struct CatalogEntry ced; struct CatalogEntry *ce = &ced; struct VolId vid; char buf[256]; char *string; uint64_t value; uint32_t mask; int field; int status; if (CatalogInit(program_name) == -1) { error(EXIT_FAILURE, errno, GetCustMsg(18211)); /* Catalog initialization failed */ } argv++; argc--; if (argc < 2 || argc > 3) { if (argc == 1 && strcmp(*argv, "-flags") == 0) { usage_help(); } else { usage(); } } if (strcmp(*argv, "-capacity") == 0) { argc--; argv++; field = CEF_Capacity; if (StrToFsize(*argv, &value) == -1) { error(EXIT_USAGE, 0, GetCustMsg(13612), *argv); } value /= 1024; } else if (strcmp(*argv, "-count") == 0) { char *final_char; argc--; argv++; field = CEF_Access; value = strtoll(*argv, &final_char, 0); if (final_char != NULL && *final_char != '\0') { error(0, 0, GetCustMsg(13614), *argv); usage(); } } else if (strcmp(*argv, "-mtype") == 0) { argc--; argv++; field = CEF_MediaType; string = *argv; } else if (strcmp(*argv, "-space") == 0) { argc--; argv++; field = CEF_Space; if (StrToFsize(*argv, &value) == -1) { error(EXIT_USAGE, 0, GetCustMsg(13613), *argv); } value /= 1024; } else if (strcmp(*argv, "-time") == 0) { argc--; argv++; field = CEF_MountTime; value = StrToTime(*argv); if ((int64_t)value <= 0) { /* N.B. bad indentation here to meet cstyle requirements */ fprintf(stderr, "%s: Cannot convert date \"%s\". Valid formats are:\n" " yyyy-mm-dd [hh:mm[:ss]]\n" " Month-name Day [4-digit-year] [hh:mm]\n" " -or- Day Month-name [4-digit-year] [hh:mm]\n", program_name, *argv); exit(EXIT_FAILURE); } } else if (strcmp(*argv, "-vsn") == 0) { argc--; argv++; field = CEF_Vsn; string = *argv; } else if (strcmp(*argv, "-I") == 0) { argc--; argv++; field = CEF_VolInfo; string = *argv; } else if (**argv == '-' || **argv == '+') { char *flags; /* User specified "+-flags specifier" */ field = CEF_Status; flags = *argv + 1; mask = 0; while (*flags != '\0') { switch (*flags++) { case 'A': mask |= CES_needs_audit; break; case 'l': mask |= CES_labeled; break; case 'E': mask |= CES_bad_media; break; case 'o': mask |= CES_occupied; break; case 'C': mask |= CES_cleaning; break; case 'b': mask |= CES_bar_code; break; case 'W': mask |= CES_writeprotect; break; case 'R': mask |= CES_read_only; break; case 'c': mask |= CES_recycle; break; case 'U': mask |= CES_unavail; break; case 'N': mask |= CES_non_sam; break; case 'p': mask |= CES_priority; break; case 'X': mask |= CES_export_slot; break; case 'd': mask |= CES_dupvsn; break; case 'f': mask |= CES_archfull; break; default: error(0, 0, GetCustMsg(13615), *argv); usage(); break; } } if (**argv == '-') value = 0; else value = mask; } else { error(0, 0, GetCustMsg(13611), *argv); usage(); } argc--; argv++; /* * There must be only one argument left - the volume identifier. */ if (*argv == NULL) { /* not enough */ usage(); } else if (argc != 1) { /* too many */ error(0, 0, GetCustMsg(13600), *argv); usage(); } /* * Convert argument to volume identifier. */ if (StrToVolId(*argv, &vid) != 0) { error(EXIT_FAILURE, errno, GetCustMsg(13600), *argv); } /* * Use CatalogGetEntry() to validate the specifier. */ if ((ce = CatalogGetEntry(&vid, &ced)) == NULL) { error(EXIT_FAILURE, errno, GetCustMsg(13600), *argv); } /* * Make the required change. */ if ((field != CEF_Vsn) && (field != CEF_MediaType) && (field != CEF_VolInfo)) { if ((field != CEF_Capacity) && (field != CEF_Space)) status = CatalogSetField(&vid, field, (uint32_t)value, mask); else { status = CatalogSetField(&vid, field, value, mask); if (field == CEF_Capacity) { field = CEF_Status; value = mask = CES_capacity_set; (void) CatalogSetField(&vid, field, (uint32_t)value, mask); } } } else { status = CatalogSetString(&vid, field, string); } if (status != 0) { error(EXIT_FAILURE, errno, GetCustMsg(13616), *argv); } /* * Display results. */ if (vid.ViFlags == VI_cart) { /* * Volume was specified as eq:slot[:partition] * If tape, list partition 0 * If m.o., list partitions 1 and 2 */ vid.ViFlags |= VI_part; for (vid.ViPart = 0; /* Terminated inside. */; vid.ViPart++) { if ((ce = CatalogGetEntry(&vid, &ced)) == NULL) break; printf("%s\n", CatalogStrFromEntry(ce, buf, sizeof (buf))); vid.ViPart = ce->CePart; } } else if ((ce = CatalogGetEntry(&vid, &ced)) != NULL) { printf("%s\n", CatalogStrFromEntry(ce, buf, sizeof (buf))); } return (EXIT_SUCCESS); }