5127N/A# This patch has been developed inhouse and has not been submitted
5127N/A# to the community. This is a Solaris specific patch which is needed
830N/A@@ -3,7 +3,7 @@ ast-base :PACKAGE: \
830N/A libdll libexpr libodelta librecsort libsum libuu libvdelta \
830N/A libbz libz tests 3d coshell cpp cs mam msgcc nmake probe ss \
830N/A libcoshell libcs libmam libpp libcodex paxlib codexlib \
5127N/A- libdss libpz dsslib libtaso
5127N/A+ libdss libpz dsslib libtaso alias
830N/A :COVERS: ast-make ast-ksh ast-ast
830N/A+ * The contents of this file are subject to the terms of the
830N/A+ * Common Development and Distribution License (the "License").
830N/A+ * You may not use this file except in compliance with the License.
830N/A+ * See the License for the specific language governing permissions
830N/A+ * and limitations under the License.
830N/A+ * When distributing Covered Code, include this CDDL HEADER in each
830N/A+ * If applicable, add the following below this CDDL HEADER, with the
830N/A+ * fields enclosed by brackets "[]" replaced with your own identifying
830N/A+ * information: Portions Copyright [yyyy] [name of copyright owner]
5127N/A+ * Copyright (c) 2009, 2015, Oracle
and/or its affiliates. All rights reserved.
5127N/A+ int (* func)(int, char **, Shbltin_t *);
830N/A+ * We've disabled the "fastpath" codepath for some commands below
830N/A+ * because it causes a paradoxon for large input files (as used by
830N/A+ * first discovered) it looks like this:
830N/A+ * with 1000 iterations (8 seconds with fastpath, 14 seconds without
830N/A+ * reaches 24884706 bytes) the benchmark reverses: The fastpath now
830N/A+ * needs 40 seconds and without fastpath it needs 30 seconds (for 100
830N/A+#define ENABLE_PERFORMANCE_PARADOXON 1
830N/A+ * List of libcmd builtins which do not require a |Shell_t| context.
830N/A+bfastpathrec fastpath_builtins[] =
830N/A+ /* This list must be alphabetically sorted for |strcmp()| usage */
830N/A+ { "basename", b_basename },
830N/A+#ifdef ENABLE_PERFORMANCE_PARADOXON
830N/A+#endif /* ENABLE_PERFORMANCE_PARADOXON */
830N/A+ { "dirname", b_dirname },
830N/A+ { "getconf", b_getconf },
830N/A+ { "logname", b_logname },
830N/A+ { "md5sum", b_md5sum },
830N/A+ { "mkfifo", b_mkfifo },
830N/A+ { "mktemp", b_mktemp },
830N/A+ { "pathchk", b_pathchk },
830N/A+#ifdef ENABLE_PERFORMANCE_PARADOXON
830N/A+#endif /* ENABLE_PERFORMANCE_PARADOXON */
830N/A+#ifdef ENABLE_PERFORMANCE_PARADOXON
830N/A+#endif /* ENABLE_PERFORMANCE_PARADOXON */
5127N/A+ { NULL, (int (*)(int, char **, Shbltin_t *))NULL }
830N/A+find_bfastpathrec(const char *name)
830N/A+ for (i = 0; fastpath_builtins[i].name != NULL; i++) {
830N/A+ cmpres = strcmp(fastpath_builtins[i].name, name);
830N/A+ return (&fastpath_builtins[i]);
830N/A+fastpath_builtin_main(const bfastpathrec *brec, int argc, char *argv[])
830N/A+ setlocale(LC_ALL, ""); /* calls |_ast_setlocale()| */
830N/A+ return ((*brec->func)(argc, argv, NULL));
830N/A+static const char *script = "\n"
830N/A+/* Get name of builtin */
830N/A+"typeset cmd=\"${0##*/}\"\n"
830N/A+ * If the requested command is not an alias load it explicitly
830N/A+ * to make sure it is not bound to a path (those built-ins which
830N/A+ * are mapped via shell aliases point to commands which are
830N/A+ * "special shell built-ins" which cannot be bound to a specific
830N/A+ * PATH element) - otherwise we may execute the wrong command
830N/A+ * if an executable with the same name sits in a PATH element
830N/A+"if [[ \"${cmd}\" != ~(Elr)(alias|unalias|command) ]] && "
830N/A+ "PATH='' builtin \"${cmd}\"\n"
830N/A+/* command is a keyword and needs to be handled separately */
830N/A+"if [[ \"${cmd}\" == \"command\" ]] ; then\n"
830N/A+#ifdef WORKAROUND_FOR_ALIAS_CRASH
830N/A+ * an error handler which does a |longjmp()| but somehow the code
830N/A+ * failed to do the |setjmp()| before this point.
830N/A+ * Putting the "alias" command in a subshell avoids the crash.
830N/A+ * Real cause of the issue is under investigation and a fix be
830N/A+ * delivered with the next ast-ksh update.
830N/A+ "( \"${cmd}\" \"$@\" )\n"
830N/A+#endif /* WORKAROUND_FOR_ALIAS_CRASH */
830N/A+script_builtin_main(int argc, char *argv[])
830N/A+ * Create copy of |argv| array shifted by one position to
830N/A+ * values may trigger special shell modes (
e.g. *rsh* will
830N/A+ * trigger "restricted" shell mode etc.).
830N/A+ xargv[1] = "scriptname";
830N/A+ for (i = 0; i < argc; i++) {
830N/A+ shp = sh_init(argc+1, xargv, 0);
830N/A+ error(ERROR_exit(1), "shell initialisation failed.");
830N/A+ (void) sh_trap(script, 0);
830N/A+ np = nv_open("exitval", shp->var_tree, 0);
830N/A+ error(ERROR_exit(1), "variable %s not found.", "exitval");
830N/A+ exitval = (int)nv_getnum(np);
830N/A+main(int argc, char *argv[])
830N/A+ const bfastpathrec *brec;
830N/A+ char execnamebuff[PATH_MAX+1];
830N/A+ /* Get program name */
830N/A+ if (pathprog(argv[0], execnamebuff, sizeof (execnamebuff)) <= 0)
830N/A+ error(ERROR_exit(1), "could not determinate exec name.");
830N/A+ progname = (const char *)strrchr(execnamebuff, '/');
830N/A+ if (progname != NULL) {
830N/A+ progname = execnamebuff;
830N/A+ /* Execute command... */
830N/A+ if (brec = find_bfastpathrec(progname)) {
830N/A+ /* ... either via a fast path (calling the code directly) ... */
830N/A+ return (fastpath_builtin_main(brec, argc, argv));
830N/A+ /* ... or from within a full shell. */
830N/A+ return (script_builtin_main(argc, argv));
830N/A+/***********************************************************************
830N/A+* This software is part of the ast package *
5127N/A+* Copyright (c) 1982-2012 AT&T Intellectual Property *
830N/A+* and is licensed under the *
5127N/A+* Eclipse Public License, Version 1.0 *
830N/A+* by AT&T Intellectual Property *
830N/A+* A copy of the License is available at *
5127N/A+* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
830N/A+* Information and Software Systems Research *
830N/A+* David Korn <dgk@research.att.com> *
830N/A+***********************************************************************/
5127N/A+extern int b_asa (int, char**, Shbltin_t *);
5127N/A+extern int b_basename (int, char**, Shbltin_t *);
5127N/A+extern int b_cat (int, char**, Shbltin_t *);
5127N/A+extern int b_chgrp (int, char**, Shbltin_t *);
5127N/A+extern int b_chmod (int, char**, Shbltin_t *);
5127N/A+extern int b_chown (int, char**, Shbltin_t *);
5127N/A+extern int b_cksum (int, char**, Shbltin_t *);
5127N/A+extern int b_cmp (int, char**, Shbltin_t *);
5127N/A+extern int b_comm (int, char**, Shbltin_t *);
5127N/A+extern int b_cp (int, char**, Shbltin_t *);
5127N/A+extern int b_cut (int, char**, Shbltin_t *);
5127N/A+extern int b_date (int, char**, Shbltin_t *);
5127N/A+extern int b_dirname (int, char**, Shbltin_t *);
5127N/A+extern int b_egrep (int, char**, Shbltin_t *);
5127N/A+extern int b_expr (int, char**, Shbltin_t *);
5127N/A+extern int b_fds (int, char**, Shbltin_t *);
5127N/A+extern int b_fgrep (int, char**, Shbltin_t *);
5127N/A+extern int b_find (int, char**, Shbltin_t *);
5127N/A+extern int b_fmt (int, char**, Shbltin_t *);
5127N/A+extern int b_fold (int, char**, Shbltin_t *);
5127N/A+extern int b_getconf (int, char**, Shbltin_t *);
5127N/A+extern int b_grep (int, char**, Shbltin_t *);
5127N/A+extern int b_head (int, char**, Shbltin_t *);
5127N/A+extern int b_id (int, char**, Shbltin_t *);
5127N/A+extern int b_join (int, char**, Shbltin_t *);
5127N/A+extern int b_line (int, char**, Shbltin_t *);
5127N/A+extern int b_ln (int, char**, Shbltin_t *);
5127N/A+extern int b_logname (int, char**, Shbltin_t *);
5127N/A+extern int b_ls (int, char**, Shbltin_t *);
5127N/A+extern int b_md5sum (int, char**, Shbltin_t *);
5127N/A+extern int b_mkdir (int, char**, Shbltin_t *);
5127N/A+extern int b_mkfifo (int, char**, Shbltin_t *);
5127N/A+extern int b_mktemp (int, char**, Shbltin_t *);
5127N/A+extern int b_mv (int, char**, Shbltin_t *);
5127N/A+extern int b_paste (int, char**, Shbltin_t *);
5127N/A+extern int b_od (int, char**, Shbltin_t *);
5127N/A+extern int b_pathchk (int, char**, Shbltin_t *);
5127N/A+extern int b_pids (int, char**, Shbltin_t *);
5127N/A+extern int b_pr (int, char**, Shbltin_t *);
5127N/A+extern int b_rev (int, char**, Shbltin_t *);
5127N/A+extern int b_readlink (int, char**, Shbltin_t *);
5127N/A+extern int b_rm (int, char**, Shbltin_t *);
5127N/A+extern int b_rmdir (int, char**, Shbltin_t *);
5127N/A+extern int b_stty (int, char**, Shbltin_t *);
5127N/A+extern int b_sum (int, char**, Shbltin_t *);
5127N/A+extern int b_sync (int, char**, Shbltin_t *);
5127N/A+extern int b_strings (int, char**, Shbltin_t *);
5127N/A+extern int b_tail (int, char**, Shbltin_t *);
5127N/A+extern int b_tee (int, char**, Shbltin_t *);
5127N/A+extern int b_tr (int, char**, Shbltin_t *);
5127N/A+extern int b_tty (int, char**, Shbltin_t *);
5127N/A+extern int b_uname (int, char**, Shbltin_t *);
5127N/A+extern int b_uniq (int, char**, Shbltin_t *);
5127N/A+extern int b_vmstate (int, char**, Shbltin_t *);
5127N/A+extern int b_wc (int, char**, Shbltin_t *);
5127N/A+extern int b_who (int, char**, Shbltin_t *);
5127N/A+extern int b_xgrep (int, char**, Shbltin_t *);
5127N/A+extern int b_xargs (int, char**, Shbltin_t *);