1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 24*7c478bd9Sstevel@tonic-gate 25*7c478bd9Sstevel@tonic-gate 26*7c478bd9Sstevel@tonic-gate /* 27*7c478bd9Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 28*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 29*7c478bd9Sstevel@tonic-gate */ 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 32*7c478bd9Sstevel@tonic-gate /* 33*7c478bd9Sstevel@tonic-gate * UNIX shell 34*7c478bd9Sstevel@tonic-gate */ 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate #include "defs.h" 38*7c478bd9Sstevel@tonic-gate #include "sym.h" 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate /* 41*7c478bd9Sstevel@tonic-gate * error messages 42*7c478bd9Sstevel@tonic-gate */ 43*7c478bd9Sstevel@tonic-gate #ifndef __STDC__ 44*7c478bd9Sstevel@tonic-gate #define const 45*7c478bd9Sstevel@tonic-gate #endif 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate const char badopt[] = "bad option(s)"; 48*7c478bd9Sstevel@tonic-gate const char mailmsg[] = "you have mail\n"; 49*7c478bd9Sstevel@tonic-gate const char nospace[] = "no space"; 50*7c478bd9Sstevel@tonic-gate const char nostack[] = "no stack space"; 51*7c478bd9Sstevel@tonic-gate const char synmsg[] = "syntax error"; 52*7c478bd9Sstevel@tonic-gate 53*7c478bd9Sstevel@tonic-gate const char badnum[] = "bad number"; 54*7c478bd9Sstevel@tonic-gate const char badsig[] = "bad signal"; 55*7c478bd9Sstevel@tonic-gate const char badid[] = "invalid id"; 56*7c478bd9Sstevel@tonic-gate const char badparam[] = "parameter null or not set"; 57*7c478bd9Sstevel@tonic-gate const char unset[] = "parameter not set"; 58*7c478bd9Sstevel@tonic-gate const char badsub[] = "bad substitution"; 59*7c478bd9Sstevel@tonic-gate const char badcreate[] = "cannot create"; 60*7c478bd9Sstevel@tonic-gate const char nofork[] = "fork failed - too many processes"; 61*7c478bd9Sstevel@tonic-gate const char noswap[] = "cannot fork: no swap space"; 62*7c478bd9Sstevel@tonic-gate const char restricted[] = "restricted"; 63*7c478bd9Sstevel@tonic-gate const char piperr[] = "cannot make pipe"; 64*7c478bd9Sstevel@tonic-gate const char badopen[] = "cannot open"; 65*7c478bd9Sstevel@tonic-gate const char coredump[] = " - core dumped"; 66*7c478bd9Sstevel@tonic-gate const char arglist[] = "arg list too long"; 67*7c478bd9Sstevel@tonic-gate const char txtbsy[] = "text busy"; 68*7c478bd9Sstevel@tonic-gate const char toobig[] = "too big"; 69*7c478bd9Sstevel@tonic-gate const char badexec[] = "cannot execute"; 70*7c478bd9Sstevel@tonic-gate const char notfound[] = "not found"; 71*7c478bd9Sstevel@tonic-gate const char badfile[] = "bad file number"; 72*7c478bd9Sstevel@tonic-gate const char badshift[] = "cannot shift"; 73*7c478bd9Sstevel@tonic-gate const char baddir[] = "bad directory"; 74*7c478bd9Sstevel@tonic-gate const char badtrap[] = "bad trap"; 75*7c478bd9Sstevel@tonic-gate const char wtfailed[] = "is read only"; 76*7c478bd9Sstevel@tonic-gate const char notid[] = "is not an identifier"; 77*7c478bd9Sstevel@tonic-gate const char badulimit[] = "bad ulimit"; 78*7c478bd9Sstevel@tonic-gate const char badresource[] = "no such resource"; 79*7c478bd9Sstevel@tonic-gate const char badreturn[] = "cannot return when not in function"; 80*7c478bd9Sstevel@tonic-gate const char badexport[] = "cannot export functions"; 81*7c478bd9Sstevel@tonic-gate const char badunset[] = "cannot unset"; 82*7c478bd9Sstevel@tonic-gate const char nohome[] = "no home directory"; 83*7c478bd9Sstevel@tonic-gate const char badperm[] = "execute permission denied"; 84*7c478bd9Sstevel@tonic-gate const char longpwd[] = "sh error: pwd too long"; 85*7c478bd9Sstevel@tonic-gate const char mssgargn[] = "missing arguments"; 86*7c478bd9Sstevel@tonic-gate const char libacc[] = "can't access a needed shared library"; 87*7c478bd9Sstevel@tonic-gate const char libbad[] = "accessing a corrupted shared library"; 88*7c478bd9Sstevel@tonic-gate const char libscn[] = ".lib section in a.out corrupted"; 89*7c478bd9Sstevel@tonic-gate const char libmax[] = "attempting to link in too many libs"; 90*7c478bd9Sstevel@tonic-gate const char emultihop[] = "Multihop attempted"; 91*7c478bd9Sstevel@tonic-gate const char nulldir[] = "null directory"; 92*7c478bd9Sstevel@tonic-gate const char enotdir[] = "not a directory"; 93*7c478bd9Sstevel@tonic-gate const char enoent[] = "does not exist"; 94*7c478bd9Sstevel@tonic-gate const char eacces[] = "permission denied"; 95*7c478bd9Sstevel@tonic-gate const char enolink[] = "remote link inactive"; 96*7c478bd9Sstevel@tonic-gate const char badscale[] = "bad scaling"; 97*7c478bd9Sstevel@tonic-gate const char exited[] = "Done"; 98*7c478bd9Sstevel@tonic-gate const char running[] = "Running"; 99*7c478bd9Sstevel@tonic-gate const char ambiguous[] = "ambiguous"; 100*7c478bd9Sstevel@tonic-gate const char usage[] = "usage"; 101*7c478bd9Sstevel@tonic-gate const char nojc[] = "no job control"; 102*7c478bd9Sstevel@tonic-gate const char stopuse[] = "stop id ..."; 103*7c478bd9Sstevel@tonic-gate const char ulimuse[] = "ulimit [ -HSacdfnstv ] [ limit ]"; 104*7c478bd9Sstevel@tonic-gate const char killuse[] = "kill [ [ -sig ] id ... | -l ]"; 105*7c478bd9Sstevel@tonic-gate const char jobsuse[] = "jobs [ [ -l | -p ] [ id ... ] | -x cmd ]"; 106*7c478bd9Sstevel@tonic-gate const char nosuchjob[] = "no such job"; 107*7c478bd9Sstevel@tonic-gate const char nosuchpid[] = "no such process"; 108*7c478bd9Sstevel@tonic-gate const char nosuchpgid[] = "no such process group"; 109*7c478bd9Sstevel@tonic-gate const char nocurjob[] = "no current job"; 110*7c478bd9Sstevel@tonic-gate const char jobsstopped[] = "there are stopped jobs"; 111*7c478bd9Sstevel@tonic-gate const char jobsrunning[] = "there are running jobs"; 112*7c478bd9Sstevel@tonic-gate const char loginsh[] = "cannot stop login shell"; 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate /* 115*7c478bd9Sstevel@tonic-gate * messages for 'builtin' functions 116*7c478bd9Sstevel@tonic-gate */ 117*7c478bd9Sstevel@tonic-gate const char btest[] = "test"; 118*7c478bd9Sstevel@tonic-gate const char badop[] = "unknown operator "; 119*7c478bd9Sstevel@tonic-gate /* 120*7c478bd9Sstevel@tonic-gate * built in names 121*7c478bd9Sstevel@tonic-gate */ 122*7c478bd9Sstevel@tonic-gate const char pathname[] = "PATH"; 123*7c478bd9Sstevel@tonic-gate const char cdpname[] = "CDPATH"; 124*7c478bd9Sstevel@tonic-gate const char homename[] = "HOME"; 125*7c478bd9Sstevel@tonic-gate const char mailname[] = "MAIL"; 126*7c478bd9Sstevel@tonic-gate const char ifsname[] = "IFS"; 127*7c478bd9Sstevel@tonic-gate const char ps1name[] = "PS1"; 128*7c478bd9Sstevel@tonic-gate const char ps2name[] = "PS2"; 129*7c478bd9Sstevel@tonic-gate const char mchkname[] = "MAILCHECK"; 130*7c478bd9Sstevel@tonic-gate const char acctname[] = "SHACCT"; 131*7c478bd9Sstevel@tonic-gate const char mailpname[] = "MAILPATH"; 132*7c478bd9Sstevel@tonic-gate 133*7c478bd9Sstevel@tonic-gate /* 134*7c478bd9Sstevel@tonic-gate * string constants 135*7c478bd9Sstevel@tonic-gate */ 136*7c478bd9Sstevel@tonic-gate const char nullstr[] = ""; 137*7c478bd9Sstevel@tonic-gate const char sptbnl[] = " \t\n"; 138*7c478bd9Sstevel@tonic-gate const char defpath[] = "/usr/bin:"; 139*7c478bd9Sstevel@tonic-gate const char colon[] = ": "; 140*7c478bd9Sstevel@tonic-gate const char minus[] = "-"; 141*7c478bd9Sstevel@tonic-gate const char endoffile[] = "end of file"; 142*7c478bd9Sstevel@tonic-gate const char unexpected[] = " unexpected"; 143*7c478bd9Sstevel@tonic-gate const char atline[] = " at line "; 144*7c478bd9Sstevel@tonic-gate const char devnull[] = "/dev/null"; 145*7c478bd9Sstevel@tonic-gate const char execpmsg[] = "+ "; 146*7c478bd9Sstevel@tonic-gate const char readmsg[] = "> "; 147*7c478bd9Sstevel@tonic-gate const char stdprompt[] = "$ "; 148*7c478bd9Sstevel@tonic-gate const char supprompt[] = "# "; 149*7c478bd9Sstevel@tonic-gate const char profile[] = ".profile"; 150*7c478bd9Sstevel@tonic-gate const char sysprofile[] = "/etc/profile"; 151*7c478bd9Sstevel@tonic-gate 152*7c478bd9Sstevel@tonic-gate /* 153*7c478bd9Sstevel@tonic-gate * locale testing 154*7c478bd9Sstevel@tonic-gate */ 155*7c478bd9Sstevel@tonic-gate const char localedir[] = "/usr/lib/locale"; 156*7c478bd9Sstevel@tonic-gate int localedir_exists; 157*7c478bd9Sstevel@tonic-gate 158*7c478bd9Sstevel@tonic-gate /* 159*7c478bd9Sstevel@tonic-gate * tables 160*7c478bd9Sstevel@tonic-gate */ 161*7c478bd9Sstevel@tonic-gate 162*7c478bd9Sstevel@tonic-gate const struct sysnod reserved[] = 163*7c478bd9Sstevel@tonic-gate { 164*7c478bd9Sstevel@tonic-gate { "case", CASYM }, 165*7c478bd9Sstevel@tonic-gate { "do", DOSYM }, 166*7c478bd9Sstevel@tonic-gate { "done", ODSYM }, 167*7c478bd9Sstevel@tonic-gate { "elif", EFSYM }, 168*7c478bd9Sstevel@tonic-gate { "else", ELSYM }, 169*7c478bd9Sstevel@tonic-gate { "esac", ESSYM }, 170*7c478bd9Sstevel@tonic-gate { "fi", FISYM }, 171*7c478bd9Sstevel@tonic-gate { "for", FORSYM }, 172*7c478bd9Sstevel@tonic-gate { "if", IFSYM }, 173*7c478bd9Sstevel@tonic-gate { "in", INSYM }, 174*7c478bd9Sstevel@tonic-gate { "then", THSYM }, 175*7c478bd9Sstevel@tonic-gate { "until", UNSYM }, 176*7c478bd9Sstevel@tonic-gate { "while", WHSYM }, 177*7c478bd9Sstevel@tonic-gate { "{", BRSYM }, 178*7c478bd9Sstevel@tonic-gate { "}", KTSYM } 179*7c478bd9Sstevel@tonic-gate }; 180*7c478bd9Sstevel@tonic-gate 181*7c478bd9Sstevel@tonic-gate const int no_reserved = sizeof(reserved)/sizeof(struct sysnod); 182*7c478bd9Sstevel@tonic-gate 183*7c478bd9Sstevel@tonic-gate const char *sysmsg[] = 184*7c478bd9Sstevel@tonic-gate { 185*7c478bd9Sstevel@tonic-gate 0, 186*7c478bd9Sstevel@tonic-gate "Hangup", 187*7c478bd9Sstevel@tonic-gate 0, /* Interrupt */ 188*7c478bd9Sstevel@tonic-gate "Quit", 189*7c478bd9Sstevel@tonic-gate "Illegal instruction", 190*7c478bd9Sstevel@tonic-gate "Trace/BPT trap", 191*7c478bd9Sstevel@tonic-gate "abort", 192*7c478bd9Sstevel@tonic-gate "EMT trap", 193*7c478bd9Sstevel@tonic-gate "Floating exception", 194*7c478bd9Sstevel@tonic-gate "Killed", 195*7c478bd9Sstevel@tonic-gate "Bus error", 196*7c478bd9Sstevel@tonic-gate "Memory fault", 197*7c478bd9Sstevel@tonic-gate "Bad system call", 198*7c478bd9Sstevel@tonic-gate 0, /* Broken pipe */ 199*7c478bd9Sstevel@tonic-gate "Alarm call", 200*7c478bd9Sstevel@tonic-gate "Terminated", 201*7c478bd9Sstevel@tonic-gate "Signal 16", 202*7c478bd9Sstevel@tonic-gate "Signal 17", 203*7c478bd9Sstevel@tonic-gate "Child death", 204*7c478bd9Sstevel@tonic-gate "Power Fail" 205*7c478bd9Sstevel@tonic-gate }; 206*7c478bd9Sstevel@tonic-gate 207*7c478bd9Sstevel@tonic-gate const char export[] = "export"; 208*7c478bd9Sstevel@tonic-gate const char duperr[] = "cannot dup"; 209*7c478bd9Sstevel@tonic-gate const char readonly[] = "readonly"; 210*7c478bd9Sstevel@tonic-gate 211*7c478bd9Sstevel@tonic-gate 212*7c478bd9Sstevel@tonic-gate const struct sysnod commands[] = 213*7c478bd9Sstevel@tonic-gate { 214*7c478bd9Sstevel@tonic-gate { ".", SYSDOT }, 215*7c478bd9Sstevel@tonic-gate { ":", SYSNULL }, 216*7c478bd9Sstevel@tonic-gate 217*7c478bd9Sstevel@tonic-gate #ifndef RES 218*7c478bd9Sstevel@tonic-gate { "[", SYSTST }, 219*7c478bd9Sstevel@tonic-gate #endif 220*7c478bd9Sstevel@tonic-gate { "bg", SYSFGBG }, 221*7c478bd9Sstevel@tonic-gate { "break", SYSBREAK }, 222*7c478bd9Sstevel@tonic-gate { "cd", SYSCD }, 223*7c478bd9Sstevel@tonic-gate { "chdir", SYSCD }, 224*7c478bd9Sstevel@tonic-gate { "continue", SYSCONT }, 225*7c478bd9Sstevel@tonic-gate { "echo", SYSECHO }, 226*7c478bd9Sstevel@tonic-gate { "eval", SYSEVAL }, 227*7c478bd9Sstevel@tonic-gate { "exec", SYSEXEC }, 228*7c478bd9Sstevel@tonic-gate { "exit", SYSEXIT }, 229*7c478bd9Sstevel@tonic-gate { "export", SYSXPORT }, 230*7c478bd9Sstevel@tonic-gate { "fg", SYSFGBG }, 231*7c478bd9Sstevel@tonic-gate { "getopts", SYSGETOPT }, 232*7c478bd9Sstevel@tonic-gate { "hash", SYSHASH }, 233*7c478bd9Sstevel@tonic-gate { "jobs", SYSJOBS }, 234*7c478bd9Sstevel@tonic-gate { "kill", SYSKILL }, 235*7c478bd9Sstevel@tonic-gate #ifdef RES 236*7c478bd9Sstevel@tonic-gate { "login", SYSLOGIN }, 237*7c478bd9Sstevel@tonic-gate { "newgrp", SYSLOGIN }, 238*7c478bd9Sstevel@tonic-gate #else 239*7c478bd9Sstevel@tonic-gate { "newgrp", SYSNEWGRP }, 240*7c478bd9Sstevel@tonic-gate #endif 241*7c478bd9Sstevel@tonic-gate 242*7c478bd9Sstevel@tonic-gate { "pwd", SYSPWD }, 243*7c478bd9Sstevel@tonic-gate { "read", SYSREAD }, 244*7c478bd9Sstevel@tonic-gate { "readonly", SYSRDONLY }, 245*7c478bd9Sstevel@tonic-gate { "return", SYSRETURN }, 246*7c478bd9Sstevel@tonic-gate { "set", SYSSET }, 247*7c478bd9Sstevel@tonic-gate { "shift", SYSSHFT }, 248*7c478bd9Sstevel@tonic-gate { "stop", SYSSTOP }, 249*7c478bd9Sstevel@tonic-gate { "suspend", SYSSUSP}, 250*7c478bd9Sstevel@tonic-gate { "test", SYSTST }, 251*7c478bd9Sstevel@tonic-gate { "times", SYSTIMES }, 252*7c478bd9Sstevel@tonic-gate { "trap", SYSTRAP }, 253*7c478bd9Sstevel@tonic-gate { "type", SYSTYPE }, 254*7c478bd9Sstevel@tonic-gate 255*7c478bd9Sstevel@tonic-gate 256*7c478bd9Sstevel@tonic-gate #ifndef RES 257*7c478bd9Sstevel@tonic-gate { "ulimit", SYSULIMIT }, 258*7c478bd9Sstevel@tonic-gate { "umask", SYSUMASK }, 259*7c478bd9Sstevel@tonic-gate #endif 260*7c478bd9Sstevel@tonic-gate 261*7c478bd9Sstevel@tonic-gate { "unset", SYSUNS }, 262*7c478bd9Sstevel@tonic-gate { "wait", SYSWAIT } 263*7c478bd9Sstevel@tonic-gate }; 264*7c478bd9Sstevel@tonic-gate 265*7c478bd9Sstevel@tonic-gate const int no_commands = sizeof(commands)/sizeof(struct sysnod); 266*7c478bd9Sstevel@tonic-gate 267