Permalink
Browse files

TS-2401: Remove system_config_directory

Remove all the places the global system_config_directory is used,
replacing it with Layout::get()->sysconfdir where appropriate.
  • Loading branch information...
1 parent f438ab4 commit 67306a71da65f135ff85c2f4d9b966122fa5590a @jpeach jpeach committed Dec 2, 2013
View
7 example/app-template/app-template.cc
@@ -53,8 +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_config_directory[PATH_NAME_MAX + 1];
-
//int system_remote_management_flag = DEFAULT_REMOTE_MANAGEMENT_FLAG;
//Diags *diags = NULL;
@@ -154,9 +152,6 @@ int main(int argc, char * argv[])
_exit(0);
}
- // Get TS directories
- ink_strlcpy(system_config_directory, Layout::get()->sysconfdir, sizeof(system_config_directory));
-
if (chdir(Layout::get()->prefix) < 0) {
fprintf(stderr,"unable to change to root directory \"%s\" [%d '%s']\n", Layout::get()->prefix, errno, strerror(errno));
fprintf(stderr," please set correct path in env variable TS_ROOT \n");
@@ -226,8 +221,6 @@ int main(int argc, char * argv[])
// initialize logging (after event and net processor)
//Log::init(system_remote_management_flag ? 0 : Log::NO_REMOTE_MANAGEMENT);
- //plugin_init(system_config_directory); // plugin.config
-
// Create accept continuation
MyAccept *a = new MyAccept;
a->accept_port = tsapp_port;
View
11 lib/records/I_RecCore.h
@@ -46,9 +46,18 @@ 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().
+// caller MUST release the result with ats_free().
char * RecConfigReadRuntimeDir();
+// Return a copy of the system's snapshot directory, taking proxy.config.snapshot_dir into account. The caller
+// MUST release the result with ats_free().
+char * RecConfigReadSnapshotDir();
+
+// Return a copy of a configuration file that is relative to sysconfdir. The relative path to the configuration
+// file is specified in the configuration variable named by "file_variable". If the configuration variable has no
+// value, NULL is returned. The caller MUST release the result with ats_free().
+char * RecConfigReadConfigPath(const char * file_variable);
+
// 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
3 lib/records/I_RecDefs.h
@@ -175,7 +175,4 @@ 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_config_directory[PATH_NAME_MAX + 1];
-
#endif
View
34 lib/records/RecCore.cc
@@ -1071,6 +1071,40 @@ RecConfigReadRuntimeDir()
}
//-------------------------------------------------------------------------
+// RecConfigReadSnapshotDir.
+//-------------------------------------------------------------------------
+char *
+RecConfigReadSnapshotDir()
+{
+ char buf[PATH_NAME_MAX + 1];
+
+ buf[0] = '\0';
+ RecGetRecordString("proxy.config.snapshot_dir", buf, PATH_NAME_MAX);
+ if (strlen(buf) > 0) {
+ return Layout::get()->relative_to(Layout::get()->sysconfdir, buf);
+ } else {
+ return Layout::get()->relative_to(Layout::get()->sysconfdir, "snapshots");
+ }
+}
+
+//-------------------------------------------------------------------------
+// RecConfigReadConfigPath
+//-------------------------------------------------------------------------
+char *
+RecConfigReadConfigPath(const char * file_variable)
+{
+ char buf[PATH_NAME_MAX + 1];
+
+ buf[0] = '\0';
+ RecGetRecordString(file_variable, buf, PATH_NAME_MAX);
+ if (strlen(buf) > 0) {
+ return Layout::get()->relative_to(Layout::get()->sysconfdir, buf);
+ }
+
+ return NULL;
+}
+
+//-------------------------------------------------------------------------
// REC_SignalManager (TS)
//-------------------------------------------------------------------------
#if defined (REC_BUILD_MGMT)
View
92 mgmt/FileManager.cc
@@ -32,10 +32,6 @@
#include "ExpandingArray.h"
#include "MgmtSocket.h"
-
-
-static const char snapDir[] = "snapshots";
-
#define DIR_MODE S_IRWXU
#define FILE_MODE S_IRWXU
@@ -56,51 +52,24 @@ const char *SnapshotStrings[] = { "Request Successful\n",
FileManager::FileManager()
{
- char configTmp[PATH_NAME_MAX + 1];
- int pathLen;
-
bindings = ink_hash_table_create(InkHashTableKeyType_String);
-
ink_assert(bindings != NULL);
ink_mutex_init(&accessLock, "File Manager Mutex");
ink_mutex_init(&cbListLock, "File Changed Callback Mutex");
- if (varStrFromName("proxy.config.config_dir", configTmp, sizeof(configTmp)) == false) {
- mgmt_fatal(stderr, 0,
- "[FileManager::FileManager] Unable to find configuration directory from proxy.config.config_dir\n");
- }
- if (configTmp[0] != '/') {
- // Make it TS_ROOT relative
- Layout::get()->relative(configTmp, sizeof(configTmp), configTmp);
- }
- if (access(configTmp, R_OK) == -1) {
- ink_strlcpy(configTmp, system_config_directory,sizeof(configTmp));
- if (access(configTmp, R_OK) == -1) {
- mgmt_elog(0, "[FileManager::FileManager] unable to access() directory '%s': %d, %s\n",
- mgmt_path, errno, strerror(errno));
- mgmt_elog(0, "[FileManager::FileManager] please set config path via command line '-path <path>' or 'proxy.config.config_dir' \n");
- _exit(1);
- }
- }
- // Set up the path to the snap shot dir
- pathLen = strlen(configTmp) + strlen(snapDir) + 3;
- const size_t snapshotDir_size = pathLen + 1;
- snapshotDir = new char[snapshotDir_size];
- ink_filepath_make(snapshotDir, snapshotDir_size, configTmp, snapDir);
-
- // Set up info for MultiFile
- managedDir = snapshotDir;
- dirDescript = "snapshot";
-
- // Check to see if the directory already exists, if not create
- // it
+ xptr<char> snapshotDir(RecConfigReadSnapshotDir());
+
+ // Check to see if the directory already exists, if not create it.
if (access(snapshotDir, F_OK) == -1) {
if (mkdir(snapshotDir, DIR_MODE) < 0) {
// Failed to create the snapshot directory
- mgmt_fatal(stderr, 0, "[FileManager::FileManager] Failed to create the snapshot directory %s: %s\n", snapshotDir, strerror(errno));
+ mgmt_fatal(stderr, 0, "[FileManager::FileManager] Failed to create the snapshot directory %s: %s\n", (const char *)snapshotDir, strerror(errno));
}
}
+
+ this->managedDir = snapshotDir.release();
+ this->dirDescript = "snapshot";
}
// FileManager::~FileManager
@@ -117,11 +86,12 @@ FileManager::~FileManager()
InkHashTableEntry *entry;
InkHashTableIteratorState iterator_state;
- // Let other operations finish and do not start any
- // new ones
+ // Let other operations finish and do not start any new ones
ink_mutex_acquire(&accessLock);
- delete[]snapshotDir;
+ ats_free(this->managedDir);
+ this->managedDir = NULL;
+ this->dirDescript = NULL;
for (cb = cblist.pop(); cb != NULL; cb = cblist.pop()) {
delete cb;
@@ -688,45 +658,13 @@ FileManager::copyFile(Rollback * rb, const char *snapPath)
SnapResult
FileManager::WalkSnaps(ExpandingArray * snapList)
{
-
MFresult r;
- // These aren't used.
- //char altSnapshotDir[256];
- //InkHashTableValue snapDirLookup;
- //fileBinding* snapBind;
- //InkHashTableEntry *entry;
- //InkHashTableIteratorState iterator_state;
- //char *filePath;
- bool found;
- char config_dir[256];
- char *snapshot_dir;
- ink_mutex_acquire(&accessLock);
- snapshot_dir = (char *) REC_readString("proxy.config.snapshot_dir", &found);
- ink_assert(found);
- //config_dir = lmgmt->record_data->readString("proxy.config.config_dir", &found);
- //ink_assert(found);
-
- if (varStrFromName("proxy.config.config_dir", config_dir, 256) == false) {
- mgmt_fatal(stderr, 0,
- "[FileManager::FileManager] Unable to find configuration directory from proxy.config.config_dir\n");
- }
-
- if (snapshot_dir == NULL) {
- const size_t snapshot_dir_size = strlen("snapshots");
- snapshot_dir = new char[snapshot_dir_size];
- ink_assert(snapshot_dir);
- snprintf(snapshot_dir, snapshot_dir_size, "%s", "snapshots");
- RecSetRecordString("proxy.config.snapshot_dir", snapshot_dir);
- }
- //if(strncmp(snapshot_dir, config_dir, strlen(config_dir)))
- if (snapshot_dir[0] != '/')
- managedDir = newPathString(config_dir, snapshot_dir);
- else
- managedDir = snapshot_dir;
- //else
- //managedDir = snapshot_dir;
+ // The original code reset this->managedDir from proxy.config.snapshot_dir at this point. There doesn't appear to be
+ // any need for that, since managedDir is always set in the constructor and should not be changed.
+ ink_release_assert(this->managedDir != NULL);
+ ink_mutex_acquire(&accessLock);
r = WalkFiles(snapList);
//lmgmt->record_data ->setString("proxy.config.snapshot_dir", managedDir);
View
1 mgmt/FileManager.h
@@ -134,7 +134,6 @@ class FileManager:public MultiFile
DLL<callbackListable> cblist;
InkHashTable *bindings;
//InkHashTable* g_snapshot_directory_ht;
- char *snapshotDir;
SnapResult copyFile(Rollback * rb, const char *snapPath);
SnapResult readFile(const char *filePath, textBuffer * contents);
void abortRestore(const char *abortTo);
View
18 mgmt/LocalManager.cc
@@ -200,7 +200,7 @@ LocalManager::processRunning()
}
}
-LocalManager::LocalManager(char * /* mpath ATS_UNUSED */, bool proxy_on)
+LocalManager::LocalManager(bool proxy_on)
: BaseManager(), run_proxy(proxy_on)
{
bool found;
@@ -238,18 +238,10 @@ LocalManager::LocalManager(char * /* mpath ATS_UNUSED */, bool proxy_on)
// Get the default IP binding values.
RecHttpLoadIp("proxy.local.incoming_ip_to_bind", m_inbound_ip4, m_inbound_ip6);
- config_path = REC_readString("proxy.config.config_dir", &found);
- char *absolute_config_path = Layout::get()->relative(config_path);
- ats_free(config_path);
- if (access(absolute_config_path, R_OK) == -1) {
- config_path = ats_strdup(system_config_directory);
- if (access(config_path, R_OK) == -1) {
- mgmt_elog(0, "[LocalManager::LocalManager] unable to access() directory '%s': %d, %s\n",
- config_path, errno, strerror(errno));
- mgmt_fatal(0, "[LocalManager::LocalManager] please set config path via command line '-path <path>' or 'proxy.config.config_dir' \n");
- }
- } else {
- config_path = absolute_config_path;
+ if (access(Layout::get()->sysconfdir, R_OK) == -1) {
+ mgmt_elog(0, "[LocalManager::LocalManager] unable to access() directory '%s': %d, %s\n",
+ Layout::get()->sysconfdir, errno, strerror(errno));
+ mgmt_fatal(0, "[LocalManager::LocalManager] please set the 'TS_ROOT' environment variable\n");
}
#if TS_HAS_WCCP
View
4 mgmt/LocalManager.h
@@ -50,14 +50,13 @@
class LocalManager: public BaseManager
{
public:
- LocalManager(char *mpath, bool proxy_on);
+ LocalManager(bool proxy_on);
~LocalManager()
{
delete alarm_keeper;
delete virt_map;
delete ccom;
- ats_free(config_path);
ats_free(bin_path);
ats_free(absolute_proxy_binary);
ats_free(proxy_name);
@@ -125,7 +124,6 @@ class LocalManager: public BaseManager
int process_server_timeout_msecs;
char pserver_path[PATH_NAME_MAX];
- char *config_path;
char *bin_path;
char *absolute_proxy_binary;
char *proxy_name;
View
18 mgmt/Main.cc
@@ -64,6 +64,8 @@
extern "C" int getpwnam_r(const char *name, struct passwd *result, char *buffer, size_t buflen, struct passwd **resptr);
#endif
+static void extractConfigInfo(char *mgmt_path, const char *recs_conf, char *userName, int *fds_throttle);
+
LocalManager *lmgmt = NULL;
FileManager *configFiles;
@@ -77,9 +79,6 @@ static char debug_tags[1024] = "";
static char action_tags[1024] = "";
static bool proxy_on = true;
-// TODO: Check if really need those
-char system_config_directory[PATH_NAME_MAX + 1];
-
char mgmt_path[PATH_NAME_MAX + 1];
// By default, set the current directory as base
@@ -267,18 +266,13 @@ static void
init_dirs()
{
xptr<char> rundir(RecConfigReadRuntimeDir());
- char buf[PATH_NAME_MAX + 1];
- REC_ReadConfigString(buf, "proxy.config.config_dir", PATH_NAME_MAX);
- Layout::get()->relative(system_config_directory, PATH_NAME_MAX, buf);
- if (access(system_config_directory, R_OK) == -1) {
- mgmt_elog(0, "unable to access() config dir '%s': %d, %s\n", system_config_directory, errno, strerror(errno));
- mgmt_elog(0, "please set config path via 'proxy.config.config_dir' \n");
+ if (access(Layout::get()->sysconfdir, R_OK) == -1) {
+ mgmt_elog(0, "unable to access() config dir '%s': %d, %s\n", Layout::get()->sysconfdir, errno, strerror(errno));
+ mgmt_elog(0, "please set the 'TS_ROOT' environment variable\n");
_exit(1);
}
- ink_strlcpy(mgmt_path, system_config_directory, sizeof(mgmt_path));
-
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");
@@ -562,7 +556,7 @@ main(int argc, char **argv)
Init_Errata_Logging();
#endif
ts_host_res_global_init();
- lmgmt = new LocalManager(mgmt_path, proxy_on);
+ lmgmt = new LocalManager(proxy_on);
RecLocalInitMessage();
lmgmt->initAlarm();
View
1 mgmt/Main.h
@@ -37,7 +37,6 @@
void MgmtShutdown(int status);
void fileUpdated(char *fname, bool incVersion);
void runAsUser(char *userName);
-void extractConfigInfo(char *mgmt_path, const char *recs_conf, char *userName, int *fds_throttle);
void printUsage(void);
extern FileManager *configFiles;
View
34 mgmt/Rollback.cc
@@ -30,6 +30,7 @@
#include "ExpandingArray.h"
#include "MgmtSocket.h"
#include "ink_cap.h"
+#include "I_Layout.h"
#define MAX_VERSION_DIGITS 11
#define DEFAULT_BACKUPS 2
@@ -45,14 +46,11 @@ const char *RollbackStrings[] = { "Rollback Ok",
Rollback::Rollback(const char *baseFileName, bool root_access_needed_)
: root_access_needed(root_access_needed_)
{
- char configTmp[PATH_NAME_MAX + 1];
version_t highestSeen; // the highest backup version
ExpandingArray existVer(25, true); // Exsisting versions
struct stat fileInfo;
MgmtInt numBak;
char *alarmMsg;
- struct stat s;
- int err;
// To Test, Read/Write access to the file
int testFD; // For open test
@@ -70,20 +68,13 @@ Rollback::Rollback(const char *baseFileName, bool root_access_needed_)
fileName = new char[fileNameLen + 1];
ink_strlcpy(fileName, baseFileName, fileNameLen + 1);
-
- // Get the configuration directory - SHOULD BE CENTRALIZED SOMEWHERE
// TODO: Use the runtime directory for storing mutable data
// XXX: Sysconfdir should be imutable!!!
- //
- if (varStrFromName("proxy.config.config_dir", configTmp, PATH_NAME_MAX) == false) {
- mgmt_log(stderr, "[Rollback::Rollback] Unable to find configuration directory from proxy.config.config_dir\n");
- ink_assert(0);
- }
- if ((err = stat(system_config_directory, &s)) < 0) {
- mgmt_elog(0, "[Rollback::Rollback] unable to stat() directory '%s': %d %d, %s\n",
- system_config_directory, err, errno, strerror(errno));
- mgmt_elog(0, "[Rollback::Rollback] please set config path via command line '-path <path>' or 'proxy.config.config_dir' \n");
+ if (access(Layout::get()->sysconfdir, F_OK) < 0) {
+ mgmt_elog(0, "[Rollback::Rollback] unable to access() directory '%s': %d, %s\n",
+ Layout::get()->sysconfdir, errno, strerror(errno));
+ mgmt_elog(0, "[Rollback::Rollback] please set the 'TS_ROOT' environment variable\n");
_exit(1);
}
@@ -96,12 +87,6 @@ Rollback::Rollback(const char *baseFileName, bool root_access_needed_)
} else {
numberBackups = DEFAULT_BACKUPS;
}
- // TODO: Use strdup/free instead C++ new
- //
- int configDirLen = strlen(system_config_directory) + 1;
- configDir = new char[configDirLen];
- ink_strlcpy(configDir, system_config_directory, configDirLen);
-
ink_mutex_init(&fileAccessLock, "RollBack Mutex");
@@ -227,7 +212,6 @@ Rollback::Rollback(const char *baseFileName, bool root_access_needed_)
Rollback::~Rollback()
{
delete[]fileName;
- delete[]configDir;
}
@@ -240,11 +224,11 @@ Rollback::createPathStr(version_t version)
{
char *buffer;
- int bufSize = strlen(configDir) + fileNameLen + MAX_VERSION_DIGITS + 1;
+ int bufSize = strlen(Layout::get()->sysconfdir) + fileNameLen + MAX_VERSION_DIGITS + 1;
buffer = new char[bufSize];
- ink_filepath_make(buffer, bufSize, configDir, fileName);
+ Layout::get()->relative_to(buffer, bufSize, Layout::get()->sysconfdir, fileName);
if (version != ACTIVE_VERSION) {
size_t pos = strlen(buffer);
@@ -727,11 +711,11 @@ Rollback::findVersions_ml(ExpandingArray * listNames)
struct dirent *dirEntrySpace;
struct dirent *entryPtr;
- dir = opendir(configDir);
+ dir = opendir(Layout::get()->sysconfdir);
if (dir == NULL) {
mgmt_log(stderr, "[Rollback::findVersions] Unable to open configuration directory: %s: %s\n",
- configDir, strerror(errno));
+ Layout::get()->sysconfdir, strerror(errno));
return INVALID_VERSION;
}
// The fun of Solaris - readdir_r requires a buffer passed into it
View
1 mgmt/Rollback.h
@@ -207,7 +207,6 @@ class Rollback
int statFile(version_t version, struct stat *buf);
char *createPathStr(version_t version);
RollBackCodes internalUpdate(textBuffer * buf, version_t newVersion, bool notifyChange = true, bool incVersion = true);
- char *configDir;
ink_mutex fileAccessLock;
char *fileName;
size_t fileNameLen;
View
13 mgmt/cluster/VMap.cc
@@ -35,6 +35,7 @@
#include "VMap.h"
#include "MgmtUtils.h"
#include "P_RecLocal.h"
+#include "I_Layout.h"
// for linux and freebsd
#ifndef C_ISUID
@@ -303,19 +304,17 @@ VMap::lt_runGambit()
* vaddr file.
*/
void
-VMap::lt_readAListFile(char *data)
+VMap::lt_readAListFile(char * data)
{
int tmp_num_addrs = 0;
- char buf[1024], fname[1024];
+ char buf[1024];
char tmp_addr[1024], tmp_interface[1024];
FILE *fin;
char tmp_id[1024];
+ xptr<char> vaddr_path(Layout::get()->relative_to(Layout::get()->sysconfdir, data));
- if (!data)
- return;
- snprintf(fname, sizeof(fname), "%s/%s", lmgmt->config_path, data);
- if (!(fin = fopen(fname, "r"))) {
- mgmt_log(stderr, "[VMap::lt_readAListFile] Unable to open file: %s, addr list unchanged\n", fname);
+ if (!(fin = fopen(vaddr_path, "r"))) {
+ mgmt_log(stderr, "[VMap::lt_readAListFile] Unable to open file: %s, addr list unchanged\n", (const char *)vaddr_path);
return;
}
View
4 mgmt/web2/WebIntrMain.cc
@@ -415,11 +415,11 @@ webIntr_main(void *)
if ((err = stat(autoconfContext.docRoot, &s)) < 0) {
ats_free(autoconfContext.docRoot);
- autoconfContext.docRoot = ats_strdup(system_config_directory);
+ autoconfContext.docRoot = ats_strdup(Layout::get()->sysconfdir);
if ((err = stat(autoconfContext.docRoot, &s)) < 0) {
mgmt_elog(0, "[WebIntrMain] unable to stat() directory '%s': %d %d, %s\n",
autoconfContext.docRoot, err, errno, strerror(errno));
- mgmt_elog(0, "[WebIntrMain] please set config path via command line '-path <path>' or 'proxy.config.config_dir' \n");
+ mgmt_elog(0, "[WebIntrMain] please set the 'TS_ROOT' environment variable\n");
mgmt_fatal(stderr, 0, "[WebIntrMain] No Client AutoConf Root\n");
}
}
View
13 proxy/ControlMatcher.cc
@@ -694,25 +694,21 @@ template<class Data, class Result>
ControlMatcher<Data, Result>::ControlMatcher(const char *file_var, const char *name, const matcher_tags * tags,
int flags_in)
{
- char *config_file = NULL;
-
flags = flags_in;
ink_assert(flags & (ALLOW_HOST_TABLE | ALLOW_REGEX_TABLE | ALLOW_URL_TABLE | ALLOW_IP_TABLE));
config_tags = tags;
ink_assert(config_tags != NULL);
matcher_name = name;
- config_file_var = ats_strdup(file_var);
config_file_path[0] = '\0';
- REC_ReadConfigStringAlloc(config_file, config_file_var);
-
if (!(flags & DONT_BUILD_TABLE)) {
- ink_release_assert(config_file != NULL);
- ink_filepath_make(config_file_path, sizeof(config_file_path), system_config_directory, config_file);
+ xptr<char> config_path(RecConfigReadConfigPath(file_var));
+
+ ink_release_assert(config_path);
+ ink_strlcpy(config_file_path, config_path, sizeof(config_file_path));
}
- ats_free(config_file);
reMatch = NULL;
urlMatch = NULL;
@@ -729,7 +725,6 @@ ControlMatcher<Data, Result>::ControlMatcher(const char *file_var, const char *n
template<class Data, class Result> ControlMatcher<Data, Result>::~ControlMatcher()
{
- ats_free(config_file_var);
delete reMatch;
delete urlMatch;
View
5 proxy/ControlMatcher.h
@@ -32,8 +32,8 @@
*
* The control matcher module provides the ability to lookup arbitrary
* information specific to a URL and IP address. The outside
- * world only sees the ControlMatcher class which parses the revelvant
- * configuration file and builds the lookups table
+ * world only sees the ControlMatcher class which parses the relevant
+ * configuration file and builds the lookup table
*
* Four types of matched are supported: hostname, domain name, ip address
* and URL regex. For these four types, three lookup tables are used. Regex and
@@ -277,7 +277,6 @@ template<class Data, class Result> class ControlMatcher {
int BuildTableFromString(char *str);
void Match(RequestData * rdata, Result * result);
void Print();
- char *config_file_var; // temporary: until config is integerated
int getEntryCount() { return m_numEntries; }
HostMatcher<Data, Result> *getHostMatcher() { return hostMatch; }
View
13 proxy/ICPConfig.cc
@@ -38,6 +38,7 @@
#include "ICPProcessor.h"
#include "ICPlog.h"
#include "BaseManager.h"
+#include "I_Layout.h"
//--------------------------------------------------------------------------
// Each ICP peer is described in "icp.config" with the
@@ -542,14 +543,10 @@ ICPConfiguration::icp_config_change_callback(void *data, void *value, int startu
//
// Build pathname to "icp.config" and open file
//
- ink_assert(filename);
- char ConfigFilePath[PATH_NAME_MAX];
- if (filename) {
- ink_strlcpy(ConfigFilePath, system_config_directory, sizeof(ConfigFilePath));
- ink_strlcat(ConfigFilePath, "/", sizeof(ConfigFilePath));
- ink_strlcat(ConfigFilePath, filename, sizeof(ConfigFilePath));
- }
- int fd = open(ConfigFilePath, O_RDONLY);
+ ink_release_assert(filename != NULL);
+
+ xptr<char> config_path(Layout::get()->relative_to(Layout::get()->sysconfdir, filename));
+ int fd = open(config_path, O_RDONLY);
if (fd < 0) {
Warning("read icp.config, open failed");
REC_SignalWarning(REC_SIGNAL_CONFIG_ERROR, "read icp.config, open failed");
View
13 proxy/IPAllow.cc
@@ -104,20 +104,15 @@ IpAllow::IpAllow(
const char *config_var,
const char *name,
const char *action_val
-) : config_file_var(config_var),
- module_name(name),
+) : module_name(name),
action(action_val)
{
+ xptr<char> config_path(RecConfigReadConfigPath(config_var));
- char *config_file;
-
- config_file_var = ats_strdup(config_var);
config_file_path[0] = '\0';
+ ink_release_assert(config_path);
- REC_ReadConfigStringAlloc(config_file, (char *) config_file_var);
- ink_release_assert(config_file != NULL);
- ink_filepath_make(config_file_path, sizeof(config_file_path), system_config_directory, config_file);
- ats_free(config_file);
+ ink_strlcpy(config_file_path, config_path, sizeof(config_file_path));
}
IpAllow::~IpAllow()
View
1 proxy/IPAllow.h
@@ -98,7 +98,6 @@ class IpAllow : public ConfigInfo
int BuildTable();
- const char *config_file_var;
char config_file_path[PATH_NAME_MAX];
const char *module_name;
const char *action;
View
3 proxy/InkAPI.cc
@@ -1711,14 +1711,15 @@ TSInstallDirGet(void)
const char *
TSConfigDirGet(void)
{
- return system_config_directory;
+ return Layout::get()->sysconfdir;
}
const char *
TSTrafficServerVersionGet(void)
{
return traffic_server_version;
}
+
int TSTrafficServerVersionGetMajor() { return ts_major_version; }
int TSTrafficServerVersionGetMinor() { return ts_minor_version; }
int TSTrafficServerVersionGetPatch() { return ts_patch_version; }
View
35 proxy/Main.cc
@@ -144,8 +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_config_directory[PATH_NAME_MAX + 1]; // Layout->sysconfdir
-
static char error_tags[1024] = "";
static char action_tags[1024] = "";
static int show_statistics = 0;
@@ -274,29 +272,15 @@ check_lockfile()
}
static void
-init_dirs(void)
+check_config_directories(void)
{
xptr<char> rundir(RecConfigReadRuntimeDir());
- char buf[PATH_NAME_MAX + 1];
-
- ink_strlcpy(system_config_directory, Layout::get()->sysconfdir, PATH_NAME_MAX);
-
- /*
- * XXX: There is not much sense in the following code
- * The purpose of proxy.config.foo_dir should
- * be checked BEFORE checking default foo directory.
- * Otherwise one cannot change the config dir to something else
- */
- if (access(system_config_directory, R_OK) == -1) {
- REC_ReadConfigString(buf, "proxy.config.config_dir", PATH_NAME_MAX);
- Layout::get()->relative(system_config_directory, PATH_NAME_MAX, buf);
- if (access(system_config_directory, R_OK) == -1) {
- fprintf(stderr,"unable to access() config dir '%s': %d, %s\n",
- system_config_directory, errno, strerror(errno));
- fprintf(stderr, "please set config path via 'proxy.config.config_dir' \n");
- _exit(1);
- }
+ if (access(Layout::get()->sysconfdir, R_OK) == -1) {
+ fprintf(stderr,"unable to access() config dir '%s': %d, %s\n",
+ Layout::get()->sysconfdir, errno, strerror(errno));
+ fprintf(stderr, "please set the 'TS_ROOT' environment variable\n");
+ _exit(1);
}
if (access(rundir, R_OK | W_OK) == -1) {
@@ -327,15 +311,14 @@ initialize_process_manager()
LibRecordsConfigInit();
RecordsConfigOverrideFromEnvironment();
}
- //
+
// Start up manager
- //
pmgmt = NEW(new ProcessManager(remote_management_flag));
pmgmt->start();
RecProcessInitMessage(remote_management_flag ? RECM_CLIENT : RECM_STAND_ALONE);
pmgmt->reconfigure();
- init_dirs();// setup directories
+ check_config_directories();
//
// Define version info records
@@ -1531,7 +1514,7 @@ main(int /* argc ATS_UNUSED */, char **argv)
Log::init(remote_management_flag ? 0 : Log::NO_REMOTE_MANAGEMENT);
// Init plugins as soon as logging is ready.
- plugin_init(system_config_directory); // plugin.config
+ plugin_init(); // plugin.config
pmgmt->registerPluginCallbacks(global_config_cbs);
cacheProcessor.set_after_init_callback(&CB_After_Cache_Init);
View
32 proxy/Plugin.cc
@@ -221,36 +221,8 @@ plugin_expand(char *arg)
return NULL;
}
-
-int
-plugins_exist(const char *config_dir)
-{
- char path[PATH_NAME_MAX + 1];
- char line[1024], *p;
- int fd;
- int plugin_count = 0;
-
- ink_filepath_make(path, sizeof(path), config_dir, "plugin.config");
- fd = open(path, O_RDONLY);
- if (fd < 0) {
- Warning("unable to open plugin config file '%s': %d, %s", path, errno, strerror(errno));
- return 0;
- }
- while (ink_file_fd_readline(fd, sizeof(line) - 1, line) > 0) {
- p = line;
- // strip leading white space and test for comment or blank line
- while (*p && ParseRules::is_wslfcr(*p))
- ++p;
- if ((*p == '\0') || (*p == '#'))
- continue;
- plugin_count++;
- }
- close(fd);
- return plugin_count;
-}
-
void
-plugin_init(const char *config_dir)
+plugin_init(void)
{
char path[PATH_NAME_MAX + 1];
char line[1024], *p;
@@ -267,7 +239,7 @@ plugin_init(const char *config_dir)
INIT_ONCE = false;
}
- ink_filepath_make(path, sizeof(path), config_dir, "plugin.config");
+ Layout::get()->relative_to(path, sizeof(path), Layout::get()->sysconfdir, "plugin.config");
fd = open(path, O_RDONLY);
if (fd < 0) {
Warning("unable to open plugin config file '%s': %d, %s", path, errno, strerror(errno));
View
3 proxy/Plugin.h
@@ -56,7 +56,6 @@ struct PluginRegInfo
extern DLL<PluginRegInfo> plugin_reg_list;
extern PluginRegInfo *plugin_reg_current;
-void plugin_init(const char *config_dir);
-int plugins_exist(const char *config_dir);
+void plugin_init(void);
#endif /* __PLUGIN_H__ */
View
15 proxy/Prefetch.cc
@@ -26,7 +26,6 @@
#include "Prefetch.h"
#include "HdrUtils.h"
#include "HttpCompat.h"
-#include "I_Layout.h"
#include <records/I_RecHttp.h>
#include <ts/IpMapConf.h>
@@ -1906,8 +1905,7 @@ config_read_proto(PrefetchBlastData &blast, const char *str)
int
PrefetchConfiguration::readConfiguration()
{
- char *conf_file_name;
- char conf_path[PATH_NAME_MAX + 1];
+ xptr<char> conf_path;
int fd = -1;
local_http_server_port = stuffer_port = 0;
@@ -1944,24 +1942,21 @@ PrefetchConfiguration::readConfiguration()
//pre_parse_hook = 0;
//embedded_url_hook = 0;
- conf_file_name = TS_ConfigReadString("proxy.config.prefetch.config_file");
-
- if (conf_file_name == NULL) {
+ conf_path = RecConfigReadConfigPath("proxy.config.prefetch.config_file");
+ if (!conf_path) {
Warning("PrefetchProcessor: No prefetch configuration file specified. Prefetch disabled\n");
goto Lerror;
}
- Layout::relative_to(conf_path, sizeof(conf_path), system_config_directory, conf_file_name);
- ats_free(conf_file_name);
fd = open(conf_path, O_RDONLY);
if (fd < 0) {
- Error("PrefetchProcessor: Error, could not open '%s' disabling Prefetch\n", conf_path);
+ Error("PrefetchProcessor: Error, could not open '%s' disabling Prefetch\n", (const char *)conf_path);
goto Lerror;
}
char *temp_str;
if ((temp_str = Load_IpMap_From_File(&ip_map, fd, "prefetch_children")) != 0) {
- Error("PrefetchProcessor: Error in reading ip_range from %s: %.256s\n", conf_path, temp_str);
+ Error("PrefetchProcessor: Error in reading ip_range from %s: %.256s\n", (const char *)conf_path, temp_str);
ats_free(temp_str);
goto Lerror;
}
View
10 proxy/Update.cc
@@ -32,7 +32,7 @@
#include "URL.h"
#include "HdrUtils.h"
#include <records/I_RecHttp.h>
-//#include "MixtAPIInternal.h"
+#include "I_Layout.h"
RecRawStatBlock *update_rsb;
@@ -875,17 +875,15 @@ UpdateConfigList *
UpdateConfigManager::BuildUpdateList()
{
// Build pathname to "update.config" and open file
+ xptr<char> config_path;
- char ConfigFilePath[PATH_NAME_MAX];
if (_filename) {
- ink_strlcpy(ConfigFilePath, system_config_directory, sizeof(ConfigFilePath));
- ink_strlcat(ConfigFilePath, "/", sizeof(ConfigFilePath));
- ink_strlcat(ConfigFilePath, _filename, sizeof(ConfigFilePath));
+ config_path = Layout::get()->relative_to(Layout::get()->sysconfdir, _filename);
} else {
return (UpdateConfigList *) NULL;
}
- int fd = open(ConfigFilePath, O_RDONLY);
+ int fd = open(config_path, O_RDONLY);
if (fd < 0) {
Warning("read update.config, open failed");
SignalWarning(MGMT_SIGNAL_CONFIG_ERROR, "read update.config, open failed");
View
27 proxy/http/HttpBodyFactory.cc
@@ -39,6 +39,7 @@
#include <logging/LogAccess.h>
#include <logging/LogAccessHttp.h>
#include "HttpCompat.h"
+#include "I_Layout.h"
//////////////////////////////////////////////////////////////////////
// The HttpBodyFactory creates HTTP response page bodies, supported //
@@ -258,11 +259,9 @@ HttpBodyFactory::reconfigure()
//#endif
{
RecInt e;
- RecString s;
+ RecString s = NULL;
bool all_found;
int rec_err;
- struct stat st;
- int err;
lock();
sanity_check();
@@ -296,27 +295,26 @@ HttpBodyFactory::reconfigure()
all_found = all_found && (rec_err == REC_ERR_OKAY);
Debug("body_factory", "response_suppression_mode = %d (found = %" PRId64")", response_suppression_mode, e);
+ xptr<char> directory_of_template_sets;
+
rec_err = RecGetRecordString_Xmalloc("proxy.config.body_factory.template_sets_dir", &s);
all_found = all_found && (rec_err == REC_ERR_OKAY);
if (rec_err == REC_ERR_OKAY) {
- ats_free(directory_of_template_sets);
- directory_of_template_sets = s;
- if ((err = stat(directory_of_template_sets, &st)) < 0) {
- if ((err = stat(system_config_directory, &st)) < 0) {
- Warning("Unable to stat() directory '%s': %d %d, %s", system_config_directory, err, errno, strerror(errno));
- Warning(" Please set 'proxy.config.body_factory.template_sets_dir' ");
- } else {
- ats_free(directory_of_template_sets);
- directory_of_template_sets = ats_strdup(system_config_directory);
- }
+ directory_of_template_sets = Layout::get()->relative(s);
+ if (access(directory_of_template_sets, R_OK) < 0) {
+ Warning("Unable to access() directory '%s': %d, %s", (const char *)directory_of_template_sets, errno, strerror(errno));
+ Warning(" Please set 'proxy.config.body_factory.template_sets_dir' ");
}
+
}
- Debug("body_factory", "directory_of_template_sets = '%s' (found = %" PRId64")", directory_of_template_sets, e);
+ Debug("body_factory", "directory_of_template_sets = '%s' (found = %s)", (const char *)directory_of_template_sets, s);
+ ats_free(s);
if (!all_found) {
Warning("config changed, but can't fetch all proxy.config.body_factory values");
}
+
/////////////////////////////////////////////
// clear out previous template hash tables //
/////////////////////////////////////////////
@@ -353,7 +351,6 @@ HttpBodyFactory::HttpBodyFactory()
ink_mutex_init(&mutex, "HttpBodyFactory::lock");
table_of_sets = NULL;
- directory_of_template_sets = NULL;
enable_customizations = 0;
enable_logging = true;
callbacks_established = false;
View
1 proxy/http/HttpBodyFactory.h
@@ -227,7 +227,6 @@ class HttpBodyFactory
/////////////////////////////////////
int enable_customizations; // 0:no custom,1:custom,2:language-targeted
bool enable_logging; // the user wants body factory logging
- char *directory_of_template_sets; // root directory for template sets
int response_suppression_mode; // when to suppress responses
////////////////////
View
30 proxy/logging/LogConfig.cc
@@ -1624,29 +1624,25 @@ static char xml_config_buffer[] = "<LogFilter> \
void
LogConfig::read_xml_log_config(int from_memory)
{
- char config_path[PATH_NAME_MAX];
+ xptr<char> config_path;
- if (from_memory) {
- snprintf(config_path, PATH_NAME_MAX, "%s", "from_memory");
- Debug("log", "Reading from memory %s", config_path);
- } else {
+ if (!from_memory) {
if (xml_config_file == NULL) {
Note("No log config file to read");
return;
}
- snprintf(config_path, PATH_NAME_MAX, "%s/%s", system_config_directory, xml_config_file);
- }
+ config_path = Layout::get()->relative_to(Layout::get()->sysconfdir, xml_config_file);
+ }
- Debug("log-config", "Reading log config file %s", config_path);
- Debug("xml", "%s is an XML-based config file", config_path);
-
- InkXmlConfigFile log_config(config_path);
+ InkXmlConfigFile log_config(config_path ? (const char *)config_path : "memory://builtin");
if (!from_memory) {
+ Debug("log-config", "Reading log config file %s", (const char *)config_path);
+ Debug("xml", "%s is an XML-based config file", (const char *)config_path);
if (log_config.parse() < 0) {
- Note("Error parsing log config file %s; ensure that it is XML-based", config_path);
+ Note("Error parsing log config file %s; ensure that it is XML-based", (const char *)config_path);
return;
}
@@ -2231,18 +2227,16 @@ LogConfig::read_xml_log_config(int from_memory)
char **
LogConfig::read_log_hosts_file(size_t * num_hosts)
{
- char config_path[PATH_NAME_MAX];
+ xptr<char> config_path(Layout::get()->relative_to(Layout::get()->sysconfdir, hosts_config_file));
char line[LOG_MAX_FORMAT_LINE];
char **hosts = NULL;
- snprintf(config_path, PATH_NAME_MAX, "%s/%s", system_config_directory, hosts_config_file);
-
- Debug("log-config", "Reading log hosts from %s", config_path);
+ Debug("log-config", "Reading log hosts from %s", (const char *)config_path);
size_t nhosts = 0;
int fd = open(config_path, O_RDONLY);
if (fd < 0) {
- Warning("Traffic Server can't open %s for reading log hosts " "for splitting: %s.", config_path, strerror(errno));
+ Warning("Traffic Server can't open %s for reading log hosts " "for splitting: %s.", (const char *)config_path, strerror(errno));
} else {
//
// First, count the number of hosts in the file
@@ -2261,7 +2255,7 @@ LogConfig::read_log_hosts_file(size_t * num_hosts)
//
if (nhosts) {
if (lseek(fd, 0, SEEK_SET) != 0) {
- Warning("lseek failed on file %s: %s", config_path, strerror(errno));
+ Warning("lseek failed on file %s: %s", (const char *)config_path, strerror(errno));
nhosts = 0;
} else {
hosts = NEW(new char *[nhosts]);
View
4 proxy/logging/LogStandalone.cc
@@ -56,8 +56,6 @@ int remote_management_flag = 0;
int auto_clear_hostdb_flag = 0;
char proxy_name[MAXDNAME + 1] = "unknown";
-char system_config_directory[PATH_NAME_MAX + 1] = "";
-
char error_tags[1024] = "";
char action_tags[1024] = "";
char command_string[512] = "";
@@ -116,8 +114,6 @@ initialize_process_manager()
pmgmt->reconfigure();
- REC_ReadConfigString(system_config_directory, "proxy.config.config_dir", PATH_NAME_MAX);
-
//
// Define version info records
//
View
8 proxy/sac.cc
@@ -46,21 +46,16 @@
#include "DiagsConfig.h"
#include "I_Machine.h"
-int auto_clear_cache_flag = 0;
-
// sac-specific command-line flags
//
-int version_flag = 0;
+static int version_flag = 0;
// command-line argument descriptions
//
-static char configDirectoryType[8] = "S1024";
ArgumentDescription argument_descriptions[] = {
{"version", 'V', "Print Version Id", "T", &version_flag, NULL, NULL},
- {"config_dir", 'c', "Config Directory", configDirectoryType,
- &system_config_directory, NULL, NULL},
#ifdef DEBUG
{"error_tags", 'T', "Colon-Separated Debug Tags", "S1023", &error_tags,
NULL, NULL},
@@ -86,7 +81,6 @@ main(int /* argc ATS_UNUSED */, char *argv[])
Layout::create();
// take care of command-line arguments
//
- snprintf(configDirectoryType, sizeof(configDirectoryType), "S%d", PATH_NAME_MAX - 1);
process_args(argument_descriptions, countof(argument_descriptions), argv);
// check for the version number request

0 comments on commit 67306a7

Please sign in to comment.