MAPREDUCE-4219. make default container-executor.conf.dir be a path relative to the container-executor binary. (rvs via tucu)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1333241 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Alejandro Abdelnur 2012-05-02 22:53:50 +00:00
parent e1a961d1bc
commit ca5b406ac0
6 changed files with 56 additions and 3 deletions

View File

@ -160,6 +160,9 @@ Release 2.0.0 - UNRELEASED
MAPREDUCE-3883. Document yarn.nodemanager.delete.debug-delay-sec MAPREDUCE-3883. Document yarn.nodemanager.delete.debug-delay-sec
configuration property (Eugene Koontz via tgraves) 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 OPTIMIZATIONS
BUG FIXES BUG FIXES

View File

@ -27,7 +27,7 @@
<properties> <properties>
<!-- Basedir eeded for generating FindBugs warnings using parent pom --> <!-- Basedir eeded for generating FindBugs warnings using parent pom -->
<yarn.basedir>${project.parent.parent.basedir}</yarn.basedir> <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> <container-executor.additional_cflags></container-executor.additional_cflags>
</properties> </properties>

View File

@ -29,6 +29,7 @@
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <limits.h>
#define MAX_SIZE 10 #define MAX_SIZE 10
@ -86,6 +87,25 @@ static int is_only_root_writable(const char *file) {
return 1; 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 * Ensure that the configuration file and all of the containing directories
* are only writable by root. Otherwise, an attacker can change the * are only writable by root. Otherwise, an attacker can change the

View File

@ -24,6 +24,13 @@
*/ */
int check_configuration_permissions(const char* file_name); 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 // read the given configuration file
void read_config(const char* config_file); void read_config(const char* config_file);

View File

@ -33,6 +33,12 @@
#define STRINGIFY(X) _STRINGIFY(X) #define STRINGIFY(X) _STRINGIFY(X)
#define CONF_FILENAME "container-executor.cfg" #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 #ifndef HADOOP_CONF_DIR
#error HADOOP_CONF_DIR must be defined #error HADOOP_CONF_DIR must be defined
#endif #endif
@ -96,7 +102,7 @@ int main(int argc, char **argv) {
char *executable_file = get_executable(); char *executable_file = get_executable();
char *orig_conf_file = STRINGIFY(HADOOP_CONF_DIR) "/" CONF_FILENAME; 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; char *local_dirs, *log_dirs;
if (conf_file == NULL) { if (conf_file == NULL) {

View File

@ -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() { void test_check_configuration_permissions() {
printf("\nTesting check_configuration_permissions\n"); printf("\nTesting check_configuration_permissions\n");
if (check_configuration_permissions("/etc/passwd") != 0) { if (check_configuration_permissions("/etc/passwd") != 0) {
@ -668,7 +680,9 @@ int main(int argc, char **argv) {
int my_username = 0; int my_username = 0;
// clean up any junk from previous run // 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) { if (mkdirs(TEST_ROOT "/logs/userlogs", 0755) != 0) {
exit(1); exit(1);
@ -700,6 +714,9 @@ int main(int argc, char **argv) {
printf("\nStarting tests\n"); printf("\nStarting tests\n");
printf("\nTesting resolve_config_path()\n");
test_resolve_config_path();
printf("\nTesting get_user_directory()\n"); printf("\nTesting get_user_directory()\n");
test_get_user_directory(); test_get_user_directory();