mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-07-05 19:30:49 +02:00
Bash-4.4 distribution sources and documentation
This commit is contained in:
@@ -0,0 +1,160 @@
|
||||
#!/bin/bash
|
||||
# @(#) dirstack
|
||||
|
||||
###
|
||||
# Another implementation of the directory manipulation functions
|
||||
# published in the Bolsky & Korn book : "The new Korn shell" :
|
||||
# cd, to change current directory
|
||||
# d, to display the stack content
|
||||
# Eric Sanchis (eric.sanchis@iut-rodez.fr), 2012
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
###
|
||||
|
||||
|
||||
shopt -s expand_aliases
|
||||
shopt -s extglob
|
||||
shopt -s cdable_vars
|
||||
|
||||
alias integer='declare -i'
|
||||
|
||||
integer MAX=32
|
||||
integer INDMAX=MAX-1
|
||||
integer INDTOP=0
|
||||
|
||||
unalias cd 2>/dev/null
|
||||
alias cd=cdir
|
||||
|
||||
unset tab
|
||||
tab[INDTOP]="$(pwd)"
|
||||
|
||||
|
||||
function cdir
|
||||
{
|
||||
local -i ind
|
||||
local dir
|
||||
|
||||
dir="${1:-$HOME}"
|
||||
case "$dir" in
|
||||
- ) # cd - => equivalent to : cd -1
|
||||
ind=INDTOP-1
|
||||
cd_by_number $ind
|
||||
;;
|
||||
-+([[:digit:]]) ) # cd -n
|
||||
ind=$INDTOP-${dir#-}
|
||||
cd_by_number $ind
|
||||
;;
|
||||
*) # cd ~ or cd dir_name
|
||||
cd_by_name "$dir"
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
function cd_by_number
|
||||
{
|
||||
local -i k=$1
|
||||
local -i j
|
||||
local dirtmp
|
||||
|
||||
if (( k < 0 ))
|
||||
then
|
||||
echo Impossible to change directory >&2
|
||||
return 1
|
||||
else
|
||||
dirtmp="${tab[k]}"
|
||||
j=k+1
|
||||
while (( j <= INDTOP ))
|
||||
do
|
||||
tab[j-1]="${tab[j]}"
|
||||
j=j+1
|
||||
done
|
||||
tab[INDTOP]="$dirtmp"
|
||||
\cd "${tab[INDTOP]}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
function cd_by_name
|
||||
{
|
||||
local -i i
|
||||
local rep
|
||||
|
||||
rep=$( \cd "$1" &>/dev/null && pwd)
|
||||
if [[ -z "$rep" ]]
|
||||
then
|
||||
echo cd : "$1" unknown >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
i=$INDTOP
|
||||
while (( i >= 0 ))
|
||||
do
|
||||
if [[ "${tab[i]}" == "$rep" ]]
|
||||
then break
|
||||
fi
|
||||
i=i-1
|
||||
done
|
||||
|
||||
if (( i == INDTOP ))
|
||||
then # cd -0 => we do nothing !
|
||||
return 0
|
||||
elif (( i == -1 ))
|
||||
then # the directory isn't in the stack
|
||||
if (( INDTOP == INDMAX ))
|
||||
then # the stack is FULL
|
||||
# the oldest directory is removed
|
||||
local -i m
|
||||
|
||||
m=1
|
||||
while (( m <= INDMAX ))
|
||||
do
|
||||
tab[m-1]="${tab[m]}"
|
||||
m=m+1
|
||||
done
|
||||
else # the new directory is added to the top of the stack
|
||||
INDTOP=INDTOP+1
|
||||
fi
|
||||
tab[INDTOP]="$rep"
|
||||
\cd "${tab[INDTOP]}"
|
||||
return 0
|
||||
|
||||
else # the directory is already in the stack
|
||||
# $i gives its index
|
||||
cd_by_number $i
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
function d # display the directory stack
|
||||
{
|
||||
local -i i
|
||||
local rep
|
||||
|
||||
i=0
|
||||
while (( $i <= $INDTOP ))
|
||||
do
|
||||
rep="${tab[INDTOP-i]#$HOME/}"
|
||||
case "$rep" in
|
||||
$HOME) rep="~" ;;
|
||||
/* ) : ;;
|
||||
* ) rep="~/$rep"
|
||||
esac
|
||||
|
||||
echo "$i ) $rep"
|
||||
i=i+1
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#
|
||||
# Simple makefile for the sample loadable builtins
|
||||
#
|
||||
# Copyright (C) 1996-2009 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1996-2015 Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -17,6 +17,9 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
PACKAGE = @PACKAGE_NAME@
|
||||
VERSION = @PACKAGE_VERSION@
|
||||
|
||||
# Include some boilerplate Gnu makefile definitions.
|
||||
prefix = @prefix@
|
||||
|
||||
@@ -28,10 +31,22 @@ includedir = @includedir@
|
||||
|
||||
datarootdir = @datarootdir@
|
||||
|
||||
loadablesdir = @loadablesdir@
|
||||
headersdir = @headersdir@
|
||||
|
||||
topdir = @top_srcdir@
|
||||
BUILD_DIR = @BUILD_DIR@
|
||||
srcdir = @srcdir@
|
||||
VPATH = .:@srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
# Support an alternate destination root directory for package building
|
||||
DESTDIR =
|
||||
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALLMODE= -m 0755
|
||||
|
||||
@SET_MAKE@
|
||||
CC = @CC@
|
||||
@@ -52,6 +67,8 @@ CPPFLAGS = @CPPFLAGS@
|
||||
|
||||
BASHINCDIR = ${topdir}/include
|
||||
|
||||
SUPPORT_SRC = $(topdir)/support/
|
||||
|
||||
LIBBUILD = ${BUILD_DIR}/lib
|
||||
|
||||
INTL_LIBSRC = ${topdir}/lib/intl
|
||||
@@ -75,7 +92,7 @@ SHOBJ_XLDFLAGS = @SHOBJ_XLDFLAGS@
|
||||
SHOBJ_LIBS = @SHOBJ_LIBS@
|
||||
SHOBJ_STATUS = @SHOBJ_STATUS@
|
||||
|
||||
INC = -I. -I.. -I$(topdir) -I$(topdir)/lib -I$(topdir)/builtins \
|
||||
INC = -I. -I.. -I$(topdir) -I$(topdir)/lib -I$(topdir)/builtins -I${srcdir} \
|
||||
-I$(BASHINCDIR) -I$(BUILD_DIR) -I$(LIBBUILD) \
|
||||
-I$(BUILD_DIR)/builtins $(INTL_INC)
|
||||
|
||||
@@ -83,10 +100,10 @@ INC = -I. -I.. -I$(topdir) -I$(topdir)/lib -I$(topdir)/builtins \
|
||||
$(SHOBJ_CC) $(SHOBJ_CFLAGS) $(CCFLAGS) $(INC) -c -o $@ $<
|
||||
|
||||
|
||||
ALLPROG = print truefalse sleep pushd finfo logname basename dirname \
|
||||
ALLPROG = print truefalse sleep finfo logname basename dirname \
|
||||
tty pathchk tee head mkdir rmdir printenv id whoami \
|
||||
uname sync push ln unlink realpath strftime mypid
|
||||
OTHERPROG = necho hello cat
|
||||
uname sync push ln unlink realpath strftime mypid setpgid
|
||||
OTHERPROG = necho hello cat pushd
|
||||
|
||||
all: $(SHOBJ_STATUS)
|
||||
|
||||
@@ -98,7 +115,7 @@ unsupported:
|
||||
@echo "${topdir}/support/shobj-conf script."
|
||||
@echo "If your operating system provides facilities for dynamic"
|
||||
@echo "loading of shared objects using the dlopen(3) interface,"
|
||||
@echo "please update the script and re-run configure.
|
||||
@echo "please update the script and re-run configure."
|
||||
@echo "Please send the changes you made to bash-maintainers@gnu.org"
|
||||
@echo "for inclusion in future bash releases."
|
||||
|
||||
@@ -185,6 +202,10 @@ strftime: strftime.o
|
||||
mypid: mypid.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ mypid.o $(SHOBJ_LIBS)
|
||||
|
||||
|
||||
setpgid: setpgid.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ setpgid.o $(SHOBJ_LIBS)
|
||||
|
||||
# pushd is a special case. We use the same source that the builtin version
|
||||
# uses, with special compilation options.
|
||||
#
|
||||
@@ -207,9 +228,36 @@ mostlyclean: clean
|
||||
-( cd perl && ${MAKE} ${MFLAGS} $@ )
|
||||
|
||||
distclean maintainer-clean: clean
|
||||
$(RM) Makefile pushd.c
|
||||
$(RM) Makefile Makefile.inc pushd.c
|
||||
-( cd perl && ${MAKE} ${MFLAGS} $@ )
|
||||
|
||||
installdirs:
|
||||
@${SHELL} $(SUPPORT_SRC)mkinstalldirs $(DESTDIR)$(loadablesdir)
|
||||
|
||||
install-dev: installdirs
|
||||
@$(INSTALL_DATA) Makefile.inc $(DESTDIR)$(loadablesdir)/Makefile.inc
|
||||
@( cd $(BUILD_DIR) && ${MAKE} ${MFLAGS} DESTDIR="$(DESTDIR)" install-headers)
|
||||
|
||||
install-supported: all installdirs install-dev
|
||||
@echo installing example loadable builtins in $(DESTDIR)${loadablesdir}
|
||||
@for prog in ${ALLPROG}; do \
|
||||
echo $$prog ; \
|
||||
$(INSTALL_PROGRAM) $(INSTALLMODE) $$prog $(DESTDIR)$(loadablesdir)/$$prog ;\
|
||||
done
|
||||
|
||||
uninstall-dev:
|
||||
-$(RM) $(DESTDIR)$(loadablesdir)/Makefile.inc
|
||||
-( cd $(BUILD_DIR) && ${MAKE} ${MFLAGS} DESTDIR="$(DESTDIR)" uninstall-headers)
|
||||
|
||||
uninstall-supported: uninstall-dev
|
||||
-( cd $(DESTDIR)${loadablesdir} && $(RM) ${ALLPROG} )
|
||||
|
||||
install-unsupported:
|
||||
uninstall-unsupported:
|
||||
|
||||
install: install-$(SHOBJ_STATUS)
|
||||
uninstall: uninstall-$(SHOBJ_STATUS)
|
||||
|
||||
print.o: print.c
|
||||
truefalse.o: truefalse.c
|
||||
sleep.o: sleep.c
|
||||
@@ -234,4 +282,4 @@ push.o: push.c
|
||||
mkdir.o: mkdir.c
|
||||
realpath.o: realpath.c
|
||||
strftime.o: strftime.c
|
||||
mypid.o: mypid.c
|
||||
setpgid.o: setpgid.c
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
#
|
||||
# Sample makefile for bash loadable builtin development
|
||||
#
|
||||
# Copyright (C) 2015 Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
PACKAGE = @PACKAGE_NAME@
|
||||
VERSION = @PACKAGE_VERSION@
|
||||
|
||||
PACKAGE_NAME = @PACKAGE_NAME@
|
||||
PACKAGE_VERSION = @PACKAGE_VERSION@
|
||||
|
||||
# Include some boilerplate Gnu makefile definitions.
|
||||
prefix = @prefix@
|
||||
|
||||
exec_prefix = @exec_prefix@
|
||||
bindir = @bindir@
|
||||
libdir = @libdir@
|
||||
infodir = @infodir@
|
||||
includedir = @includedir@
|
||||
|
||||
datarootdir = @datarootdir@
|
||||
|
||||
loadablesdir = @loadablesdir@
|
||||
headersdir = @headersdir@
|
||||
|
||||
topdir = @top_srcdir@
|
||||
BUILD_DIR = @BUILD_DIR@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
# Support an alternate destination root directory for package building
|
||||
DESTDIR =
|
||||
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALLMODE= -m 0755
|
||||
|
||||
@SET_MAKE@
|
||||
CC = @CC@
|
||||
RM = rm -f
|
||||
|
||||
SHELL = @MAKE_SHELL@
|
||||
|
||||
host_os = @host_os@
|
||||
host_cpu = @host_cpu@
|
||||
host_vendor = @host_vendor@
|
||||
|
||||
CFLAGS = @CFLAGS@
|
||||
LOCAL_CFLAGS = @LOCAL_CFLAGS@
|
||||
DEFS = @DEFS@
|
||||
LOCAL_DEFS = @LOCAL_DEFS@
|
||||
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
|
||||
BASHINCDIR = ${topdir}/include
|
||||
|
||||
SUPPORT_SRC = $(topdir)/support/
|
||||
|
||||
LIBBUILD = ${BUILD_DIR}/lib
|
||||
|
||||
INTL_LIBSRC = ${topdir}/lib/intl
|
||||
INTL_BUILDDIR = ${LIBBUILD}/intl
|
||||
INTL_INC = @INTL_INC@
|
||||
LIBINTL_H = @LIBINTL_H@
|
||||
|
||||
CCFLAGS = $(DEFS) $(LOCAL_DEFS) $(LOCAL_CFLAGS) $(CFLAGS)
|
||||
|
||||
#
|
||||
# These values are generated for configure by ${topdir}/support/shobj-conf.
|
||||
# If your system is not supported by that script, but includes facilities for
|
||||
# dynamic loading of shared objects, please update the script and send the
|
||||
# changes to bash-maintainers@gnu.org.
|
||||
#
|
||||
SHOBJ_CC = @SHOBJ_CC@
|
||||
SHOBJ_CFLAGS = @SHOBJ_CFLAGS@
|
||||
SHOBJ_LD = @SHOBJ_LD@
|
||||
SHOBJ_LDFLAGS = @SHOBJ_LDFLAGS@ @LDFLAGS@
|
||||
SHOBJ_XLDFLAGS = @SHOBJ_XLDFLAGS@
|
||||
SHOBJ_LIBS = @SHOBJ_LIBS@
|
||||
SHOBJ_STATUS = @SHOBJ_STATUS@
|
||||
|
||||
INC = -I$(headersdir) -I$(headersdir)/include -I$(headersdir)/builtins
|
||||
|
||||
.c.o:
|
||||
$(SHOBJ_CC) $(SHOBJ_CFLAGS) $(CCFLAGS) $(INC) -c -o $@ $<
|
||||
|
||||
all: example
|
||||
|
||||
example: example.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ example.o $(SHOBJ_LIBS)
|
||||
|
||||
example.o: example.c
|
||||
@@ -34,18 +34,17 @@ new loadable builtins.
|
||||
|
||||
basename.c Return non-directory portion of pathname.
|
||||
cat.c cat(1) replacement with no options - the way cat was intended.
|
||||
cut.c cut(1) replacement.
|
||||
dirname.c Return directory portion of pathname.
|
||||
finfo.c Print file info.
|
||||
getconf.c POSIX.2 getconf utility.
|
||||
getconf.h Replacement definitions for ones the system doesn't provide.
|
||||
head.c Copy first part of files.
|
||||
hello.c Obligatory "Hello World" / sample loadable.
|
||||
id.c POSIX.2 user identity.
|
||||
ln.c Make links.
|
||||
loadables.h Start at a file loadable builtins can include for shell definitions
|
||||
logname.c Print login name of current user.
|
||||
Makefile.in Simple makefile for the sample loadable builtins.
|
||||
mkdir.c Make directories.
|
||||
mypid.c Add $MYPID variable, demonstrate use of unload hook function
|
||||
necho.c echo without options or argument interpretation.
|
||||
pathchk.c Check pathnames for validity and portability.
|
||||
print.c Loadable ksh-93 style print builtin.
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "shell.h"
|
||||
#include "common.h"
|
||||
|
||||
int
|
||||
basename_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "shell.h"
|
||||
#include "common.h"
|
||||
|
||||
int
|
||||
dirname_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "shell.h"
|
||||
#include "builtins.h"
|
||||
#include "common.h"
|
||||
#include "getopt.h"
|
||||
|
||||
#ifndef errno
|
||||
extern int errno;
|
||||
@@ -46,8 +47,10 @@ extern int errno;
|
||||
|
||||
extern char **make_builtin_argv ();
|
||||
|
||||
static void perms();
|
||||
static int printst();
|
||||
static int printsome();
|
||||
static void printmode();
|
||||
static int printfinfo();
|
||||
static int finfo_main();
|
||||
|
||||
@@ -192,7 +195,7 @@ int m;
|
||||
return (m & (S_IRWXU|S_IRWXG|S_IRWXO|S_ISUID|S_ISGID));
|
||||
}
|
||||
|
||||
static int
|
||||
static void
|
||||
perms(m)
|
||||
int m;
|
||||
{
|
||||
@@ -236,7 +239,7 @@ int m;
|
||||
printf ("u=%s,g=%s,o=%s", ubits, gbits, obits);
|
||||
}
|
||||
|
||||
static int
|
||||
static void
|
||||
printmode(mode)
|
||||
int mode;
|
||||
{
|
||||
@@ -262,7 +265,7 @@ int mode;
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static int
|
||||
static int
|
||||
printst(st)
|
||||
struct stat *st;
|
||||
{
|
||||
@@ -459,7 +462,7 @@ char **argv;
|
||||
void
|
||||
builtin_usage()
|
||||
{
|
||||
fprintf(stderr, "%s: usage: %s [-%s] [file ...]\n", prog, OPTIONS);
|
||||
fprintf(stderr, "%s: usage: %s [-%s] [file ...]\n", prog, prog, OPTIONS);
|
||||
}
|
||||
|
||||
#ifndef HAVE_STRERROR
|
||||
|
||||
@@ -88,8 +88,10 @@ file_head (fp, cnt)
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
int
|
||||
head_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
|
||||
@@ -29,9 +29,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "builtins.h"
|
||||
#include "shell.h"
|
||||
#include "bashgetopt.h"
|
||||
#include "loadables.h"
|
||||
|
||||
/* A builtin `xxx' is normally implemented with an `xxx_builtin' function.
|
||||
If you're converting a command that uses the normal Unix argc/argv
|
||||
@@ -58,6 +56,23 @@ hello_builtin (list)
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
int
|
||||
hello_builtin_load (s)
|
||||
char *s;
|
||||
{
|
||||
printf ("hello builtin loaded\n");
|
||||
fflush (stdout);
|
||||
return (1);
|
||||
}
|
||||
|
||||
void
|
||||
hello_builtin_unload (s)
|
||||
char *s;
|
||||
{
|
||||
printf ("hello builtin unloaded\n");
|
||||
fflush (stdout);
|
||||
}
|
||||
|
||||
/* An array of strings forming the `long' documentation for a builtin xxx,
|
||||
which is printed by `help xxx'. It must end with a NULL. By convention,
|
||||
the first line is a short description. */
|
||||
@@ -79,4 +94,3 @@ struct builtin hello_struct = {
|
||||
"hello", /* usage synopsis; becomes short_doc */
|
||||
0 /* reserved for internal use */
|
||||
};
|
||||
|
||||
|
||||
+12
-3
@@ -46,10 +46,12 @@ typedef int unix_link_syscall_t __P((const char *, const char *));
|
||||
|
||||
#define LN_SYMLINK 0x01
|
||||
#define LN_UNLINK 0x02
|
||||
#define LN_NOFOLLOW 0x04
|
||||
|
||||
static unix_link_syscall_t *linkfn;
|
||||
static int dolink ();
|
||||
|
||||
int
|
||||
ln_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
@@ -70,6 +72,10 @@ ln_builtin (list)
|
||||
case 's':
|
||||
flags |= LN_SYMLINK;
|
||||
break;
|
||||
case 'h':
|
||||
case 'n':
|
||||
flags |= LN_NOFOLLOW;
|
||||
break;
|
||||
default:
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
@@ -138,8 +144,10 @@ mkdirpath (dir, file)
|
||||
|
||||
#if defined (HAVE_LSTAT)
|
||||
# define LSTAT lstat
|
||||
# define LSTAT_OR_STAT_IF(c, f, b) ((c) ? lstat((f), (b)) : stat((f), (b)))
|
||||
#else
|
||||
# define LSTAT stat
|
||||
# define LSTAT_OR_STAT_IF(c, f, b) (stat((f), (b)))
|
||||
#endif
|
||||
|
||||
static int
|
||||
@@ -171,7 +179,7 @@ dolink (src, dst, flags)
|
||||
/* If the destination is a directory, create the final filename by appending
|
||||
the basename of the source to the destination. */
|
||||
dst_path = 0;
|
||||
if ((stat (dst, &dsb) == 0) && S_ISDIR (dsb.st_mode))
|
||||
if ((LSTAT_OR_STAT_IF((flags & LN_NOFOLLOW), dst, &dsb) == 0) && S_ISDIR (dsb.st_mode))
|
||||
{
|
||||
if ((p = strrchr (src, '/')) == 0)
|
||||
p = src;
|
||||
@@ -210,7 +218,8 @@ char *ln_doc[] = {
|
||||
"Create a new directory entry with the same modes as the original",
|
||||
"file. The -f option means to unlink any existing file, permitting",
|
||||
"the link to occur. The -s option means to create a symbolic link.",
|
||||
"By default, ln makes hard links.",
|
||||
"By default, ln makes hard links. Specifying -n or its synonym -h",
|
||||
"causes ln to not resolve symlinks in the target file or directory.",
|
||||
(char *)NULL
|
||||
};
|
||||
|
||||
@@ -221,6 +230,6 @@ struct builtin ln_struct = {
|
||||
ln_builtin, /* function implementing the builtin */
|
||||
BUILTIN_ENABLED, /* initial flags for builtin */
|
||||
ln_doc, /* array of long documentation strings. */
|
||||
"ln [-fs] file1 [file2] OR ln [-fs] file ... directory", /* usage synopsis; becomes short_doc */
|
||||
"ln [-fhns] file1 [file2] OR ln [-fhns] file ... directory", /* usage synopsis; becomes short_doc */
|
||||
0 /* reserved for internal use */
|
||||
};
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/* loadables.h -- Include files needed by all loadable builtins */
|
||||
|
||||
/* Copyright (C) 2015 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne Again SHell.
|
||||
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Bash is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Bash. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __LOADABLES_H_
|
||||
#define __LOADABLES_H_
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "builtins.h"
|
||||
#include "shell.h"
|
||||
#include "bashgetopt.h"
|
||||
#include "common.h"
|
||||
|
||||
#endif
|
||||
@@ -35,6 +35,7 @@
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
int
|
||||
logname_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
|
||||
@@ -52,7 +52,7 @@ int
|
||||
mkdir_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
int opt, pflag, omode, rval, octal, nmode, parent_mode, um;
|
||||
int opt, pflag, omode, rval, nmode, parent_mode;
|
||||
char *mode;
|
||||
WORD_LIST *l;
|
||||
|
||||
@@ -90,7 +90,6 @@ mkdir_builtin (list)
|
||||
builtin_error ("invalid file mode: %s", mode);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
octal = 1;
|
||||
}
|
||||
else if (mode)
|
||||
{
|
||||
@@ -101,7 +100,6 @@ mkdir_builtin (list)
|
||||
builtin_error ("invalid file mode: %s", mode);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
octal = 0;
|
||||
}
|
||||
|
||||
/* Make the new mode */
|
||||
|
||||
@@ -5,7 +5,13 @@
|
||||
* Then, from within bash, enable -f ./mypid enable_mypid, where ./mypid
|
||||
* is the binary obtained from running make. Hereafter, `${MYPID}'
|
||||
* is a shell builtin variable.
|
||||
*
|
||||
* This defines an unload hook function that is called when the builtin is
|
||||
* deleted with enable -d that will unbind the MYPID variable so future
|
||||
* references to it do not attempt to access memory that is no longer part
|
||||
* of this process's address space.
|
||||
*/
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
@@ -17,8 +23,11 @@
|
||||
#define INIT_DYNAMIC_VAR(var, val, gfunc, afunc) \
|
||||
do \
|
||||
{ SHELL_VAR *v = bind_variable (var, (val), 0); \
|
||||
v->dynamic_value = gfunc; \
|
||||
v->assign_func = afunc; \
|
||||
if (v) \
|
||||
{ \
|
||||
v->dynamic_value = gfunc; \
|
||||
v->assign_func = afunc; \
|
||||
} \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
@@ -56,6 +65,12 @@ enable_mypid_builtin(WORD_LIST *list)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
enable_mypid_builtin_unload (char *s)
|
||||
{
|
||||
unbind_variable ("MYPID");
|
||||
}
|
||||
|
||||
char const *enable_mypid_doc[] = {
|
||||
"Enable $MYPID.",
|
||||
"",
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "builtins.h"
|
||||
#include "shell.h"
|
||||
|
||||
int
|
||||
necho_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
|
||||
@@ -98,6 +98,7 @@ extern char *strerror ();
|
||||
|
||||
static int validate_path ();
|
||||
|
||||
int
|
||||
pathchk_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
@@ -323,7 +324,7 @@ validate_path (path, portability)
|
||||
if (!last_elem)
|
||||
{
|
||||
exists = dir_ok (path);
|
||||
if (dir_ok == 0)
|
||||
if (exists == 0)
|
||||
{
|
||||
free (parent);
|
||||
return 1;
|
||||
@@ -370,8 +371,8 @@ validate_path (path, portability)
|
||||
free (parent);
|
||||
if (strlen (path) > path_max)
|
||||
{
|
||||
builtin_error ("path `%s' has length %d; exceeds limit of %d",
|
||||
path, strlen (path), path_max);
|
||||
builtin_error ("path `%s' has length %lu; exceeds limit of %d",
|
||||
path, (unsigned long)strlen (path), path_max);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ datarootdir = @datarootdir@
|
||||
topdir = @top_srcdir@
|
||||
BUILD_DIR = @BUILD_DIR@
|
||||
srcdir = @srcdir@
|
||||
VPATH = .:@srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
@SET_MAKE@
|
||||
CC = @CC@
|
||||
|
||||
@@ -60,6 +60,7 @@ extern int errno;
|
||||
|
||||
extern char *sh_realpath();
|
||||
|
||||
int
|
||||
realpath_builtin(list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
int
|
||||
rmdir_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
/* setpgid.c: bash loadable wrapper for setpgid system call
|
||||
|
||||
An example of how to wrap a system call with a loadable builtin.
|
||||
|
||||
Originally contributed by Jason Vas Dias <jason.vas.dias@gmail.com>
|
||||
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Bash is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Bash. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if defined (HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "bashtypes.h"
|
||||
#include "posixtime.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "builtins.h"
|
||||
#include "shell.h"
|
||||
#include "common.h"
|
||||
|
||||
#include "bashgetopt.h"
|
||||
|
||||
#if !defined (_POSIX_VERSION)
|
||||
# define setpgid(pid, pgrp) setpgrp (pid, pgrp)
|
||||
#endif
|
||||
|
||||
int
|
||||
setpgid_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
register WORD_LIST *wl;
|
||||
intmax_t pid_arg, pgid_arg;
|
||||
pid_t pid, pgid;
|
||||
char *pidstr, *pgidstr;
|
||||
|
||||
wl = list;
|
||||
pid = pgid = 0;
|
||||
|
||||
if (wl == 0 || wl->next == 0)
|
||||
{
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
|
||||
pidstr = wl->word ? wl->word->word : 0;
|
||||
pgidstr = wl->next->word ? wl->next->word->word : 0;
|
||||
|
||||
if (pidstr == 0 || pgidstr == 0)
|
||||
{
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
|
||||
if (legal_number (pidstr, &pid_arg) == 0)
|
||||
{
|
||||
builtin_error ("%s: pid argument must be numeric", pidstr);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
if (pid_arg < 0)
|
||||
{
|
||||
builtin_error("%s: negative pid values not allowed", pidstr);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
pid = pid_arg;
|
||||
|
||||
if (legal_number (pgidstr, &pgid_arg) == 0)
|
||||
{
|
||||
builtin_error ("%s: pgrp argument must be numeric", pgidstr);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
if (pgid_arg < 0)
|
||||
{
|
||||
builtin_error ("%s: negative pgrp values not allowed", pgidstr);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
pgid = pgid_arg;
|
||||
|
||||
errno = 0;
|
||||
if (setpgid(pid, pgid) < 0)
|
||||
{
|
||||
builtin_error("setpgid failed: %s", strerror (errno));
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
const char *setpgid_doc[] = {
|
||||
"invoke the setpgid(2) system call",
|
||||
"",
|
||||
"Arguments:",
|
||||
" pid : numeric process identifer, >= 0",
|
||||
" pgrpid: numeric process group identifier, >=0",
|
||||
"See the setpgid(2) manual page.",
|
||||
(const char *)NULL
|
||||
};
|
||||
|
||||
struct builtin setpgid_struct = {
|
||||
"setpgid",
|
||||
setpgid_builtin,
|
||||
BUILTIN_ENABLED,
|
||||
(char **)setpgid_doc,
|
||||
"setpgid pid pgrpid",
|
||||
0
|
||||
};
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "shell.h"
|
||||
#include "bashgetopt.h"
|
||||
|
||||
int
|
||||
sync_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
|
||||
@@ -60,6 +60,7 @@ extern int interrupt_immediately;
|
||||
|
||||
extern char *strerror ();
|
||||
|
||||
int
|
||||
tee_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
|
||||
@@ -11,9 +11,7 @@
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "builtins.h"
|
||||
#include "shell.h"
|
||||
#include "bashgetopt.h"
|
||||
#include "loadables.h"
|
||||
|
||||
#if !defined (errno)
|
||||
extern int errno;
|
||||
@@ -21,6 +19,7 @@ extern int errno;
|
||||
|
||||
extern char *strerror ();
|
||||
|
||||
int
|
||||
template_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
@@ -42,6 +41,22 @@ template_builtin (list)
|
||||
return (rval);
|
||||
}
|
||||
|
||||
/* Called when `template' is enabled and loaded from the shared object. If this
|
||||
function returns 0, the load fails. */
|
||||
int
|
||||
template_builtin_load (name)
|
||||
char *name;
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Called when `template' is disabled. */
|
||||
void
|
||||
template_builtin_unload (name)
|
||||
char *name;
|
||||
{
|
||||
}
|
||||
|
||||
char *template_doc[] = {
|
||||
"Short description.",
|
||||
""
|
||||
|
||||
@@ -25,12 +25,14 @@
|
||||
#include "builtins.h"
|
||||
#include "common.h"
|
||||
|
||||
int
|
||||
true_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
return EXECUTION_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
false_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
extern char *ttyname ();
|
||||
|
||||
int
|
||||
tty_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
|
||||
@@ -63,6 +63,7 @@ static void uprint();
|
||||
|
||||
static int uname_flags;
|
||||
|
||||
int
|
||||
uname_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
int
|
||||
unlink_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "bashgetopt.h"
|
||||
#include "common.h"
|
||||
|
||||
int
|
||||
whoami_builtin (list)
|
||||
WORD_LIST *list;
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user