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 5*39e7390aSna195498 * Common Development and Distribution License (the "License"). 6*39e7390aSna195498 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21965005c8Schin 22965005c8Schin /* 23*39e7390aSna195498 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24965005c8Schin * Use is subject to license terms. 25965005c8Schin */ 26965005c8Schin 277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 287c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 297c478bd9Sstevel@tonic-gate 30965005c8Schin #pragma ident "%Z%%M% %I% %E% SMI" 317c478bd9Sstevel@tonic-gate /* 327c478bd9Sstevel@tonic-gate * 337c478bd9Sstevel@tonic-gate * UNIX shell 347c478bd9Sstevel@tonic-gate * 357c478bd9Sstevel@tonic-gate */ 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate #include "defs.h" 397c478bd9Sstevel@tonic-gate #include <errno.h> 407c478bd9Sstevel@tonic-gate #include "sym.h" 417c478bd9Sstevel@tonic-gate #include "hash.h" 427c478bd9Sstevel@tonic-gate #include <sys/types.h> 437c478bd9Sstevel@tonic-gate #include <sys/times.h> 447c478bd9Sstevel@tonic-gate 45965005c8Schin void 46965005c8Schin builtin(int type, int argc, unsigned char **argv, struct trenod *t) 477c478bd9Sstevel@tonic-gate { 487c478bd9Sstevel@tonic-gate short index = initio(t->treio, (type != SYSEXEC)); 497c478bd9Sstevel@tonic-gate unsigned char *a1 = argv[1]; 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate switch (type) 527c478bd9Sstevel@tonic-gate { 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate case SYSSUSP: 557c478bd9Sstevel@tonic-gate syssusp(argc,argv); 567c478bd9Sstevel@tonic-gate break; 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate case SYSSTOP: 597c478bd9Sstevel@tonic-gate sysstop(argc,argv); 607c478bd9Sstevel@tonic-gate break; 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate case SYSKILL: 637c478bd9Sstevel@tonic-gate syskill(argc,argv); 647c478bd9Sstevel@tonic-gate break; 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate case SYSFGBG: 677c478bd9Sstevel@tonic-gate sysfgbg(argc,argv); 687c478bd9Sstevel@tonic-gate break; 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate case SYSJOBS: 717c478bd9Sstevel@tonic-gate sysjobs(argc,argv); 727c478bd9Sstevel@tonic-gate break; 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate case SYSDOT: 757c478bd9Sstevel@tonic-gate if (a1) 767c478bd9Sstevel@tonic-gate { 77965005c8Schin int f; 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate if ((f = pathopen(getpath(a1), a1)) < 0) 807c478bd9Sstevel@tonic-gate failed(a1, notfound); 817c478bd9Sstevel@tonic-gate else 827c478bd9Sstevel@tonic-gate execexp(0, f); 837c478bd9Sstevel@tonic-gate } 847c478bd9Sstevel@tonic-gate break; 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate case SYSTIMES: 877c478bd9Sstevel@tonic-gate { 887c478bd9Sstevel@tonic-gate struct tms tms; 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate times(&tms); 917c478bd9Sstevel@tonic-gate prt(tms.tms_cutime); 927c478bd9Sstevel@tonic-gate prc_buff(SPACE); 937c478bd9Sstevel@tonic-gate prt(tms.tms_cstime); 947c478bd9Sstevel@tonic-gate prc_buff(NL); 957c478bd9Sstevel@tonic-gate } 967c478bd9Sstevel@tonic-gate break; 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate case SYSEXIT: 997c478bd9Sstevel@tonic-gate if ( tried_to_exit++ || endjobs(JOB_STOPPED) ){ 1007c478bd9Sstevel@tonic-gate flags |= forcexit; /* force exit */ 1017c478bd9Sstevel@tonic-gate exitsh(a1 ? stoi(a1) : retval); 1027c478bd9Sstevel@tonic-gate } 1037c478bd9Sstevel@tonic-gate break; 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate case SYSNULL: 1067c478bd9Sstevel@tonic-gate t->treio = 0; 1077c478bd9Sstevel@tonic-gate break; 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate case SYSCONT: 1107c478bd9Sstevel@tonic-gate if (loopcnt) 1117c478bd9Sstevel@tonic-gate { 1127c478bd9Sstevel@tonic-gate execbrk = breakcnt = 1; 1137c478bd9Sstevel@tonic-gate if (a1) 1147c478bd9Sstevel@tonic-gate breakcnt = stoi(a1); 1157c478bd9Sstevel@tonic-gate if (breakcnt > loopcnt) 1167c478bd9Sstevel@tonic-gate breakcnt = loopcnt; 1177c478bd9Sstevel@tonic-gate else 1187c478bd9Sstevel@tonic-gate breakcnt = -breakcnt; 1197c478bd9Sstevel@tonic-gate } 1207c478bd9Sstevel@tonic-gate break; 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate case SYSBREAK: 1237c478bd9Sstevel@tonic-gate if (loopcnt) 1247c478bd9Sstevel@tonic-gate { 1257c478bd9Sstevel@tonic-gate execbrk = breakcnt = 1; 1267c478bd9Sstevel@tonic-gate if (a1) 1277c478bd9Sstevel@tonic-gate breakcnt = stoi(a1); 1287c478bd9Sstevel@tonic-gate if (breakcnt > loopcnt) 1297c478bd9Sstevel@tonic-gate breakcnt = loopcnt; 1307c478bd9Sstevel@tonic-gate } 1317c478bd9Sstevel@tonic-gate break; 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate case SYSTRAP: 1347c478bd9Sstevel@tonic-gate systrap(argc,argv); 1357c478bd9Sstevel@tonic-gate break; 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate case SYSEXEC: 1387c478bd9Sstevel@tonic-gate argv++; 1397c478bd9Sstevel@tonic-gate ioset = 0; 1407c478bd9Sstevel@tonic-gate if (a1 == 0) { 1417c478bd9Sstevel@tonic-gate setmode(0); 1427c478bd9Sstevel@tonic-gate break; 1437c478bd9Sstevel@tonic-gate } 1447c478bd9Sstevel@tonic-gate /* FALLTHROUGH */ 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate #ifdef RES /* Research includes login as part of the shell */ 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate case SYSLOGIN: 1497c478bd9Sstevel@tonic-gate if (!endjobs(JOB_STOPPED|JOB_RUNNING)) 1507c478bd9Sstevel@tonic-gate break; 1517c478bd9Sstevel@tonic-gate oldsigs(); 1527c478bd9Sstevel@tonic-gate execa(argv, -1); 1537c478bd9Sstevel@tonic-gate done(0); 1547c478bd9Sstevel@tonic-gate #else 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate case SYSNEWGRP: 1577c478bd9Sstevel@tonic-gate if (flags & rshflg) 1587c478bd9Sstevel@tonic-gate failed(argv[0], restricted); 1597c478bd9Sstevel@tonic-gate else if (!endjobs(JOB_STOPPED|JOB_RUNNING)) 1607c478bd9Sstevel@tonic-gate break; 1617c478bd9Sstevel@tonic-gate else 1627c478bd9Sstevel@tonic-gate { 1637c478bd9Sstevel@tonic-gate flags |= forcexit; /* bad exec will terminate shell */ 1647c478bd9Sstevel@tonic-gate oldsigs(); 1657c478bd9Sstevel@tonic-gate rmtemp(0); 1667c478bd9Sstevel@tonic-gate rmfunctmp(); 1677c478bd9Sstevel@tonic-gate #ifdef ACCT 1687c478bd9Sstevel@tonic-gate doacct(); 1697c478bd9Sstevel@tonic-gate #endif 1707c478bd9Sstevel@tonic-gate execa(argv, -1); 1717c478bd9Sstevel@tonic-gate done(0); 1727c478bd9Sstevel@tonic-gate } 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate #endif 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate case SYSCD: 1777c478bd9Sstevel@tonic-gate if (flags & rshflg) 1787c478bd9Sstevel@tonic-gate failed(argv[0], restricted); 1797c478bd9Sstevel@tonic-gate else if ((a1 && *a1) || (a1 == 0 && (a1 = homenod.namval))) 1807c478bd9Sstevel@tonic-gate { 1817c478bd9Sstevel@tonic-gate unsigned char *cdpath; 1827c478bd9Sstevel@tonic-gate unsigned char *dir; 1837c478bd9Sstevel@tonic-gate int f; 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate if ((cdpath = cdpnod.namval) == 0 || 1867c478bd9Sstevel@tonic-gate *a1 == '/' || 1877c478bd9Sstevel@tonic-gate cf(a1, ".") == 0 || 1887c478bd9Sstevel@tonic-gate cf(a1, "..") == 0 || 1897c478bd9Sstevel@tonic-gate (*a1 == '.' && (*(a1+1) == '/' || *(a1+1) == '.' && *(a1+2) == '/'))) 1907c478bd9Sstevel@tonic-gate cdpath = (unsigned char *)nullstr; 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate do 1937c478bd9Sstevel@tonic-gate { 1947c478bd9Sstevel@tonic-gate dir = cdpath; 1957c478bd9Sstevel@tonic-gate cdpath = catpath(cdpath,a1); 1967c478bd9Sstevel@tonic-gate } 1977c478bd9Sstevel@tonic-gate while ((f = (chdir((const char *) curstak()) < 0)) && 1987c478bd9Sstevel@tonic-gate cdpath); 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate if (f) { 2017c478bd9Sstevel@tonic-gate switch(errno) { 2027c478bd9Sstevel@tonic-gate case EMULTIHOP: 2037c478bd9Sstevel@tonic-gate failed(a1, emultihop); 2047c478bd9Sstevel@tonic-gate break; 2057c478bd9Sstevel@tonic-gate case ENOTDIR: 2067c478bd9Sstevel@tonic-gate failed(a1, enotdir); 2077c478bd9Sstevel@tonic-gate break; 2087c478bd9Sstevel@tonic-gate case ENOENT: 2097c478bd9Sstevel@tonic-gate failed(a1, enoent); 2107c478bd9Sstevel@tonic-gate break; 2117c478bd9Sstevel@tonic-gate case EACCES: 2127c478bd9Sstevel@tonic-gate failed(a1, eacces); 2137c478bd9Sstevel@tonic-gate break; 2147c478bd9Sstevel@tonic-gate case ENOLINK: 2157c478bd9Sstevel@tonic-gate failed(a1, enolink); 2167c478bd9Sstevel@tonic-gate break; 2177c478bd9Sstevel@tonic-gate default: 2187c478bd9Sstevel@tonic-gate failed(a1, baddir); 2197c478bd9Sstevel@tonic-gate break; 2207c478bd9Sstevel@tonic-gate } 2217c478bd9Sstevel@tonic-gate } 2227c478bd9Sstevel@tonic-gate else 2237c478bd9Sstevel@tonic-gate { 2247c478bd9Sstevel@tonic-gate cwd(curstak()); 2257c478bd9Sstevel@tonic-gate if (cf(nullstr, dir) && 2267c478bd9Sstevel@tonic-gate *dir != ':' && 2277c478bd9Sstevel@tonic-gate any('/', curstak()) && 2287c478bd9Sstevel@tonic-gate flags & prompt) 2297c478bd9Sstevel@tonic-gate { 2307c478bd9Sstevel@tonic-gate prs_buff(cwdget()); 2317c478bd9Sstevel@tonic-gate prc_buff(NL); 2327c478bd9Sstevel@tonic-gate } 2337c478bd9Sstevel@tonic-gate } 2347c478bd9Sstevel@tonic-gate zapcd(); 2357c478bd9Sstevel@tonic-gate } 2367c478bd9Sstevel@tonic-gate else 2377c478bd9Sstevel@tonic-gate { 2387c478bd9Sstevel@tonic-gate if (a1) 2397c478bd9Sstevel@tonic-gate error(nulldir); 2407c478bd9Sstevel@tonic-gate else 2417c478bd9Sstevel@tonic-gate error(nohome); 2427c478bd9Sstevel@tonic-gate } 2437c478bd9Sstevel@tonic-gate 2447c478bd9Sstevel@tonic-gate break; 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate case SYSSHFT: 2477c478bd9Sstevel@tonic-gate { 2487c478bd9Sstevel@tonic-gate int places; 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate places = a1 ? stoi(a1) : 1; 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate if ((dolc -= places) < 0) 2537c478bd9Sstevel@tonic-gate { 2547c478bd9Sstevel@tonic-gate dolc = 0; 2557c478bd9Sstevel@tonic-gate error(badshift); 2567c478bd9Sstevel@tonic-gate } 2577c478bd9Sstevel@tonic-gate else 2587c478bd9Sstevel@tonic-gate dolv += places; 2597c478bd9Sstevel@tonic-gate } 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate break; 2627c478bd9Sstevel@tonic-gate 2637c478bd9Sstevel@tonic-gate case SYSWAIT: 2647c478bd9Sstevel@tonic-gate syswait(argc,argv); 2657c478bd9Sstevel@tonic-gate break; 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate case SYSREAD: 2687c478bd9Sstevel@tonic-gate if(argc < 2) 2697c478bd9Sstevel@tonic-gate failed(argv[0],mssgargn); 2707c478bd9Sstevel@tonic-gate rwait = 1; 2717c478bd9Sstevel@tonic-gate exitval = readvar(&argv[1]); 2727c478bd9Sstevel@tonic-gate rwait = 0; 2737c478bd9Sstevel@tonic-gate break; 2747c478bd9Sstevel@tonic-gate 2757c478bd9Sstevel@tonic-gate case SYSSET: 2767c478bd9Sstevel@tonic-gate if (a1) 2777c478bd9Sstevel@tonic-gate { 2787c478bd9Sstevel@tonic-gate int cnt; 2797c478bd9Sstevel@tonic-gate 2807c478bd9Sstevel@tonic-gate cnt = options(argc, argv); 2817c478bd9Sstevel@tonic-gate if (cnt > 1) 2827c478bd9Sstevel@tonic-gate setargs(argv + argc - cnt); 2837c478bd9Sstevel@tonic-gate } 2847c478bd9Sstevel@tonic-gate else if (comptr(t)->comset == 0) 2857c478bd9Sstevel@tonic-gate { 2867c478bd9Sstevel@tonic-gate /* 2877c478bd9Sstevel@tonic-gate * scan name chain and print 2887c478bd9Sstevel@tonic-gate */ 2897c478bd9Sstevel@tonic-gate namscan(printnam); 2907c478bd9Sstevel@tonic-gate } 2917c478bd9Sstevel@tonic-gate break; 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate case SYSRDONLY: 2947c478bd9Sstevel@tonic-gate exitval = 0; 2957c478bd9Sstevel@tonic-gate if (a1) 2967c478bd9Sstevel@tonic-gate { 2977c478bd9Sstevel@tonic-gate while (*++argv) 2987c478bd9Sstevel@tonic-gate attrib(lookup(*argv), N_RDONLY); 2997c478bd9Sstevel@tonic-gate } 3007c478bd9Sstevel@tonic-gate else 3017c478bd9Sstevel@tonic-gate namscan(printro); 3027c478bd9Sstevel@tonic-gate 3037c478bd9Sstevel@tonic-gate break; 3047c478bd9Sstevel@tonic-gate 3057c478bd9Sstevel@tonic-gate case SYSXPORT: 3067c478bd9Sstevel@tonic-gate { 3077c478bd9Sstevel@tonic-gate struct namnod *n; 3087c478bd9Sstevel@tonic-gate 3097c478bd9Sstevel@tonic-gate exitval = 0; 3107c478bd9Sstevel@tonic-gate if (a1) 3117c478bd9Sstevel@tonic-gate { 3127c478bd9Sstevel@tonic-gate while (*++argv) 3137c478bd9Sstevel@tonic-gate { 3147c478bd9Sstevel@tonic-gate n = lookup(*argv); 3157c478bd9Sstevel@tonic-gate if (n->namflg & N_FUNCTN) 3167c478bd9Sstevel@tonic-gate error(badexport); 3177c478bd9Sstevel@tonic-gate else 3187c478bd9Sstevel@tonic-gate attrib(n, N_EXPORT); 3197c478bd9Sstevel@tonic-gate } 3207c478bd9Sstevel@tonic-gate } 3217c478bd9Sstevel@tonic-gate else 3227c478bd9Sstevel@tonic-gate namscan(printexp); 3237c478bd9Sstevel@tonic-gate } 3247c478bd9Sstevel@tonic-gate break; 3257c478bd9Sstevel@tonic-gate 3267c478bd9Sstevel@tonic-gate case SYSEVAL: 3277c478bd9Sstevel@tonic-gate if (a1) 3287c478bd9Sstevel@tonic-gate execexp(a1, &argv[2]); 3297c478bd9Sstevel@tonic-gate break; 3307c478bd9Sstevel@tonic-gate 3317c478bd9Sstevel@tonic-gate #ifndef RES 3327c478bd9Sstevel@tonic-gate case SYSULIMIT: 3337c478bd9Sstevel@tonic-gate sysulimit(argc, argv); 3347c478bd9Sstevel@tonic-gate break; 3357c478bd9Sstevel@tonic-gate 3367c478bd9Sstevel@tonic-gate case SYSUMASK: 3377c478bd9Sstevel@tonic-gate if (a1) 3387c478bd9Sstevel@tonic-gate { 3397c478bd9Sstevel@tonic-gate int c; 3407c478bd9Sstevel@tonic-gate mode_t i; 3417c478bd9Sstevel@tonic-gate 3427c478bd9Sstevel@tonic-gate i = 0; 3437c478bd9Sstevel@tonic-gate while ((c = *a1++) >= '0' && c <= '7') 3447c478bd9Sstevel@tonic-gate i = (i << 3) + c - '0'; 3457c478bd9Sstevel@tonic-gate umask(i); 3467c478bd9Sstevel@tonic-gate } 3477c478bd9Sstevel@tonic-gate else 3487c478bd9Sstevel@tonic-gate { 3497c478bd9Sstevel@tonic-gate mode_t i; 3507c478bd9Sstevel@tonic-gate int j; 3517c478bd9Sstevel@tonic-gate 3527c478bd9Sstevel@tonic-gate umask(i = umask(0)); 3537c478bd9Sstevel@tonic-gate prc_buff('0'); 3547c478bd9Sstevel@tonic-gate for (j = 6; j >= 0; j -= 3) 3557c478bd9Sstevel@tonic-gate prc_buff(((i >> j) & 07) +'0'); 3567c478bd9Sstevel@tonic-gate prc_buff(NL); 3577c478bd9Sstevel@tonic-gate } 3587c478bd9Sstevel@tonic-gate break; 3597c478bd9Sstevel@tonic-gate 3607c478bd9Sstevel@tonic-gate #endif 3617c478bd9Sstevel@tonic-gate 3627c478bd9Sstevel@tonic-gate case SYSTST: 3637c478bd9Sstevel@tonic-gate exitval = test(argc, argv); 3647c478bd9Sstevel@tonic-gate break; 3657c478bd9Sstevel@tonic-gate 3667c478bd9Sstevel@tonic-gate case SYSECHO: 3677c478bd9Sstevel@tonic-gate exitval = echo(argc, argv); 3687c478bd9Sstevel@tonic-gate break; 3697c478bd9Sstevel@tonic-gate 3707c478bd9Sstevel@tonic-gate case SYSHASH: 3717c478bd9Sstevel@tonic-gate exitval = 0; 3727c478bd9Sstevel@tonic-gate 3737c478bd9Sstevel@tonic-gate if (a1) 3747c478bd9Sstevel@tonic-gate { 3757c478bd9Sstevel@tonic-gate if (a1[0] == '-') 3767c478bd9Sstevel@tonic-gate { 3777c478bd9Sstevel@tonic-gate if (a1[1] == 'r') 3787c478bd9Sstevel@tonic-gate zaphash(); 3797c478bd9Sstevel@tonic-gate else 3807c478bd9Sstevel@tonic-gate error(badopt); 3817c478bd9Sstevel@tonic-gate } 3827c478bd9Sstevel@tonic-gate else 3837c478bd9Sstevel@tonic-gate { 3847c478bd9Sstevel@tonic-gate while (*++argv) 3857c478bd9Sstevel@tonic-gate { 3867c478bd9Sstevel@tonic-gate if (hashtype(hash_cmd(*argv)) == NOTFOUND) 3877c478bd9Sstevel@tonic-gate failed(*argv, notfound); 3887c478bd9Sstevel@tonic-gate } 3897c478bd9Sstevel@tonic-gate } 3907c478bd9Sstevel@tonic-gate } 3917c478bd9Sstevel@tonic-gate else 3927c478bd9Sstevel@tonic-gate hashpr(); 3937c478bd9Sstevel@tonic-gate 3947c478bd9Sstevel@tonic-gate break; 3957c478bd9Sstevel@tonic-gate 3967c478bd9Sstevel@tonic-gate case SYSPWD: 3977c478bd9Sstevel@tonic-gate { 3987c478bd9Sstevel@tonic-gate exitval = 0; 3997c478bd9Sstevel@tonic-gate cwdprint(); 4007c478bd9Sstevel@tonic-gate } 4017c478bd9Sstevel@tonic-gate break; 4027c478bd9Sstevel@tonic-gate 4037c478bd9Sstevel@tonic-gate case SYSRETURN: 4047c478bd9Sstevel@tonic-gate if (funcnt == 0) 4057c478bd9Sstevel@tonic-gate error(badreturn); 4067c478bd9Sstevel@tonic-gate 4077c478bd9Sstevel@tonic-gate execbrk = 1; 4087c478bd9Sstevel@tonic-gate exitval = (a1 ? stoi(a1) : retval); 4097c478bd9Sstevel@tonic-gate break; 4107c478bd9Sstevel@tonic-gate 4117c478bd9Sstevel@tonic-gate case SYSTYPE: 4127c478bd9Sstevel@tonic-gate exitval = 0; 4137c478bd9Sstevel@tonic-gate if (a1) 4147c478bd9Sstevel@tonic-gate { 4157c478bd9Sstevel@tonic-gate /* return success only if all names are found */ 4167c478bd9Sstevel@tonic-gate while (*++argv) 4177c478bd9Sstevel@tonic-gate exitval |= what_is_path(*argv); 4187c478bd9Sstevel@tonic-gate } 4197c478bd9Sstevel@tonic-gate break; 4207c478bd9Sstevel@tonic-gate 4217c478bd9Sstevel@tonic-gate case SYSUNS: 4227c478bd9Sstevel@tonic-gate exitval = 0; 4237c478bd9Sstevel@tonic-gate if (a1) 4247c478bd9Sstevel@tonic-gate { 4257c478bd9Sstevel@tonic-gate while (*++argv) 4267c478bd9Sstevel@tonic-gate unset_name(*argv); 4277c478bd9Sstevel@tonic-gate } 4287c478bd9Sstevel@tonic-gate break; 4297c478bd9Sstevel@tonic-gate 4307c478bd9Sstevel@tonic-gate case SYSGETOPT: { 4317c478bd9Sstevel@tonic-gate int getoptval; 4327c478bd9Sstevel@tonic-gate struct namnod *n; 4337c478bd9Sstevel@tonic-gate extern unsigned char numbuf[]; 4347c478bd9Sstevel@tonic-gate unsigned char *varnam = argv[2]; 4357c478bd9Sstevel@tonic-gate unsigned char c[2]; 4367c478bd9Sstevel@tonic-gate if(argc < 3) { 4377c478bd9Sstevel@tonic-gate failure(argv[0],mssgargn); 4387c478bd9Sstevel@tonic-gate break; 4397c478bd9Sstevel@tonic-gate } 4407c478bd9Sstevel@tonic-gate exitval = 0; 4417c478bd9Sstevel@tonic-gate n = lookup("OPTIND"); 4427c478bd9Sstevel@tonic-gate optind = stoi(n->namval); 4437c478bd9Sstevel@tonic-gate if(argc > 3) { 4447c478bd9Sstevel@tonic-gate argv[2] = dolv[0]; 4457c478bd9Sstevel@tonic-gate getoptval = getopt(argc-2, (char **)&argv[2], (char *)argv[1]); 4467c478bd9Sstevel@tonic-gate } 4477c478bd9Sstevel@tonic-gate else 4487c478bd9Sstevel@tonic-gate getoptval = getopt(dolc+1, (char **)dolv, (char *)argv[1]); 4497c478bd9Sstevel@tonic-gate if(getoptval == -1) { 4507c478bd9Sstevel@tonic-gate itos(optind); 4517c478bd9Sstevel@tonic-gate assign(n, numbuf); 4527c478bd9Sstevel@tonic-gate n = lookup(varnam); 453965005c8Schin assign(n, (unsigned char *)nullstr); 4547c478bd9Sstevel@tonic-gate exitval = 1; 4557c478bd9Sstevel@tonic-gate break; 4567c478bd9Sstevel@tonic-gate } 4577c478bd9Sstevel@tonic-gate argv[2] = varnam; 4587c478bd9Sstevel@tonic-gate itos(optind); 4597c478bd9Sstevel@tonic-gate assign(n, numbuf); 4607c478bd9Sstevel@tonic-gate c[0] = getoptval; 4617c478bd9Sstevel@tonic-gate c[1] = 0; 4627c478bd9Sstevel@tonic-gate n = lookup(varnam); 4637c478bd9Sstevel@tonic-gate assign(n, c); 4647c478bd9Sstevel@tonic-gate n = lookup("OPTARG"); 465965005c8Schin assign(n, (unsigned char *)optarg); 4667c478bd9Sstevel@tonic-gate } 4677c478bd9Sstevel@tonic-gate break; 4687c478bd9Sstevel@tonic-gate 4697c478bd9Sstevel@tonic-gate default: 470*39e7390aSna195498 prs_buff(_gettext("unknown builtin\n")); 4717c478bd9Sstevel@tonic-gate } 4727c478bd9Sstevel@tonic-gate 4737c478bd9Sstevel@tonic-gate 4747c478bd9Sstevel@tonic-gate flushb(); 4757c478bd9Sstevel@tonic-gate restore(index); 4767c478bd9Sstevel@tonic-gate chktrap(); 4777c478bd9Sstevel@tonic-gate } 478