Skip to content
Browse files

TS-2401: Remove global system_runtime_dir

Introduce RecConfigReadRuntimeDir() to centralize overriding
Layout::runtimedir with proxy.config.local_state_dir. Use this to
replace all the instances of system_runtime_dir.
  • Loading branch information...
1 parent 88f5176 commit f438ab45e6c467a6e4fbb595c0547a06e91715d3 @jpeach jpeach committed Nov 27, 2013
View
16 cmd/traffic_cop/traffic_cop.cc
@@ -542,6 +542,20 @@ config_read_int(const char *name, int *val, bool miss_ok = false)
exit(1);
}
+static const char *
+config_read_runtime_dir()
+{
+ char state_dir[PATH_NAME_MAX + 1];
+
+ state_dir[0] = '\0';
+ config_read_string("proxy.config.local_state_dir", state_dir, sizeof(state_dir), true);
+ if (strlen(state_dir) > 0) {
+ return Layout::get()->relative(state_dir);
+ } else {
+ return ats_strdup(Layout::get()->runtimedir);
+ }
+}
+
static void
config_reload_records()
{
@@ -1700,7 +1714,7 @@ init_config_dir()
cop_log_trace("Entering init_config_dir()\n");
root_dir = Layout::get()->prefix;
- runtime_dir = Layout::get()->runtimedir;
+ runtime_dir = config_read_runtime_dir();
config_dir = Layout::get()->sysconfdir;
if (chdir(root_dir) < 0) {
View
2 example/app-template/app-template.cc
@@ -53,7 +53,6 @@ int system_num_of_processors = ink_number_of_processors();
int system_num_of_net_threads = DEFAULT_NUMBER_OF_THREADS;
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];
//int system_remote_management_flag = DEFAULT_REMOTE_MANAGEMENT_FLAG;
@@ -157,7 +156,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));
if (chdir(Layout::get()->prefix) < 0) {
fprintf(stderr,"unable to change to root directory \"%s\" [%d '%s']\n", Layout::get()->prefix, errno, strerror(errno));
View
31 iocore/hostdb/HostDB.cc
@@ -380,6 +380,8 @@ HostDBCache::start(int flags)
bool reconfigure = ((flags & PROCESSOR_RECONFIGURE) ? true : false);
bool fix = ((flags & PROCESSOR_FIX) ? true : false);
+ storage_path[0] = '\0';
+
// Read configuration
// Command line overrides manager configuration.
//
@@ -390,33 +392,36 @@ HostDBCache::start(int flags)
REC_ReadConfigString(storage_path, "proxy.config.hostdb.storage_path", PATH_NAME_MAX);
REC_ReadConfigInt32(storage_size, "proxy.config.hostdb.storage_size");
- if (storage_path[0] != '/') {
- Layout::relative_to(storage_path, PATH_NAME_MAX, Layout::get()->prefix, storage_path);
+ // If proxy.config.hostdb.storage_path is not set, use the local state dir. If it is set to
+ // a relative path, make it relative to the prefix.
+ if (storage_path[0] == '\0') {
+ xptr<char> rundir(RecConfigReadRuntimeDir());
+ ink_strlcpy(storage_path, rundir, sizeof(storage_path));
+ } else if (storage_path[0] != '/') {
+ Layout::relative_to(storage_path, sizeof(storage_path), Layout::get()->prefix, storage_path);
}
Debug("hostdb", "Storage path is %s", storage_path);
- // XXX: Should this be W_OK?
- if (access(storage_path, R_OK) == -1) {
- ink_strlcpy(storage_path, system_runtime_dir, sizeof(storage_path));
- if (access(storage_path, R_OK) == -1) {
- Warning("Unable to access() directory '%s': %d, %s", storage_path, errno, strerror(errno));
- Warning(" Please set 'proxy.config.hostdb.storage_path' or 'proxy.config.local_state_dir' ");
- }
+ if (access(storage_path, W_OK | R_OK) == -1) {
+ Warning("Unable to access() directory '%s': %d, %s", storage_path, errno, strerror(errno));
+ Warning("Please set 'proxy.config.hostdb.storage_path' or 'proxy.config.local_state_dir'");
}
+
hostDBStore = NEW(new Store);
hostDBSpan = NEW(new Span);
hostDBSpan->init(storage_path, storage_size);
hostDBStore->add(hostDBSpan);
Debug("hostdb", "Opening %s, size=%d", hostdb_filename, hostdb_size);
if (open(hostDBStore, "hostdb.config", hostdb_filename, hostdb_size, reconfigure, fix, false /* slient */ ) < 0) {
+ xptr<char> rundir(RecConfigReadRuntimeDir());
+ xptr<char> config(Layout::relative_to(rundir, "hostdb.config"));
+
Note("reconfiguring host database");
- char p[PATH_NAME_MAX + 1];
- Layout::relative_to(p, PATH_NAME_MAX, system_runtime_dir, "hostdb.config");
- if (unlink(p) < 0)
- Debug("hostdb", "unable to unlink %s", p);
+ if (unlink(config) < 0)
+ Debug("hostdb", "unable to unlink %s", (const char *)config);
delete hostDBStore;
hostDBStore = NEW(new Store);
View
6 iocore/hostdb/MultiCache.cc
@@ -501,9 +501,10 @@ int
MultiCacheBase::read_config(const char *config_filename, Store & s, char *fn, int *pi, int *pbuck)
{
int scratch;
+ xptr<char> rundir(RecConfigReadRuntimeDir());
char p[PATH_NAME_MAX + 1], buf[256];
- Layout::relative_to(p, sizeof(p), system_runtime_dir, config_filename);
+ Layout::relative_to(p, sizeof(p), rundir, config_filename);
int fd =::open(p, O_RDONLY);
if (fd < 0)
@@ -537,10 +538,11 @@ MultiCacheBase::read_config(const char *config_filename, Store & s, char *fn, in
int
MultiCacheBase::write_config(const char *config_filename, int nominal_size, int abuckets)
{
+ xptr<char> rundir(RecConfigReadRuntimeDir());
char p[PATH_NAME_MAX + 1], buf[256];
int fd, retcode = -1;
- Layout::relative_to(p, sizeof(p), system_runtime_dir, config_filename);
+ Layout::relative_to(p, sizeof(p), rundir, config_filename);
// XXX: Shouldn't that be 0664?
//
View
4 lib/records/I_RecCore.h
@@ -45,6 +45,10 @@ typedef void (*RecConfigEntryCallback)(RecT rec_type, RecDataT data_type, const
void RecConfigFileInit(void);
int RecConfigFileParse(const char * path, RecConfigEntryCallback handler, bool inc_version);
+// Return a copy of the system's local state directory, taking proxy.config.local_state_dir into account. The
+// caller MUST releease the result with ats_free().
+char * RecConfigReadRuntimeDir();
+
// Test whether the named configuration value is overridden by an environment variable. Return either
// the overridden value, or the original value. Caller MUST NOT free the result.
const char * RecConfigOverrideFromEnvironment(const char * name, const char * value);
View
2 lib/records/I_RecDefs.h
@@ -175,9 +175,7 @@ typedef int (*RecRawStatSyncCb) (const char *name, RecDataT data_type, RecData *
#define REC_VAR_NAME_DELIMITOR '.'
#define REC_VAR_NAME_WILDCARD '*'
-
// System Defaults
-extern char system_runtime_dir[PATH_NAME_MAX + 1];
extern char system_config_directory[PATH_NAME_MAX + 1];
#endif
View
1 lib/records/RecConfigParse.cc
@@ -30,6 +30,7 @@
#include "P_RecUtils.h"
#include "P_RecMessage.h"
#include "P_RecCore.h"
+#include "I_Layout.h"
const char *g_rec_config_fpath = NULL;
LLQ *g_rec_config_contents_llq = NULL;
View
16 lib/records/RecCore.cc
@@ -1053,6 +1053,22 @@ REC_readString(const char *name, bool * found, bool lock)
return _tmp;
}
+//-------------------------------------------------------------------------
+// RecConfigReadRuntimeDir
+//-------------------------------------------------------------------------
+char *
+RecConfigReadRuntimeDir()
+{
+ char buf[PATH_NAME_MAX + 1];
+
+ buf[0] = '\0';
+ RecGetRecordString("proxy.config.local_state_dir", buf, PATH_NAME_MAX);
+ if (strlen(buf) > 0) {
+ return Layout::get()->relative(buf);
+ } else {
+ return ats_strdup(Layout::get()->runtimedir);
+ }
+}
//-------------------------------------------------------------------------
// REC_SignalManager (TS)
View
5 mgmt/LocalManager.cc
@@ -204,6 +204,8 @@ LocalManager::LocalManager(char * /* mpath ATS_UNUSED */, bool proxy_on)
: BaseManager(), run_proxy(proxy_on)
{
bool found;
+ xptr<char> rundir(RecConfigReadRuntimeDir());
+
#ifdef MGMT_USE_SYSLOG
syslog_facility = 0;
#endif
@@ -221,7 +223,8 @@ LocalManager::LocalManager(char * /* mpath ATS_UNUSED */, bool proxy_on)
mgmt_log("Bad or missing proxy.config.lm.sem_id value; using default id %d\n", MGMT_SEMID_DEFAULT);
mgmt_sync_key = MGMT_SEMID_DEFAULT;
}
- ink_strlcpy(pserver_path, system_runtime_dir, sizeof(pserver_path));
+
+ ink_strlcpy(pserver_path, rundir, sizeof(pserver_path));
virt_map = NULL;
View
8 mgmt/Main.cc
@@ -78,7 +78,6 @@ static char action_tags[1024] = "";
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 mgmt_path[PATH_NAME_MAX + 1];
@@ -267,6 +266,7 @@ setup_coredump()
static void
init_dirs()
{
+ xptr<char> rundir(RecConfigReadRuntimeDir());
char buf[PATH_NAME_MAX + 1];
REC_ReadConfigString(buf, "proxy.config.config_dir", PATH_NAME_MAX);
@@ -279,10 +279,8 @@ init_dirs()
ink_strlcpy(mgmt_path, system_config_directory, sizeof(mgmt_path));
- REC_ReadConfigString(buf, "proxy.config.local_state_dir", PATH_NAME_MAX);
- Layout::get()->relative(system_runtime_dir, PATH_NAME_MAX, buf);
- if (access(system_runtime_dir, R_OK) == -1) {
- mgmt_elog(0, "unable to access() local state dir '%s': %d, %s\n", system_runtime_dir, errno, strerror(errno));
+ if (access(rundir, R_OK) == -1) {
+ mgmt_elog(0, "unable to access() local state dir '%s': %d, %s\n", (const char *)rundir, errno, strerror(errno));
mgmt_elog(0, "please set 'proxy.config.local_state_dir'\n");
_exit(1);
}
View
4 mgmt/ProcessManager.cc
@@ -69,7 +69,9 @@ startProcessManager(void *arg)
ProcessManager::ProcessManager(bool rlm):
BaseManager(), require_lm(rlm), mgmt_sync_key(0), local_manager_sockfd(0), cbtable(NULL)
{
- ink_strlcpy(pserver_path, Layout::get()->runtimedir, sizeof(pserver_path));
+ xptr<char> rundir(RecConfigReadRuntimeDir());
+
+ ink_strlcpy(pserver_path, rundir, sizeof(pserver_path));
mgmt_signal_queue = create_queue();
// Set temp. process/manager timeout. Will be reconfigure later.
View
5 mgmt/web2/WebIntrMain.cc
@@ -432,11 +432,12 @@ webIntr_main(void *)
// set up socket paths;
char api_sock_path[1024];
char event_sock_path[1024];
+ xptr<char> rundir(RecConfigReadRuntimeDir());
bzero(api_sock_path, 1024);
bzero(event_sock_path, 1024);
- snprintf(api_sock_path, sizeof(api_sock_path), "%s/mgmtapisocket", system_runtime_dir);
- snprintf(event_sock_path, sizeof(event_sock_path), "%s/eventapisocket", system_runtime_dir);
+ snprintf(api_sock_path, sizeof(api_sock_path), "%s/mgmtapisocket", (const char *)rundir);
+ snprintf(event_sock_path, sizeof(event_sock_path), "%s/eventapisocket", (const char *)rundir);
// INKqa12562: MgmtAPI sockets should be created with 775 permission
mode_t oldmask = umask(S_IWOTH);
View
49 proxy/Main.cc
@@ -144,7 +144,6 @@ char cluster_host[MAXDNAME + 1] = DEFAULT_CLUSTER_HOST;
static char command_string[512] = "";
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
static char error_tags[1024] = "";
@@ -247,24 +246,19 @@ init_system()
static void
check_lockfile()
{
- char *lockfile = NULL;
+ xptr<char> rundir(RecConfigReadRuntimeDir());
+ xptr<char> lockfile;
pid_t holding_pid;
int err;
- if (access(Layout::get()->runtimedir, R_OK | W_OK) == -1) {
- fprintf(stderr,"unable to access() dir'%s': %d, %s\n",
- Layout::get()->runtimedir, errno, strerror(errno));
- fprintf(stderr," please set correct path in env variable TS_ROOT \n");
- _exit(1);
- }
- lockfile = Layout::relative_to(Layout::get()->runtimedir, SERVER_LOCK);
+ lockfile = Layout::relative_to(rundir, SERVER_LOCK);
Lockfile server_lockfile(lockfile);
err = server_lockfile.Get(&holding_pid);
if (err != 1) {
char *reason = strerror(-err);
- fprintf(stderr, "WARNING: Can't acquire lockfile '%s'", lockfile);
+ fprintf(stderr, "WARNING: Can't acquire lockfile '%s'", (const char *)lockfile);
if ((err == 0) && (holding_pid != -1)) {
fprintf(stderr, " (Lock file held by process ID %ld)\n", (long)holding_pid);
@@ -277,16 +271,16 @@ check_lockfile()
}
_exit(1);
}
- ats_free(lockfile);
}
static void
init_dirs(void)
{
+ xptr<char> rundir(RecConfigReadRuntimeDir());
+
char buf[PATH_NAME_MAX + 1];
ink_strlcpy(system_config_directory, Layout::get()->sysconfdir, PATH_NAME_MAX);
- ink_strlcpy(system_runtime_dir, Layout::get()->runtimedir, PATH_NAME_MAX);
/*
* XXX: There is not much sense in the following code
@@ -305,15 +299,11 @@ init_dirs(void)
}
}
- if (access(system_runtime_dir, R_OK | W_OK) == -1) {
- REC_ReadConfigString(buf, "proxy.config.local_state_dir", PATH_NAME_MAX);
- Layout::get()->relative(system_runtime_dir, PATH_NAME_MAX, buf);
- if (access(system_runtime_dir, R_OK | W_OK) == -1) {
- fprintf(stderr,"unable to access() local state dir '%s': %d, %s\n",
- system_runtime_dir, errno, strerror(errno));
- fprintf(stderr,"please set 'proxy.config.local_state_dir'\n");
- _exit(1);
- }
+ if (access(rundir, R_OK | W_OK) == -1) {
+ fprintf(stderr,"unable to access() local state dir '%s': %d, %s\n",
+ (const char *)rundir, errno, strerror(errno));
+ fprintf(stderr,"please set 'proxy.config.local_state_dir'\n");
+ _exit(1);
}
}
@@ -553,12 +543,13 @@ cmd_clear(char *cmd)
//bool c_adb = !strcmp(cmd, "clear_authdb");
bool c_cache = !strcmp(cmd, "clear_cache");
- char p[PATH_NAME_MAX];
if (c_all || c_hdb) {
- Note("Clearing Configuration");
- Layout::relative_to(p, sizeof(p), system_runtime_dir, "hostdb.config");
- if (unlink(p) < 0)
- Note("unable to unlink %s", p);
+ xptr<char> rundir(RecConfigReadRuntimeDir());
+ xptr<char> config(Layout::relative_to(rundir, "hostdb.config"));
+
+ Note("Clearing HostDB Configuration");
+ if (unlink(config) < 0)
+ Note("unable to unlink %s", (const char *)config);
}
if (c_all || c_cache) {
@@ -569,6 +560,7 @@ cmd_clear(char *cmd)
return CMD_FAILED;
}
}
+
if (c_hdb || c_all) {
Note("Clearing Host Database");
if (hostDBProcessor.cache()->start(PROCESSOR_RECONFIGURE) < 0) {
@@ -1288,8 +1280,6 @@ main(int /* argc ATS_UNUSED */, char **argv)
fprintf(stderr, "%s\n", appVersionInfo.FullVersionInfoStr);
_exit(0);
}
- // Ensure only one copy of traffic server is running
- check_lockfile();
// Set stdout/stdin to be unbuffered
setbuf(stdout, NULL);
@@ -1321,6 +1311,9 @@ main(int /* argc ATS_UNUSED */, char **argv)
// Local process manager
initialize_process_manager();
+ // Ensure only one copy of traffic server is running
+ check_lockfile();
+
// Set the core limit for the process
init_core_size();
init_system();
View
20 proxy/StatSystem.cc
@@ -474,24 +474,14 @@ initialize_all_global_stats()
{
int istat, i;
char snap_file[PATH_NAME_MAX + 1];
- char local_state_dir[PATH_NAME_MAX + 1];
+ xptr<char> rundir(RecConfigReadRuntimeDir());
- // Jira TS-21
- REC_ReadConfigString(local_state_dir, "proxy.config.local_state_dir", PATH_NAME_MAX);
- if (local_state_dir[0] != '/') {
- // Not an absolute path
- Layout::get()->relative(local_state_dir, sizeof(local_state_dir), local_state_dir);
- }
- if (access(local_state_dir, R_OK | W_OK) == -1) {
- ink_strlcpy(local_state_dir, system_runtime_dir, sizeof(local_state_dir));
- if (access(local_state_dir, R_OK | W_OK) == -1) {
- Warning("Unable to access() local state directory '%s': %d, %s", local_state_dir, errno, strerror(errno));
- Warning(" Please set 'proxy.config.local_state_dir' to allow statistics collection");
- }
+ if (access(rundir, R_OK | W_OK) == -1) {
+ Warning("Unable to access() local state directory '%s': %d, %s", (const char *)rundir, errno, strerror(errno));
+ Warning(" Please set 'proxy.config.local_state_dir' to allow statistics collection");
}
REC_ReadConfigString(snap_file, "proxy.config.stats.snap_file", PATH_NAME_MAX);
- Layout::relative_to(snap_filename, sizeof(snap_filename),
- local_state_dir, snap_file);
+ Layout::relative_to(snap_filename, sizeof(snap_filename), (const char *)rundir, snap_file);
Debug("stats", "stat snap filename %s", snap_filename);
statPagesManager.register_http("stat", stat_callback);
View
1 proxy/logging/LogStandalone.cc
@@ -57,7 +57,6 @@ int auto_clear_hostdb_flag = 0;
char proxy_name[MAXDNAME + 1] = "unknown";
char system_config_directory[PATH_NAME_MAX + 1] = "";
-char system_runtime_dir[PATH_NAME_MAX + 1] = "";
char error_tags[1024] = "";
char action_tags[1024] = "";

0 comments on commit f438ab4

Please sign in to comment.
Something went wrong with that request. Please try again.