| 1 | This file is enable.def, from which is created enable.c.
|
|---|
| 2 | It implements the builtin "enable" in Bash.
|
|---|
| 3 |
|
|---|
| 4 | Copyright (C) 1987-2003 Free Software Foundation, Inc.
|
|---|
| 5 |
|
|---|
| 6 | This file is part of GNU Bash, the Bourne Again SHell.
|
|---|
| 7 |
|
|---|
| 8 | Bash is free software; you can redistribute it and/or modify it under
|
|---|
| 9 | the terms of the GNU General Public License as published by the Free
|
|---|
| 10 | Software Foundation; either version 2, or (at your option) any later
|
|---|
| 11 | version.
|
|---|
| 12 |
|
|---|
| 13 | Bash is distributed in the hope that it will be useful, but WITHOUT ANY
|
|---|
| 14 | WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|---|
| 15 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|---|
| 16 | for more details.
|
|---|
| 17 |
|
|---|
| 18 | You should have received a copy of the GNU General Public License along
|
|---|
| 19 | with Bash; see the file COPYING. If not, write to the Free Software
|
|---|
| 20 | Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
|---|
| 21 |
|
|---|
| 22 | $PRODUCES enable.c
|
|---|
| 23 |
|
|---|
| 24 | $BUILTIN enable
|
|---|
| 25 | $FUNCTION enable_builtin
|
|---|
| 26 | $SHORT_DOC enable [-pnds] [-a] [-f filename] [name ...]
|
|---|
| 27 | Enable and disable builtin shell commands. This allows
|
|---|
| 28 | you to use a disk command which has the same name as a shell
|
|---|
| 29 | builtin without specifying a full pathname. If -n is used, the
|
|---|
| 30 | NAMEs become disabled; otherwise NAMEs are enabled. For example,
|
|---|
| 31 | to use the `test' found in $PATH instead of the shell builtin
|
|---|
| 32 | version, type `enable -n test'. On systems supporting dynamic
|
|---|
| 33 | loading, the -f option may be used to load new builtins from the
|
|---|
| 34 | shared object FILENAME. The -d option will delete a builtin
|
|---|
| 35 | previously loaded with -f. If no non-option names are given, or
|
|---|
| 36 | the -p option is supplied, a list of builtins is printed. The
|
|---|
| 37 | -a option means to print every builtin with an indication of whether
|
|---|
| 38 | or not it is enabled. The -s option restricts the output to the POSIX.2
|
|---|
| 39 | `special' builtins. The -n option displays a list of all disabled builtins.
|
|---|
| 40 | $END
|
|---|
| 41 |
|
|---|
| 42 | #include <config.h>
|
|---|
| 43 |
|
|---|
| 44 | #if defined (HAVE_UNISTD_H)
|
|---|
| 45 | # ifdef _MINIX
|
|---|
| 46 | # include <sys/types.h>
|
|---|
| 47 | # endif
|
|---|
| 48 | # include <unistd.h>
|
|---|
| 49 | #endif
|
|---|
| 50 |
|
|---|
| 51 | #include <stdio.h>
|
|---|
| 52 | #include "../bashansi.h"
|
|---|
| 53 | #include "../bashintl.h"
|
|---|
| 54 |
|
|---|
| 55 | #include "../shell.h"
|
|---|
| 56 | #include "../builtins.h"
|
|---|
| 57 | #include "../flags.h"
|
|---|
| 58 | #include "common.h"
|
|---|
| 59 | #include "bashgetopt.h"
|
|---|
| 60 |
|
|---|
| 61 | #if defined (PROGRAMMABLE_COMPLETION)
|
|---|
| 62 | # include "../pcomplete.h"
|
|---|
| 63 | #endif
|
|---|
| 64 |
|
|---|
| 65 | #define ENABLED 1
|
|---|
| 66 | #define DISABLED 2
|
|---|
| 67 | #define SPECIAL 4
|
|---|
| 68 |
|
|---|
| 69 | #define AFLAG 0x01
|
|---|
| 70 | #define DFLAG 0x02
|
|---|
| 71 | #define FFLAG 0x04
|
|---|
| 72 | #define NFLAG 0x08
|
|---|
| 73 | #define PFLAG 0x10
|
|---|
| 74 | #define SFLAG 0x20
|
|---|
| 75 |
|
|---|
| 76 | #if defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)
|
|---|
| 77 | static int dyn_load_builtin __P((WORD_LIST *, int, char *));
|
|---|
| 78 | #endif
|
|---|
| 79 |
|
|---|
| 80 | #if defined (HAVE_DLCLOSE)
|
|---|
| 81 | static int dyn_unload_builtin __P((char *));
|
|---|
| 82 | static void delete_builtin __P((struct builtin *));
|
|---|
| 83 | static int local_dlclose __P((void *));
|
|---|
| 84 | #endif
|
|---|
| 85 |
|
|---|
| 86 | static void list_some_builtins __P((int));
|
|---|
| 87 | static int enable_shell_command __P((char *, int));
|
|---|
| 88 |
|
|---|
| 89 | /* Enable/disable shell commands present in LIST. If list is not specified,
|
|---|
| 90 | then print out a list of shell commands showing which are enabled and
|
|---|
| 91 | which are disabled. */
|
|---|
| 92 | int
|
|---|
| 93 | enable_builtin (list)
|
|---|
| 94 | WORD_LIST *list;
|
|---|
| 95 | {
|
|---|
| 96 | int result, flags;
|
|---|
| 97 | int opt, filter;
|
|---|
| 98 | #if defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)
|
|---|
| 99 | char *filename;
|
|---|
| 100 | #endif
|
|---|
| 101 |
|
|---|
| 102 | result = EXECUTION_SUCCESS;
|
|---|
| 103 | flags = 0;
|
|---|
| 104 |
|
|---|
| 105 | reset_internal_getopt ();
|
|---|
| 106 | while ((opt = internal_getopt (list, "adnpsf:")) != -1)
|
|---|
| 107 | {
|
|---|
| 108 | switch (opt)
|
|---|
| 109 | {
|
|---|
| 110 | case 'a':
|
|---|
| 111 | flags |= AFLAG;
|
|---|
| 112 | break;
|
|---|
| 113 | case 'n':
|
|---|
| 114 | flags |= NFLAG;
|
|---|
| 115 | break;
|
|---|
| 116 | case 'p':
|
|---|
| 117 | flags |= PFLAG;
|
|---|
| 118 | break;
|
|---|
| 119 | case 's':
|
|---|
| 120 | flags |= SFLAG;
|
|---|
| 121 | break;
|
|---|
| 122 | case 'f':
|
|---|
| 123 | #if defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)
|
|---|
| 124 | flags |= FFLAG;
|
|---|
| 125 | filename = list_optarg;
|
|---|
| 126 | break;
|
|---|
| 127 | #else
|
|---|
| 128 | builtin_error (_("dynamic loading not available"));
|
|---|
| 129 | return (EX_USAGE);
|
|---|
| 130 | #endif
|
|---|
| 131 | #if defined (HAVE_DLCLOSE)
|
|---|
| 132 | case 'd':
|
|---|
| 133 | flags |= DFLAG;
|
|---|
| 134 | break;
|
|---|
| 135 | #else
|
|---|
| 136 | builtin_error (_("dynamic loading not available"));
|
|---|
| 137 | return (EX_USAGE);
|
|---|
| 138 | #endif /* HAVE_DLCLOSE */
|
|---|
| 139 | default:
|
|---|
| 140 | builtin_usage ();
|
|---|
| 141 | return (EX_USAGE);
|
|---|
| 142 | }
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | list = loptend;
|
|---|
| 146 |
|
|---|
| 147 | #if defined (RESTRICTED_SHELL)
|
|---|
| 148 | /* Restricted shells cannot load new builtins. */
|
|---|
| 149 | if (restricted && (flags & (FFLAG|DFLAG)))
|
|---|
| 150 | {
|
|---|
| 151 | sh_restricted ((char *)NULL);
|
|---|
| 152 | return (EXECUTION_FAILURE);
|
|---|
| 153 | }
|
|---|
| 154 | #endif
|
|---|
| 155 |
|
|---|
| 156 | if (list == 0 || (flags & PFLAG))
|
|---|
| 157 | {
|
|---|
| 158 | filter = (flags & AFLAG) ? (ENABLED | DISABLED)
|
|---|
| 159 | : (flags & NFLAG) ? DISABLED : ENABLED;
|
|---|
| 160 |
|
|---|
|
|---|