[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bash 2.05 porting fixes for pid_t wider than int, and randomness
From: |
Paul Eggert |
Subject: |
bash 2.05 porting fixes for pid_t wider than int, and randomness |
Date: |
Fri, 13 Apr 2001 01:06:57 -0700 (PDT) |
Configuration Information [Automatically generated, do not change]:
Machine: sparc
OS: solaris2.8
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='sparc'
-DCONF_OSTYPE='solaris2.8' -DCONF_MACHTYPE='sparc-sun-solaris2.8'
-DCONF_VENDOR='sun' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib
-I/opt/reb/include -g -O2 -Wall
uname output: SunOS shade.twinsun.com 5.8 Generic_108528-06 sun4u sparc
SUNW,Ultra-1
Machine Type: sparc-sun-solaris2.8
Bash Version: 2.05
Patch Level: 0
Release Status: release
Description:
Here are some patches for one other portability glitch in bash
2.05. The current code assumes that Bash's process-ID fits in
'int', which POSIX does not guarantee. Also, in a related
area, Bash unnecessarily discards some info when generating
random numbers.
Repeat-By:
Fix:
2001-04-13 Paul Eggert <eggert@twinsun.com>
* lib/sh/tmpfile.c (sh_mktmpname, sh_mktmpfd):
Do not truncate time_t to int.
* subst.c (dollar_dollar_pid): Now pid_t, not int.
* lib/sh/tmpfile.c (dollar_dollar_pid): Likewise.
* variables.c (dollar_dollar_pid): Likewise.
* variables.c (sbrand): Now prototyped, since it converts args.
(initialize_shell_variables): Do not truncate pid.
Do not discard info when initializing randum number generator.
(last_random_value): Now int, not unsigned long, since int suffices.
(sbrand): Now takes unsigned long, not int, so that the caller can
pass in a bigger seed.
(assign_random, get_random_number): Do not truncate seed to int.
(get_random_number): Remove unnecessary cast to int.
===================================================================
RCS file: lib/sh/tmpfile.c,v
retrieving revision 2.5
retrieving revision 2.5.0.1
diff -pu -r2.5 -r2.5.0.1
--- lib/sh/tmpfile.c 2001/02/14 22:03:53 2.5
+++ lib/sh/tmpfile.c 2001/04/13 07:56:16 2.5.0.1
@@ -44,7 +44,7 @@ extern int errno;
#define DEFAULT_TMPDIR "." /* bogus default, should be changed */
#define DEFAULT_NAMEROOT "shtmp"
-extern int dollar_dollar_pid;
+extern pid_t dollar_dollar_pid;
static char *sys_tmpdir = (char *)NULL;
static int ntmpfiles;
@@ -118,7 +118,7 @@ sh_mktmpname (nameroot, flags)
while (1)
{
- filenum *= (int)time ((time_t *)0) * dollar_dollar_pid *
+ filenum *= time ((time_t *)0) * dollar_dollar_pid *
((flags & MT_USERANDOM) ? get_random_number () : ntmpfiles++);
sprintf (filename, "%s/%s-%lu", tdir, nameroot, filenum);
if (tmpnamelen > 0 && tmpnamelen < 32)
@@ -153,7 +153,7 @@ sh_mktmpfd (nameroot, flags, namep)
do
{
- filenum *= (int)time ((time_t *)0) * dollar_dollar_pid *
+ filenum *= time ((time_t *)0) * dollar_dollar_pid *
((flags & MT_USERANDOM) ? get_random_number () : ntmpfiles++);
sprintf (filename, "%s/%s-%lu", tdir, nameroot, filenum);
if (tmpnamelen > 0 && tmpnamelen < 32)
===================================================================
RCS file: subst.c,v
retrieving revision 2.5.0.1
retrieving revision 2.5.0.2
diff -pu -r2.5.0.1 -r2.5.0.2
--- subst.c 2001/04/13 07:08:33 2.5.0.1
+++ subst.c 2001/04/13 07:56:16 2.5.0.2
@@ -109,7 +109,7 @@ pid_t current_command_subst_pid = NO_PID
extern int last_command_exit_value, interactive, interactive_shell;
extern int subshell_environment, startup_state;
extern int return_catch_flag, return_catch_value;
-extern int dollar_dollar_pid;
+extern pid_t dollar_dollar_pid;
extern int posixly_correct;
extern char *this_command_name;
extern struct fd_bitmap *current_fds_to_close;
===================================================================
RCS file: variables.c,v
retrieving revision 2.5.0.1
retrieving revision 2.5.0.2
diff -pu -r2.5.0.1 -r2.5.0.2
--- variables.c 2001/04/13 07:08:33 2.5.0.1
+++ variables.c 2001/04/13 07:56:16 2.5.0.2
@@ -108,7 +108,7 @@ char *dollar_vars[10];
WORD_LIST *rest_of_args = (WORD_LIST *)NULL;
/* The value of $$. */
-int dollar_dollar_pid;
+pid_t dollar_dollar_pid;
/* An array which is passed to commands as their environment. It is
manufactured from the union of the initial environment and the
@@ -135,7 +135,7 @@ static void initialize_shell_level ();
static void uidset ();
static void initialize_dynamic_variables ();
static void make_vers_array ();
-static void sbrand (); /* set bash random number generator. */
+static void sbrand __P((unsigned long));
static int qsort_var_comp ();
static SHELL_VAR *bind_tempenv_variable ();
@@ -245,7 +245,7 @@ initialize_shell_variables (env, privmod
temp_var = bind_variable ("_", dollar_vars[0]);
/* Remember this pid. */
- dollar_dollar_pid = (int)getpid ();
+ dollar_dollar_pid = getpid ();
/* Now make our own defaults in case the vars that we think are
important are missing. */
@@ -357,7 +357,7 @@ initialize_shell_variables (env, privmod
#endif /* HISTORY */
/* Seed the random number generator. */
- sbrand (dollar_dollar_pid + (long)shell_start_time);
+ sbrand (dollar_dollar_pid + shell_start_time);
/* Handle some "special" variables that we may have inherited from a
parent shell. */
@@ -1013,7 +1013,7 @@ get_seconds (var)
/* The random number seed. You can change this by setting RANDOM. */
static unsigned long rseed = 1;
-static unsigned long last_random_value;
+static int last_random_value;
/* A linear congruential random number generator based on the ANSI
C standard. This one isn't very good (the values are alternately
@@ -1030,7 +1030,7 @@ brand ()
/* Set the random number generator seed to SEED. */
static void
sbrand (seed)
- int seed;
+ unsigned long seed;
{
rseed = seed;
last_random_value = 0;
@@ -1041,7 +1041,7 @@ assign_random (self, value)
SHELL_VAR *self;
char *value;
{
- sbrand (atoi (value));
+ sbrand (strtoul (value, (char **) NULL, 10));
return (self);
}
@@ -1052,11 +1052,11 @@ get_random_number ()
/* Reset for command and process substitution. */
if (subshell_environment)
- sbrand (rseed + (int)(getpid() + NOW));
+ sbrand (rseed + getpid () + NOW);
do
rv = brand ();
- while (rv == (int)last_random_value);
+ while (rv == last_random_value);
return rv;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- bash 2.05 porting fixes for pid_t wider than int, and randomness,
Paul Eggert <=