< prev index next >

src/java.base/unix/native/libjava/childproc.c

Print this page




 217         /* unshared address space; we can mutate environ. */
 218         environ = (char **) envp;
 219         execvp(file, (char **) argv);
 220     }
 221 }
 222 
 223 /**
 224  * 'execvpe' should have been included in the Unix standards,
 225  * and is a GNU extension in glibc 2.10.
 226  *
 227  * JDK_execvpe is identical to execvp, except that the child environment is
 228  * specified via the 3rd argument instead of being inherited from environ.
 229  */
 230 void
 231 JDK_execvpe(int mode, const char *file,
 232             const char *argv[],
 233             const char *const envp[])
 234 {
 235     if (envp == NULL || (char **) envp == environ) {
 236         execvp(file, (char **) argv);
 237         return;






 238     }
 239 
 240     if (*file == '\0') {
 241         errno = ENOENT;
 242         return;
 243     }
 244 
 245     if (strchr(file, '/') != NULL) {
 246         execve_with_shell_fallback(mode, file, argv, envp);
 247     } else {
 248         /* We must search PATH (parent's, not child's) */
 249         char expanded_file[PATH_MAX];
 250         int filelen = strlen(file);
 251         int sticky_errno = 0;
 252         const char * const * dirs;
 253         for (dirs = parentPathv; *dirs; dirs++) {
 254             const char * dir = *dirs;
 255             int dirlen = strlen(dir);
 256             if (filelen + dirlen + 2 >= PATH_MAX) {
 257                 errno = ENAMETOOLONG;




 217         /* unshared address space; we can mutate environ. */
 218         environ = (char **) envp;
 219         execvp(file, (char **) argv);
 220     }
 221 }
 222 
 223 /**
 224  * 'execvpe' should have been included in the Unix standards,
 225  * and is a GNU extension in glibc 2.10.
 226  *
 227  * JDK_execvpe is identical to execvp, except that the child environment is
 228  * specified via the 3rd argument instead of being inherited from environ.
 229  */
 230 void
 231 JDK_execvpe(int mode, const char *file,
 232             const char *argv[],
 233             const char *const envp[])
 234 {
 235     if (envp == NULL || (char **) envp == environ) {
 236         execvp(file, (char **) argv);
 237         // ENOEXEC indicates that the file header was not recognized. The musl C
 238         // library does not implement the fallback to /bin/sh for that case, so fall
 239         // through to the code below which implements that fallback using
 240         // execve_with_shell_fallback.
 241         if (errno != ENOEXEC) {
 242             return;
 243         }
 244     }
 245 
 246     if (*file == '\0') {
 247         errno = ENOENT;
 248         return;
 249     }
 250 
 251     if (strchr(file, '/') != NULL) {
 252         execve_with_shell_fallback(mode, file, argv, envp);
 253     } else {
 254         /* We must search PATH (parent's, not child's) */
 255         char expanded_file[PATH_MAX];
 256         int filelen = strlen(file);
 257         int sticky_errno = 0;
 258         const char * const * dirs;
 259         for (dirs = parentPathv; *dirs; dirs++) {
 260             const char * dir = *dirs;
 261             int dirlen = strlen(dir);
 262             if (filelen + dirlen + 2 >= PATH_MAX) {
 263                 errno = ENAMETOOLONG;


< prev index next >