diff --git a/hadoop-mapreduce-project/CHANGES.txt b/hadoop-mapreduce-project/CHANGES.txt index 9f695c57c92..5d8a5404e78 100644 --- a/hadoop-mapreduce-project/CHANGES.txt +++ b/hadoop-mapreduce-project/CHANGES.txt @@ -160,6 +160,9 @@ Release 2.0.0 - UNRELEASED MAPREDUCE-3883. Document yarn.nodemanager.delete.debug-delay-sec configuration property (Eugene Koontz via tgraves) + MAPREDUCE-4219. make default container-executor.conf.dir be a path + relative to the container-executor binary. (rvs via tucu) + OPTIMIZATIONS BUG FIXES diff --git a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/pom.xml b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/pom.xml index 6032aabd6a4..cf5d7ff8dc5 100644 --- a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/pom.xml +++ b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/pom.xml @@ -27,7 +27,7 @@ ${project.parent.parent.basedir} - /etc/hadoop + ../etc/hadoop diff --git a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/configuration.c b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/configuration.c index aa723033512..eb85eb2f18e 100644 --- a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/configuration.c +++ b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/configuration.c @@ -29,6 +29,7 @@ #include #include #include +#include #define MAX_SIZE 10 @@ -86,6 +87,25 @@ static int is_only_root_writable(const char *file) { return 1; } +/** + * Return a string with the configuration file path name resolved via realpath(3) + * + * NOTE: relative path names are resolved relative to the second argument not getwd(3) + */ +char *resolve_config_path(const char* file_name, const char *root) { + const char *real_fname = NULL; + char buffer[PATH_MAX*2 + 1]; + + if (file_name[0] == '/') { + real_fname = file_name; + } else if (realpath(root, buffer) != NULL) { + strncpy(strrchr(buffer, '/') + 1, file_name, PATH_MAX); + real_fname = buffer; + } + + return (real_fname == NULL) ? NULL : realpath(real_fname, NULL); +} + /** * Ensure that the configuration file and all of the containing directories * are only writable by root. Otherwise, an attacker can change the diff --git a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/configuration.h b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/configuration.h index b0d4814b310..fb9529f0dc7 100644 --- a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/configuration.h +++ b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/configuration.h @@ -24,6 +24,13 @@ */ int check_configuration_permissions(const char* file_name); +/** + * Return a string with the configuration file path name resolved via realpath(3) + * + * NOTE: relative path names are resolved relative to the second argument not getwd(3) + */ +char *resolve_config_path(const char* file_name, const char *root); + // read the given configuration file void read_config(const char* config_file); diff --git a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/main.c b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/main.c index d039f05ea43..cd8caabe333 100644 --- a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/main.c +++ b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/main.c @@ -33,6 +33,12 @@ #define STRINGIFY(X) _STRINGIFY(X) #define CONF_FILENAME "container-executor.cfg" +// When building as part of a Maven build this value gets defined by using +// container-executor.conf.dir property. See: +// hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/pom.xml +// for details. +// NOTE: if this ends up being a relative path it gets resolved relative to +// the location of the container-executor binary itself, not getwd(3) #ifndef HADOOP_CONF_DIR #error HADOOP_CONF_DIR must be defined #endif @@ -96,7 +102,7 @@ int main(int argc, char **argv) { char *executable_file = get_executable(); char *orig_conf_file = STRINGIFY(HADOOP_CONF_DIR) "/" CONF_FILENAME; - char *conf_file = realpath(orig_conf_file, NULL); + char *conf_file = resolve_config_path(orig_conf_file, argv[0]); char *local_dirs, *log_dirs; if (conf_file == NULL) { diff --git a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c index b7796586a4d..07a343c69f3 100644 --- a/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c +++ b/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c @@ -196,6 +196,18 @@ void test_check_user() { } } +void test_resolve_config_path() { + printf("\nTesting resolve_config_path\n"); + if (strcmp(resolve_config_path("/etc/passwd", NULL), "/etc/passwd") != 0) { + printf("FAIL: failed to resolve config_name on an absolute path name: /etc/passwd\n"); + exit(1); + } + if (strcmp(resolve_config_path("../etc/passwd", "/etc/passwd"), "/etc/passwd") != 0) { + printf("FAIL: failed to resolve config_name on a relative path name: ../etc/passwd (relative to /etc/passwd)"); + exit(1); + } +} + void test_check_configuration_permissions() { printf("\nTesting check_configuration_permissions\n"); if (check_configuration_permissions("/etc/passwd") != 0) { @@ -668,7 +680,9 @@ int main(int argc, char **argv) { int my_username = 0; // clean up any junk from previous run - system("chmod -R u=rwx " TEST_ROOT "; rm -fr " TEST_ROOT); + if (system("chmod -R u=rwx " TEST_ROOT "; rm -fr " TEST_ROOT)) { + exit(1); + } if (mkdirs(TEST_ROOT "/logs/userlogs", 0755) != 0) { exit(1); @@ -700,6 +714,9 @@ int main(int argc, char **argv) { printf("\nStarting tests\n"); + printf("\nTesting resolve_config_path()\n"); + test_resolve_config_path(); + printf("\nTesting get_user_directory()\n"); test_get_user_directory();