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 enum ExitCode {
COULD_NOT_CREATE_WORK_DIRECTORIES(35), COULD_NOT_CREATE_WORK_DIRECTORIES(35),
COULD_NOT_CREATE_APP_LOG_DIRECTORIES(36), COULD_NOT_CREATE_APP_LOG_DIRECTORIES(36),
COULD_NOT_CREATE_TMP_DIRECTORIES(37), 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; private final int code;
ExitCode(int exitCode) { ExitCode(int exitCode) {

View File

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

View File

@ -337,6 +337,16 @@ const char *get_error_message(const int error_code) {
return "runC run failed"; return "runC run failed";
case ERROR_RUNC_REAP_LAYER_MOUNTS_FAILED: case ERROR_RUNC_REAP_LAYER_MOUNTS_FAILED:
return "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: default:
return "Unknown error code"; return "Unknown error code";
} }

View File

@ -104,7 +104,12 @@ enum errorcodes {
ERROR_RUNC_SETUP_FAILED = 76, ERROR_RUNC_SETUP_FAILED = 76,
ERROR_RUNC_RUN_FAILED = 77, ERROR_RUNC_RUN_FAILED = 77,
ERROR_RUNC_REAP_LAYER_MOUNTS_FAILED = 78, 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. */ /* Macros for min/max. */