Skip to content

Commit

Permalink
TS-2401: Remove global system_log_dir
Browse files Browse the repository at this point in the history
In the 2 places that actually look at this, we implement the
predictable semantics of using proxy.config.log.logfile_dir (relative
to $PREFIX) if it is specified. Otherwise we use the compile-time
log directory.  In either case, we never fall back to different
directories. We either use the one specified by the operator or
fail loudly and suddenly.
  • Loading branch information
jpeach committed Dec 6, 2013
1 parent bdd7af5 commit 88f5176
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 65 deletions.
2 changes: 0 additions & 2 deletions example/app-template/app-template.cc
Expand Up @@ -55,7 +55,6 @@ int system_num_of_udp_threads = DEFAULT_NUMBER_OF_UDP_THREADS;

char system_runtime_dir[PATH_NAME_MAX + 1];
char system_config_directory[PATH_NAME_MAX + 1];
char system_log_dir[PATH_NAME_MAX + 1];

//int system_remote_management_flag = DEFAULT_REMOTE_MANAGEMENT_FLAG;

Expand Down Expand Up @@ -159,7 +158,6 @@ int main(int argc, char * argv[])
// Get TS directories
ink_strlcpy(system_config_directory, Layout::get()->sysconfdir, sizeof(system_config_directory));
ink_strlcpy(system_runtime_dir, Layout::get()->runtimedir, sizeof(system_runtime_dir));
ink_strlcpy(system_log_dir, Layout::get()->logdir, sizeof(system_log_dir));

if (chdir(Layout::get()->prefix) < 0) {
fprintf(stderr,"unable to change to root directory \"%s\" [%d '%s']\n", Layout::get()->prefix, errno, strerror(errno));
Expand Down
1 change: 0 additions & 1 deletion lib/records/I_RecDefs.h
Expand Up @@ -179,6 +179,5 @@ typedef int (*RecRawStatSyncCb) (const char *name, RecDataT data_type, RecData *
// System Defaults
extern char system_runtime_dir[PATH_NAME_MAX + 1];
extern char system_config_directory[PATH_NAME_MAX + 1];
extern char system_log_dir[PATH_NAME_MAX + 1];

#endif
9 changes: 0 additions & 9 deletions mgmt/Main.cc
Expand Up @@ -80,7 +80,6 @@ static bool proxy_on = true;
// TODO: Check if really need those
char system_runtime_dir[PATH_NAME_MAX + 1];
char system_config_directory[PATH_NAME_MAX + 1];
char system_log_dir[PATH_NAME_MAX + 1];

char mgmt_path[PATH_NAME_MAX + 1];

Expand Down Expand Up @@ -287,14 +286,6 @@ init_dirs()
mgmt_elog(0, "please set 'proxy.config.local_state_dir'\n");
_exit(1);
}

REC_ReadConfigString(buf, "proxy.config.log.logfile_dir", PATH_NAME_MAX);
Layout::get()->relative(system_log_dir, PATH_NAME_MAX, buf);
if (access(system_log_dir, W_OK) == -1) {
mgmt_elog(0, "unable to access() log dir'%s': %d, %s\n", system_log_dir, errno, strerror(errno));
mgmt_elog(0, "please set 'proxy.config.log.logfile_dir'\n");
_exit(1);
}
}

static void
Expand Down
2 changes: 1 addition & 1 deletion proxy/Initialize.cc
Expand Up @@ -276,7 +276,7 @@ init_system_diags(char *bdt, char *bat)
char diags_logpath[PATH_NAME_MAX + 1];

ink_filepath_make(diags_logpath, sizeof(diags_logpath),
system_log_dir, DIAGS_LOG_FILE);
Layout::get()->logdir, DIAGS_LOG_FILE);

diags_log_fp = fopen(diags_logpath, "w");
if (diags_log_fp) {
Expand Down
13 changes: 0 additions & 13 deletions proxy/Main.cc
Expand Up @@ -146,7 +146,6 @@ int remote_management_flag = DEFAULT_REMOTE_MANAGEMENT_FLAG;

char system_runtime_dir[PATH_NAME_MAX + 1]; // Layout->runtimedir
char system_config_directory[PATH_NAME_MAX + 1]; // Layout->sysconfdir
char system_log_dir[PATH_NAME_MAX + 1]; // Layout->logdir

static char error_tags[1024] = "";
static char action_tags[1024] = "";
Expand Down Expand Up @@ -288,7 +287,6 @@ init_dirs(void)

ink_strlcpy(system_config_directory, Layout::get()->sysconfdir, PATH_NAME_MAX);
ink_strlcpy(system_runtime_dir, Layout::get()->runtimedir, PATH_NAME_MAX);
ink_strlcpy(system_log_dir, Layout::get()->logdir, PATH_NAME_MAX);

/*
* XXX: There is not much sense in the following code
Expand Down Expand Up @@ -318,17 +316,6 @@ init_dirs(void)
}
}

if (access(system_log_dir, W_OK) == -1) {
REC_ReadConfigString(buf, "proxy.config.log.logfile_dir", PATH_NAME_MAX);
Layout::get()->relative(system_log_dir, PATH_NAME_MAX, buf);
if (access(system_log_dir, W_OK) == -1) {
fprintf(stderr,"unable to access() log dir'%s':%d, %s\n",
system_log_dir, errno, strerror(errno));
fprintf(stderr,"please set 'proxy.config.log.logfile_dir'\n");
_exit(1);
}
}

}

//
Expand Down
24 changes: 10 additions & 14 deletions proxy/logging/LogConfig.cc
Expand Up @@ -66,8 +66,6 @@

#define PARTITION_HEADROOM_MB 10

char *ink_prepare_dir(char *logfile_dir);

void
LogConfig::setup_default_values()
{
Expand Down Expand Up @@ -248,20 +246,18 @@ LogConfig::read_configuration_variables()
// Make it relative from Layout
logfile_dir = Layout::get()->relative(ptr);
ats_free(ptr);
if (access(logfile_dir, W_OK) == -1) {
ats_free(logfile_dir);
logfile_dir = NULL;
if (access(system_log_dir, W_OK) == -1) {
// Try 'system_root_dir/var/log/trafficserver' directory
fprintf(stderr,"unable to access() log dir'%s': %d, %s\n",
system_log_dir, errno, strerror(errno));
fprintf(stderr,"please set 'proxy.config.log.logfile_dir'\n");
_exit(1);
}
logfile_dir = ats_strdup(system_log_dir);
}
} else {
ats_free(logfile_dir);
logfile_dir = ats_strdup(Layout::get()->logdir);
}

if (access(logfile_dir, R_OK | W_OK | X_OK) == -1) {
// Try 'system_root_dir/var/log/trafficserver' directory
fprintf(stderr,"unable to access log directory '%s': %d, %s\n",
logfile_dir, errno, strerror(errno));
fprintf(stderr,"please set 'proxy.config.log.logfile_dir'\n");
_exit(1);
}

//
// for each predefined logging format, we need to know:
Expand Down
1 change: 0 additions & 1 deletion proxy/logging/LogStandalone.cc
Expand Up @@ -58,7 +58,6 @@ char proxy_name[MAXDNAME + 1] = "unknown";

char system_config_directory[PATH_NAME_MAX + 1] = "";
char system_runtime_dir[PATH_NAME_MAX + 1] = "";
char system_log_dir[PATH_NAME_MAX + 1] = "";

char error_tags[1024] = "";
char action_tags[1024] = "";
Expand Down
8 changes: 0 additions & 8 deletions proxy/sac.cc
Expand Up @@ -89,14 +89,6 @@ main(int /* argc ATS_UNUSED */, char *argv[])
snprintf(configDirectoryType, sizeof(configDirectoryType), "S%d", PATH_NAME_MAX - 1);
process_args(argument_descriptions, countof(argument_descriptions), argv);

// Get log directory
ink_strlcpy(system_log_dir, Layout::get()->logdir, sizeof(system_log_dir));
if (access(system_log_dir, R_OK) == -1) {
fprintf(stderr, "unable to change to log directory \"%s\" [%d '%s']\n", system_log_dir, errno, strerror(errno));
fprintf(stderr, " please set correct path in env variable TS_ROOT \n");
exit(1);
}

// check for the version number request
//
if (version_flag) {
Expand Down
37 changes: 21 additions & 16 deletions proxy/shared/DiagsConfig.cc
Expand Up @@ -288,6 +288,8 @@ DiagsConfig::RegisterDiagConfig()
DiagsConfig::DiagsConfig(char *bdt, char *bat, bool use_records)
{
char diags_logpath[PATH_NAME_MAX + 1];
xptr<char> logpath;

callbacks_established = false;
diags_log_fp = (FILE *) NULL;
diags = NULL;
Expand All @@ -303,23 +305,26 @@ DiagsConfig::DiagsConfig(char *bdt, char *bat, bool use_records)
config_diags_norecords();
return;
}
////////////////////////
// open the diags log //
////////////////////////

if (access(system_log_dir, R_OK) == -1) {
REC_ReadConfigString(diags_logpath, "proxy.config.log.logfile_dir", PATH_NAME_MAX);
Layout::get()->relative(system_log_dir, PATH_NAME_MAX, diags_logpath);

if (access(system_log_dir, R_OK) == -1) {
fprintf(stderr,"unable to access() log dir'%s': %d, %s\n",
system_log_dir, errno, strerror(errno));
fprintf(stderr,"please set 'proxy.config.log.logfile_dir'\n");
_exit(1);
}

// Open the diagnostics log. If proxy.config.log.logfile_dir is set use that, otherwise fall
// back to the configured log directory.

diags_logpath[0] = '\0';
REC_ReadConfigString(diags_logpath, "proxy.config.log.logfile_dir", PATH_NAME_MAX);
if (strlen(diags_logpath) > 0) {
logpath = Layout::get()->relative(diags_logpath);
} else {
logpath = ats_strdup(Layout::get()->logdir);
}

if (access(logpath, W_OK | R_OK) == -1) {
fprintf(stderr, "unable to access log directory '%s': %d, %s\n",
(const char *)logpath, errno, strerror(errno));
fprintf(stderr, "please set 'proxy.config.log.logfile_dir'\n");
_exit(1);
}
ink_filepath_make(diags_logpath, sizeof(diags_logpath),
system_log_dir, DIAGS_LOG_FILE);

ink_filepath_make(diags_logpath, sizeof(diags_logpath), logpath, DIAGS_LOG_FILE);

// open write append
// diags_log_fp = fopen(diags_logpath,"w");
Expand Down

0 comments on commit 88f5176

Please sign in to comment.