tls: code shrink
[oweals/busybox.git] / shell / ash.c
index 3adb6d0d23f41592a0b9548d5ef9e18ec0389572..04e4006c89d4b0a1b6680eb6e7d1a63090c0927d 100644 (file)
 //config:      at build time. Like applets, scripts can be run as
 //config:      'busybox SCRIPT ...' or by linking their name to the binary.
 //config:
+//config:      This also allows applets to be implemented as scripts: place
+//config:      the script in 'applets_sh' and a stub C file containing
+//config:      configuration in the appropriate subsystem directory.
+//config:
 //config:endif # ash options
 
 //applet:IF_ASH(APPLET(ash, BB_DIR_BIN, BB_SUID_DROP))
@@ -2420,13 +2424,12 @@ setvar(const char *name, const char *val, int flags)
        }
 
        INT_OFF;
-       nameeq = ckmalloc(namelen + vallen + 2);
+       nameeq = ckzalloc(namelen + vallen + 2);
        p = mempcpy(nameeq, name, namelen);
        if (val) {
                *p++ = '=';
-               p = mempcpy(p, val, vallen);
+               memcpy(p, val, vallen);
        }
-       *p = '\0';
        vp = setvareq(nameeq, flags | VNOSAVE);
        INT_ON;
 
@@ -8039,6 +8042,7 @@ tryexec(IF_FEATURE_SH_STANDALONE(int applet_no,) const char *cmd, char **argv, c
 #else
        execve(cmd, argv, envp);
 #endif
+
        if (cmd != bb_busybox_exec_path && errno == ENOEXEC) {
                /* Run "cmd" as a shell script:
                 * http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html
@@ -12957,6 +12961,7 @@ parseheredoc(void)
        heredoclist = NULL;
 
        while (here) {
+               tokpushback = 0;
                setprompt_if(needprompt, 2);
                readtoken1(pgetc(), here->here->type == NHERE ? SQSYNTAX : DQSYNTAX,
                                here->eofmark, here->striptabs);
@@ -14036,11 +14041,11 @@ procargs(char **argv)
        int login_sh;
 
        xargv = argv;
+       login_sh = xargv[0] && xargv[0][0] == '-';
 #if NUM_SCRIPTS > 0
        if (minusc)
                goto setarg0;
 #endif
-       login_sh = xargv[0] && xargv[0][0] == '-';
        arg0 = xargv[0];
        /* if (xargv[0]) - mmm, this is always true! */
                xargv++;
@@ -14148,7 +14153,11 @@ extern int etext();
  * is used to figure out how far we had gotten.
  */
 int ash_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+#if NUM_SCRIPTS > 0
+int ash_main(int argc, char **argv)
+#else
 int ash_main(int argc UNUSED_PARAM, char **argv)
+#endif
 /* note: 'argc' is used only if embedded scripts are enabled */
 {
        volatile smallint state;