Skip to content

Commit

Permalink
TS-2401: Remove system_config_directory
Browse files Browse the repository at this point in the history
Remove all the places the global system_config_directory is used,
replacing it with Layout::get()->sysconfdir where appropriate.
  • Loading branch information
jpeach committed Dec 6, 2013
1 parent f438ab4 commit 67306a7
Show file tree
Hide file tree
Showing 30 changed files with 151 additions and 303 deletions.
7 changes: 0 additions & 7 deletions example/app-template/app-template.cc
Expand Up @@ -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_net_threads = DEFAULT_NUMBER_OF_THREADS;
int system_num_of_udp_threads = DEFAULT_NUMBER_OF_UDP_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; //int system_remote_management_flag = DEFAULT_REMOTE_MANAGEMENT_FLAG;


//Diags *diags = NULL; //Diags *diags = NULL;
Expand Down Expand Up @@ -154,9 +152,6 @@ int main(int argc, char * argv[])
_exit(0); _exit(0);
} }


// Get TS directories
ink_strlcpy(system_config_directory, Layout::get()->sysconfdir, sizeof(system_config_directory));

if (chdir(Layout::get()->prefix) < 0) { 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,"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"); fprintf(stderr," please set correct path in env variable TS_ROOT \n");
Expand Down Expand Up @@ -226,8 +221,6 @@ int main(int argc, char * argv[])
// initialize logging (after event and net processor) // initialize logging (after event and net processor)
//Log::init(system_remote_management_flag ? 0 : Log::NO_REMOTE_MANAGEMENT); //Log::init(system_remote_management_flag ? 0 : Log::NO_REMOTE_MANAGEMENT);


//plugin_init(system_config_directory); // plugin.config

// Create accept continuation // Create accept continuation
MyAccept *a = new MyAccept; MyAccept *a = new MyAccept;
a->accept_port = tsapp_port; a->accept_port = tsapp_port;
Expand Down
11 changes: 10 additions & 1 deletion lib/records/I_RecCore.h
Expand Up @@ -46,9 +46,18 @@ void RecConfigFileInit(void);
int RecConfigFileParse(const char * path, RecConfigEntryCallback handler, bool inc_version); 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 // 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(); 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 // 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. // the overridden value, or the original value. Caller MUST NOT free the result.
const char * RecConfigOverrideFromEnvironment(const char * name, const char * value); const char * RecConfigOverrideFromEnvironment(const char * name, const char * value);
Expand Down
3 changes: 0 additions & 3 deletions lib/records/I_RecDefs.h
Expand Up @@ -175,7 +175,4 @@ typedef int (*RecRawStatSyncCb) (const char *name, RecDataT data_type, RecData *
#define REC_VAR_NAME_DELIMITOR '.' #define REC_VAR_NAME_DELIMITOR '.'
#define REC_VAR_NAME_WILDCARD '*' #define REC_VAR_NAME_WILDCARD '*'


// System Defaults
extern char system_config_directory[PATH_NAME_MAX + 1];

#endif #endif
34 changes: 34 additions & 0 deletions lib/records/RecCore.cc
Expand Up @@ -1070,6 +1070,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) // REC_SignalManager (TS)
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
Expand Down
92 changes: 15 additions & 77 deletions mgmt/FileManager.cc
Expand Up @@ -32,10 +32,6 @@
#include "ExpandingArray.h" #include "ExpandingArray.h"
#include "MgmtSocket.h" #include "MgmtSocket.h"




static const char snapDir[] = "snapshots";

#define DIR_MODE S_IRWXU #define DIR_MODE S_IRWXU
#define FILE_MODE S_IRWXU #define FILE_MODE S_IRWXU


Expand All @@ -56,51 +52,24 @@ const char *SnapshotStrings[] = { "Request Successful\n",


FileManager::FileManager() FileManager::FileManager()
{ {
char configTmp[PATH_NAME_MAX + 1];
int pathLen;

bindings = ink_hash_table_create(InkHashTableKeyType_String); bindings = ink_hash_table_create(InkHashTableKeyType_String);

ink_assert(bindings != NULL); ink_assert(bindings != NULL);


ink_mutex_init(&accessLock, "File Manager Mutex"); ink_mutex_init(&accessLock, "File Manager Mutex");
ink_mutex_init(&cbListLock, "File Changed Callback Mutex"); ink_mutex_init(&cbListLock, "File Changed Callback Mutex");


if (varStrFromName("proxy.config.config_dir", configTmp, sizeof(configTmp)) == false) { xptr<char> snapshotDir(RecConfigReadSnapshotDir());
mgmt_fatal(stderr, 0,
"[FileManager::FileManager] Unable to find configuration directory from proxy.config.config_dir\n"); // Check to see if the directory already exists, if not create it.
}
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
if (access(snapshotDir, F_OK) == -1) { if (access(snapshotDir, F_OK) == -1) {
if (mkdir(snapshotDir, DIR_MODE) < 0) { if (mkdir(snapshotDir, DIR_MODE) < 0) {
// Failed to create the snapshot directory // 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 // FileManager::~FileManager
Expand All @@ -117,11 +86,12 @@ FileManager::~FileManager()
InkHashTableEntry *entry; InkHashTableEntry *entry;
InkHashTableIteratorState iterator_state; InkHashTableIteratorState iterator_state;


// Let other operations finish and do not start any // Let other operations finish and do not start any new ones
// new ones
ink_mutex_acquire(&accessLock); 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()) { for (cb = cblist.pop(); cb != NULL; cb = cblist.pop()) {
delete cb; delete cb;
Expand Down Expand Up @@ -688,45 +658,13 @@ FileManager::copyFile(Rollback * rb, const char *snapPath)
SnapResult SnapResult
FileManager::WalkSnaps(ExpandingArray * snapList) FileManager::WalkSnaps(ExpandingArray * snapList)
{ {

MFresult r; 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); // The original code reset this->managedDir from proxy.config.snapshot_dir at this point. There doesn't appear to be
snapshot_dir = (char *) REC_readString("proxy.config.snapshot_dir", &found); // any need for that, since managedDir is always set in the constructor and should not be changed.
ink_assert(found); ink_release_assert(this->managedDir != NULL);
//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;


ink_mutex_acquire(&accessLock);


r = WalkFiles(snapList); r = WalkFiles(snapList);
//lmgmt->record_data ->setString("proxy.config.snapshot_dir", managedDir); //lmgmt->record_data ->setString("proxy.config.snapshot_dir", managedDir);
Expand Down
1 change: 0 additions & 1 deletion mgmt/FileManager.h
Expand Up @@ -134,7 +134,6 @@ class FileManager:public MultiFile
DLL<callbackListable> cblist; DLL<callbackListable> cblist;
InkHashTable *bindings; InkHashTable *bindings;
//InkHashTable* g_snapshot_directory_ht; //InkHashTable* g_snapshot_directory_ht;
char *snapshotDir;
SnapResult copyFile(Rollback * rb, const char *snapPath); SnapResult copyFile(Rollback * rb, const char *snapPath);
SnapResult readFile(const char *filePath, textBuffer * contents); SnapResult readFile(const char *filePath, textBuffer * contents);
void abortRestore(const char *abortTo); void abortRestore(const char *abortTo);
Expand Down
18 changes: 5 additions & 13 deletions mgmt/LocalManager.cc
Expand Up @@ -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) : BaseManager(), run_proxy(proxy_on)
{ {
bool found; bool found;
Expand Down Expand Up @@ -238,18 +238,10 @@ LocalManager::LocalManager(char * /* mpath ATS_UNUSED */, bool proxy_on)
// Get the default IP binding values. // Get the default IP binding values.
RecHttpLoadIp("proxy.local.incoming_ip_to_bind", m_inbound_ip4, m_inbound_ip6); RecHttpLoadIp("proxy.local.incoming_ip_to_bind", m_inbound_ip4, m_inbound_ip6);


config_path = REC_readString("proxy.config.config_dir", &found); if (access(Layout::get()->sysconfdir, R_OK) == -1) {
char *absolute_config_path = Layout::get()->relative(config_path); mgmt_elog(0, "[LocalManager::LocalManager] unable to access() directory '%s': %d, %s\n",
ats_free(config_path); Layout::get()->sysconfdir, errno, strerror(errno));
if (access(absolute_config_path, R_OK) == -1) { mgmt_fatal(0, "[LocalManager::LocalManager] please set the 'TS_ROOT' environment variable\n");
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 TS_HAS_WCCP #if TS_HAS_WCCP
Expand Down
4 changes: 1 addition & 3 deletions mgmt/LocalManager.h
Expand Up @@ -50,14 +50,13 @@
class LocalManager: public BaseManager class LocalManager: public BaseManager
{ {
public: public:
LocalManager(char *mpath, bool proxy_on); LocalManager(bool proxy_on);


~LocalManager() ~LocalManager()
{ {
delete alarm_keeper; delete alarm_keeper;
delete virt_map; delete virt_map;
delete ccom; delete ccom;
ats_free(config_path);
ats_free(bin_path); ats_free(bin_path);
ats_free(absolute_proxy_binary); ats_free(absolute_proxy_binary);
ats_free(proxy_name); ats_free(proxy_name);
Expand Down Expand Up @@ -125,7 +124,6 @@ class LocalManager: public BaseManager
int process_server_timeout_msecs; int process_server_timeout_msecs;


char pserver_path[PATH_NAME_MAX]; char pserver_path[PATH_NAME_MAX];
char *config_path;
char *bin_path; char *bin_path;
char *absolute_proxy_binary; char *absolute_proxy_binary;
char *proxy_name; char *proxy_name;
Expand Down
18 changes: 6 additions & 12 deletions mgmt/Main.cc
Expand Up @@ -64,6 +64,8 @@
extern "C" int getpwnam_r(const char *name, struct passwd *result, char *buffer, size_t buflen, struct passwd **resptr); extern "C" int getpwnam_r(const char *name, struct passwd *result, char *buffer, size_t buflen, struct passwd **resptr);
#endif #endif


static void extractConfigInfo(char *mgmt_path, const char *recs_conf, char *userName, int *fds_throttle);

LocalManager *lmgmt = NULL; LocalManager *lmgmt = NULL;
FileManager *configFiles; FileManager *configFiles;


Expand All @@ -77,9 +79,6 @@ static char debug_tags[1024] = "";
static char action_tags[1024] = ""; static char action_tags[1024] = "";
static bool proxy_on = true; 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]; char mgmt_path[PATH_NAME_MAX + 1];


// By default, set the current directory as base // By default, set the current directory as base
Expand Down Expand Up @@ -267,18 +266,13 @@ static void
init_dirs() init_dirs()
{ {
xptr<char> rundir(RecConfigReadRuntimeDir()); xptr<char> rundir(RecConfigReadRuntimeDir());
char buf[PATH_NAME_MAX + 1];


REC_ReadConfigString(buf, "proxy.config.config_dir", PATH_NAME_MAX); if (access(Layout::get()->sysconfdir, R_OK) == -1) {
Layout::get()->relative(system_config_directory, PATH_NAME_MAX, buf); mgmt_elog(0, "unable to access() config dir '%s': %d, %s\n", Layout::get()->sysconfdir, errno, strerror(errno));
if (access(system_config_directory, R_OK) == -1) { mgmt_elog(0, "please set the 'TS_ROOT' environment variable\n");
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");
_exit(1); _exit(1);
} }


ink_strlcpy(mgmt_path, system_config_directory, sizeof(mgmt_path));

if (access(rundir, R_OK) == -1) { 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, "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"); mgmt_elog(0, "please set 'proxy.config.local_state_dir'\n");
Expand Down Expand Up @@ -562,7 +556,7 @@ main(int argc, char **argv)
Init_Errata_Logging(); Init_Errata_Logging();
#endif #endif
ts_host_res_global_init(); ts_host_res_global_init();
lmgmt = new LocalManager(mgmt_path, proxy_on); lmgmt = new LocalManager(proxy_on);
RecLocalInitMessage(); RecLocalInitMessage();
lmgmt->initAlarm(); lmgmt->initAlarm();


Expand Down
1 change: 0 additions & 1 deletion mgmt/Main.h
Expand Up @@ -37,7 +37,6 @@
void MgmtShutdown(int status); void MgmtShutdown(int status);
void fileUpdated(char *fname, bool incVersion); void fileUpdated(char *fname, bool incVersion);
void runAsUser(char *userName); void runAsUser(char *userName);
void extractConfigInfo(char *mgmt_path, const char *recs_conf, char *userName, int *fds_throttle);
void printUsage(void); void printUsage(void);


extern FileManager *configFiles; extern FileManager *configFiles;
Expand Down

0 comments on commit 67306a7

Please sign in to comment.