/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
*/
#include <shell.h>
#include <nval.h>
#include <cmdext.h>
#include <stdio.h>
typedef struct {
const char *name;
int (* func)(int, char **, void *);
} bfastpathrec;
/*
* We've disabled the "fastpath" codepath for some commands below
* because it causes a paradoxon for large input files (as used by
* first discovered) it looks like this:
* with 1000 iterations (8 seconds with fastpath, 14 seconds without
* fastpath)
* reaches 24884706 bytes) the benchmark reverses: The fastpath now
* needs 40 seconds and without fastpath it needs 30 seconds (for 100
* iterations).
*/
#if 0
#define ENABLE_PERFORMANCE_PARADOXON 1
#endif
/*
* List of libcmd builtins which do not require a |Shell_t| context.
*/
static const
{
/* This list must be alphabetically sorted for |strcmp()| usage */
{ "basename", b_basename },
{ "cat", b_cat },
{ "chgrp", b_chgrp },
{ "chmod", b_chmod },
{ "chown", b_chown },
#ifdef ENABLE_PERFORMANCE_PARADOXON
{ "cksum", b_cksum },
#endif /* ENABLE_PERFORMANCE_PARADOXON */
{ "cmp", b_cmp },
{ "comm", b_comm },
{ "cp", b_cp },
{ "cut", b_cut },
{ "date", b_date },
{ "dirname", b_dirname },
{ "egrep", b_egrep },
{ "expr", b_expr },
{ "fds", b_fds },
{ "fgrep", b_fgrep },
{ "fmt", b_fmt },
{ "fold", b_fold },
{ "getconf", b_getconf },
{ "grep", b_grep },
{ "head", b_head },
{ "id", b_id },
{ "join", b_join },
{ "ln", b_ln },
{ "logname", b_logname },
{ "md5sum", b_md5sum },
{ "mkdir", b_mkdir },
{ "mkfifo", b_mkfifo },
{ "mktemp", b_mktemp },
{ "mv", b_mv },
{ "paste", b_paste },
{ "pathchk", b_pathchk },
{ "pids", b_pids },
{ "readlink", b_readlink },
#ifdef ENABLE_PERFORMANCE_PARADOXON
{ "rev", b_rev },
#endif /* ENABLE_PERFORMANCE_PARADOXON */
{ "rm", b_rm },
{ "rmdir", b_rmdir },
{ "stty", b_stty },
#ifdef ENABLE_PERFORMANCE_PARADOXON
{ "sum", b_sum },
#endif /* ENABLE_PERFORMANCE_PARADOXON */
{ "sync", b_sync },
{ "tail", b_tail },
{ "tee", b_tee },
{ "tty", b_tty },
{ "uname", b_uname },
{ "uniq", b_uniq },
{ "wc", b_wc },
{ "xgrep", b_xgrep },
};
static inline
const bfastpathrec *
{
unsigned int i;
signed int cmpres;
if (cmpres == 0)
return (&fastpath_builtins[i]);
else if (cmpres > 0)
return (NULL);
}
return (NULL);
}
static inline
int
{
}
/* Builtin script, original derived from alias.sh */
/* Get name of builtin */
"typeset cmd=\"${0##*/}\"\n"
/*
* If the requested command is not an alias load it explicitly
* to make sure it is not bound to a path (those built-ins which
* are mapped via shell aliases point to commands which are
* "special shell built-ins" which cannot be bound to a specific
* PATH element) - otherwise we may execute the wrong command
* if an executable with the same name sits in a PATH element
*/
"if [[ \"${cmd}\" != ~(Elr)(alias|unalias|command) ]] && "
"PATH='' builtin \"${cmd}\"\n"
"fi\n"
/* command is a keyword and needs to be handled separately */
"if [[ \"${cmd}\" == \"command\" ]] ; then\n"
"command \"$@\"\n"
"else\n"
#ifdef WORKAROUND_FOR_ALIAS_CRASH
/*
* an error handler which does a |longjmp()| but somehow the code
* failed to do the |setjmp()| before this point.
* Putting the "alias" command in a subshell avoids the crash.
* Real cause of the issue is under investigation and a fix be
* delivered with the next ast-ksh update.
*/
"( \"${cmd}\" \"$@\" )\n"
#else
"\"${cmd}\" \"$@\"\n"
#endif /* WORKAROUND_FOR_ALIAS_CRASH */
"fi\n"
"exitval=$?";
static inline
int
{
int i;
int exitval;
/*
* Create copy of |argv| array shifted by one position to
* values may trigger special shell modes (e.g. *rsh* will
* trigger "restricted" shell mode etc.).
*/
for (i = 0; i < argc; i++) {
}
if (!shp)
if (!np)
return (exitval);
}
int
{
const char *progname;
/* Get program name */
progname++;
}
else
{
}
/* Execute command... */
/* ... either via a fast path (calling the code directly) ... */
}
else
{
/* ... or from within a full shell. */
}
}