You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by mt...@apache.org on 2010/05/19 13:31:26 UTC
svn commit: r946129 - in /trafficserver/traffic/trunk/proxy/mgmt2:
api2/INKMgmtAPI.cc api2/Makefile.am api2/remote/APITestCliRemote.cc
api2/remote/CoreAPIRemote.cc api2/remote/Makefile.am
api2/remote/NetworkUtilsRemote.cc cli2/Makefile.am cli2/cliMain.cc
Author: mturk
Date: Wed May 19 11:31:25 2010
New Revision: 946129
URL: http://svn.apache.org/viewvc?rev=946129&view=rev
Log:
TS-345 Cleanup absolue paths and use Layout engine.
Modified:
trafficserver/traffic/trunk/proxy/mgmt2/api2/INKMgmtAPI.cc
trafficserver/traffic/trunk/proxy/mgmt2/api2/Makefile.am
trafficserver/traffic/trunk/proxy/mgmt2/api2/remote/APITestCliRemote.cc
trafficserver/traffic/trunk/proxy/mgmt2/api2/remote/CoreAPIRemote.cc
trafficserver/traffic/trunk/proxy/mgmt2/api2/remote/Makefile.am
trafficserver/traffic/trunk/proxy/mgmt2/api2/remote/NetworkUtilsRemote.cc
trafficserver/traffic/trunk/proxy/mgmt2/cli2/Makefile.am
trafficserver/traffic/trunk/proxy/mgmt2/cli2/cliMain.cc
Modified: trafficserver/traffic/trunk/proxy/mgmt2/api2/INKMgmtAPI.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt2/api2/INKMgmtAPI.cc?rev=946129&r1=946128&r2=946129&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt2/api2/INKMgmtAPI.cc (original)
+++ trafficserver/traffic/trunk/proxy/mgmt2/api2/INKMgmtAPI.cc Wed May 19 11:31:25 2010
@@ -42,13 +42,6 @@
#include "TextBuffer.h"
-// TODO: consolidate location of these defaults
-#define DEFAULT_ROOT_DIRECTORY PREFIX
-#define DEFAULT_LOCAL_STATE_DIRECTORY "var/trafficserver"
-#define DEFAULT_SYSTEM_CONFIG_DIRECTORY "etc/trafficserver"
-#define DEFAULT_LOG_DIRECTORY "var/log/trafficserver"
-#define DEFAULT_TS_DIRECTORY_FILE PREFIX "/etc/traffic_server"
-
// forward declarations
void init_pdss_format(INKPdSsFormat * info);
@@ -2892,35 +2885,17 @@ get_rmserver_path()
char *path = NULL;
#if (HOST_OS == linux)
- FILE *ts_file, *rec_file;
+ FILE *rec_file;
int i = 0, num_args = 0;
char buffer[1024];
char proxy_restart_cmd[1024];
- char ts_base_dir[1024];
char rec_config[1024];
static char *restart_cmd_args[100];
INKString tmp;
INKString tmp2;
- char *env_path;
-
- if ((env_path = getenv("TS_ROOT"))) {
- ink_strncpy(ts_base_dir, env_path, sizeof(ts_base_dir));
- } else {
- if ((ts_file = fopen(DEFAULT_TS_DIRECTORY_FILE, "r")) == NULL) {
- ink_strncpy(ts_base_dir, PREFIX, sizeof(ts_base_dir));
- } else {
- NOWARN_UNUSED_RETURN(fgets(buffer, 1024, ts_file));
- fclose(ts_file);
- while (!isspace(buffer[i])) {
- ts_base_dir[i] = buffer[i];
- i++;
- }
- ts_base_dir[i] = '\0';
- }
- }
-
- snprintf(rec_config, sizeof(rec_config), "%s/etc/trafficserver/records.config", ts_base_dir);
+ Layout::relative_to(rec_config, sizeof(rec_config),
+ Layout::get()->sysconfdir, "records.config");
if ((rec_file = fopen(rec_config, "r")) == NULL) {
//fprintf(stderr, "Error: unable to open %s.\n", rec_config);
return NULL;
@@ -3271,42 +3246,6 @@ inkapi INKError rm_change_hostname(INKSt
return INK_ERR_OKAY;
}
-#if (HOST_OS == linux)
-int
-getTSdirectory(char *ts_path, size_t ts_path_len)
-{
- FILE *fp;
- char *env_path;
-
- if ((env_path = getenv("TS_ROOT"))) {
- ink_strncpy(ts_path, env_path, ts_path_len);
- return 0;
- }
-
- if ((fp = fopen(DEFAULT_TS_DIRECTORY_FILE, "r")) == NULL) {
- ink_strncpy(ts_path, "/usr/local", ts_path_len);
- return 0;
- }
-
- if (fgets(ts_path, ts_path_len, fp) == NULL) {
- fclose(fp);
- return INK_ERR_READ_FILE;
- }
- // strip newline if it exists
- int len = strlen(ts_path);
- if (ts_path[len - 1] == '\n') {
- ts_path[len - 1] = '\0';
- }
- // strip trailing "/" if it exists
- len = strlen(ts_path);
- if (ts_path[len - 1] == '/') {
- ts_path[len - 1] = '\0';
- }
-
- fclose(fp);
- return INK_ERR_OKAY;
-}
-
// close all file descriptors belong to process specified by pid
void
closeAllFds()
@@ -3342,8 +3281,6 @@ closeAllFds()
}
}
-#endif
-
inkapi INKError rm_start_proxy()
{
@@ -3358,13 +3295,9 @@ inkapi INKError rm_start_proxy()
argv[0] = "net_config";
argv[1] = "7";
argv[2] = NULL;
- char command_path[512];
- char ts_path[256];
- if (getTSdirectory(ts_path, sizeof(ts_path))) {
- perror("[rm_start_proxy] unable to determine install directory\n");
- return INK_ERR_READ_FILE;
- }
- snprintf(command_path, sizeof(command_path), "%s/bin/net_config", ts_path);
+ char command_path[PATH_NAME_MAX + 1];
+ Layout::relative_to(command_path, sizeof(command_path),
+ Layout::get()->bindir, "net_config");
rm_last_stop = time(NULL);
Modified: trafficserver/traffic/trunk/proxy/mgmt2/api2/Makefile.am
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt2/api2/Makefile.am?rev=946129&r1=946128&r2=946129&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt2/api2/Makefile.am (original)
+++ trafficserver/traffic/trunk/proxy/mgmt2/api2/Makefile.am Wed May 19 11:31:25 2010
@@ -33,12 +33,7 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/proxy/hdrs \
-I$(top_srcdir)/proxy/mgmt2/api2/include \
-I$(top_srcdir)/proxy/mgmt2/api2 \
- $(iocore_include_dirs) \
- -DPREFIX=\"$(prefix)\" \
- -DPKGLIBEXECDIR=\"$(pkglibexecdir)\" \
- -DPKGLOCALSTATEDIR=\"$(pkglocalstatedir)\" \
- -DPKGLOGDIR=\"$(pkglogdir)\" \
- -DPKGSYSCONFDIR=\"$(pkgsysconfdir)\"
+ $(iocore_include_dirs)
MGMT_DEFS = @MGMT_DEFS@
DEFS += $(MGMT_DEFS)
Modified: trafficserver/traffic/trunk/proxy/mgmt2/api2/remote/APITestCliRemote.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt2/api2/remote/APITestCliRemote.cc?rev=946129&r1=946128&r2=946129&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt2/api2/remote/APITestCliRemote.cc (original)
+++ trafficserver/traffic/trunk/proxy/mgmt2/api2/remote/APITestCliRemote.cc Wed May 19 11:31:25 2010
@@ -100,6 +100,7 @@
#include <stdio.h>
#include <strings.h>
#include "ink_string.h"
+#include "I_Layout.h"
#include "INKMgmtAPI.h"
#include "CfgContextUtils.h"
@@ -2695,10 +2696,17 @@ main(int argc, char **argv)
INKError ret;
// initialize
+ Layout::create();
+ // XXX: What's the INSTALL_TEST?
+ // IMKInit calls setup_socket which
+ // setup unix sockets which live inside
+ // runtimedir not sysconfdir
#if INSTALL_TEST
- if ((ret = INKInit("../etc/trafficserver/")) != INK_ERR_OKAY)
+ // XXX: This was ../etc/trafficserver/
+ if ((ret = INKInit(Layout::get()->runtimedir)) != INK_ERR_OKAY)
#else
- if ((ret = INKInit("../../../../etc/trafficserver/")) != INK_ERR_OKAY)
+ // XXX: This was even more wired; ../../../../etc/trafficserver/
+ if ((ret = INKInit(Layout::get()->runtimedir)) != INK_ERR_OKAY)
#endif
{
print_err("main", ret);
Modified: trafficserver/traffic/trunk/proxy/mgmt2/api2/remote/CoreAPIRemote.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt2/api2/remote/CoreAPIRemote.cc?rev=946129&r1=946128&r2=946129&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt2/api2/remote/CoreAPIRemote.cc (original)
+++ trafficserver/traffic/trunk/proxy/mgmt2/api2/remote/CoreAPIRemote.cc Wed May 19 11:31:25 2010
@@ -49,13 +49,6 @@
#include "EventRegistration.h"
#include "EventCallback.h"
-// TODO: consolidate location of these defaults
-#define DEFAULT_ROOT_DIRECTORY PREFIX
-#define DEFAULT_LOCAL_STATE_DIRECTORY "var/trafficserver"
-#define DEFAULT_SYSTEM_CONFIG_DIRECTORY "etc/trafficserver"
-#define DEFAULT_LOG_DIRECTORY "var/log/trafficserver"
-#define DEFAULT_TS_DIRECTORY_FILE PREFIX "/etc/traffic_server"
-
// extern variables
extern CallbackTable *remote_event_callbacks; // from EventRegistration
extern int main_socket_fd; // from NetworkUtils
@@ -67,7 +60,6 @@ INKError send_and_parse_list(OpType op,
INKError send_and_parse_name(OpType op, char *name);
INKError mgmt_record_set(const char *rec_name, const char *rec_val, INKActionNeedT * action_need);
bool start_binary(const char *abs_bin_path);
-char *get_root_dir();
// global variables
// need to store the thread id associated with socket_test_thread
@@ -233,50 +225,6 @@ start_binary(const char *abs_bin_path)
return true;
}
-/*-------------------------------------------------------------------------
- * get_root_dir
- *-------------------------------------------------------------------------
- * This function retrieves the root directory path from DEFAULT_TS_DIRECTORY_FILE
- * file. If there is no DEFAULT_TS_DIRECTORY_FILE file to be found, returns NULL
- * (copied from TrafficCop.cc). The string returned is NOT ALLOCATED.
- * Used by HardRestart to determine full path of start/stop_traffic_server scripts.
- */
-#ifndef _WIN32
-char *
-get_root_dir()
-{
- FILE *ts_file;
- char buffer[1024];
- int i = 0;
- // Changed this to static, this function is not reentrant ... /leif
- static char root_dir[1024];
- char *env_path;
-
- bzero(root_dir, 1024);
-
- if ((env_path = getenv("TS_ROOT"))) {
- ink_strncpy(root_dir, env_path, sizeof(root_dir));
- return root_dir;
- }
-
- if ((ts_file = fopen(DEFAULT_TS_DIRECTORY_FILE, "r")) != NULL) {
- NOWARN_UNUSED_RETURN(fgets(buffer, 1024, ts_file));
- fclose(ts_file);
- while (!ParseRules::is_space(buffer[i])) {
- root_dir[i] = buffer[i];
- i++;
- }
- root_dir[i] = '\0';
- } else {
- ink_strncpy(root_dir, PREFIX, sizeof(root_dir));
- }
-
- if (root_dir[0] == '\0')
- return NULL;
- else
- return root_dir;
-}
-#endif
/***************************************************************************
* SetUp Operations
@@ -458,18 +406,15 @@ HardRestart()
char start_path[1024];
char stop_path[1024];
- // determine the path of where start and stop TS scripts stored
- char *root_dir = get_root_dir();
- INKDiags(INK_DIAG_NOTE, "Root Directory: %s", root_dir);
- if (!root_dir)
+ if (!Layout::get() || !Layout::get()->bindir)
return INK_ERR_FAIL;
+ // determine the path of where start and stop TS scripts stored
+ INKDiags(INK_DIAG_NOTE, "Root Directory: %s", Layout::get()->bindir);
- bzero(start_path, 1024);
- bzero(stop_path, 1024);
- char *root_copy = xstrdup(root_dir);
- snprintf(start_path, sizeof(start_path), "%s/bin/start_traffic_server", root_copy);
- snprintf(stop_path, sizeof(stop_path), "%s/bin/stop_traffic_server", root_copy);
- xfree(root_copy);
+ Layout::relative_to(start_path, sizeof(start_path),
+ Layout::get()->bindir, "start_traffic_server");
+ Layout::relative_to(stop_path, sizeof(stop_path),
+ Layout::get()->bindir, "stop_traffic_server");
INKDiags(INK_DIAG_NOTE, "[HardRestart] start_path = %s", start_path);
INKDiags(INK_DIAG_NOTE, "[HardRestart] stop_path = %s", stop_path);
Modified: trafficserver/traffic/trunk/proxy/mgmt2/api2/remote/Makefile.am
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt2/api2/remote/Makefile.am?rev=946129&r1=946128&r2=946129&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt2/api2/remote/Makefile.am (original)
+++ trafficserver/traffic/trunk/proxy/mgmt2/api2/remote/Makefile.am Wed May 19 11:31:25 2010
@@ -29,12 +29,7 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/proxy/mgmt2/api2 \
-I$(top_srcdir)/proxy/mgmt2/api2/remote \
-I$(top_srcdir)/proxy/mgmt2/api2/include \
- $(iocore_include_dirs) \
- -DPREFIX=\"$(prefix)\" \
- -DPKGLIBEXECDIR=\"$(pkglibexecdir)\" \
- -DPKGLOCALSTATEDIR=\"$(pkglocalstatedir)\" \
- -DPKGLOGDIR=\"$(pkglogdir)\" \
- -DPKGSYSCONFDIR=\"$(pkgsysconfdir)\"
+ $(iocore_include_dirs)
MGMT_DEFS = @MGMT_DEFS@
DEFS += $(MGMT_DEFS)
@@ -59,7 +54,7 @@ libmgmtapiremote_a_SOURCES = \
traffic_api_cli_remote_SOURCES = APITestCliRemote.cc
traffic_api_cli_remote_LDADD = \
libmgmtapiremote.a \
- $(top_builddir)/libinktomi++/libinktomi++.a \
$(top_builddir)/iocore/utils/libinkutils.a \
+ $(top_builddir)/libinktomi++/libinktomi++.a \
@LIBTHREAD@ @LIBSOCKET@ @LIBNSL@ @LIBRESOLV@ \
@LIBTCL@ @LIBDB@ @LIBRT@ @LIBDL@ @LIBSSL@ @LIBICONV@ @LIBEXECINFO@
Modified: trafficserver/traffic/trunk/proxy/mgmt2/api2/remote/NetworkUtilsRemote.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt2/api2/remote/NetworkUtilsRemote.cc?rev=946129&r1=946128&r2=946129&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt2/api2/remote/NetworkUtilsRemote.cc (original)
+++ trafficserver/traffic/trunk/proxy/mgmt2/api2/remote/NetworkUtilsRemote.cc Wed May 19 11:31:25 2010
@@ -35,6 +35,7 @@
#include "ink_config.h"
#include "ink_sock.h"
#include "ink_string.h"
+#include "I_Layout.h"
#include "NetworkUtilsRemote.h"
#include "CoreAPI.h"
#include "CoreAPIShared.h"
@@ -65,15 +66,8 @@ set_socket_paths(const char *path)
// construct paths based on user input
// form by replacing "mgmtapisocket" with "eventapisocket"
if (path) {
- int api_len = strlen(path) + strlen("mgmtapisocket");
- int event_len = strlen(path) + strlen("eventapisocket");
-
- main_socket_path = (char *) xmalloc(sizeof(char) * (api_len + 1));
- event_socket_path = (char *) xmalloc(sizeof(char) * (event_len + 1));
- snprintf(main_socket_path, (sizeof(char) * (api_len + 1)), "%smgmtapisocket", path);
- snprintf(event_socket_path, (sizeof(char) * (event_len + 1)), "%seventapisocket", path);
- main_socket_path[api_len] = '\0';
- event_socket_path[event_len] = '\0';
+ main_socket_path = Layout::relative_to(path, "mgmtapisocket");
+ event_socket_path = Layout::relative_to(path, "eventapisocket");
} else {
main_socket_path = NULL;
event_socket_path = NULL;
Modified: trafficserver/traffic/trunk/proxy/mgmt2/cli2/Makefile.am
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt2/cli2/Makefile.am?rev=946129&r1=946128&r2=946129&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt2/cli2/Makefile.am (original)
+++ trafficserver/traffic/trunk/proxy/mgmt2/cli2/Makefile.am Wed May 19 11:31:25 2010
@@ -23,6 +23,7 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/proxy/mgmt2/utils \
-I$(top_srcdir)/libinktomi++ \
-I$(top_srcdir)/proxy \
+ -I$(top_srcdir)/proxy/mgmt2/api2/include \
-I$(top_srcdir)/proxy/mgmt2/tools \
$(iocore_include_dirs) \
-DPREFIX=\"$(prefix)\" \
Modified: trafficserver/traffic/trunk/proxy/mgmt2/cli2/cliMain.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt2/cli2/cliMain.cc?rev=946129&r1=946128&r2=946129&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt2/cli2/cliMain.cc (original)
+++ trafficserver/traffic/trunk/proxy/mgmt2/cli2/cliMain.cc Wed May 19 11:31:25 2010
@@ -30,8 +30,8 @@
#include "ink_file.h"
#include "I_Layout.h"
#include "I_Version.h"
-#include <CliMgmtUtils.h>
-#include "../api2/include/INKMgmtAPI.h"
+#include "CliMgmtUtils.h"
+#include "INKMgmtAPI.h"
extern int Tcl_AppInit(Tcl_Interp * interp);
extern int CliDisplayPrintf;
@@ -49,8 +49,8 @@ int version_flag = 0;
int
main(int argc, char *argv[])
{
- char ts_path[512];
- char config_path[512];
+ char root_path[PATH_NAME_MAX + 1];
+ char runtime_path[PATH_NAME_MAX + 1];
INKError status;
// build the application information structure
@@ -81,22 +81,25 @@ main(int argc, char *argv[])
// traffic_shell binary should use printf to display information onscreen
CliDisplayPrintf = 1;
- // initialize MgmtAPI using TS directory specified in DEFAULT_TS_DIRECTORY_FILE
- // or DEFAULT_LOCAL_STATE_DIRECTORY if DEFAULT_TS_DIRECTORY_FILE does not exist
-
- if (GetTSDirectory(ts_path, sizeof(ts_path))) {
- status = INKInit(DEFAULT_LOCAL_STATE_DIRECTORY);
+ // initialize MgmtAPI using TS runtime directory
+ // TODO: This can be simplified
+ if (GetTSDirectory(root_path, sizeof(root_path))) {
+ status = INKInit(Layout::get()->runtimedir);
if (status) {
- printf("INKInit %d: Failed to initialize MgmtAPI in %s\n", status, DEFAULT_LOCAL_STATE_DIRECTORY);
+ printf("INKInit %d: Failed to initialize MgmtAPI in %s\n",
+ status, Layout::get()->runtimedir);
} else {
- printf("Successfully Initialized MgmtAPI in %s \n", DEFAULT_LOCAL_STATE_DIRECTORY);
+ printf("Successfully Initialized MgmtAPI in %s \n",
+ Layout::get()->runtimedir);
}
} else {
- snprintf(config_path, sizeof(config_path), "%s/var/trafficserver/", ts_path);
+ Layout::relative_to(runtime_path, sizeof(runtime_path),
+ root_path, Layout::get()->runtimedir);
// initialize MgmtAPI
- INKError status = INKInit(config_path);
+ INKError status = INKInit(runtime_path);
if (status) {
- printf("INKInit %d: Failed to initialize MgmtAPI in %s\n", status, config_path);
+ printf("INKInit %d: Failed to initialize MgmtAPI in %s\n",
+ status, runtime_path);
}
}