void env_opt_end(int emptyok) { int len; len = opt_replyp - opt_reply + 2; if (emptyok || len > 6) { opt_add(IAC); opt_add(SE); if (NETROOM() > len) { ring_supply_data(&netoring, opt_reply, len); printsub('>', &opt_reply[2], len - 2); } /*@*/ else printf("slc_end_reply: not enough room\n"); } if (opt_reply) { free(opt_reply); opt_reply = opt_replyp = opt_replyend = NULL; } }
static void env_opt_start(void) { unsigned char *p; p = realloc(opt_reply, OPT_REPLY_SIZE); if (p == NULL) free(opt_reply); opt_reply = p; if (opt_reply == NULL) { /*@*/ printf("env_opt_start: realloc() failed!!!\n"); opt_reply = opt_replyp = opt_replyend = NULL; return; } opt_replyp = opt_reply; opt_replyend = opt_reply + OPT_REPLY_SIZE; opt_add(IAC); opt_add(SB); opt_add(telopt_environ); opt_add(TELQUAL_IS); }
char * qp_plot_opt_gen( PlotOptions * opt, bool hplot_only ) { char * p; p = str_new( "" ); opt_add( &p, "LEGO1", opt->lego1 ); opt_add( &p, "LEGO2", opt->lego2 ); if ( !hplot_only ) opt_add( &p, "PROFI", opt->profi ); if ( !hplot_only ) opt_add( &p, "PROFS", opt->profs ); opt_add( &p, "SURF1", opt->surf1 ); opt_add( &p, "SURF2", opt->surf2 ); opt_add( &p, "SURF3", opt->surf3 ); opt_add( &p, "SURF4", opt->surf4 ); opt_add( &p, "CHAR", opt->chr ); opt_add( &p, "CONT", opt->cont ); opt_add( &p, "FUNC", opt->func ); opt_add( &p, "HIST", opt->hist ); opt_add( &p, "LEGO", opt->lego ); if ( !hplot_only ) opt_add( &p, "PROF", opt->prof ); opt_add( &p, "SURF", opt->surf ); opt_add( &p, "TEXT", opt->text ); opt_add( &p, "BOX", opt->box ); opt_add( &p, "COL", opt->col ); opt_add( &p, "CYL", opt->cyl ); opt_add( &p, "POL", opt->pol ); opt_add( &p, "PSD", opt->psd ); opt_add( &p, "SPH", opt->sph ); opt_add( &p, "+-", opt->diff ); opt_add( &p, "BB", opt->BB ); opt_add( &p, "E0", opt->e0 ); opt_add( &p, "E1", opt->e1 ); opt_add( &p, "E2", opt->e2 ); opt_add( &p, "E3", opt->e3 ); opt_add( &p, "E4", opt->e4 ); opt_add( &p, "FB", opt->FB ); opt_add( &p, "*", opt->star ); opt_add( &p, "+", opt->add ); opt_add( &p, "-", opt->sub ); opt_add( &p, "A", opt->A ); opt_add( &p, "B", opt->B ); opt_add( &p, "C", opt->C ); opt_add( &p, "E", opt->E ); opt_add( &p, "G", opt->gouraud ); opt_add( &p, "K", opt->K ); opt_add( &p, "L", opt->line ); opt_add( &p, "P", opt->P ); opt_add( &p, "S", opt->S ); opt_add( &p, "U", opt->U ); opt_add( &p, "Z", opt->Z ); return p; }
static void tar_options(int argc, char **argv) { int c; int fstdin = 0; int Oflag = 0; int nincfiles = 0; int incfiles_max = 0; struct incfile { char *file; char *dir; }; struct incfile *incfiles = NULL; /* * Set default values. */ rmleadslash = 1; /* * process option flags */ while ((c = getoldopt(argc, argv, "b:cef:hjmopqruts:vwxzBC:HI:LNOPXZ014578")) != -1) { switch (c) { case 'b': /* * specify blocksize in 512-byte blocks */ if ((wrblksz = (int)str_offt(optarg)) <= 0) { paxwarn(1, "Invalid block size %s", optarg); tar_usage(); } wrblksz *= 512; /* XXX - check for int oflow */ break; case 'c': /* * create an archive */ act = ARCHIVE; break; case 'e': /* * stop after first error */ maxflt = 0; break; case 'f': /* * filename where the archive is stored */ if ((optarg[0] == '-') && (optarg[1]== '\0')) { /* * treat a - as stdin */ fstdin = 1; arcname = NULL; break; } fstdin = 0; arcname = optarg; break; case 'h': /* * follow symlinks */ Lflag = 1; break; case 'j': /* * use bzip2. Non standard option. */ gzip_program = BZIP2_CMD; break; case 'm': /* * do not preserve modification time */ pmtime = 0; break; case 'O': Oflag = 1; break; case 'o': Oflag = 2; break; case 'p': /* * preserve uid/gid and file mode, regardless of umask */ pmode = 1; pids = 1; break; case 'q': /* * select first match for a pattern only */ nflag = 1; break; case 'r': case 'u': /* * append to the archive */ act = APPND; break; case 's': /* * file name substitution name pattern */ if (rep_add(optarg) < 0) { tar_usage(); break; } break; case 't': /* * list contents of the tape */ act = LIST; break; case 'v': /* * verbose operation mode */ vflag++; break; case 'w': /* * interactive file rename */ iflag = 1; break; case 'x': /* * extract an archive, preserving mode, * and mtime if possible. */ act = EXTRACT; pmtime = 1; break; case 'z': /* * use gzip. Non standard option. */ gzip_program = GZIP_CMD; break; case 'B': /* * Nothing to do here, this is pax default */ break; case 'C': havechd++; chdname = optarg; break; case 'H': /* * follow command line symlinks only */ Hflag = 1; break; case 'I': if (++nincfiles > incfiles_max) { size_t n = nincfiles + 3; struct incfile *p; p = realloc(incfiles, sizeof(*incfiles) * n); if (p == NULL) { free(incfiles); incfiles = NULL; paxwarn(0, "Unable to allocate space " "for option list"); exit(1); } incfiles = p; incfiles_max = n; } incfiles[nincfiles - 1].file = optarg; incfiles[nincfiles - 1].dir = chdname; break; case 'L': /* * follow symlinks */ Lflag = 1; break; case 'N': /* numeric uid and gid only */ Nflag = 1; break; case 'P': /* * do not remove leading '/' from pathnames */ rmleadslash = 0; break; case 'X': /* * do not pass over mount points in the file system */ Xflag = 1; break; case 'Z': /* * use compress. */ gzip_program = COMPRESS_CMD; break; case '0': arcname = DEV_0; break; case '1': arcname = DEV_1; break; case '4': arcname = DEV_4; break; case '5': arcname = DEV_5; break; case '7': arcname = DEV_7; break; case '8': arcname = DEV_8; break; default: tar_usage(); break; } } argc -= optind; argv += optind; /* Traditional tar behaviour (pax uses stderr unless in list mode) */ if (fstdin == 1 && act == ARCHIVE) listf = stderr; else listf = stdout; /* Traditional tar behaviour (pax wants to read file list from stdin) */ if ((act == ARCHIVE || act == APPND) && argc == 0 && nincfiles == 0) exit(0); /* * process the args as they are interpreted by the operation mode */ switch (act) { case LIST: case EXTRACT: default: { int sawpat = 0; char *file, *dir; while (nincfiles || *argv != NULL) { /* * If we queued up any include files, * pull them in now. Otherwise, check * for -I and -C positional flags. * Anything else must be a file to * extract. */ if (nincfiles) { file = incfiles->file; dir = incfiles->dir; incfiles++; nincfiles--; } else if (strcmp(*argv, "-I") == 0) { if (*++argv == NULL) break; file = *argv++; dir = chdname; } else file = NULL; if (file != NULL) { FILE *fp; char *str; if (strcmp(file, "-") == 0) fp = stdin; else if ((fp = fopen(file, "r")) == NULL) { paxwarn(1, "Unable to open file '%s' for read", file); tar_usage(); } while ((str = get_line(fp)) != NULL) { if (pat_add(str, dir) < 0) tar_usage(); sawpat = 1; } if (strcmp(file, "-") != 0) fclose(fp); if (getline_error) { paxwarn(1, "Problem with file '%s'", file); tar_usage(); } } else if (strcmp(*argv, "-C") == 0) { if (*++argv == NULL) break; chdname = *argv++; havechd++; } else if (pat_add(*argv++, chdname) < 0) tar_usage(); else sawpat = 1; } /* * if patterns were added, we are doing chdir() * on a file-by-file basis, else, just one * global chdir (if any) after opening input. */ if (sawpat > 0) chdname = NULL; } break; case ARCHIVE: case APPND: frmt = &(fsub[Oflag ? F_OTAR : F_TAR]); if (Oflag == 2 && opt_add("write_opt=nodir") < 0) tar_usage(); if (chdname != NULL) { /* initial chdir() */ if (ftree_add(chdname, 1) < 0) tar_usage(); } while (nincfiles || *argv != NULL) { char *file, *dir; /* * If we queued up any include files, pull them in * now. Otherwise, check for -I and -C positional * flags. Anything else must be a file to include * in the archive. */ if (nincfiles) { file = incfiles->file; dir = incfiles->dir; incfiles++; nincfiles--; } else if (strcmp(*argv, "-I") == 0) { if (*++argv == NULL) break; file = *argv++; dir = NULL; } else file = NULL; if (file != NULL) { FILE *fp; char *str; /* Set directory if needed */ if (dir) { if (ftree_add(dir, 1) < 0) tar_usage(); } if (strcmp(file, "-") == 0) fp = stdin; else if ((fp = fopen(file, "r")) == NULL) { paxwarn(1, "Unable to open file '%s' for read", file); tar_usage(); } while ((str = get_line(fp)) != NULL) { if (ftree_add(str, 0) < 0) tar_usage(); } if (strcmp(file, "-") != 0) fclose(fp); if (getline_error) { paxwarn(1, "Problem with file '%s'", file); tar_usage(); } } else if (strcmp(*argv, "-C") == 0) { if (*++argv == NULL) break; if (ftree_add(*argv++, 1) < 0) tar_usage(); havechd++; } else if (ftree_add(*argv++, 0) < 0) tar_usage(); } /* * no read errors allowed on updates/append operation! */ maxflt = 0; break; } if (!fstdin && ((arcname == NULL) || (*arcname == '\0'))) { arcname = getenv("TAPE"); if ((arcname == NULL) || (*arcname == '\0')) arcname = _PATH_DEFTAPE; } }
static void pax_options(int argc, char **argv) { int c; unsigned i; unsigned int flg = 0; unsigned int bflg = 0; char *pt; /* * process option flags */ while ((c=getopt(argc,argv,"ab:cdf:ijklno:p:rs:tuvwx:zB:DE:G:HLOPT:U:XYZ0")) != -1) { switch (c) { case 'a': /* * append */ flg |= AF; break; case 'b': /* * specify blocksize */ flg |= BF; if ((wrblksz = (int)str_offt(optarg)) <= 0) { paxwarn(1, "Invalid block size %s", optarg); pax_usage(); } break; case 'c': /* * inverse match on patterns */ cflag = 1; flg |= CF; break; case 'd': /* * match only dir on extract, not the subtree at dir */ dflag = 1; flg |= DF; break; case 'f': /* * filename where the archive is stored */ arcname = optarg; flg |= FF; break; case 'i': /* * interactive file rename */ iflag = 1; flg |= IF; break; case 'j': /* * use bzip2. Non standard option. */ gzip_program = BZIP2_CMD; break; case 'k': /* * do not clobber files that exist */ kflag = 1; flg |= KF; break; case 'l': /* * try to link src to dest with copy (-rw) */ lflag = 1; flg |= LF; break; case 'n': /* * select first match for a pattern only */ nflag = 1; flg |= NF; break; case 'o': /* * pass format specific options */ flg |= OF; if (opt_add(optarg) < 0) pax_usage(); break; case 'p': /* * specify file characteristic options */ for (pt = optarg; *pt != '\0'; ++pt) { switch (*pt) { case 'a': /* * do not preserve access time */ patime = 0; break; case 'e': /* * preserve user id, group id, file * mode, access/modification times */ pids = 1; pmode = 1; patime = 1; pmtime = 1; break; case 'm': /* * do not preserve modification time */ pmtime = 0; break; case 'o': /* * preserve uid/gid */ pids = 1; break; case 'p': /* * preserve file mode bits */ pmode = 1; break; default: paxwarn(1, "Invalid -p string: %c", *pt); pax_usage(); break; } } flg |= PF; break; case 'r': /* * read the archive */ flg |= RF; break; case 's': /* * file name substitution name pattern */ if (rep_add(optarg) < 0) { pax_usage(); break; } flg |= SF; break; case 't': /* * preserve access time on filesystem nodes we read */ tflag = 1; flg |= TF; break; case 'u': /* * ignore those older files */ uflag = 1; flg |= UF; break; case 'v': /* * verbose operation mode */ vflag = 1; flg |= VF; break; case 'w': /* * write an archive */ flg |= WF; break; case 'x': /* * specify an archive format on write */ for (i = 0; i < sizeof(fsub)/sizeof(FSUB); ++i) if (fsub[i].name != NULL && strcmp(fsub[i].name, optarg) == 0) break; if (i < sizeof(fsub)/sizeof(FSUB)) { frmt = &fsub[i]; flg |= XF; break; } paxwarn(1, "Unknown -x format: %s", optarg); (void)fputs("pax: Known -x formats are:", stderr); for (i = 0; i < (sizeof(fsub)/sizeof(FSUB)); ++i) if (fsub[i].name != NULL) (void)fprintf(stderr, " %s", fsub[i].name); (void)fputs("\n\n", stderr); pax_usage(); break; case 'z': /* * use gzip. Non standard option. */ gzip_program = GZIP_CMD; break; case 'B': /* * non-standard option on number of bytes written on a * single archive volume. */ if ((wrlimit = str_offt(optarg)) <= 0) { paxwarn(1, "Invalid write limit %s", optarg); pax_usage(); } if (wrlimit % BLKMULT) { paxwarn(1, "Write limit is not a %d byte multiple", BLKMULT); pax_usage(); } flg |= CBF; break; case 'D': /* * On extraction check file inode change time before the * modification of the file name. Non standard option. */ Dflag = 1; flg |= CDF; break; case 'E': /* * non-standard limit on read faults * 0 indicates stop after first error, values * indicate a limit, "NONE" try forever */ flg |= CEF; if (strcmp(NONE, optarg) == 0) maxflt = -1; else if ((maxflt = atoi(optarg)) < 0) { paxwarn(1, "Error count value must be positive"); pax_usage(); } break; case 'G': /* * non-standard option for selecting files within an * archive by group (gid or name) */ if (grp_add(optarg) < 0) { pax_usage(); break; } flg |= CGF; break; case 'H': /* * follow command line symlinks only */ Hflag = 1; flg |= CHF; break; case 'L': /* * follow symlinks */ Lflag = 1; flg |= CLF; break; case 'O': /* * Force one volume. Non standard option. */ force_one_volume = 1; break; case 'P': /* * do NOT follow symlinks (default) */ Lflag = 0; flg |= CPF; break; case 'T': /* * non-standard option for selecting files within an * archive by modification time range (lower,upper) */ if (trng_add(optarg) < 0) { pax_usage(); break; } flg |= CTF; break; case 'U': /* * non-standard option for selecting files within an * archive by user (uid or name) */ if (usr_add(optarg) < 0) { pax_usage(); break; } flg |= CUF; break; case 'X': /* * do not pass over mount points in the file system */ Xflag = 1; flg |= CXF; break; case 'Y': /* * On extraction check file inode change time after the * modification of the file name. Non standard option. */ Yflag = 1; flg |= CYF; break; case 'Z': /* * On extraction check modification time after the * modification of the file name. Non standard option. */ Zflag = 1; flg |= CZF; break; case '0': /* * Use \0 as pathname terminator. * (For use with the -print0 option of find(1).) */ zeroflag = 1; flg |= C0F; break; default: pax_usage(); break; } } /* * figure out the operation mode of pax read,write,extract,copy,append * or list. check that we have not been given a bogus set of flags * for the operation mode. */ if (ISLIST(flg)) { act = LIST; listf = stdout; bflg = flg & BDLIST; } else if (ISEXTRACT(flg)) { act = EXTRACT; bflg = flg & BDEXTR; } else if (ISARCHIVE(flg)) { act = ARCHIVE; bflg = flg & BDARCH; } else if (ISAPPND(flg)) { act = APPND; bflg = flg & BDARCH; } else if (ISCOPY(flg)) { act = COPY; bflg = flg & BDCOPY; } else pax_usage(); if (bflg) { printflg(flg); pax_usage(); } /* * if we are writing (ARCHIVE) we use the default format if the user * did not specify a format. when we write during an APPEND, we will * adopt the format of the existing archive if none was supplied. */ if (!(flg & XF) && (act == ARCHIVE)) frmt = &(fsub[DEFLT]); /* * process the args as they are interpreted by the operation mode */ switch (act) { case LIST: case EXTRACT: for (; optind < argc; optind++) if (pat_add(argv[optind], NULL) < 0) pax_usage(); break; case COPY: if (optind >= argc) { paxwarn(0, "Destination directory was not supplied"); pax_usage(); } --argc; dirptr = argv[argc]; /* FALL THROUGH */ case ARCHIVE: case APPND: for (; optind < argc; optind++) if (ftree_add(argv[optind], 0) < 0) pax_usage(); /* * no read errors allowed on updates/append operation! */ maxflt = 0; break; } }
/* called without aufs lock */ int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts) { int err, n, token; aufs_bindex_t bindex; unsigned char skipped; struct dentry *root; struct au_opt *opt, *opt_tail; char *opt_str; /* reduce the stack space */ union { struct au_opt_xino_itrunc *xino_itrunc; struct au_opt_wbr_create *create; } u; struct { substring_t args[MAX_OPT_ARGS]; } *a; err = -ENOMEM; a = kmalloc(sizeof(*a), GFP_NOFS); if (unlikely(!a)) goto out; root = sb->s_root; err = 0; bindex = 0; opt = opts->opt; opt_tail = opt + opts->max_opt - 1; opt->type = Opt_tail; while (!err && (opt_str = strsep(&str, ",")) && *opt_str) { err = -EINVAL; skipped = 0; token = match_token(opt_str, options, a->args); switch (token) { case Opt_br: err = 0; while (!err && (opt_str = strsep(&a->args[0].from, ":")) && *opt_str) { err = opt_add(opt, opt_str, opts->sb_flags, bindex++); if (unlikely(!err && ++opt > opt_tail)) { err = -E2BIG; break; } opt->type = Opt_tail; skipped = 1; } break; case Opt_add: if (unlikely(match_int(&a->args[0], &n))) { pr_err("bad integer in %s\n", opt_str); break; } bindex = n; err = opt_add(opt, a->args[1].from, opts->sb_flags, bindex); if (!err) opt->type = token; break; case Opt_append: err = opt_add(opt, a->args[0].from, opts->sb_flags, /*dummy bindex*/1); if (!err) opt->type = token; break; case Opt_prepend: err = opt_add(opt, a->args[0].from, opts->sb_flags, /*bindex*/0); if (!err) opt->type = token; break; case Opt_del: err = au_opts_parse_del(&opt->del, a->args); if (!err) opt->type = token; break; #if 0 /* reserved for future use */ case Opt_idel: del->pathname = "(indexed)"; if (unlikely(match_int(&args[0], &n))) { pr_err("bad integer in %s\n", opt_str); break; } err = au_opts_parse_idel(sb, n, &opt->del, a->args); if (!err) opt->type = token; break; #endif case Opt_mod: err = au_opts_parse_mod(&opt->mod, a->args); if (!err) opt->type = token; break; #ifdef IMOD /* reserved for future use */ case Opt_imod: u.mod->path = "(indexed)"; if (unlikely(match_int(&a->args[0], &n))) { pr_err("bad integer in %s\n", opt_str); break; } err = au_opts_parse_imod(sb, n, &opt->mod, a->args); if (!err) opt->type = token; break; #endif case Opt_xino: err = au_opts_parse_xino(sb, &opt->xino, a->args); if (!err) opt->type = token; break; case Opt_trunc_xino_path: err = au_opts_parse_xino_itrunc_path (sb, &opt->xino_itrunc, a->args); if (!err) opt->type = token; break; case Opt_itrunc_xino: u.xino_itrunc = &opt->xino_itrunc; if (unlikely(match_int(&a->args[0], &n))) { pr_err("bad integer in %s\n", opt_str); break; } u.xino_itrunc->bindex = n; aufs_read_lock(root, AuLock_FLUSH); if (n < 0 || au_sbend(sb) < n) { pr_err("out of bounds, %d\n", n); aufs_read_unlock(root, !AuLock_IR); break; } aufs_read_unlock(root, !AuLock_IR); err = 0; opt->type = token; break; case Opt_dirwh: if (unlikely(match_int(&a->args[0], &opt->dirwh))) break; err = 0; opt->type = token; break; case Opt_rdcache: if (unlikely(match_int(&a->args[0], &n))) { pr_err("bad integer in %s\n", opt_str); break; } if (unlikely(n > AUFS_RDCACHE_MAX)) { pr_err("rdcache must be smaller than %d\n", AUFS_RDCACHE_MAX); break; } opt->rdcache = n; err = 0; opt->type = token; break; case Opt_rdblk: if (unlikely(match_int(&a->args[0], &n) || n < 0 || n > KMALLOC_MAX_SIZE)) { pr_err("bad integer in %s\n", opt_str); break; } if (unlikely(n && n < NAME_MAX)) { pr_err("rdblk must be larger than %d\n", NAME_MAX); break; } opt->rdblk = n; err = 0; opt->type = token; break; case Opt_rdhash: if (unlikely(match_int(&a->args[0], &n) || n < 0 || n * sizeof(struct hlist_head) > KMALLOC_MAX_SIZE)) { pr_err("bad integer in %s\n", opt_str); break; } opt->rdhash = n; err = 0; opt->type = token; break; case Opt_trunc_xino: case Opt_notrunc_xino: case Opt_noxino: case Opt_trunc_xib: case Opt_notrunc_xib: case Opt_shwh: case Opt_noshwh: case Opt_plink: case Opt_noplink: case Opt_list_plink: case Opt_dio: case Opt_nodio: case Opt_diropq_a: case Opt_diropq_w: case Opt_warn_perm: case Opt_nowarn_perm: case Opt_refrof: case Opt_norefrof: case Opt_verbose: case Opt_noverbose: case Opt_sum: case Opt_nosum: case Opt_wsum: case Opt_rdblk_def: case Opt_rdhash_def: err = 0; opt->type = token; break; case Opt_udba: opt->udba = udba_val(a->args[0].from); if (opt->udba >= 0) { err = 0; opt->type = token; } else pr_err("wrong value, %s\n", opt_str); break; case Opt_wbr_create: u.create = &opt->wbr_create; u.create->wbr_create = au_wbr_create_val(a->args[0].from, u.create); if (u.create->wbr_create >= 0) { err = 0; opt->type = token; } else pr_err("wrong value, %s\n", opt_str); break; case Opt_wbr_copyup: opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from); if (opt->wbr_copyup >= 0) { err = 0; opt->type = token; } else pr_err("wrong value, %s\n", opt_str); break; case Opt_ignore: pr_warn("ignored %s\n", opt_str); /*FALLTHROUGH*/ case Opt_ignore_silent: skipped = 1; err = 0; break; case Opt_err: pr_err("unknown option %s\n", opt_str); break; } if (!err && !skipped) { if (unlikely(++opt > opt_tail)) { err = -E2BIG; opt--; opt->type = Opt_tail; break; } opt->type = Opt_tail; } } kfree(a); dump_opts(opts); if (unlikely(err)) au_opts_free(opts); out: return err; }
static void tar_options(int argc, char **argv) { int c; int fstdin = 0; int Oflag = 0; int nincfiles = 0; int incfiles_max = 0; struct incfile { char *file; char *dir; }; struct incfile *incfiles = NULL; /* * Set default values. */ rmleadslash = 1; is_gnutar = 1; /* * process option flags */ while ((c = getoldopt(argc, argv, "+b:cef:hjklmopqrs:tuvwxzBC:HI:OPST:X:Z014578", tar_longopts, NULL)) != -1) { switch(c) { case 'b': /* * specify blocksize in 512-byte blocks */ if ((wrblksz = (int)str_offt(optarg)) <= 0) { tty_warn(1, "Invalid block size %s", optarg); tar_usage(); } wrblksz *= 512; /* XXX - check for int oflow */ break; case 'c': /* * create an archive */ act = ARCHIVE; break; case 'e': /* * stop after first error */ maxflt = 0; break; case 'f': /* * filename where the archive is stored */ if ((optarg[0] == '-') && (optarg[1]== '\0')) { /* * treat a - as stdin */ fstdin = 1; arcname = NULL; break; } fstdin = 0; arcname = optarg; break; case 'h': /* * follow symlinks */ Lflag = 1; break; case 'j': /* * pass through bzip2. not a standard option */ jflag = 1; gzip_program = BZIP2_CMD; break; case 'k': /* * do not clobber files that exist */ kflag = 1; break; case 'l': /* * do not pass over mount points in the file system */ Xflag = 1; break; case 'm': /* * do not preserve modification time */ pmtime = 0; break; case 'o': /* * This option does several things based on whether * this is a create or extract operation. */ if (act == ARCHIVE) { /* GNU tar: write V7 format archives. */ Oflag = 1; /* 4.2BSD: don't add directory entries. */ if (opt_add("write_opt=nodir") < 0) tar_usage(); } else { /* SUS: don't preserve owner/group. */ pids = 0; nopids = 1; } break; case 'O': Oflag = 1; break; case 'p': /* * preserve user id, group id, file * mode, access/modification times */ if (!nopids) pids = 1; pmode = 1; patime = 1; pmtime = 1; break; case 'q': /* * select first match for a pattern only */ nflag = 1; break; case 'r': case 'u': /* * append to the archive */ act = APPND; break; case 's': /* * file name substitution name pattern */ if (rep_add(optarg) < 0) { tar_usage(); break; } break; case 't': /* * list contents of the tape */ act = LIST; break; case 'v': /* * verbose operation mode */ vflag = 1; break; case 'w': /* * interactive file rename */ iflag = 1; break; case 'x': /* * extract an archive, preserving mode, * and mtime if possible. */ act = EXTRACT; pmtime = 1; break; case 'z': /* * use gzip. Non standard option. */ zflag = 1; gzip_program = GZIP_CMD; break; case 'B': /* * Nothing to do here, this is pax default */ break; case 'C': chdname = optarg; break; case 'H': /* * follow command line symlinks only */ Hflag = 1; break; case 'I': case 'T': if (++nincfiles > incfiles_max) { incfiles_max = nincfiles + 3; incfiles = realloc(incfiles, sizeof(*incfiles) * incfiles_max); if (incfiles == NULL) { tty_warn(0, "Unable to allocate space " "for option list"); exit(1); } } incfiles[nincfiles - 1].file = optarg; incfiles[nincfiles - 1].dir = chdname; break; case 'P': /* * do not remove leading '/' from pathnames */ rmleadslash = 0; Aflag = 1; break; case 'S': /* do nothing; we already generate sparse files */ break; case 'X': /* * GNU tar compat: exclude the files listed in optarg */ if (tar_gnutar_X_compat(optarg) != 0) tar_usage(); break; case 'Z': /* * use compress. */ zflag = 1; gzip_program = COMPRESS_CMD; break; case '0': arcname = DEV_0; break; case '1': arcname = DEV_1; break; case '4': arcname = DEV_4; break; case '5': arcname = DEV_5; break; case '7': arcname = DEV_7; break; case '8': arcname = DEV_8; break; case OPT_ATIME_PRESERVE: patime = 1; break; case OPT_UNLINK: /* Just ignore -- we always unlink first. */ break; case OPT_USE_COMPRESS_PROGRAM: zflag = 1; gzip_program = optarg; break; case OPT_FORCE_LOCAL: forcelocal = 1; break; case OPT_INSECURE: secure = 0; break; case OPT_STRICT: /* disable gnu extensions */ is_gnutar = 0; break; case OPT_EXCLUDE: if (tar_gnutar_minus_minus_exclude(optarg) != 0) tar_usage(); break; case OPT_NORECURSE: dflag = 1; break; #if !HAVE_NBTOOL_CONFIG_H #ifdef HAVE_FCHROOT case OPT_CHROOT: do_chroot = 1; break; #endif /* HAVE_FCHROOT */ #endif default: tar_usage(); break; } } argc -= optind; argv += optind; /* Tar requires an action. */ if (act == ERROR) tar_usage(); /* Traditional tar behaviour (pax uses stderr unless in list mode) */ if (fstdin == 1 && act == ARCHIVE) listf = stderr; else listf = stdout; /* Traditional tar behaviour (pax wants to read file list from stdin) */ if ((act == ARCHIVE || act == APPND) && argc == 0 && nincfiles == 0) exit(0); /* * if we are writing (ARCHIVE) specify tar, otherwise run like pax * (unless -o specified) */ if (act == ARCHIVE || act == APPND) frmt = &(fsub[Oflag ? F_TAR : F_USTAR]); else if (Oflag) { if (act == EXTRACT) to_stdout = 1; else { tty_warn(1, "The -O/-o options are only valid when " "writing or extracting an archive"); tar_usage(); } } /* * process the args as they are interpreted by the operation mode */ switch (act) { case LIST: case EXTRACT: default: { int sawpat = 0; int dirisnext = 0; char *file, *dir; while (nincfiles || *argv != NULL) { /* * If we queued up any include files, * pull them in now. Otherwise, check * for -I and -C positional flags. * Anything else must be a file to * extract. */ if (nincfiles) { file = incfiles->file; dir = incfiles->dir; incfiles++; nincfiles--; } else if (strcmp(*argv, "-I") == 0) { if (*++argv == NULL) break; file = *argv++; dir = chdname; } else { file = NULL; dir = NULL; } if (file != NULL) { FILE *fp; char *str; if (strcmp(file, "-") == 0) fp = stdin; else if ((fp = fopen(file, "r")) == NULL) { tty_warn(1, "Unable to open file '%s' for read", file); tar_usage(); } while ((str = getline(fp)) != NULL) { if (dirisnext) { dir = str; dirisnext = 0; continue; } if (strcmp(str, "-C") == 0) { dirisnext = 1; continue; } if (strncmp(str, "-C ", 3) == 0) { dir = str + 3; continue; } if (pat_add(str, dir) < 0) tar_usage(); sawpat = 1; } /* Bomb if given -C w/out a dir. */ if (dirisnext) tar_usage(); if (strcmp(file, "-") != 0) fclose(fp); if (getline_error) { tty_warn(1, "Problem with file '%s'", file); tar_usage(); } } else if (strcmp(*argv, "-C") == 0) { if (*++argv == NULL) break; chdname = *argv++; } else if (pat_add(*argv++, chdname) < 0) tar_usage(); else sawpat = 1; } /* * if patterns were added, we are doing chdir() * on a file-by-file basis, else, just one * global chdir (if any) after opening input. */ if (sawpat > 0) chdname = NULL; } break; case ARCHIVE: case APPND: if (chdname != NULL) { /* initial chdir() */ if (ftree_add(chdname, 1) < 0) tar_usage(); } while (nincfiles || *argv != NULL) { char *file, *dir; /* * If we queued up any include files, pull them in * now. Otherwise, check for -I and -C positional * flags. Anything else must be a file to include * in the archive. */ if (nincfiles) { file = incfiles->file; dir = incfiles->dir; incfiles++; nincfiles--; } else if (strcmp(*argv, "-I") == 0) { if (*++argv == NULL) break; file = *argv++; dir = NULL; } else { file = NULL; dir = NULL; } if (file != NULL) { FILE *fp; char *str; int dirisnext = 0; /* Set directory if needed */ if (dir) { if (ftree_add(dir, 1) < 0) tar_usage(); } if (strcmp(file, "-") == 0) fp = stdin; else if ((fp = fopen(file, "r")) == NULL) { tty_warn(1, "Unable to open file '%s' for read", file); tar_usage(); } while ((str = getline(fp)) != NULL) { if (dirisnext) { if (ftree_add(str, 1) < 0) tar_usage(); dirisnext = 0; continue; } if (strcmp(str, "-C") == 0) { dirisnext = 1; continue; } if (strncmp(str, "-C ", 3) == 0) { if (ftree_add(str + 3, 1) < 0) tar_usage(); continue; } if (ftree_add(str, 0) < 0) tar_usage(); } /* Bomb if given -C w/out a dir. */ if (dirisnext) tar_usage(); if (strcmp(file, "-") != 0) fclose(fp); if (getline_error) { tty_warn(1, "Problem with file '%s'", file); tar_usage(); } } else if (strcmp(*argv, "-C") == 0) { if (*++argv == NULL) break; if (ftree_add(*argv++, 1) < 0) tar_usage(); } else if (ftree_add(*argv++, 0) < 0) tar_usage(); } /* * no read errors allowed on updates/append operation! */ maxflt = 0; break; } if (!fstdin && ((arcname == (char *)NULL) || (*arcname == '\0'))) { arcname = getenv("TAPE"); if ((arcname == NULL) || (*arcname == '\0')) arcname = _PATH_DEFTAPE; } }
static void pax_options(int argc, char **argv) { int c; size_t i; u_int64_t flg = 0; u_int64_t bflg = 0; char *pt; FSUB tmp; /* * process option flags */ while ((c = getopt_long(argc, argv, "0ab:cdf:ijklno:p:rs:tuvwx:zAB:DE:G:HLMN:OPT:U:VXYZ", pax_longopts, NULL)) != -1) { switch (c) { case '0': sep = '\0'; break; case 'a': /* * append */ flg |= AF; break; case 'b': /* * specify blocksize */ flg |= BF; if ((wrblksz = (int)str_offt(optarg)) <= 0) { tty_warn(1, "Invalid block size %s", optarg); pax_usage(); } break; case 'c': /* * inverse match on patterns */ cflag = 1; flg |= CF; break; case 'd': /* * match only dir on extract, not the subtree at dir */ dflag = 1; flg |= DF; break; case 'f': /* * filename where the archive is stored */ arcname = optarg; flg |= FF; break; case 'i': /* * interactive file rename */ iflag = 1; flg |= IF; break; case 'j': /* * pass through bzip2 */ gzip_program = BZIP2_CMD; break; case 'k': /* * do not clobber files that exist */ kflag = 1; flg |= KF; break; case 'l': /* * try to link src to dest with copy (-rw) */ lflag = 1; flg |= LF; break; case 'n': /* * select first match for a pattern only */ nflag = 1; flg |= NF; break; case 'o': /* * pass format specific options */ flg |= OF; if (opt_add(optarg) < 0) pax_usage(); break; case 'p': /* * specify file characteristic options */ for (pt = optarg; *pt != '\0'; ++pt) { switch(*pt) { case 'a': /* * do not preserve access time */ patime = 0; break; case 'e': /* * preserve user id, group id, file * mode, access/modification times * and file flags. */ pids = 1; pmode = 1; patime = 1; pmtime = 1; pfflags = 1; break; #if 0 case 'f': /* * do not preserve file flags */ pfflags = 0; break; #endif case 'm': /* * do not preserve modification time */ pmtime = 0; break; case 'o': /* * preserve uid/gid */ pids = 1; break; case 'p': /* * preserve file mode bits */ pmode = 1; break; default: tty_warn(1, "Invalid -p string: %c", *pt); pax_usage(); break; } } flg |= PF; break; case 'r': /* * read the archive */ flg |= RF; break; case 's': /* * file name substitution name pattern */ if (rep_add(optarg) < 0) { pax_usage(); break; } flg |= SF; break; case 't': /* * preserve access time on filesystem nodes we read */ tflag = 1; flg |= TF; break; case 'u': /* * ignore those older files */ uflag = 1; flg |= UF; break; case 'v': /* * verbose operation mode */ vflag = 1; flg |= VF; break; case 'w': /* * write an archive */ flg |= WF; break; case 'x': /* * specify an archive format on write */ tmp.name = optarg; frmt = (FSUB *)bsearch((void *)&tmp, (void *)fsub, sizeof(fsub)/sizeof(FSUB), sizeof(FSUB), c_frmt); if (frmt != NULL) { flg |= XF; break; } tty_warn(1, "Unknown -x format: %s", optarg); (void)fputs("pax: Known -x formats are:", stderr); for (i = 0; i < (sizeof(fsub)/sizeof(FSUB)); ++i) (void)fprintf(stderr, " %s", fsub[i].name); (void)fputs("\n\n", stderr); pax_usage(); break; case 'z': /* * use gzip. Non standard option. */ gzip_program = GZIP_CMD; break; case 'A': Aflag = 1; flg |= CAF; break; case 'B': /* * non-standard option on number of bytes written on a * single archive volume. */ if ((wrlimit = str_offt(optarg)) <= 0) { tty_warn(1, "Invalid write limit %s", optarg); pax_usage(); } if (wrlimit % BLKMULT) { tty_warn(1, "Write limit is not a %d byte multiple", BLKMULT); pax_usage(); } flg |= CBF; break; case 'D': /* * On extraction check file inode change time before the * modification of the file name. Non standard option. */ Dflag = 1; flg |= CDF; break; case 'E': /* * non-standard limit on read faults * 0 indicates stop after first error, values * indicate a limit, "none" try forever */ flg |= CEF; if (strcmp(none, optarg) == 0) maxflt = -1; else if ((maxflt = atoi(optarg)) < 0) { tty_warn(1, "Error count value must be positive"); pax_usage(); } break; case 'G': /* * non-standard option for selecting files within an * archive by group (gid or name) */ if (grp_add(optarg) < 0) { pax_usage(); break; } flg |= CGF; break; case 'H': /* * follow command line symlinks only */ Hflag = 1; flg |= CHF; break; case 'L': /* * follow symlinks */ Lflag = 1; flg |= CLF; break; #ifdef SMALL case 'M': case 'N': tty_warn(1, "Support for -%c is not compiled in", c); exit(1); #else /* !SMALL */ case 'M': /* * Treat list of filenames on stdin as an * mtree(8) specfile. Non standard option. */ Mflag = 1; flg |= CMF; break; case 'N': /* * Use alternative directory for user db lookups. */ if (!setup_getid(optarg)) { tty_warn(1, "Unable to use user and group databases in `%s'", optarg); pax_usage(); } break; #endif /* !SMALL */ case 'O': /* * Force one volume. Non standard option. */ force_one_volume = 1; break; case 'P': /* * do NOT follow symlinks (default) */ Lflag = 0; flg |= CPF; break; case 'T': /* * non-standard option for selecting files within an * archive by modification time range (lower,upper) */ if (trng_add(optarg) < 0) { pax_usage(); break; } flg |= CTF; break; case 'U': /* * non-standard option for selecting files within an * archive by user (uid or name) */ if (usr_add(optarg) < 0) { pax_usage(); break; } flg |= CUF; break; case 'V': /* * somewhat verbose operation mode (no listing) */ Vflag = 1; flg |= VSF; break; case 'X': /* * do not pass over mount points in the file system */ Xflag = 1; flg |= CXF; break; case 'Y': /* * On extraction check file inode change time after the * modification of the file name. Non standard option. */ Yflag = 1; flg |= CYF; break; case 'Z': /* * On extraction check modification time after the * modification of the file name. Non standard option. */ Zflag = 1; flg |= CZF; break; case OPT_INSECURE: secure = 0; break; case OPT_FORCE_LOCAL: forcelocal = 1; break; case OPT_USE_COMPRESS_PROGRAM: gzip_program = optarg; break; case OPT_XZ: gzip_program = XZ_CMD; break; case OPT_GNU: is_gnutar = 1; break; case '?': default: pax_usage(); break; } } /* * figure out the operation mode of pax read,write,extract,copy,append * or list. check that we have not been given a bogus set of flags * for the operation mode. */ if (ISLIST(flg)) { act = LIST; listf = stdout; bflg = flg & BDLIST; } else if (ISEXTRACT(flg)) { act = EXTRACT; bflg = flg & BDEXTR; } else if (ISARCHIVE(flg)) { act = ARCHIVE; bflg = flg & BDARCH; } else if (ISAPPND(flg)) { act = APPND; bflg = flg & BDARCH; } else if (ISCOPY(flg)) { act = COPY; bflg = flg & BDCOPY; } else pax_usage(); if (bflg) { printflg(flg); pax_usage(); } /* * if we are writing (ARCHIVE) we use the default format if the user * did not specify a format. when we write during an APPEND, we will * adopt the format of the existing archive if none was supplied. */ if (!(flg & XF) && (act == ARCHIVE)) frmt = &(fsub[DEFLT]); /* * process the args as they are interpreted by the operation mode */ switch (act) { case LIST: case EXTRACT: for (; optind < argc; optind++) if (pat_add(argv[optind], NULL, 0) < 0) pax_usage(); break; case COPY: if (optind >= argc) { tty_warn(0, "Destination directory was not supplied"); pax_usage(); } --argc; dirptr = argv[argc]; if (mkpath(dirptr) < 0) exit(1); /* FALLTHROUGH */ case ARCHIVE: case APPND: for (; optind < argc; optind++) if (ftree_add(argv[optind], 0) < 0) pax_usage(); /* * no read errors allowed on updates/append operation! */ maxflt = 0; break; } }
static inline lagopus_result_t initialize_internal(void) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; datastore_interp_t s_interp = datastore_get_master_interp(); /* create hashmap for sub cmds. */ if ((ret = lagopus_hashmap_create(&sub_cmd_table, LAGOPUS_HASHMAP_TYPE_STRING, NULL)) != LAGOPUS_RESULT_OK) { lagopus_perror(ret); goto done; } if (((ret = sub_cmd_add(ADD_SUB_CMD, add_sub_cmd_parse, &sub_cmd_table)) != LAGOPUS_RESULT_OK) || ((ret = sub_cmd_add(MOD_SUB_CMD, mod_sub_cmd_parse, &sub_cmd_table)) != LAGOPUS_RESULT_OK) || ((ret = sub_cmd_add(DEL_SUB_CMD, del_sub_cmd_parse, &sub_cmd_table)) != LAGOPUS_RESULT_OK)) { goto done; } /* create hashmap for sub cmds (not name). */ if ((ret = lagopus_hashmap_create(&sub_cmd_not_name_table, LAGOPUS_HASHMAP_TYPE_STRING, NULL)) != LAGOPUS_RESULT_OK) { lagopus_perror(ret); goto done; } if (((ret = sub_cmd_add(CONFIG_SUB_CMD, config_sub_cmd_parse, &sub_cmd_not_name_table)) != LAGOPUS_RESULT_OK)) { goto done; } /* create hashmap for dump opts. */ if ((ret = lagopus_hashmap_create(&dump_opt_table, LAGOPUS_HASHMAP_TYPE_STRING, NULL)) != LAGOPUS_RESULT_OK) { lagopus_perror(ret); goto done; } if (((ret = opt_add(opt_strs[OPT_TABLE_ID], table_id_opt_parse, &dump_opt_table)) != LAGOPUS_RESULT_OK) || ((ret = opt_add(opt_strs[OPT_WITH_STATS], with_stats_opt_parse, &dump_opt_table)) != LAGOPUS_RESULT_OK)) { goto done; } /* create hashmap for config opts. */ if ((ret = lagopus_hashmap_create(&config_opt_table, LAGOPUS_HASHMAP_TYPE_STRING, NULL)) != LAGOPUS_RESULT_OK) { lagopus_perror(ret); goto done; } if ((ret = opt_add(opt_strs[OPT_TMP_DIR], tmp_dir_opt_parse, &config_opt_table)) != LAGOPUS_RESULT_OK) { goto done; } if ((ret = flow_cmd_mod_initialize()) != LAGOPUS_RESULT_OK) { goto done; } if ((ret = datastore_interp_register_command(&s_interp, CONFIGURATOR_NAME, CMD_NAME, flow_cmd_parse)) != LAGOPUS_RESULT_OK) { lagopus_perror(ret); goto done; } if ((ret = flow_cmd_dump_initialize()) != LAGOPUS_RESULT_OK) { goto done; } done: return ret; }
void env_opt_add(char *ep) { char *vp, c; if (opt_reply == NULL) /*XXX*/ return; /*XXX*/ if (ep == NULL || *ep == '\0') { /* Send user defined variables first. */ env_default(1, 0); while ((ep = env_default(0, 0))) env_opt_add(ep); /* Now add the list of well know variables. */ env_default(1, 1); while ((ep = env_default(0, 1))) env_opt_add(ep); return; } vp = env_getvalue(ep, 1); if (2 * (vp ? strlen(vp) : 0) + 2 * strlen(ep) + 6 > opt_replyend - opt_replyp) { size_t len; unsigned char *p; len = opt_replyend - opt_reply; len += OPT_REPLY_SIZE + 2 * strlen(ep); if (vp) len += 2 * strlen(vp); p = realloc(opt_reply, len); if (p == NULL) { free(opt_reply); /*@*/ printf("env_opt_add: realloc() failed!!!\n"); opt_reply = opt_replyp = opt_replyend = NULL; return; } opt_replyp = p + (opt_replyp - opt_reply); opt_replyend = p + len; opt_reply = p; } if (opt_welldefined(ep)) opt_add(NEW_ENV_VAR); else opt_add(ENV_USERVAR); for (;;) { while ((c = *ep++)) { switch(c&0xff) { case IAC: opt_add(IAC); break; case NEW_ENV_VAR: case NEW_ENV_VALUE: case ENV_ESC: case ENV_USERVAR: opt_add(ENV_ESC); break; } opt_add(c); } if ((ep = vp)) { opt_add(NEW_ENV_VALUE); vp = NULL; } else break; } }