commit bash-20140124 snapshot

This commit is contained in:
Chet Ramey
2014-02-04 09:33:06 -05:00
parent 4a2c75c650
commit c61bfbfd13
96 changed files with 12481 additions and 4060 deletions
+9 -1
View File
@@ -59,6 +59,14 @@
#include "../builtins.h"
#include "tmpbuiltins.h"
#if defined (USING_BASH_MALLOC)
#undef xmalloc
#undef xrealloc
#undef xfree
#undef free /* defined in xmalloc.h */
#endif
#ifndef errno
extern int errno;
#endif
@@ -90,7 +98,7 @@ char *helpfile_directory;
/* Forward declarations. */
int write_helpfiles ();
int write_helpfiles __P((struct builtin *));
/* For each file mentioned on the command line, process it and
write the information to STRUCTFILE and EXTERNFILE, while
+192
View File
@@ -0,0 +1,192 @@
/* gen-helpfiles - create files containing builtin help text */
/* Copyright (C) 2012 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/>.
*/
/* This links with a specially-generated version of builtins.c and takes
the long_doc members of each struct builtin element and writes those to
the file named by the `handle' member of the struct builtin element. */
#if !defined (CROSS_COMPILING)
# include <config.h>
#else /* CROSS_COMPILING */
/* A conservative set of defines based on POSIX/SUS3/XPG6 */
# define HAVE_UNISTD_H
# define HAVE_STRING_H
# define HAVE_STDLIB_H
# define HAVE_RENAME
#endif /* CROSS_COMPILING */
#if defined (HAVE_UNISTD_H)
# ifdef _MINIX
# include <sys/types.h>
# endif
# include <unistd.h>
#endif
#ifndef _MINIX
# include "../bashtypes.h"
# if defined (HAVE_SYS_FILE_H)
# include <sys/file.h>
# endif
#endif
#include "posixstat.h"
#include "filecntl.h"
#include "../bashansi.h"
#include <stdio.h>
#include <errno.h>
#include "stdc.h"
#include "../builtins.h"
#include "tmpbuiltins.h"
#undef xmalloc
#undef xfree
#ifndef errno
extern int errno;
#endif
#if !defined (__STDC__) && !defined (strcpy)
extern char *strcpy ();
#endif /* !__STDC__ && !strcpy */
#define whitespace(c) (((c) == ' ') || ((c) == '\t'))
/* Flag values that builtins can have. */
#define BUILTIN_FLAG_SPECIAL 0x01
#define BUILTIN_FLAG_ASSIGNMENT 0x02
#define BUILTIN_FLAG_POSIX_BUILTIN 0x04
#define BASE_INDENT 4
/* Non-zero means to produce separate help files for each builtin, named by
the builtin name, in `./helpfiles'. */
int separate_helpfiles = 0;
/* Non-zero means to create single C strings for each `longdoc', with
embedded newlines, for ease of translation. */
int single_longdoc_strings = 1;
/* The name of a directory into which the separate external help files will
eventually be installed. */
char *helpfile_directory;
/* Forward declarations. */
int write_helpfiles __P((struct builtin *));
/* For each file mentioned on the command line, process it and
write the information to STRUCTFILE and EXTERNFILE, while
creating the production file if neccessary. */
int
main (argc, argv)
int argc;
char **argv;
{
int arg_index = 1;
while (arg_index < argc && argv[arg_index][0] == '-')
{
char *arg = argv[arg_index++];
if (strcmp (arg, "-noproduction") == 0)
;
else if (strcmp (arg, "-H") == 0)
helpfile_directory = argv[arg_index++];
else if (strcmp (arg, "-S") == 0)
single_longdoc_strings = 0;
else
{
fprintf (stderr, "%s: Unknown flag %s.\n", argv[0], arg);
exit (2);
}
}
write_helpfiles(shell_builtins);
exit (0);
}
/* Write DOCUMENTATION to STREAM, perhaps surrounding it with double-quotes
and quoting special characters in the string. Handle special things for
internationalization (gettext) and the single-string vs. multiple-strings
issues. */
void
write_documentation (stream, documentation, indentation)
FILE *stream;
char *documentation;
int indentation;
{
if (stream == 0)
return;
if (documentation)
fprintf (stream, "%*s%s\n", indentation, " ", documentation);
}
int
write_helpfiles (builtins)
struct builtin *builtins;
{
char *helpfile, *bname, *fname;
FILE *helpfp;
int i, hdlen;
struct builtin b;
i = mkdir ("helpfiles", 0777);
if (i < 0 && errno != EEXIST)
{
fprintf (stderr, "write_helpfiles: helpfiles: cannot create directory\n");
return -1;
}
hdlen = strlen ("helpfiles/");
for (i = 0; i < num_shell_builtins; i++)
{
b = builtins[i];
fname = (char *)b.handle;
helpfile = (char *)malloc (hdlen + strlen (fname) + 1);
if (helpfile == 0)
{
fprintf (stderr, "gen-helpfiles: cannot allocate memory\n");
exit (1);
}
sprintf (helpfile, "helpfiles/%s", fname);
helpfp = fopen (helpfile, "w");
if (helpfp == 0)
{
fprintf (stderr, "write_helpfiles: cannot open %s\n", helpfile);
free (helpfile);
continue;
}
write_documentation (helpfp, b.long_doc[0], 4);
fflush (helpfp);
fclose (helpfp);
free (helpfile);
}
return 0;
}
+1 -1
View File
@@ -31,7 +31,7 @@ Without options, the status of all active jobs is displayed.
Options:
-l lists process IDs in addition to the normal information
-n list only processes that have changed status since the last
-n lists only processes that have changed status since the last
notification
-p lists process IDs only
-r restrict output to running jobs
+298
View File
@@ -0,0 +1,298 @@
This file is jobs.def, from which is created jobs.c.
It implements the builtins "jobs" and "disown" in Bash.
Copyright (C) 1987-2009 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/>.
$PRODUCES jobs.c
$BUILTIN jobs
$FUNCTION jobs_builtin
$DEPENDS_ON JOB_CONTROL
$SHORT_DOC jobs [-lnprs] [jobspec ...] or jobs -x command [args]
Display status of jobs.
Lists the active jobs. JOBSPEC restricts output to that job.
Without options, the status of all active jobs is displayed.
Options:
-l lists process IDs in addition to the normal information
-n list only processes that have changed status since the last
notification
-p lists process IDs only
-r restrict output to running jobs
-s restrict output to stopped jobs
If -x is supplied, COMMAND is run after all job specifications that
appear in ARGS have been replaced with the process ID of that job's
process group leader.
Exit Status:
Returns success unless an invalid option is given or an error occurs.
If -x is used, returns the exit status of COMMAND.
$END
#include <config.h>
#if defined (JOB_CONTROL)
#include "../bashtypes.h"
#include <signal.h>
#if defined (HAVE_UNISTD_H)
# include <unistd.h>
#endif
#include "../bashansi.h"
#include "../bashintl.h"
#include "../shell.h"
#include "../jobs.h"
#include "../execute_cmd.h"
#include "bashgetopt.h"
#include "common.h"
#define JSTATE_ANY 0x0
#define JSTATE_RUNNING 0x1
#define JSTATE_STOPPED 0x2
static int execute_list_with_replacements __P((WORD_LIST *));
/* The `jobs' command. Prints outs a list of active jobs. If the
argument `-l' is given, then the process id's are printed also.
If the argument `-p' is given, print the process group leader's
pid only. If `-n' is given, only processes that have changed
status since the last notification are printed. If -x is given,
replace all job specs with the pid of the appropriate process
group leader and execute the command. The -r and -s options mean
to print info about running and stopped jobs only, respectively. */
int
jobs_builtin (list)
WORD_LIST *list;
{
int form, execute, state, opt, any_failed, job;
sigset_t set, oset;
execute = any_failed = 0;
form = JLIST_STANDARD;
state = JSTATE_ANY;
reset_internal_getopt ();
while ((opt = internal_getopt (list, "lpnxrs")) != -1)
{
switch (opt)
{
case 'l':
form = JLIST_LONG;
break;
case 'p':
form = JLIST_PID_ONLY;
break;
case 'n':
form = JLIST_CHANGED_ONLY;
break;
case 'x':
if (form != JLIST_STANDARD)
{
builtin_error (_("no other options allowed with `-x'"));
return (EXECUTION_FAILURE);
}
execute++;
break;
case 'r':
state = JSTATE_RUNNING;
break;
case 's':
state = JSTATE_STOPPED;
break;
default:
builtin_usage ();
return (EX_USAGE);
}
}
list = loptend;
if (execute)
return (execute_list_with_replacements (list));
if (!list)
{
switch (state)
{
case JSTATE_ANY:
list_all_jobs (form);
break;
case JSTATE_RUNNING:
list_running_jobs (form);
break;
case JSTATE_STOPPED:
list_stopped_jobs (form);
break;
}
return (EXECUTION_SUCCESS);
}
while (list)
{
BLOCK_CHILD (set, oset);
job = get_job_spec (list);
if ((job == NO_JOB) || jobs == 0 || get_job_by_jid (job) == 0)
{
sh_badjob (list->word->word);
any_failed++;
}
else if (job != DUP_JOB)
list_one_job ((JOB *)NULL, form, 0, job);
UNBLOCK_CHILD (oset);
list = list->next;
}
return (any_failed ? EXECUTION_FAILURE : EXECUTION_SUCCESS);
}
static int
execute_list_with_replacements (list)
WORD_LIST *list;
{
register WORD_LIST *l;
int job, result;
COMMAND *command;
JOB *j;
/* First do the replacement of job specifications with pids. */
for (l = list; l; l = l->next)
{
if (l->word->word[0] == '%') /* we have a winner */
{
job = get_job_spec (l);
/* A bad job spec is not really a job spec! Pass it through. */
if (INVALID_JOB (job))
continue;
j = get_job_by_jid (job);
free (l->word->word);
l->word->word = itos (j->pgrp);
}
}
/* Next make a new simple command and execute it. */
begin_unwind_frame ("jobs_builtin");
command = make_bare_simple_command ();
command->value.Simple->words = copy_word_list (list);
command->value.Simple->redirects = (REDIRECT *)NULL;
command->flags |= CMD_INHIBIT_EXPANSION;
command->value.Simple->flags |= CMD_INHIBIT_EXPANSION;
add_unwind_protect (dispose_command, command);
result = execute_command (command);
dispose_command (command);
discard_unwind_frame ("jobs_builtin");
return (result);
}
#endif /* JOB_CONTROL */
$BUILTIN disown
$FUNCTION disown_builtin
$DEPENDS_ON JOB_CONTROL
$SHORT_DOC disown [-h] [-ar] [jobspec ...]
Remove jobs from current shell.
Removes each JOBSPEC argument from the table of active jobs. Without
any JOBSPECs, the shell uses its notion of the current job.
Options:
-a remove all jobs if JOBSPEC is not supplied
-h mark each JOBSPEC so that SIGHUP is not sent to the job if the
shell receives a SIGHUP
-r remove only running jobs
Exit Status:
Returns success unless an invalid option or JOBSPEC is given.
$END
#if defined (JOB_CONTROL)
int
disown_builtin (list)
WORD_LIST *list;
{
int opt, job, retval, nohup_only, running_jobs, all_jobs;
sigset_t set, oset;
intmax_t pid_value;
nohup_only = running_jobs = all_jobs = 0;
reset_internal_getopt ();
while ((opt = internal_getopt (list, "ahr")) != -1)
{
switch (opt)
{
case 'a':
all_jobs = 1;
break;
case 'h':
nohup_only = 1;
break;
case 'r':
running_jobs = 1;
break;
default:
builtin_usage ();
return (EX_USAGE);
}
}
list = loptend;
retval = EXECUTION_SUCCESS;
/* `disown -a' or `disown -r' */
if (list == 0 && (all_jobs || running_jobs))
{
if (nohup_only)
nohup_all_jobs (running_jobs);
else
delete_all_jobs (running_jobs);
return (EXECUTION_SUCCESS);
}
do
{
BLOCK_CHILD (set, oset);
job = (list && legal_number (list->word->word, &pid_value) && pid_value == (pid_t) pid_value)
? get_job_by_pid ((pid_t) pid_value, 0)
: get_job_spec (list);
if (job == NO_JOB || jobs == 0 || INVALID_JOB (job))
{
sh_badjob (list ? list->word->word : _("current"));
retval = EXECUTION_FAILURE;
}
else if (nohup_only)
nohup_job (job);
else
delete_job (job, 1);
UNBLOCK_CHILD (oset);
if (list)
list = list->next;
}
while (list);
return (retval);
}
#endif /* JOB_CONTROL */