tls: code shrink
[oweals/busybox.git] / shell / ash.c
index 25468d7965e3550868ce18bebc736ab2ed2ea0b9..04e4006c89d4b0a1b6680eb6e7d1a63090c0927d 100644 (file)
 //config:      default y
 //config:      depends on ASH || SH_IS_ASH || BASH_IS_ASH
 //config:      help
-//config:      Allow scripts to be compressed and embedded in the BusyBox
+//config:      Allow scripts to be compressed and embedded in the busybox
 //config:      binary. The scripts should be placed in the 'embed' directory
-//config:      at build time. In standalone shell mode such scripts can be
-//config:      run directly and are subject to tab completion; otherwise they
-//config:      can be run by giving their name as an argument to the shell.
-//config:      For convenience shell aliases are created. The '-L' shell
-//config:      argument lists the names of the scripts. Like applets scripts
-//config:      can be run as 'busybox name ...' or by linking their name to
-//config:      the binary.
+//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
 
@@ -2425,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;
 
@@ -8044,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
@@ -12962,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);
@@ -14041,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++;
@@ -14153,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;