ash: in standalone mode, search in $PATH if /proc/self/exe doesn't exist
authorDenys Vlasenko <vda.linux@googlemail.com>
Tue, 20 Dec 2011 05:10:35 +0000 (06:10 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 20 Dec 2011 05:10:35 +0000 (06:10 +0100)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/ash.c

index b4ed8e57835fdb99b598b86ab4c183124831a346..d197fa19a4d44cdad139b2f2224e617e72e2e567 100644 (file)
@@ -7471,9 +7471,7 @@ shellexec(char **argv, const char *path, int idx)
        int e;
        char **envp;
        int exerrno;
-#if ENABLE_FEATURE_SH_STANDALONE
-       int applet_no = -1;
-#endif
+       int applet_no = -1; /* used only by FEATURE_SH_STANDALONE */
 
        clearredir(/*drop:*/ 1);
        envp = listvars(VEXPORT, VUNSET, /*end:*/ NULL);
@@ -7483,8 +7481,16 @@ shellexec(char **argv, const char *path, int idx)
 #endif
        ) {
                tryexec(IF_FEATURE_SH_STANDALONE(applet_no,) argv[0], argv, envp);
+               if (applet_no >= 0) {
+                       /* We tried execing ourself, but it didn't work.
+                        * Maybe /proc/self/exe doesn't exist?
+                        * Try $PATH search.
+                        */
+                       goto try_PATH;
+               }
                e = errno;
        } else {
+ try_PATH:
                e = ENOENT;
                while ((cmdname = path_advance(&path, argv[0])) != NULL) {
                        if (--idx < 0 && pathopt == NULL) {