• Home
  • Raw
  • Download

Lines Matching +full:set +full:- +full:job +full:- +full:env +full:- +full:vars

6 /*-
14 * is granted to deal in this work without restriction, including un-
76 Ttypeset, "-i10", "COLUMNS", "LINES", "SECONDS", "TMOUT", NULL,
78 "integer=\\\\builtin typeset -i",
80 /* not "alias -t --": hash -r needs to work */
81 "hash=\\\\builtin alias -t",
82 "type=\\\\builtin whence -v",
83 "autoload=\\\\builtin typeset -fu",
84 "functions=\\\\builtin typeset -f",
85 "history=\\\\builtin fc -l",
86 "nameref=\\\\builtin typeset -n",
88 "r=\\\\builtin fc -e -",
96 Talias, "-tU",
109 /* top-level parsing and execution environment */
110 static struct env env; variable
111 struct env *e = &env;
113 /* compile-time assertions */
119 ((int)(unsigned char)0x100 == 0) && ((int)(unsigned char)(int)-1 == 0xFF));
134 cta(ari_has_31_bit, 0 < (mksh_ari_t)(((((mksh_ari_t)1 << 15) << 15) - 1) * 2 + 1));
138 cta(uari_has_31_bit, 0 < (mksh_uari_t)(((((mksh_uari_t)1 << 15) << 15) - 1) * 2 + 1));
139 cta(uari_has_32_bit, 0 < (mksh_uari_t)(((((mksh_uari_t)1 << 15) << 15) - 1) * 4 + 3));
141 (mksh_uari_t)(((((mksh_uari_t)1 << 15) << 15) - 1) * 4 + 3) >
142 (mksh_uari_t)(((((mksh_uari_t)1 << 15) << 15) - 1) * 4 + 4));
145 cta(ari_is_signed, (mksh_ari_t)-1 < (mksh_ari_t)0);
146 cta(uari_is_unsigned, (mksh_uari_t)-1 > (mksh_uari_t)0);
171 cp = alloc(sizeof(*bufptr) - sizeof(ALLOC_ITEM), APERM); in rndsetup()
173 memset(cp, 0, sizeof(*bufptr) - sizeof(ALLOC_ITEM)); in rndsetup()
175 bufptr = (void *)(cp - sizeof(ALLOC_ITEM)); in rndsetup()
177 bufptr->dataptr = &rndsetupstate; in rndsetup()
179 bufptr->stkptr = &bufptr; in rndsetup()
181 bufptr->mallocptr = bufptr; in rndsetup()
184 sigsetjmp(bufptr->jbuf, 1); in rndsetup()
187 mksh_TIME(bufptr->tv); in rndsetup()
225 /* check for UTF-8 */ in isuc()
226 if (strstr(x, "UTF-8") || strstr(x, "UTF8")) in isuc()
277 /* max. name length: -2147483648 = 11 (+ NUL) */ in main_init()
280 /* set up base environment */ in main_init()
281 env.type = E_NONE; in main_init()
282 ainit(&env.area); in main_init()
283 /* set up global l->vars and l->funs */ in main_init()
289 /* determine the basename (without '-' or path) of the executable */ in main_init()
299 Flag(FLOGIN) = (ord(*ccp) == ORD('-')) || (ord(*kshname) == ORD('-')); in main_init()
300 if (ord(*ccp) == ORD('-')) in main_init()
307 * option - it always sends the hup). in main_init()
318 * Turn on "set -x" inheritance by default. in main_init()
322 /* define built-in commands and see if we were called as one */ in main_init()
339 /* check for -T option early */ in main_init()
343 /* called as rsh, rmksh, -rsh, RKSH.EXE, etc.? */ in main_init()
349 /* are we called as -rsh or /bin/sh or SH.EXE or so? */ in main_init()
371 /* set up variable and command dictionaries */ in main_init()
410 * Set PATH to def_path (will set the path global variable). in main_init()
419 * Set edit mode to emacs by default, may be overridden in main_init()
439 /* Figure out the current working directory and set $PWD */ in main_init()
447 /* Only set pwd if we know where we are or if it had a bogus value */ in main_init()
467 /* Set PS1 if unset or we are root and prompt doesn't contain a # */ in main_init()
468 if (!(vp->flag & ISSET) || in main_init()
473 vp->flag |= INT_U; in main_init()
475 vp->flag |= INT_U; in main_init()
477 vp->flag |= INT_U; in main_init()
479 vp->flag |= INT_U; in main_init()
481 vp->flag |= INT_U; in main_init()
483 vp->flag |= INT_U; in main_init()
485 vp->flag |= INT_U; in main_init()
487 vp->flag |= INT_U; in main_init()
490 /* Set this before parsing arguments */ in main_init()
493 /* record if monitor is set on command line (see j_init() in jobs.c) */ in main_init()
497 /* this to note if utf-8 mode is set on command line (see below) */ in main_init()
511 /* auto-detect from environment variables, always */ in main_init()
515 if (!(s->start = s->str = argv[argi++])) in main_init()
517 while (*s->str) { in main_init()
518 if (ctype(*s->str, C_QUOTE) && (*s->str != '\'')) in main_init()
520 s->str++; in main_init()
522 if (!*s->str) in main_init()
523 s->flags |= SF_MAYEXEC; in main_init()
524 s->str = s->start; in main_init()
527 if (Flag(FSH) && argv[argi] && !strcmp(argv[argi], "--")) in main_init()
541 s->file = argv[argi++]; in main_init()
542 if (search_access(s->file, X_OK) != 0) in main_init()
543 s->file = search_path(s->file, path, X_OK, NULL); in main_init()
544 if (!s->file || !*s->file) in main_init()
545 s->file = argv[argi - 1]; in main_init()
547 s->file = argv[argi++]; in main_init()
549 s->u.shf = shf_open(s->file, O_RDONLY | O_MAYEXEC, 0, in main_init()
551 if (s->u.shf == NULL) { in main_init()
553 warningf(true, Tf_sD_s, s->file, cstrerror(errno)); in main_init()
558 kshname = s->file; in main_init()
562 s->file = "<stdin>"; in main_init()
563 s->u.shf = shf_fdopen(0, SHF_RD | can_seek(0), in main_init()
568 s->flags |= SF_TTY; in main_init()
569 s->u.shf->flags |= SHF_INTERRUPT; in main_init()
570 s->file = NULL; in main_init()
579 /* initialise job control */ in main_init()
585 /* auto-detect from locale or environment */ in main_init()
591 /* always disable UTF-8 (for interactive) */ in main_init()
607 l = e->loc; in main_init()
609 l->argc = argc; in main_init()
610 l->argv = argv; in main_init()
611 l->argv[0] = ccp; in main_init()
613 l->argc = argc - argi; in main_init()
616 * it in-place, ps(1) output changes; the meaning of argc in main_init()
620 l->argv = alloc2(l->argc + 2, sizeof(void *), APERM); in main_init()
621 l->argv[0] = kshname; in main_init()
622 memcpy(&l->argv[1], &argv[argi], l->argc * sizeof(void *)); in main_init()
623 l->argv[l->argc + 1] = NULL; in main_init()
627 /* divine the initial state of the utf8-mode Flag */ in main_init()
631 /* auto-detect from locale or environment */ in main_init()
644 /* auto-detect from environment */ in main_init()
656 /* not set on command line, not FTALKING */ in main_init()
670 /* Disable during .profile/ENV reading */ in main_init()
676 /* save flags for "set +o" handling */ in main_init()
692 * Do this before profile/$ENV so that if it causes problems in them, in main_init()
702 /* note whether -p was enabled during startup */ in main_init()
704 /* allow set -p to setuid() later */ in main_init()
707 /* turn off -p if not set explicitly */ in main_init()
709 /* track shell-imposed changes */ in main_init()
716 cp = substitute("${ENV:-" MKSHRC_PATH "}", DOTILDE); in main_init()
718 cp = substitute("${ENV:-" MKSHRC_PATH "}", 0); in main_init()
728 /* track shell-imposed changes */ in main_init()
736 /* set after ENV */ in main_init()
739 /* track shell-imposed change (might lower surprise) */ in main_init()
761 rv = c_builtin(l->argv); in main()
781 return (-1); in include()
784 old_argv = e->loc->argv; in include()
785 old_argc = e->loc->argc; in include()
791 if ((i = kshsetjmp(e->jbuf))) { in include()
792 quitenv(s ? s->u.shf : NULL); in include()
794 e->loc->argv = old_argv; in include()
795 e->loc->argc = old_argc; in include()
805 * intr_ok is set if we are including .profile or $ENV. in include()
808 if (intr_ok && ((exstat & 0xFF) - 128) != SIGTERM) in include()
822 e->loc->argv = argv; in include()
823 e->loc->argc = argc; in include()
826 s->u.shf = shf; in include()
827 strdupx(s->file, name, ATEMP); in include()
829 quitenv(s->u.shf); in include()
831 e->loc->argv = old_argv; in include()
832 e->loc->argc = old_argc; in include()
834 /* & 0xff to ensure value not -1 */ in include()
846 s->start = s->str = comm; in command()
847 s->line = line; in command()
860 volatile bool wastty = tobool(s->flags & SF_TTY); in shell()
869 e->flags |= EF_IN_EVAL; in shell()
872 switch ((i = kshsetjmp(e->jbuf))) { in shell()
900 if (Flag(FIGNOREEOF) && s->type == SEOF && wastty) in shell()
901 s->type = SSTDIN; in shell()
905 * interactive is set if we are reading from in shell()
907 * needs FMONITOR set (not FTALKING/SF_TTY)... in shell()
911 s->start = s->str = null; in shell()
937 if (s->next == NULL) { in shell()
939 s->flags |= SF_ECHO; in shell()
941 s->flags &= ~SF_ECHO; in shell()
949 histsave(&s->line, NULL, HIST_FLUSH, true); in shell()
953 if (t->type == TEOF) { in shell()
954 if (wastty && Flag(FIGNOREEOF) && --attempts > 0) { in shell()
956 s->type = SSTDIN; in shell()
960 s->type = SSTDIN; in shell()
972 } else if ((s->flags & SF_MAYEXEC) && t->type == TCOM) in shell()
973 t->u.evalflags |= DOTCOMEXEC; in shell()
974 if (!Flag(FNOEXEC) || (s->flags & SF_TTY)) in shell()
977 if (t->type != TEOF && interactive && really_exit) in shell()
994 if (i == LERREXT && (e->flags & EF_IN_EVAL)) in unwind()
1003 --trap_nested; in unwind()
1008 --trap_nested; in unwind()
1014 switch (e->type) { in unwind()
1021 kshlongjmp(e->jbuf, i); in unwind()
1025 e->flags |= EF_FAKE_SIGDIE; in unwind()
1036 struct env *ep; in newenv()
1040 * struct env includes ALLOC_ITEM for alignment constraints in newenv()
1043 cp = alloc(sizeof(struct env) - sizeof(ALLOC_ITEM), ATEMP); in newenv()
1045 ep = (void *)(cp - sizeof(ALLOC_ITEM)); in newenv()
1046 /* initialise public members of struct env (not the ALLOC_ITEM) */ in newenv()
1047 ainit(&ep->area); in newenv()
1048 ep->oenv = e; in newenv()
1049 ep->loc = e->loc; in newenv()
1050 ep->savefd = NULL; in newenv()
1051 ep->temps = NULL; in newenv()
1052 ep->yyrecursive_statep = NULL; in newenv()
1053 ep->type = type; in newenv()
1054 ep->flags = e->flags & EF_IN_EVAL; in newenv()
1061 struct env *ep = e; in quitenv()
1066 while (ep->oenv && ep->oenv->loc != ep->loc) in quitenv()
1068 if (ep->savefd != NULL) { in quitenv()
1070 /* if ep->savefd[fd] < 0, means fd was closed */ in quitenv()
1071 if (ep->savefd[fd]) in quitenv()
1072 restfd(fd, ep->savefd[fd]); in quitenv()
1073 if (ep->savefd[2]) in quitenv()
1081 if (ep->oenv == NULL) { in quitenv()
1086 if (ep->type == E_NONE) { in quitenv()
1093 if (ep->flags & EF_FAKE_SIGDIE) { in quitenv()
1094 int sig = (exstat & 0xFF) - 128; in quitenv()
1123 if ((i = fcntl(fd, F_GETFD, 0)) != -1 && in quitenv()
1136 e = e->oenv; in quitenv()
1138 /* free the struct env - tricky due to the ALLOC_ITEM inside */ in quitenv()
1147 struct env *ep; in cleanup_parents_env()
1151 * Don't clean up temporary files - parent will probably need them. in cleanup_parents_env()
1157 for (ep = e; ep; ep = ep->oenv) { in cleanup_parents_env()
1158 if (ep->savefd) { in cleanup_parents_env()
1160 if (ep->savefd[fd] > 0) in cleanup_parents_env()
1161 close(ep->savefd[fd]); in cleanup_parents_env()
1162 afree(ep->savefd, &ep->area); in cleanup_parents_env()
1163 ep->savefd = NULL; in cleanup_parents_env()
1166 if (ep->type != E_NONE) in cleanup_parents_env()
1167 ep->type = E_GONE; in cleanup_parents_env()
1171 e->oenv = NULL; in cleanup_parents_env()
1179 struct env *ep; in cleanup_proc_env()
1181 for (ep = e; ep; ep = ep->oenv) in cleanup_proc_env()
1182 remove_temps(ep->temps); in cleanup_proc_env()
1191 while ((l = e->loc) && (!e->oenv || e->oenv->loc != l)) { in reclaim()
1192 e->loc = l->next; in reclaim()
1193 afreeall(&l->area); in reclaim()
1196 remove_temps(e->temps); in reclaim()
1197 e->temps = NULL; in reclaim()
1204 if (source && source->areap == &e->area) in reclaim()
1207 afreeall(&e->area); in reclaim()
1214 if (tp->pid == procpid) in remove_temps()
1215 unlink(tp->tffn); in remove_temps()
1216 tp = tp->next; in remove_temps()
1222 * saving/resetting tty modes upon foreground job completion, and
1228 * 4 = cannot make fd close-on-exec
1230 * i.e. if tty_devtty was already set or the new would not set it.
1258 /* already got a non-devtty one */ in tty_init_fd()
1312 /* not set when main() calls parse_args() */ in vwarningf()
1366 * Used by built-in utilities to prefix shell and utility name to message
1384 /* POSIX special builtins cause non-interactive shells to exit */ in bi_errorf()
1416 /* POSIX special builtins cause non-interactive shells to exit */ in maybe_errorf()
1452 if (!fileline || !source || !source->file || in error_prefix()
1453 strcmp(source->file, kshname) != 0) in error_prefix()
1455 (*kshname == '-' ? 1 : 0)); in error_prefix()
1456 if (fileline && source && source->file != NULL) { in error_prefix()
1457 shf_fprintf(shl_out, "%s[%lu]: ", source->file, in error_prefix()
1458 (unsigned long)(source->errline ? in error_prefix()
1459 source->errline : source->line)); in error_prefix()
1460 source->errline = 0; in error_prefix()
1471 /* shl_out may not be set up yet... */ in shellf()
1525 strpathx(lfp, lfp, "mksh-dbg.txt", 1); in initio()
1535 if ((shl_dbg_fd = nfd) == -1) in initio()
1565 * set close-on-exec flag. See FDBASE in sh.h, maybe 24 not 10 here.
1574 return (-1); in savefd()
1602 errorf("can't create pipe:%s - try again", cstrerror(errno)); in openpipe()
1624 * a string (the X in 2>&X, read -uX, print -uX) into a file descriptor.
1639 return (-1); in check_fd()
1645 return (-1); in check_fd()
1660 return (-1); in check_fd()
1669 coproc.read = coproc.readw = coproc.write = -1; in coproc_init()
1674 /* Called by c_read() when eof is read - close fd if it is the co-process fd */
1681 coproc.read = -1; in coproc_read_close()
1694 coproc.readw = -1; in coproc_readw_close()
1700 * when co-process input is dup'd
1707 coproc.write = -1; in coproc_write_close()
1712 * Called to check for existence of/value of the co-process file descriptor.
1713 * (Used by check_fd() and by c_read/c_print to deal with -p option).
1724 return (-1); in coproc_getfd()
1734 /* This to allow co-processes to share output pipe */ in coproc_cleanup()
1738 coproc.read = -1; in coproc_cleanup()
1742 coproc.readw = -1; in coproc_cleanup()
1747 coproc.write = -1; in coproc_cleanup()
1767 tp->shf = NULL; in maketemp()
1768 tp->pid = procpid; in maketemp()
1769 tp->type = type; in maketemp()
1772 tp->tffn[0] = '\0'; in maketemp()
1793 if ((i = binopen3(tp->tffn, O_CREAT | O_EXCL | O_RDWR, in maketemp()
1799 /* map us high and mark as close-on-exec */ in maketemp()
1811 tp->shf = shf_fdopen(i, j, NULL); in maketemp()
1814 tp->next = *tlist; in maketemp()
1835 struct tbl **ntblp, **otblp = tp->tbls; in tgrow()
1837 if (tp->tshift > 29) in tgrow()
1841 osize = (size_t)1 << (tp->tshift++); in tgrow()
1844 ntblp = alloc2(i, sizeof(struct tbl *), tp->areap); in tgrow()
1849 tp->nfree = (tp->tshift == 30) ? 0x3FFF0000UL : in tgrow()
1852 tp->tbls = ntblp; in tgrow()
1856 mask = i - 1; in tgrow()
1859 if ((tblp->flag & DEFINED)) { in tgrow()
1861 j = perturb = tblp->ua.hval; in tgrow()
1872 tp->nfree--; in tgrow()
1873 } else if (!(tblp->flag & FINUSE)) { in tgrow()
1874 afree(tblp, tp->areap); in tgrow()
1877 afree(otblp, tp->areap); in tgrow()
1883 tp->areap = ap; in ktinit()
1884 tp->tbls = NULL; in ktinit()
1885 tp->tshift = ((initshift > INIT_TBLSHIFT) ? in ktinit()
1886 initshift : INIT_TBLSHIFT) - 1; in ktinit()
1897 mask = ((size_t)1 << (tp->tshift)) - 1; in ktscan()
1905 pp = &tp->tbls[j & mask]; in ktscan()
1906 if ((p = *pp) != NULL && (p->ua.hval != h || !(p->flag & DEFINED) || in ktscan()
1907 strcmp(p->name, name))) in ktscan()
1926 if (tp->nfree == 0) { in ktenter()
1935 p = alloc(offsetof(struct tbl, name[0]) + ++len, tp->areap); in ktenter()
1936 p->flag = 0; in ktenter()
1937 p->type = 0; in ktenter()
1938 p->areap = tp->areap; in ktenter()
1939 p->ua.hval = h; in ktenter()
1940 p->u2.field = 0; in ktenter()
1941 p->u.array = NULL; in ktenter()
1942 memcpy(p->name, n, len); in ktenter()
1944 /* enter in tp->tbls */ in ktenter()
1945 tp->nfree--; in ktenter()
1953 ts->left = (size_t)1 << (tp->tshift); in ktwalk()
1954 ts->next = tp->tbls; in ktwalk()
1960 while (--ts->left >= 0) { in ktnext()
1961 struct tbl *p = *ts->next++; in ktnext()
1962 if (p != NULL && (p->flag & DEFINED)) in ktnext()
1974 return (ascstrcmp(a->name, b->name)); in tnamecmp()
1987 i = (size_t)1 << (tp->tshift); in ktsort()
1989 sp = tp->tbls; /* source */ in ktsort()
1991 while (i--) in ktsort()
1992 if ((*dp = *sp++) != NULL && (((*dp)->flag & DEFINED) || in ktsort()
1993 ((*dp)->flag & ARRAY))) in ktsort()
1995 qsort(p, (i = dp - p), sizeof(struct tbl *), tnamecmp); in ktsort()
2086 if (skip_varname(dent->d_name, true)[0] == '\0') { in init_environ()
2087 strpathx(xp, MKSH_ENVDIR, dent->d_name, 1); in init_environ()
2091 dent->d_name, MKSH_ENVDIR, in init_environ()
2096 n = strlen(dent->d_name); in init_environ()
2099 memcpy(xp, dent->d_name, n); in init_environ()
2110 dent->d_name, MKSH_ENVDIR, in init_environ()
2171 …warningf(true, "early locale tracking enabled UTF-8 mode while in POSIX mode, you are now noncompl… in recheck_ctype()