arch/um/os-Linux/execvp.c

Source file repositories/reference/linux-study-clean/arch/um/os-Linux/execvp.c

File Facts

System
Linux kernel
Corpus path
arch/um/os-Linux/execvp.c
Extension
.c
Size
4099 bytes
Lines
151
Domain
Architecture Layer
Bucket
arch/um
Inferred role
Architecture Layer: implementation source
Status
source implementation candidate

Why This File Exists

CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.

Dependency Surface

Detected Declarations

Annotated Snippet

if (errno == ENOEXEC) {
			}
			*/

			switch (errno) {
				case EACCES:
					/* Record the we got a `Permission denied' error.  If we end
					   up finding no executable we can use, we want to diagnose
					   that we did find one but were denied access.  */
					got_eacces = 1;
					break;
				case ENOENT:
				case ESTALE:
				case ENOTDIR:
					/* Those errors indicate the file is missing or not executable
					   by us, in which case we want to just try the next path
					   directory.  */
				case ENODEV:
				case ETIMEDOUT:
					/* Some strange filesystems like AFS return even
					   stranger error numbers.  They cannot reasonably mean
					   anything else so ignore those, too.  */
				case ENOEXEC:
					/* We won't go searching for the shell
					 * if it is not executable - the Linux
					 * kernel already handles this enough,
					 * for us. */
					break;

				default:
					/* Some other error means we found an executable file, but
					   something went wrong executing it; return the error to our
					   caller.  */
					return -errno;
			}
		} while (*p++ != '\0');

		/* We tried every element and none of them worked.  */
		if (got_eacces)
			/* At least one failure was due to permissions, so report that
			   error.  */
			return -EACCES;
	}

	/* Return the error from the last attempt (probably ENOENT).  */
	return -errno;
}
#ifdef TEST
int main(int argc, char**argv)
{
	char buf[PATH_MAX];
	int ret;
	argc--;
	if (!argc) {
		os_warn("Not enough arguments\n");
		return 1;
	}
	argv++;
	if (ret = execvp_noalloc(buf, argv[0], argv)) {
		errno = -ret;
		perror("execvp_noalloc");
	}
	return 0;
}
#endif

Annotation

Implementation Notes