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-
75 Ttypeset, "-i10", "COLUMNS", "LINES", "SECONDS", "TMOUT", NULL,
77 "integer=\\\\builtin typeset -i",
79 /* not "alias -t --": hash -r needs to work */
80 "hash=\\\\builtin alias -t",
81 "type=\\\\builtin whence -v",
82 "autoload=\\\\builtin typeset -fu",
83 "functions=\\\\builtin typeset -f",
84 "history=\\\\builtin fc -l",
85 "nameref=\\\\builtin typeset -n",
87 "r=\\\\builtin fc -e -",
91 Talias, "-tU",
104 /* top-level parsing and execution environment */
105 static struct env env; variable
106 struct env *e = &env;
108 /* compile-time assertions */
114 ((int)(unsigned char)0x100 == 0) && ((int)(unsigned char)(int)-1 == 0xFF));
129 cta(ari_has_31_bit, 0 < (mksh_ari_t)(((((mksh_ari_t)1 << 15) << 15) - 1) * 2 + 1));
133 cta(uari_has_31_bit, 0 < (mksh_uari_t)(((((mksh_uari_t)1 << 15) << 15) - 1) * 2 + 1));
134 cta(uari_has_32_bit, 0 < (mksh_uari_t)(((((mksh_uari_t)1 << 15) << 15) - 1) * 4 + 3));
136 (mksh_uari_t)(((((mksh_uari_t)1 << 15) << 15) - 1) * 4 + 3) >
137 (mksh_uari_t)(((((mksh_uari_t)1 << 15) << 15) - 1) * 4 + 4));
140 cta(ari_is_signed, (mksh_ari_t)-1 < (mksh_ari_t)0);
141 cta(uari_is_unsigned, (mksh_uari_t)-1 > (mksh_uari_t)0);
166 cp = alloc(sizeof(*bufptr) - sizeof(ALLOC_ITEM), APERM); in rndsetup()
168 memset(cp, 0, sizeof(*bufptr) - sizeof(ALLOC_ITEM)); in rndsetup()
170 bufptr = (void *)(cp - sizeof(ALLOC_ITEM)); in rndsetup()
172 bufptr->dataptr = &rndsetupstate; in rndsetup()
174 bufptr->stkptr = &bufptr; in rndsetup()
176 bufptr->mallocptr = bufptr; in rndsetup()
179 sigsetjmp(bufptr->jbuf, 1); in rndsetup()
182 mksh_TIME(bufptr->tv); in rndsetup()
220 /* check for UTF-8 */ in isuc()
221 if (strstr(x, "UTF-8") || strstr(x, "UTF8")) in isuc()
272 /* max. name length: -2147483648 = 11 (+ NUL) */ in main_init()
275 /* set up base environment */ in main_init()
276 env.type = E_NONE; in main_init()
277 ainit(&env.area); in main_init()
278 /* set up global l->vars and l->funs */ in main_init()
284 /* determine the basename (without '-' or path) of the executable */ in main_init()
294 Flag(FLOGIN) = (ord(*ccp) == ORD('-')) || (ord(*kshname) == ORD('-')); in main_init()
295 if (ord(*ccp) == ORD('-')) in main_init()
302 * option - it always sends the hup). in main_init()
313 * Turn on "set -x" inheritance by default. in main_init()
317 /* define built-in commands and see if we were called as one */ in main_init()
334 /* check for -T option early */ in main_init()
338 /* called as rsh, rmksh, -rsh, RKSH.EXE, etc.? */ in main_init()
344 /* are we called as -rsh or /bin/sh or SH.EXE or so? */ in main_init()
366 /* set up variable and command dictionaries */ in main_init()
405 * Set PATH to def_path (will set the path global variable). in main_init()
414 * Set edit mode to emacs by default, may be overridden in main_init()
434 /* Figure out the current working directory and set $PWD */ in main_init()
442 /* Only set pwd if we know where we are or if it had a bogus value */ in main_init()
462 /* Set PS1 if unset or we are root and prompt doesn't contain a # */ in main_init()
463 if (!(vp->flag & ISSET) || in main_init()
468 vp->flag |= INT_U; in main_init()
470 vp->flag |= INT_U; in main_init()
472 vp->flag |= INT_U; in main_init()
474 vp->flag |= INT_U; in main_init()
476 vp->flag |= INT_U; in main_init()
478 vp->flag |= INT_U; in main_init()
480 vp->flag |= INT_U; in main_init()
482 vp->flag |= INT_U; in main_init()
485 /* Set this before parsing arguments */ in main_init()
488 /* record if monitor is set on command line (see j_init() in jobs.c) */ in main_init()
492 /* this to note if utf-8 mode is set on command line (see below) */ in main_init()
506 /* auto-detect from environment variables, always */ in main_init()
510 if (!(s->start = s->str = argv[argi++])) in main_init()
512 while (*s->str) { in main_init()
513 if (ctype(*s->str, C_QUOTE) && (*s->str != '\'')) in main_init()
515 s->str++; in main_init()
517 if (!*s->str) in main_init()
518 s->flags |= SF_MAYEXEC; in main_init()
519 s->str = s->start; in main_init()
522 if (Flag(FSH) && argv[argi] && !strcmp(argv[argi], "--")) in main_init()
536 s->file = argv[argi++]; in main_init()
537 if (search_access(s->file, X_OK) != 0) in main_init()
538 s->file = search_path(s->file, path, X_OK, NULL); in main_init()
539 if (!s->file || !*s->file) in main_init()
540 s->file = argv[argi - 1]; in main_init()
542 s->file = argv[argi++]; in main_init()
544 s->u.shf = shf_open(s->file, O_RDONLY | O_MAYEXEC, 0, in main_init()
546 if (s->u.shf == NULL) { in main_init()
548 warningf(true, Tf_sD_s, s->file, cstrerror(errno)); in main_init()
553 kshname = s->file; in main_init()
557 s->file = "<stdin>"; in main_init()
558 s->u.shf = shf_fdopen(0, SHF_RD | can_seek(0), in main_init()
563 s->flags |= SF_TTY; in main_init()
564 s->u.shf->flags |= SHF_INTERRUPT; in main_init()
565 s->file = NULL; in main_init()
574 /* initialise job control */ in main_init()
580 /* auto-detect from locale or environment */ in main_init()
586 /* always disable UTF-8 (for interactive) */ in main_init()
602 l = e->loc; in main_init()
604 l->argc = argc; in main_init()
605 l->argv = argv; in main_init()
606 l->argv[0] = ccp; in main_init()
608 l->argc = argc - argi; in main_init()
611 * it in-place, ps(1) output changes; the meaning of argc in main_init()
615 l->argv = alloc2(l->argc + 2, sizeof(void *), APERM); in main_init()
616 l->argv[0] = kshname; in main_init()
617 memcpy(&l->argv[1], &argv[argi], l->argc * sizeof(void *)); in main_init()
618 l->argv[l->argc + 1] = NULL; in main_init()
622 /* divine the initial state of the utf8-mode Flag */ in main_init()
626 /* auto-detect from locale or environment */ in main_init()
639 /* auto-detect from environment */ in main_init()
651 /* not set on command line, not FTALKING */ in main_init()
665 /* Disable during .profile/ENV reading */ in main_init()
671 /* save flags for "set +o" handling */ in main_init()
687 * Do this before profile/$ENV so that if it causes problems in them, in main_init()
697 /* note whether -p was enabled during startup */ in main_init()
699 /* allow set -p to setuid() later */ in main_init()
702 /* turn off -p if not set explicitly */ in main_init()
704 /* track shell-imposed changes */ in main_init()
711 cp = substitute("${ENV:-" MKSHRC_PATH "}", DOTILDE); in main_init()
713 cp = substitute("${ENV:-" MKSHRC_PATH "}", 0); in main_init()
723 /* track shell-imposed changes */ in main_init()
731 /* set after ENV */ in main_init()
734 /* track shell-imposed change (might lower surprise) */ in main_init()
756 rv = c_builtin(l->argv); in main()
776 return (-1); in include()
779 old_argv = e->loc->argv; in include()
780 old_argc = e->loc->argc; in include()
786 if ((i = kshsetjmp(e->jbuf))) { in include()
787 quitenv(s ? s->u.shf : NULL); in include()
789 e->loc->argv = old_argv; in include()
790 e->loc->argc = old_argc; in include()
800 * intr_ok is set if we are including .profile or $ENV. in include()
803 if (intr_ok && ((exstat & 0xFF) - 128) != SIGTERM) in include()
817 e->loc->argv = argv; in include()
818 e->loc->argc = argc; in include()
821 s->u.shf = shf; in include()
822 strdupx(s->file, name, ATEMP); in include()
824 quitenv(s->u.shf); in include()
826 e->loc->argv = old_argv; in include()
827 e->loc->argc = old_argc; in include()
829 /* & 0xff to ensure value not -1 */ in include()
841 s->start = s->str = comm; in command()
842 s->line = line; in command()
855 volatile bool wastty = tobool(s->flags & SF_TTY); in shell()
864 e->flags |= EF_IN_EVAL; in shell()
867 switch ((i = kshsetjmp(e->jbuf))) { in shell()
895 if (Flag(FIGNOREEOF) && s->type == SEOF && wastty) in shell()
896 s->type = SSTDIN; in shell()
900 * interactive is set if we are reading from in shell()
902 * needs FMONITOR set (not FTALKING/SF_TTY)... in shell()
906 s->start = s->str = null; in shell()
932 if (s->next == NULL) { in shell()
934 s->flags |= SF_ECHO; in shell()
936 s->flags &= ~SF_ECHO; in shell()
944 histsave(&s->line, NULL, HIST_FLUSH, true); in shell()
948 if (t->type == TEOF) { in shell()
949 if (wastty && Flag(FIGNOREEOF) && --attempts > 0) { in shell()
951 s->type = SSTDIN; in shell()
955 s->type = SSTDIN; in shell()
967 } else if ((s->flags & SF_MAYEXEC) && t->type == TCOM) in shell()
968 t->u.evalflags |= DOTCOMEXEC; in shell()
969 if (!Flag(FNOEXEC) || (s->flags & SF_TTY)) in shell()
972 if (t->type != TEOF && interactive && really_exit) in shell()
989 if (i == LERREXT && (e->flags & EF_IN_EVAL)) in unwind()
998 --trap_nested; in unwind()
1003 --trap_nested; in unwind()
1009 switch (e->type) { in unwind()
1016 kshlongjmp(e->jbuf, i); in unwind()
1020 e->flags |= EF_FAKE_SIGDIE; in unwind()
1031 struct env *ep; in newenv()
1035 * struct env includes ALLOC_ITEM for alignment constraints in newenv()
1038 cp = alloc(sizeof(struct env) - sizeof(ALLOC_ITEM), ATEMP); in newenv()
1040 ep = (void *)(cp - sizeof(ALLOC_ITEM)); in newenv()
1041 /* initialise public members of struct env (not the ALLOC_ITEM) */ in newenv()
1042 ainit(&ep->area); in newenv()
1043 ep->oenv = e; in newenv()
1044 ep->loc = e->loc; in newenv()
1045 ep->savefd = NULL; in newenv()
1046 ep->temps = NULL; in newenv()
1047 ep->yyrecursive_statep = NULL; in newenv()
1048 ep->type = type; in newenv()
1049 ep->flags = e->flags & EF_IN_EVAL; in newenv()
1056 struct env *ep = e; in quitenv()
1061 while (ep->oenv && ep->oenv->loc != ep->loc) in quitenv()
1063 if (ep->savefd != NULL) { in quitenv()
1065 /* if ep->savefd[fd] < 0, means fd was closed */ in quitenv()
1066 if (ep->savefd[fd]) in quitenv()
1067 restfd(fd, ep->savefd[fd]); in quitenv()
1068 if (ep->savefd[2]) in quitenv()
1076 if (ep->oenv == NULL) { in quitenv()
1081 if (ep->type == E_NONE) { in quitenv()
1088 if (ep->flags & EF_FAKE_SIGDIE) { in quitenv()
1089 int sig = (exstat & 0xFF) - 128; in quitenv()
1118 if ((i = fcntl(fd, F_GETFD, 0)) != -1 && in quitenv()
1131 e = e->oenv; in quitenv()
1133 /* free the struct env - tricky due to the ALLOC_ITEM inside */ in quitenv()
1142 struct env *ep; in cleanup_parents_env()
1146 * Don't clean up temporary files - parent will probably need them. in cleanup_parents_env()
1152 for (ep = e; ep; ep = ep->oenv) { in cleanup_parents_env()
1153 if (ep->savefd) { in cleanup_parents_env()
1155 if (ep->savefd[fd] > 0) in cleanup_parents_env()
1156 close(ep->savefd[fd]); in cleanup_parents_env()
1157 afree(ep->savefd, &ep->area); in cleanup_parents_env()
1158 ep->savefd = NULL; in cleanup_parents_env()
1161 if (ep->type != E_NONE) in cleanup_parents_env()
1162 ep->type = E_GONE; in cleanup_parents_env()
1166 e->oenv = NULL; in cleanup_parents_env()
1174 struct env *ep; in cleanup_proc_env()
1176 for (ep = e; ep; ep = ep->oenv) in cleanup_proc_env()
1177 remove_temps(ep->temps); in cleanup_proc_env()
1186 while ((l = e->loc) && (!e->oenv || e->oenv->loc != l)) { in reclaim()
1187 e->loc = l->next; in reclaim()
1188 afreeall(&l->area); in reclaim()
1191 remove_temps(e->temps); in reclaim()
1192 e->temps = NULL; in reclaim()
1199 if (source && source->areap == &e->area) in reclaim()
1201 afreeall(&e->area); in reclaim()
1208 if (tp->pid == procpid) in remove_temps()
1209 unlink(tp->tffn); in remove_temps()
1210 tp = tp->next; in remove_temps()
1216 * saving/resetting tty modes upon foreground job completion, and
1222 * 4 = cannot make fd close-on-exec
1224 * i.e. if tty_devtty was already set or the new would not set it.
1252 /* already got a non-devtty one */ in tty_init_fd()
1306 /* not set when main() calls parse_args() */ in vwarningf()
1360 * Used by built-in utilities to prefix shell and utility name to message
1378 /* POSIX special builtins cause non-interactive shells to exit */ in bi_errorf()
1410 /* POSIX special builtins cause non-interactive shells to exit */ in maybe_errorf()
1446 if (!fileline || !source || !source->file || in error_prefix()
1447 strcmp(source->file, kshname) != 0) in error_prefix()
1449 (*kshname == '-' ? 1 : 0)); in error_prefix()
1450 if (fileline && source && source->file != NULL) { in error_prefix()
1451 shf_fprintf(shl_out, "%s[%lu]: ", source->file, in error_prefix()
1452 (unsigned long)(source->errline ? in error_prefix()
1453 source->errline : source->line)); in error_prefix()
1454 source->errline = 0; in error_prefix()
1465 /* shl_out may not be set up yet... */ in shellf()
1519 strpathx(lfp, lfp, "mksh-dbg.txt", 1); in initio()
1529 if ((shl_dbg_fd = nfd) == -1) in initio()
1559 * set close-on-exec flag. See FDBASE in sh.h, maybe 24 not 10 here.
1568 return (-1); in savefd()
1596 errorf("can't create pipe - try again"); in openpipe()
1618 * a string (the X in 2>&X, read -uX, print -uX) into a file descriptor.
1633 return (-1); in check_fd()
1639 return (-1); in check_fd()
1654 return (-1); in check_fd()
1663 coproc.read = coproc.readw = coproc.write = -1; in coproc_init()
1668 /* Called by c_read() when eof is read - close fd if it is the co-process fd */
1675 coproc.read = -1; in coproc_read_close()
1688 coproc.readw = -1; in coproc_readw_close()
1694 * when co-process input is dup'd
1701 coproc.write = -1; in coproc_write_close()
1706 * Called to check for existence of/value of the co-process file descriptor.
1707 * (Used by check_fd() and by c_read/c_print to deal with -p option).
1718 return (-1); in coproc_getfd()
1728 /* This to allow co-processes to share output pipe */ in coproc_cleanup()
1732 coproc.read = -1; in coproc_cleanup()
1736 coproc.readw = -1; in coproc_cleanup()
1741 coproc.write = -1; in coproc_cleanup()
1761 tp->shf = NULL; in maketemp()
1762 tp->pid = procpid; in maketemp()
1763 tp->type = type; in maketemp()
1766 tp->tffn[0] = '\0'; in maketemp()
1787 if ((i = binopen3(tp->tffn, O_CREAT | O_EXCL | O_RDWR, in maketemp()
1793 /* map us high and mark as close-on-exec */ in maketemp()
1805 tp->shf = shf_fdopen(i, j, NULL); in maketemp()
1808 tp->next = *tlist; in maketemp()
1829 struct tbl **ntblp, **otblp = tp->tbls; in tgrow()
1831 if (tp->tshift > 29) in tgrow()
1835 osize = (size_t)1 << (tp->tshift++); in tgrow()
1838 ntblp = alloc2(i, sizeof(struct tbl *), tp->areap); in tgrow()
1843 tp->nfree = (tp->tshift == 30) ? 0x3FFF0000UL : in tgrow()
1846 tp->tbls = ntblp; in tgrow()
1850 mask = i - 1; in tgrow()
1853 if ((tblp->flag & DEFINED)) { in tgrow()
1855 j = perturb = tblp->ua.hval; in tgrow()
1866 tp->nfree--; in tgrow()
1867 } else if (!(tblp->flag & FINUSE)) { in tgrow()
1868 afree(tblp, tp->areap); in tgrow()
1871 afree(otblp, tp->areap); in tgrow()
1877 tp->areap = ap; in ktinit()
1878 tp->tbls = NULL; in ktinit()
1879 tp->tshift = ((initshift > INIT_TBLSHIFT) ? in ktinit()
1880 initshift : INIT_TBLSHIFT) - 1; in ktinit()
1891 mask = ((size_t)1 << (tp->tshift)) - 1; in ktscan()
1899 pp = &tp->tbls[j & mask]; in ktscan()
1900 if ((p = *pp) != NULL && (p->ua.hval != h || !(p->flag & DEFINED) || in ktscan()
1901 strcmp(p->name, name))) in ktscan()
1920 if (tp->nfree == 0) { in ktenter()
1929 p = alloc(offsetof(struct tbl, name[0]) + ++len, tp->areap); in ktenter()
1930 p->flag = 0; in ktenter()
1931 p->type = 0; in ktenter()
1932 p->areap = tp->areap; in ktenter()
1933 p->ua.hval = h; in ktenter()
1934 p->u2.field = 0; in ktenter()
1935 p->u.array = NULL; in ktenter()
1936 memcpy(p->name, n, len); in ktenter()
1938 /* enter in tp->tbls */ in ktenter()
1939 tp->nfree--; in ktenter()
1947 ts->left = (size_t)1 << (tp->tshift); in ktwalk()
1948 ts->next = tp->tbls; in ktwalk()
1954 while (--ts->left >= 0) { in ktnext()
1955 struct tbl *p = *ts->next++; in ktnext()
1956 if (p != NULL && (p->flag & DEFINED)) in ktnext()
1968 return (ascstrcmp(a->name, b->name)); in tnamecmp()
1981 i = (size_t)1 << (tp->tshift); in ktsort()
1983 sp = tp->tbls; /* source */ in ktsort()
1985 while (i--) in ktsort()
1986 if ((*dp = *sp++) != NULL && (((*dp)->flag & DEFINED) || in ktsort()
1987 ((*dp)->flag & ARRAY))) in ktsort()
1989 qsort(p, (i = dp - p), sizeof(struct tbl *), tnamecmp); in ktsort()
2080 if (skip_varname(dent->d_name, true)[0] == '\0') { in init_environ()
2081 strpathx(xp, MKSH_ENVDIR, dent->d_name, 1); in init_environ()
2085 dent->d_name, MKSH_ENVDIR, in init_environ()
2090 n = strlen(dent->d_name); in init_environ()
2093 memcpy(xp, dent->d_name, n); in init_environ()
2104 dent->d_name, MKSH_ENVDIR, in init_environ()
2165 …warningf(true, "early locale tracking enabled UTF-8 mode while in POSIX mode, you are now noncompl… in recheck_ctype()