#include "math.h"
#if ENABLE_ASH_RANDOM_SUPPORT
# include "random.h"
+#else
+# define CLEAR_RANDOM_T(rnd) ((void)0)
#endif
#if defined SINGLE_APPLET_MAIN
/* ============ Memory allocation */
+#if 0
+/* I consider these wrappers nearly useless:
+ * ok, they return you to nearest exception handler, but
+ * how much memory do you leak in the process, making
+ * memory starvation worse?
+ */
+static void *
+ckrealloc(void * p, size_t nbytes)
+{
+ p = realloc(p, nbytes);
+ if (!p)
+ ash_msg_and_raise_error(bb_msg_memory_exhausted);
+ return p;
+}
+
+static void *
+ckmalloc(size_t nbytes)
+{
+ return ckrealloc(NULL, nbytes);
+}
+
+static void *
+ckzalloc(size_t nbytes)
+{
+ return memset(ckmalloc(nbytes), 0, nbytes);
+}
+
+static char *
+ckstrdup(const char *s)
+{
+ char *p = strdup(s);
+ if (!p)
+ ash_msg_and_raise_error(bb_msg_memory_exhausted);
+ return p;
+}
+#else
+/* Using bbox equivalents. They exit if out of memory */
+# define ckrealloc xrealloc
+# define ckmalloc xmalloc
+# define ckzalloc xzalloc
+# define ckstrdup xstrdup
+#endif
+
/*
* It appears that grabstackstr() will barf with such alignments
* because stalloc() will return a string allocated in a new stackblock.
/* Most machines require the value returned from malloc to be aligned
* in some way. The following macro will get this right
* on many machines. */
- SHELL_SIZE = sizeof(union {int i; char *cp; double d; }) - 1,
+ SHELL_SIZE = sizeof(union { int i; char *cp; double d; }) - 1,
/* Minimum size of a block */
MINSIZE = SHELL_ALIGN(504),
};
herefd = -1; \
} while (0)
+
#define stackblock() ((void *)g_stacknxt)
#define stackblocksize() g_stacknleft
-
-static void *
-ckrealloc(void * p, size_t nbytes)
-{
- p = realloc(p, nbytes);
- if (!p)
- ash_msg_and_raise_error(bb_msg_memory_exhausted);
- return p;
-}
-
-static void *
-ckmalloc(size_t nbytes)
-{
- return ckrealloc(NULL, nbytes);
-}
-
-static void *
-ckzalloc(size_t nbytes)
-{
- return memset(ckmalloc(nbytes), 0, nbytes);
-}
-
-/*
- * Make a copy of a string in safe storage.
- */
-static char *
-ckstrdup(const char *s)
-{
- char *p = strdup(s);
- if (!p)
- ash_msg_and_raise_error(bb_msg_memory_exhausted);
- return p;
-}
-
/*
* Parse trees for commands are allocated in lifo order, so we use a stack
* to make this more efficient, and also to avoid all sorts of exception
freejob(jp);
ash_msg_and_raise_error("can't fork");
}
- if (pid == 0)
+ if (pid == 0) {
+ CLEAR_RANDOM_T(&random_gen); /* or else $RANDOM repeats in child */
forkchild(jp, n, mode);
- else
+ } else {
forkparent(jp, n, mode, pid);
+ }
return pid;
}
#define EV_TESTED 02 /* exit status is checked; ignore -e flag */
#define EV_BACKCMD 04 /* command executing within back quotes */
-static const short nodesize[N_NUMBER] = {
+static const uint8_t nodesize[N_NUMBER] = {
[NCMD ] = SHELL_ALIGN(sizeof(struct ncmd)),
[NPIPE ] = SHELL_ALIGN(sizeof(struct npipe)),
[NREDIR ] = SHELL_ALIGN(sizeof(struct nredir)),
static void FAST_FUNC
change_random(const char *value)
{
- /* Galois LFSR parameter */
- /* Taps at 32 31 29 1: */
- enum { MASK = 0x8000000b };
- /* Another example - taps at 32 31 30 10: */
- /* MASK = 0x00400007 */
-
uint32_t t;
if (value == NULL) {
#endif
rootpid = getpid();
-#if ENABLE_ASH_RANDOM_SUPPORT
- /* Can use monotonic_ns() for better randomness but for now it is
- * not used anywhere else in busybox... so avoid bloat */
- INIT_RANDOM_T(&random_gen, rootpid, monotonic_us());
-#endif
init();
setstackmark(&smark);
procargs(argv);