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
5127N/A# to implement the /usr/bin/alias Solaris functionality.
830N/Adiff -rupN b/lib/package/ast-base.pkg a/lib/package/ast-base.pkg
830N/A--- b/lib/package/ast-base.pkg 2009-09-21 20:35:51.000000000 +0000
830N/A+++ a/lib/package/ast-base.pkg 2011-11-10 16:24:52.515495613 +0000
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
830N/A :COVERS: ast-make ast-ksh ast-ast
830N/A
830N/Adiff -rupN b/src/cmd/alias/alias.c a/src/cmd/alias/alias.c
830N/A--- b/src/cmd/alias/alias.c 1970-01-01 00:00:00.000000000 +0000
830N/A+++ a/src/cmd/alias/alias.c 2011-11-10 16:24:28.356925339 +0000
5127N/A@@ -0,0 +1,256 @@
830N/A+/*
830N/A+ * CDDL HEADER START
830N/A+ *
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+ *
830N/A+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
830N/A+ * or http://www.opensolaris.org/os/licensing.
830N/A+ * See the License for the specific language governing permissions
830N/A+ * and limitations under the License.
830N/A+ *
830N/A+ * When distributing Covered Code, include this CDDL HEADER in each
830N/A+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
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]
830N/A+ *
830N/A+ * CDDL HEADER END
830N/A+ */
830N/A+
830N/A+/*
5127N/A+ * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
830N/A+ */
830N/A+
830N/A+/*
830N/A+ * alias.c is a C version of the alias.sh wrapper (which links ksh
830N/A+ * builtins to commands in /usr/bin/, e.g. calling this wrapper as
830N/A+ * /usr/bin/alias will call the ksh "alias" builtin, running it as
830N/A+ * /usr/bin/cut will call the ksh "cut" builtin etc.
830N/A+ */
830N/A+
830N/A+#include <shell.h>
830N/A+#include <nval.h>
830N/A+#include <stdio.h>
830N/A+#include <alias.h>
830N/A+
830N/A+typedef struct {
830N/A+ const char *name;
5127N/A+ int (* func)(int, char **, Shbltin_t *);
830N/A+} bfastpathrec;
830N/A+
830N/A+/*
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+ * ON PerfPIT for testing). For /usr/bin/rev (where the issue was
830N/A+ * first discovered) it looks like this:
830N/A+ * - for small files like /etc/profile the fastpath is faster in a loop
830N/A+ * with 1000 iterations (8 seconds with fastpath, 14 seconds without
830N/A+ * fastpath)
830N/A+ * - for large files (/usr/pub/UTF-8 replicated until the test file
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+ * iterations).
830N/A+ */
830N/A+#if 0
830N/A+#define ENABLE_PERFORMANCE_PARADOXON 1
830N/A+#endif
830N/A+
830N/A+/*
830N/A+ * List of libcmd builtins which do not require a |Shell_t| context.
830N/A+ * This list was automatically generated from <ast/cmdext.h>
830N/A+ */
830N/A+static const
830N/A+bfastpathrec fastpath_builtins[] =
830N/A+{
830N/A+ /* This list must be alphabetically sorted for |strcmp()| usage */
830N/A+ { "basename", b_basename },
830N/A+ { "cat", b_cat },
830N/A+ { "chgrp", b_chgrp },
830N/A+ { "chmod", b_chmod },
830N/A+ { "chown", b_chown },
830N/A+#ifdef ENABLE_PERFORMANCE_PARADOXON
830N/A+ { "cksum", b_cksum },
830N/A+#endif /* ENABLE_PERFORMANCE_PARADOXON */
830N/A+ { "cmp", b_cmp },
830N/A+ { "comm", b_comm },
830N/A+ { "cp", b_cp },
830N/A+ { "cut", b_cut },
830N/A+ { "date", b_date },
830N/A+ { "dirname", b_dirname },
830N/A+ { "expr", b_expr },
830N/A+ { "fds", b_fds },
830N/A+ { "fmt", b_fmt },
830N/A+ { "fold", b_fold },
830N/A+ { "getconf", b_getconf },
830N/A+ { "head", b_head },
830N/A+ { "id", b_id },
830N/A+ { "join", b_join },
830N/A+ { "ln", b_ln },
830N/A+ { "logname", b_logname },
830N/A+ { "md5sum", b_md5sum },
830N/A+ { "mkdir", b_mkdir },
830N/A+ { "mkfifo", b_mkfifo },
830N/A+ { "mktemp", b_mktemp },
830N/A+ { "mv", b_mv },
830N/A+ { "paste", b_paste },
830N/A+ { "pathchk", b_pathchk },
830N/A+ { "pids", b_pids },
830N/A+#ifdef ENABLE_PERFORMANCE_PARADOXON
830N/A+ { "rev", b_rev },
830N/A+#endif /* ENABLE_PERFORMANCE_PARADOXON */
830N/A+ { "rm", b_rm },
830N/A+ { "rmdir", b_rmdir },
830N/A+ { "stty", b_stty },
830N/A+#ifdef ENABLE_PERFORMANCE_PARADOXON
830N/A+ { "sum", b_sum },
830N/A+#endif /* ENABLE_PERFORMANCE_PARADOXON */
830N/A+ { "sync", b_sync },
830N/A+ { "tail", b_tail },
830N/A+ { "tee", b_tee },
830N/A+ { "tty", b_tty },
830N/A+ { "uname", b_uname },
830N/A+ { "uniq", b_uniq },
5127N/A+ { "vmstate", b_vmstate },
830N/A+ { "wc", b_wc },
5127N/A+ { NULL, (int (*)(int, char **, Shbltin_t *))NULL }
830N/A+};
830N/A+
830N/A+static inline
830N/A+const bfastpathrec *
830N/A+find_bfastpathrec(const char *name)
830N/A+{
830N/A+ unsigned int i;
830N/A+ signed int cmpres;
830N/A+ for (i = 0; fastpath_builtins[i].name != NULL; i++) {
830N/A+ cmpres = strcmp(fastpath_builtins[i].name, name);
830N/A+ if (cmpres == 0)
830N/A+ return (&fastpath_builtins[i]);
830N/A+ else if (cmpres > 0)
830N/A+ return (NULL);
830N/A+
830N/A+ }
830N/A+ return (NULL);
830N/A+}
830N/A+
830N/A+static inline
830N/A+int
830N/A+fastpath_builtin_main(const bfastpathrec *brec, int argc, char *argv[])
830N/A+{
830N/A+ setlocale(LC_ALL, ""); /* calls |_ast_setlocale()| */
830N/A+
830N/A+ return ((*brec->func)(argc, argv, NULL));
830N/A+}
830N/A+
830N/A+
830N/A+/* Builtin script, original derived from alias.sh */
830N/A+static const char *script = "\n"
830N/A+/* Get name of builtin */
830N/A+"typeset cmd=\"${0##*/}\"\n"
830N/A+/*
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+ * before /usr/bin (e.g. /usr/xpg4/bin/ls would be executed
830N/A+ * before /usr/bin/ls if the path was something like
830N/A+ * PATH=/usr/xpg4/bin:/usr/bin).
830N/A+ */
830N/A+"if [[ \"${cmd}\" != ~(Elr)(alias|unalias|command) ]] && "
830N/A+ "! alias \"${cmd}\" >/dev/null 2>&1 ; then\n"
830N/A+ "PATH='' builtin \"${cmd}\"\n"
830N/A+"fi\n"
830N/A+/* command is a keyword and needs to be handled separately */
830N/A+"if [[ \"${cmd}\" == \"command\" ]] ; then\n"
830N/A+ "command \"$@\"\n"
830N/A+"else\n"
830N/A+#ifdef WORKAROUND_FOR_ALIAS_CRASH
830N/A+/*
830N/A+ * Work around a crash in /usr/bin/alias when invalid options are
830N/A+ * passed (e.g. $ /usr/bin/alias -c #). The shell code will call
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+ */
830N/A+ "( \"${cmd}\" \"$@\" )\n"
830N/A+#else
830N/A+ "\"${cmd}\" \"$@\"\n"
830N/A+#endif /* WORKAROUND_FOR_ALIAS_CRASH */
830N/A+"fi\n"
830N/A+"exitval=$?";
830N/A+
830N/A+
830N/A+static inline
830N/A+int
830N/A+script_builtin_main(int argc, char *argv[])
830N/A+{
830N/A+ int i;
830N/A+ Shell_t *shp;
830N/A+ Namval_t *np;
830N/A+ int exitval;
830N/A+
830N/A+ /*
830N/A+ * Create copy of |argv| array shifted by one position to
830N/A+ * emulate $ /usr/bin/sh <scriptname> <args1> <arg2> ... #.
830N/A+ * First position is set to "/usr/bin/sh" since other
830N/A+ * values may trigger special shell modes (e.g. *rsh* will
830N/A+ * trigger "restricted" shell mode etc.).
830N/A+ */
830N/A+ char *xargv[argc+2];
830N/A+ xargv[0] = "/usr/bin/sh";
830N/A+ xargv[1] = "scriptname";
830N/A+ for (i = 0; i < argc; i++) {
830N/A+ xargv[i+1] = argv[i];
830N/A+ }
830N/A+ xargv[i+1] = NULL;
830N/A+
830N/A+ shp = sh_init(argc+1, xargv, 0);
830N/A+ if (!shp)
830N/A+ error(ERROR_exit(1), "shell initialisation failed.");
830N/A+ (void) sh_trap(script, 0);
830N/A+
830N/A+ np = nv_open("exitval", shp->var_tree, 0);
830N/A+ if (!np)
830N/A+ error(ERROR_exit(1), "variable %s not found.", "exitval");
830N/A+ exitval = (int)nv_getnum(np);
830N/A+ nv_close(np);
830N/A+
830N/A+ return (exitval);
830N/A+}
830N/A+
830N/A+int
830N/A+main(int argc, char *argv[])
830N/A+{
830N/A+ const char *progname;
830N/A+ const bfastpathrec *brec;
830N/A+ char execnamebuff[PATH_MAX+1];
830N/A+
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+
830N/A+ progname = (const char *)strrchr(execnamebuff, '/');
830N/A+ if (progname != NULL) {
830N/A+ progname++;
830N/A+ }
830N/A+ else
830N/A+ {
830N/A+ progname = execnamebuff;
830N/A+ }
830N/A+
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+ }
830N/A+ else
830N/A+ {
830N/A+ /* ... or from within a full shell. */
830N/A+ return (script_builtin_main(argc, argv));
830N/A+ }
830N/A+}
830N/Adiff -rupN b/src/cmd/alias/alias.h a/src/cmd/alias/alias.h
830N/A--- b/src/cmd/alias/alias.h 1970-01-01 00:00:00.000000000 +0000
830N/A+++ a/src/cmd/alias/alias.h 2011-11-10 16:24:28.357387725 +0000
5127N/A@@ -0,0 +1,67 @@
830N/A+/***********************************************************************
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+* *
830N/A+* A copy of the License is available at *
5127N/A+* http://www.eclipse.org/org/documents/epl-v10.html *
5127N/A+* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
830N/A+* *
830N/A+* Information and Software Systems Research *
830N/A+* AT&T Research *
830N/A+* Florham Park NJ *
830N/A+* *
830N/A+* David Korn <dgk@research.att.com> *
830N/A+* *
830N/A+***********************************************************************/
830N/A+
5127N/A+#include <shcmd.h>
5127N/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 *);
830N/Adiff -rupN b/src/cmd/alias/Makefile a/src/cmd/alias/Makefile
830N/A--- b/src/cmd/alias/Makefile 1970-01-01 00:00:00.000000000 +0000
830N/A+++ a/src/cmd/alias/Makefile 2011-11-10 16:24:28.357746164 +0000
830N/A@@ -0,0 +1,5 @@
830N/A+:PACKAGE: ast:static
830N/A+
830N/A+LICENSE = cddl
830N/A+libtype = :static
830N/A+alias :: RELEASE alias.c +lshell