Author: tucu Date: Wed May 2 22:53:50 2012 New Revision: 1333241 URL: http://svn.apache.org/viewvc?rev=1333241&view=rev Log: MAPREDUCE-4219. make default container-executor.conf.dir be a path relative to the container-executor binary. (rvs via tucu)
Modified: hadoop/common/trunk/hadoop-mapreduce-project/CHANGES.txt hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/pom.xml hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/configuration.c hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/configuration.h hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/main.c hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c Modified: hadoop/common/trunk/hadoop-mapreduce-project/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-mapreduce-project/CHANGES.txt?rev=1333241&r1=1333240&r2=1333241&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-mapreduce-project/CHANGES.txt (original) +++ hadoop/common/trunk/hadoop-mapreduce-project/CHANGES.txt Wed May 2 22:53:50 2012 @@ -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 Modified: hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/pom.xml URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/pom.xml?rev=1333241&r1=1333240&r2=1333241&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/pom.xml (original) +++ hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/pom.xml Wed May 2 22:53:50 2012 @@ -27,7 +27,7 @@ <properties> <!-- Basedir eeded for generating FindBugs warnings using parent pom --> <yarn.basedir>${project.parent.parent.basedir}</yarn.basedir> - <container-executor.conf.dir>/etc/hadoop</container-executor.conf.dir> + <container-executor.conf.dir>../etc/hadoop</container-executor.conf.dir> <container-executor.additional_cflags></container-executor.additional_cflags> </properties> Modified: hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/configuration.c URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/configuration.c?rev=1333241&r1=1333240&r2=1333241&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/configuration.c (original) +++ hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/configuration.c Wed May 2 22:53:50 2012 @@ -29,6 +29,7 @@ #include <string.h> #include <sys/stat.h> #include <sys/types.h> +#include <limits.h> #define MAX_SIZE 10 @@ -87,6 +88,25 @@ static int is_only_root_writable(const c } /** + * 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 * configuration and potentially cause damage. Modified: hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/configuration.h URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/configuration.h?rev=1333241&r1=1333240&r2=1333241&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/configuration.h (original) +++ hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/configuration.h Wed May 2 22:53:50 2012 @@ -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); Modified: hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/main.c URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/main.c?rev=1333241&r1=1333240&r2=1333241&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/main.c (original) +++ hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/main.c Wed May 2 22:53:50 2012 @@ -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) { Modified: hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c?rev=1333241&r1=1333240&r2=1333241&view=diff ============================================================================== --- hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c (original) +++ hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/test-container-executor.c Wed May 2 22:53:50 2012 @@ -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();