Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 15 additions & 23 deletions cmd/traffic_manager/traffic_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "FileManager.h"
#include "ts/I_Layout.h"
#include "ts/I_Version.h"
#include "ts/TextBuffer.h"
#include "DiagsConfig.h"
#include "HTTP.h"
#include "CoreAPI.h"
Expand Down Expand Up @@ -611,32 +612,23 @@ main(int argc, const char **argv)

/* Update cmd line overrides/environmental overrides/etc */
if (tsArgs) { /* Passed command line args for proxy */
ats_free(lmgmt->proxy_options);
lmgmt->proxy_options = tsArgs;
mgmt_log("[main] Traffic Server Args: '%s'\n", lmgmt->proxy_options);
lmgmt->proxy_options = ats_strdup(tsArgs);
}

// we must pass in bind_stdout and bind_stderr values to TS
// we do it so TS is able to create BaseLogFiles for each value
if (*bind_stdout != 0) {
size_t l = strlen(lmgmt->proxy_options);
size_t n = 3 /* " --" */
+ sizeof(TM_OPT_BIND_STDOUT) /* nul accounted for here */
+ 1 /* space */
+ strlen(bind_stdout);
lmgmt->proxy_options = static_cast<char *>(ats_realloc(lmgmt->proxy_options, n + l));
snprintf(lmgmt->proxy_options + l, n, " --%s %s", TM_OPT_BIND_STDOUT, bind_stdout);
// TS needs to be started up with the same outputlog bindings each time,
// so we append the outputlog location to the persistent proxy options
//
// TS needs them to be able to create BaseLogFiles for each value
textBuffer args(1024);
if (*bind_stdout) {
const char *space = args.empty() ? "" : " ";
args.format("%s%s %s", space, "--" TM_OPT_BIND_STDOUT, bind_stdout);
}

if (*bind_stderr != 0) {
size_t l = strlen(lmgmt->proxy_options);
size_t n = 3 /* space dash dash */
+ sizeof(TM_OPT_BIND_STDERR) /* nul accounted for here */
+ 1 /* space */
+ strlen(bind_stderr);
lmgmt->proxy_options = static_cast<char *>(ats_realloc(lmgmt->proxy_options, n + l));
snprintf(lmgmt->proxy_options + l, n, " --%s %s", TM_OPT_BIND_STDERR, bind_stderr);
if (*bind_stderr) {
const char *space = args.empty() ? "" : " ";
args.format("%s%s %s", space, "--" TM_OPT_BIND_STDERR, bind_stderr);
}
lmgmt->proxy_options = args.release();

if (proxy_port) {
HttpProxyPort::loadValue(lmgmt->m_proxy_ports, proxy_port);
Expand Down Expand Up @@ -813,7 +805,7 @@ main(int argc, const char **argv)
} else {
sleep_time = 1;
}
if (lmgmt->startProxy()) {
if (ProxyStateSet(TS_PROXY_ON, TS_CACHE_CLEAR_NONE) == TS_ERR_OKAY) {
just_started = 0;
sleep_time = 0;
} else {
Expand Down
15 changes: 12 additions & 3 deletions mgmt/LocalManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ LocalManager::LocalManager(bool proxy_on) : BaseManager(), run_proxy(proxy_on),
process_server_timeout_msecs = REC_readInteger("proxy.config.lm.pserver_timeout_msecs", &found);
proxy_name = REC_readString("proxy.config.proxy_name", &found);
proxy_binary = REC_readString("proxy.config.proxy_binary", &found);
proxy_options = REC_readString("proxy.config.proxy_binary_opts", &found);
env_prep = REC_readString("proxy.config.env_prep", &found);
proxy_options = NULL;

// Calculate proxy_binary from the absolute bin_path
absolute_proxy_binary = Layout::relative_to(bindir, proxy_binary);
Expand Down Expand Up @@ -831,9 +831,13 @@ LocalManager::processEventQueue()
/*
* startProxy()
* Function fires up a proxy process.
*
* Args:
* onetime_options: one time options that traffic_server should be started with (ie
* these options do not persist across reboots)
*/
bool
LocalManager::startProxy()
LocalManager::startProxy(const char *onetime_options)
{
if (proxy_launch_outstanding) {
return false;
Expand Down Expand Up @@ -902,8 +906,13 @@ LocalManager::startProxy()
Vec<char> real_proxy_options;

real_proxy_options.append(proxy_options, strlen(proxy_options));
if (onetime_options && *onetime_options) {
real_proxy_options.append(" ", strlen(" "));
real_proxy_options.append(onetime_options, strlen(onetime_options));
}

if (!strstr(proxy_options, MGMT_OPT)) { // Make sure we're starting the proxy in mgmt mode
// Make sure we're starting the proxy in mgmt mode
if (strstr(proxy_options, MGMT_OPT) == 0 && strstr(onetime_options, MGMT_OPT) == 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't you just check real_proxy_options here? If onetime_options aren't already in there, they won't be added anyway.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

real_proxy_options is the mysterious Vec class. AFAICT, I suppose we could, but it would require more allocation.

real_proxy_options.append(" ", strlen(" "));
real_proxy_options.append(MGMT_OPT, sizeof(MGMT_OPT) - 1);
}
Expand Down
4 changes: 2 additions & 2 deletions mgmt/LocalManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class LocalManager : public BaseManager
void signalAlarm(int alarm_id, const char *desc = NULL, const char *ip = NULL);

void processEventQueue();
bool startProxy();
bool startProxy(const char *onetime_options);
void listenForProxy();
void bindProxyPort(HttpProxyPort &);
void closeProxyPorts();
Expand Down Expand Up @@ -108,7 +108,7 @@ class LocalManager : public BaseManager
char *absolute_proxy_binary;
char *proxy_name;
char *proxy_binary;
char *proxy_options;
char *proxy_options; // These options should persist across proxy reboots
char *env_prep;

int process_server_sockfd;
Expand Down
15 changes: 3 additions & 12 deletions mgmt/api/CoreAPI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ ProxyStateGet()
TSMgmtError
ProxyStateSet(TSProxyStateT state, TSCacheClearT clear)
{
int i = 0;
char tsArgs[MAX_BUF_SIZE];
char *proxy_options;

Expand Down Expand Up @@ -184,24 +183,16 @@ ProxyStateSet(TSProxyStateT state, TSCacheClearT clear)
ink_strlcat(tsArgs, " -k", sizeof(tsArgs));
}

if (strlen(tsArgs) > 0) { /* Passed command line args for proxy */
ats_free(lmgmt->proxy_options);
lmgmt->proxy_options = ats_strdup(tsArgs);
mgmt_log("[ProxyStateSet] Traffic Server Args: '%s'\n", lmgmt->proxy_options);
}
mgmt_log("[ProxyStateSet] Traffic Server Args: '%s %s'\n", lmgmt->proxy_options ? lmgmt->proxy_options : "", tsArgs);

lmgmt->run_proxy = true;
lmgmt->listenForProxy();

do {
mgmt_sleep_sec(1);
} while (i++ < 20 && (lmgmt->proxy_running == 0));

if (!lmgmt->processRunning()) {
if (!lmgmt->startProxy(tsArgs)) {
goto Lerror;
}

break;

default:
goto Lerror;
}
Expand Down