17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 237c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 247c478bd9Sstevel@tonic-gate 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* 27*3d9df56cSakaplan * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 287c478bd9Sstevel@tonic-gate * Use is subject to license terms. 297c478bd9Sstevel@tonic-gate */ 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 327c478bd9Sstevel@tonic-gate /* 337c478bd9Sstevel@tonic-gate * UNIX shell 347c478bd9Sstevel@tonic-gate */ 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate #include "defs.h" 387c478bd9Sstevel@tonic-gate #include "sym.h" 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate /* 417c478bd9Sstevel@tonic-gate * error messages 427c478bd9Sstevel@tonic-gate */ 437c478bd9Sstevel@tonic-gate #ifndef __STDC__ 447c478bd9Sstevel@tonic-gate #define const 457c478bd9Sstevel@tonic-gate #endif 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate const char badopt[] = "bad option(s)"; 487c478bd9Sstevel@tonic-gate const char mailmsg[] = "you have mail\n"; 497c478bd9Sstevel@tonic-gate const char nospace[] = "no space"; 507c478bd9Sstevel@tonic-gate const char nostack[] = "no stack space"; 517c478bd9Sstevel@tonic-gate const char synmsg[] = "syntax error"; 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate const char badnum[] = "bad number"; 547c478bd9Sstevel@tonic-gate const char badsig[] = "bad signal"; 557c478bd9Sstevel@tonic-gate const char badid[] = "invalid id"; 567c478bd9Sstevel@tonic-gate const char badparam[] = "parameter null or not set"; 577c478bd9Sstevel@tonic-gate const char unset[] = "parameter not set"; 587c478bd9Sstevel@tonic-gate const char badsub[] = "bad substitution"; 597c478bd9Sstevel@tonic-gate const char badcreate[] = "cannot create"; 607c478bd9Sstevel@tonic-gate const char nofork[] = "fork failed - too many processes"; 617c478bd9Sstevel@tonic-gate const char noswap[] = "cannot fork: no swap space"; 627c478bd9Sstevel@tonic-gate const char restricted[] = "restricted"; 637c478bd9Sstevel@tonic-gate const char piperr[] = "cannot make pipe"; 647c478bd9Sstevel@tonic-gate const char badopen[] = "cannot open"; 657c478bd9Sstevel@tonic-gate const char coredump[] = " - core dumped"; 667c478bd9Sstevel@tonic-gate const char arglist[] = "arg list too long"; 677c478bd9Sstevel@tonic-gate const char txtbsy[] = "text busy"; 687c478bd9Sstevel@tonic-gate const char toobig[] = "too big"; 697c478bd9Sstevel@tonic-gate const char badexec[] = "cannot execute"; 707c478bd9Sstevel@tonic-gate const char notfound[] = "not found"; 717c478bd9Sstevel@tonic-gate const char badfile[] = "bad file number"; 727c478bd9Sstevel@tonic-gate const char badshift[] = "cannot shift"; 737c478bd9Sstevel@tonic-gate const char baddir[] = "bad directory"; 747c478bd9Sstevel@tonic-gate const char badtrap[] = "bad trap"; 757c478bd9Sstevel@tonic-gate const char wtfailed[] = "is read only"; 767c478bd9Sstevel@tonic-gate const char notid[] = "is not an identifier"; 77*3d9df56cSakaplan const char badulimit[] = "exceeds allowable limit"; 787c478bd9Sstevel@tonic-gate const char badresource[] = "no such resource"; 797c478bd9Sstevel@tonic-gate const char badreturn[] = "cannot return when not in function"; 807c478bd9Sstevel@tonic-gate const char badexport[] = "cannot export functions"; 817c478bd9Sstevel@tonic-gate const char badunset[] = "cannot unset"; 827c478bd9Sstevel@tonic-gate const char nohome[] = "no home directory"; 837c478bd9Sstevel@tonic-gate const char badperm[] = "execute permission denied"; 847c478bd9Sstevel@tonic-gate const char longpwd[] = "sh error: pwd too long"; 857c478bd9Sstevel@tonic-gate const char mssgargn[] = "missing arguments"; 867c478bd9Sstevel@tonic-gate const char libacc[] = "can't access a needed shared library"; 877c478bd9Sstevel@tonic-gate const char libbad[] = "accessing a corrupted shared library"; 887c478bd9Sstevel@tonic-gate const char libscn[] = ".lib section in a.out corrupted"; 897c478bd9Sstevel@tonic-gate const char libmax[] = "attempting to link in too many libs"; 907c478bd9Sstevel@tonic-gate const char emultihop[] = "Multihop attempted"; 917c478bd9Sstevel@tonic-gate const char nulldir[] = "null directory"; 927c478bd9Sstevel@tonic-gate const char enotdir[] = "not a directory"; 937c478bd9Sstevel@tonic-gate const char enoent[] = "does not exist"; 947c478bd9Sstevel@tonic-gate const char eacces[] = "permission denied"; 957c478bd9Sstevel@tonic-gate const char enolink[] = "remote link inactive"; 967c478bd9Sstevel@tonic-gate const char badscale[] = "bad scaling"; 977c478bd9Sstevel@tonic-gate const char exited[] = "Done"; 987c478bd9Sstevel@tonic-gate const char running[] = "Running"; 997c478bd9Sstevel@tonic-gate const char ambiguous[] = "ambiguous"; 1007c478bd9Sstevel@tonic-gate const char usage[] = "usage"; 1017c478bd9Sstevel@tonic-gate const char nojc[] = "no job control"; 1027c478bd9Sstevel@tonic-gate const char stopuse[] = "stop id ..."; 1037c478bd9Sstevel@tonic-gate const char ulimuse[] = "ulimit [ -HSacdfnstv ] [ limit ]"; 1047c478bd9Sstevel@tonic-gate const char killuse[] = "kill [ [ -sig ] id ... | -l ]"; 1057c478bd9Sstevel@tonic-gate const char jobsuse[] = "jobs [ [ -l | -p ] [ id ... ] | -x cmd ]"; 1067c478bd9Sstevel@tonic-gate const char nosuchjob[] = "no such job"; 1077c478bd9Sstevel@tonic-gate const char nosuchpid[] = "no such process"; 1087c478bd9Sstevel@tonic-gate const char nosuchpgid[] = "no such process group"; 1097c478bd9Sstevel@tonic-gate const char nocurjob[] = "no current job"; 1107c478bd9Sstevel@tonic-gate const char jobsstopped[] = "there are stopped jobs"; 1117c478bd9Sstevel@tonic-gate const char jobsrunning[] = "there are running jobs"; 1127c478bd9Sstevel@tonic-gate const char loginsh[] = "cannot stop login shell"; 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate /* 1157c478bd9Sstevel@tonic-gate * messages for 'builtin' functions 1167c478bd9Sstevel@tonic-gate */ 1177c478bd9Sstevel@tonic-gate const char btest[] = "test"; 1187c478bd9Sstevel@tonic-gate const char badop[] = "unknown operator "; 1197c478bd9Sstevel@tonic-gate /* 1207c478bd9Sstevel@tonic-gate * built in names 1217c478bd9Sstevel@tonic-gate */ 1227c478bd9Sstevel@tonic-gate const char pathname[] = "PATH"; 1237c478bd9Sstevel@tonic-gate const char cdpname[] = "CDPATH"; 1247c478bd9Sstevel@tonic-gate const char homename[] = "HOME"; 1257c478bd9Sstevel@tonic-gate const char mailname[] = "MAIL"; 1267c478bd9Sstevel@tonic-gate const char ifsname[] = "IFS"; 1277c478bd9Sstevel@tonic-gate const char ps1name[] = "PS1"; 1287c478bd9Sstevel@tonic-gate const char ps2name[] = "PS2"; 1297c478bd9Sstevel@tonic-gate const char mchkname[] = "MAILCHECK"; 1307c478bd9Sstevel@tonic-gate const char acctname[] = "SHACCT"; 1317c478bd9Sstevel@tonic-gate const char mailpname[] = "MAILPATH"; 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate /* 1347c478bd9Sstevel@tonic-gate * string constants 1357c478bd9Sstevel@tonic-gate */ 1367c478bd9Sstevel@tonic-gate const char nullstr[] = ""; 1377c478bd9Sstevel@tonic-gate const char sptbnl[] = " \t\n"; 1387c478bd9Sstevel@tonic-gate const char defpath[] = "/usr/bin:"; 1397c478bd9Sstevel@tonic-gate const char colon[] = ": "; 1407c478bd9Sstevel@tonic-gate const char minus[] = "-"; 1417c478bd9Sstevel@tonic-gate const char endoffile[] = "end of file"; 1427c478bd9Sstevel@tonic-gate const char unexpected[] = " unexpected"; 1437c478bd9Sstevel@tonic-gate const char atline[] = " at line "; 1447c478bd9Sstevel@tonic-gate const char devnull[] = "/dev/null"; 1457c478bd9Sstevel@tonic-gate const char execpmsg[] = "+ "; 1467c478bd9Sstevel@tonic-gate const char readmsg[] = "> "; 1477c478bd9Sstevel@tonic-gate const char stdprompt[] = "$ "; 1487c478bd9Sstevel@tonic-gate const char supprompt[] = "# "; 1497c478bd9Sstevel@tonic-gate const char profile[] = ".profile"; 1507c478bd9Sstevel@tonic-gate const char sysprofile[] = "/etc/profile"; 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate /* 1537c478bd9Sstevel@tonic-gate * locale testing 1547c478bd9Sstevel@tonic-gate */ 1557c478bd9Sstevel@tonic-gate const char localedir[] = "/usr/lib/locale"; 1567c478bd9Sstevel@tonic-gate int localedir_exists; 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate /* 1597c478bd9Sstevel@tonic-gate * tables 1607c478bd9Sstevel@tonic-gate */ 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate const struct sysnod reserved[] = 1637c478bd9Sstevel@tonic-gate { 1647c478bd9Sstevel@tonic-gate { "case", CASYM }, 1657c478bd9Sstevel@tonic-gate { "do", DOSYM }, 1667c478bd9Sstevel@tonic-gate { "done", ODSYM }, 1677c478bd9Sstevel@tonic-gate { "elif", EFSYM }, 1687c478bd9Sstevel@tonic-gate { "else", ELSYM }, 1697c478bd9Sstevel@tonic-gate { "esac", ESSYM }, 1707c478bd9Sstevel@tonic-gate { "fi", FISYM }, 1717c478bd9Sstevel@tonic-gate { "for", FORSYM }, 1727c478bd9Sstevel@tonic-gate { "if", IFSYM }, 1737c478bd9Sstevel@tonic-gate { "in", INSYM }, 1747c478bd9Sstevel@tonic-gate { "then", THSYM }, 1757c478bd9Sstevel@tonic-gate { "until", UNSYM }, 1767c478bd9Sstevel@tonic-gate { "while", WHSYM }, 1777c478bd9Sstevel@tonic-gate { "{", BRSYM }, 1787c478bd9Sstevel@tonic-gate { "}", KTSYM } 1797c478bd9Sstevel@tonic-gate }; 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate const int no_reserved = sizeof(reserved)/sizeof(struct sysnod); 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate const char *sysmsg[] = 1847c478bd9Sstevel@tonic-gate { 1857c478bd9Sstevel@tonic-gate 0, 1867c478bd9Sstevel@tonic-gate "Hangup", 1877c478bd9Sstevel@tonic-gate 0, /* Interrupt */ 1887c478bd9Sstevel@tonic-gate "Quit", 1897c478bd9Sstevel@tonic-gate "Illegal instruction", 1907c478bd9Sstevel@tonic-gate "Trace/BPT trap", 1917c478bd9Sstevel@tonic-gate "abort", 1927c478bd9Sstevel@tonic-gate "EMT trap", 1937c478bd9Sstevel@tonic-gate "Floating exception", 1947c478bd9Sstevel@tonic-gate "Killed", 1957c478bd9Sstevel@tonic-gate "Bus error", 1967c478bd9Sstevel@tonic-gate "Memory fault", 1977c478bd9Sstevel@tonic-gate "Bad system call", 1987c478bd9Sstevel@tonic-gate 0, /* Broken pipe */ 1997c478bd9Sstevel@tonic-gate "Alarm call", 2007c478bd9Sstevel@tonic-gate "Terminated", 2017c478bd9Sstevel@tonic-gate "Signal 16", 2027c478bd9Sstevel@tonic-gate "Signal 17", 2037c478bd9Sstevel@tonic-gate "Child death", 2047c478bd9Sstevel@tonic-gate "Power Fail" 2057c478bd9Sstevel@tonic-gate }; 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate const char export[] = "export"; 2087c478bd9Sstevel@tonic-gate const char duperr[] = "cannot dup"; 2097c478bd9Sstevel@tonic-gate const char readonly[] = "readonly"; 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate const struct sysnod commands[] = 2137c478bd9Sstevel@tonic-gate { 2147c478bd9Sstevel@tonic-gate { ".", SYSDOT }, 2157c478bd9Sstevel@tonic-gate { ":", SYSNULL }, 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate #ifndef RES 2187c478bd9Sstevel@tonic-gate { "[", SYSTST }, 2197c478bd9Sstevel@tonic-gate #endif 2207c478bd9Sstevel@tonic-gate { "bg", SYSFGBG }, 2217c478bd9Sstevel@tonic-gate { "break", SYSBREAK }, 2227c478bd9Sstevel@tonic-gate { "cd", SYSCD }, 2237c478bd9Sstevel@tonic-gate { "chdir", SYSCD }, 2247c478bd9Sstevel@tonic-gate { "continue", SYSCONT }, 2257c478bd9Sstevel@tonic-gate { "echo", SYSECHO }, 2267c478bd9Sstevel@tonic-gate { "eval", SYSEVAL }, 2277c478bd9Sstevel@tonic-gate { "exec", SYSEXEC }, 2287c478bd9Sstevel@tonic-gate { "exit", SYSEXIT }, 2297c478bd9Sstevel@tonic-gate { "export", SYSXPORT }, 2307c478bd9Sstevel@tonic-gate { "fg", SYSFGBG }, 2317c478bd9Sstevel@tonic-gate { "getopts", SYSGETOPT }, 2327c478bd9Sstevel@tonic-gate { "hash", SYSHASH }, 2337c478bd9Sstevel@tonic-gate { "jobs", SYSJOBS }, 2347c478bd9Sstevel@tonic-gate { "kill", SYSKILL }, 2357c478bd9Sstevel@tonic-gate #ifdef RES 2367c478bd9Sstevel@tonic-gate { "login", SYSLOGIN }, 2377c478bd9Sstevel@tonic-gate { "newgrp", SYSLOGIN }, 2387c478bd9Sstevel@tonic-gate #else 2397c478bd9Sstevel@tonic-gate { "newgrp", SYSNEWGRP }, 2407c478bd9Sstevel@tonic-gate #endif 2417c478bd9Sstevel@tonic-gate 2427c478bd9Sstevel@tonic-gate { "pwd", SYSPWD }, 2437c478bd9Sstevel@tonic-gate { "read", SYSREAD }, 2447c478bd9Sstevel@tonic-gate { "readonly", SYSRDONLY }, 2457c478bd9Sstevel@tonic-gate { "return", SYSRETURN }, 2467c478bd9Sstevel@tonic-gate { "set", SYSSET }, 2477c478bd9Sstevel@tonic-gate { "shift", SYSSHFT }, 2487c478bd9Sstevel@tonic-gate { "stop", SYSSTOP }, 2497c478bd9Sstevel@tonic-gate { "suspend", SYSSUSP}, 2507c478bd9Sstevel@tonic-gate { "test", SYSTST }, 2517c478bd9Sstevel@tonic-gate { "times", SYSTIMES }, 2527c478bd9Sstevel@tonic-gate { "trap", SYSTRAP }, 2537c478bd9Sstevel@tonic-gate { "type", SYSTYPE }, 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate 2567c478bd9Sstevel@tonic-gate #ifndef RES 2577c478bd9Sstevel@tonic-gate { "ulimit", SYSULIMIT }, 2587c478bd9Sstevel@tonic-gate { "umask", SYSUMASK }, 2597c478bd9Sstevel@tonic-gate #endif 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate { "unset", SYSUNS }, 2627c478bd9Sstevel@tonic-gate { "wait", SYSWAIT } 2637c478bd9Sstevel@tonic-gate }; 2647c478bd9Sstevel@tonic-gate 2657c478bd9Sstevel@tonic-gate const int no_commands = sizeof(commands)/sizeof(struct sysnod); 2667c478bd9Sstevel@tonic-gate 267