YARN-8262. get_executable in container-executor should provide meaningful error codes. Contributed by Susheel Gupta

This commit is contained in:
Szilard Nemeth 2022-11-22 13:37:55 +01:00
parent 8f971b0e54
commit 3c37a01654
4 changed files with 33 additions and 14 deletions

View File

@ -175,8 +175,12 @@ public class LinuxContainerExecutor extends ContainerExecutor {
COULD_NOT_CREATE_WORK_DIRECTORIES(35),
COULD_NOT_CREATE_APP_LOG_DIRECTORIES(36),
COULD_NOT_CREATE_TMP_DIRECTORIES(37),
ERROR_CREATE_CONTAINER_DIRECTORIES_ARGUMENTS(38);
ERROR_CREATE_CONTAINER_DIRECTORIES_ARGUMENTS(38),
CANNOT_GET_EXECUTABLE_NAME_FROM_READLINK(80),
TOO_LONG_EXECUTOR_PATH(81),
CANNOT_GET_EXECUTABLE_NAME_FROM_KERNEL(82),
CANNOT_GET_EXECUTABLE_NAME_FROM_PID(83),
WRONG_PATH_OF_EXECUTABLE(84);
private final int code;
ExitCode(int exitCode) {

View File

@ -56,17 +56,17 @@ char *__get_exec_readproc(char *procfn) {
filename = malloc(EXECUTOR_PATH_MAX);
if (!filename) {
fprintf(ERRORFILE,"cannot allocate memory for filename before readlink: %s\n",strerror(errno));
exit(-1);
exit(OUT_OF_MEMORY);
}
len = readlink(procfn, filename, EXECUTOR_PATH_MAX);
if (len == -1) {
fprintf(ERRORFILE,"Can't get executable name from %s - %s\n", procfn,
fprintf(ERRORFILE,"Cannot get executable name from %s - %s\n", procfn,
strerror(errno));
exit(-1);
exit(CANNOT_GET_EXECUTABLE_NAME_FROM_READLINK);
} else if (len >= EXECUTOR_PATH_MAX) {
fprintf(ERRORFILE,"Resolved path for %s [%s] is longer than %d characters.\n",
procfn, filename, EXECUTOR_PATH_MAX);
exit(-1);
exit(TOO_LONG_EXECUTOR_PATH);
}
filename[len] = '\0';
return filename;
@ -88,14 +88,14 @@ char *__get_exec_sysctl(int *mib)
len = sizeof(buffer);
if (sysctl(mib, 4, buffer, &len, NULL, 0) == -1) {
fprintf(ERRORFILE,"Can't get executable name from kernel: %s\n",
fprintf(ERRORFILE,"Cannot get executable name from kernel: %s\n",
strerror(errno));
exit(-1);
exit(CANNOT_GET_EXECUTABLE_NAME_FROM_KERNEL);
}
filename=malloc(EXECUTOR_PATH_MAX);
if (!filename) {
fprintf(ERRORFILE,"cannot allocate memory for filename after sysctl: %s\n",strerror(errno));
exit(-1);
exit(OUT_OF_MEMORY);
}
snprintf(filename,EXECUTOR_PATH_MAX,"%s",buffer);
return filename;
@ -120,13 +120,13 @@ char* get_executable(char *argv0) {
filename = malloc(PROC_PIDPATHINFO_MAXSIZE);
if (!filename) {
fprintf(ERRORFILE,"cannot allocate memory for filename before proc_pidpath: %s\n",strerror(errno));
exit(-1);
exit(OUT_OF_MEMORY);
}
pid = getpid();
if (proc_pidpath(pid,filename,PROC_PIDPATHINFO_MAXSIZE) <= 0) {
fprintf(ERRORFILE,"Can't get executable name from pid %u - %s\n", pid,
fprintf(ERRORFILE,"Cannot get executable name from pid %u - %s\n", pid,
strerror(errno));
exit(-1);
exit(CANNOT_GET_EXECUTABLE_NAME_FROM_PID);
}
return filename;
}
@ -194,7 +194,7 @@ char* get_executable (char *argv0) {
if (!filename) {
fprintf(ERRORFILE,"realpath of executable: %s\n",strerror(errno));
exit(-1);
exit(WRONG_PATH_OF_EXECUTABLE);
}
return filename;
}

View File

@ -337,6 +337,16 @@ const char *get_error_message(const int error_code) {
return "runC run failed";
case ERROR_RUNC_REAP_LAYER_MOUNTS_FAILED:
return "runC reap layer mounts failed";
case CANNOT_GET_EXECUTABLE_NAME_FROM_READLINK:
return "Cannot get executable name from readlink";
case TOO_LONG_EXECUTOR_PATH:
return "Too long executor path";
case CANNOT_GET_EXECUTABLE_NAME_FROM_KERNEL:
return "Cannot get executable name from kernel";
case CANNOT_GET_EXECUTABLE_NAME_FROM_PID:
return "Cannot get executable name from pid";
case WRONG_PATH_OF_EXECUTABLE:
return "Wrong path of executable";
default:
return "Unknown error code";
}

View File

@ -104,7 +104,12 @@ enum errorcodes {
ERROR_RUNC_SETUP_FAILED = 76,
ERROR_RUNC_RUN_FAILED = 77,
ERROR_RUNC_REAP_LAYER_MOUNTS_FAILED = 78,
ERROR_DOCKER_CONTAINER_EXEC_FAILED = 79
ERROR_DOCKER_CONTAINER_EXEC_FAILED = 79,
CANNOT_GET_EXECUTABLE_NAME_FROM_READLINK = 80,
TOO_LONG_EXECUTOR_PATH = 81,
CANNOT_GET_EXECUTABLE_NAME_FROM_KERNEL = 82,
CANNOT_GET_EXECUTABLE_NAME_FROM_PID = 83,
WRONG_PATH_OF_EXECUTABLE = 84
};
/* Macros for min/max. */