trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zw...@apache.org
Subject svn commit: r1060575 - in /trafficserver/traffic/trunk: lib/ts/ proxy/config/ proxy/mgmt/ proxy/mgmt/api/ proxy/mgmt/api/include/ proxy/mgmt/api/remote/ proxy/mgmt/cli2/ proxy/mgmt/cop/
Date Tue, 18 Jan 2011 20:53:22 GMT
Author: zwoop
Date: Tue Jan 18 20:53:21 2011
New Revision: 1060575

URL: http://svn.apache.org/viewvc?rev=1060575&view=rev
Log:
TS-638 and TS-640 One CLI to rule them all

Also fixes some potential thread leaks during restarts. This patch
moves traffic_cop over to use the new CLI, in preparation of
retiring mgmt/cli.

Modified:
    trafficserver/traffic/trunk/lib/ts/ink_thread.h
    trafficserver/traffic/trunk/proxy/config/Makefile.am
    trafficserver/traffic/trunk/proxy/mgmt/Makefile.am
    trafficserver/traffic/trunk/proxy/mgmt/api/CoreAPI.cc
    trafficserver/traffic/trunk/proxy/mgmt/api/CoreAPI.h
    trafficserver/traffic/trunk/proxy/mgmt/api/INKMgmtAPI.cc
    trafficserver/traffic/trunk/proxy/mgmt/api/include/INKMgmtAPI.h
    trafficserver/traffic/trunk/proxy/mgmt/api/remote/APITestCliRemote.cc
    trafficserver/traffic/trunk/proxy/mgmt/api/remote/CoreAPIRemote.cc
    trafficserver/traffic/trunk/proxy/mgmt/api/remote/EventRegistration.cc
    trafficserver/traffic/trunk/proxy/mgmt/api/remote/NetworkUtilsRemote.cc
    trafficserver/traffic/trunk/proxy/mgmt/api/remote/NetworkUtilsRemote.h
    trafficserver/traffic/trunk/proxy/mgmt/cli2/cliMain.cc
    trafficserver/traffic/trunk/proxy/mgmt/cop/Makefile.am
    trafficserver/traffic/trunk/proxy/mgmt/cop/TrafficCop.cc

Modified: trafficserver/traffic/trunk/lib/ts/ink_thread.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/lib/ts/ink_thread.h?rev=1060575&r1=1060574&r2=1060575&view=diff
==============================================================================
--- trafficserver/traffic/trunk/lib/ts/ink_thread.h (original)
+++ trafficserver/traffic/trunk/lib/ts/ink_thread.h Tue Jan 18 20:53:21 2011
@@ -106,7 +106,6 @@ ink_thread_create(void *(*f) (void *), v
 {
   ink_thread t;
   int ret;
-
   pthread_attr_t attr;
 
   pthread_attr_init(&attr);

Modified: trafficserver/traffic/trunk/proxy/config/Makefile.am
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/config/Makefile.am?rev=1060575&r1=1060574&r2=1060575&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/config/Makefile.am (original)
+++ trafficserver/traffic/trunk/proxy/config/Makefile.am Tue Jan 18 20:53:21 2011
@@ -55,4 +55,4 @@ dist_sysconf_DATA =	\
 
 if BUILD_WEBUI
   dist_sysconf_DATA += $(webui_conf)
-endif
\ No newline at end of file
+endif

Modified: trafficserver/traffic/trunk/proxy/mgmt/Makefile.am
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt/Makefile.am?rev=1060575&r1=1060574&r2=1060575&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt/Makefile.am (original)
+++ trafficserver/traffic/trunk/proxy/mgmt/Makefile.am Tue Jan 18 20:53:21 2011
@@ -18,9 +18,9 @@
 #  limitations under the License.
 
 if BUILD_WEBUI
-SUBDIRS = cli cluster cop preparse tools utils web2 html2 stats api $(CLI_DIR)
+SUBDIRS = cli cluster preparse tools utils web2 html2 stats api cop $(CLI_DIR)
 else
-SUBDIRS = cli cluster cop preparse tools utils web2 stats api $(CLI_DIR)
+SUBDIRS = cli cluster preparse tools utils web2 stats api cop $(CLI_DIR)
 endif
 
 DIST_SUBDIRS = $(SUBDIRS)

Modified: trafficserver/traffic/trunk/proxy/mgmt/api/CoreAPI.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt/api/CoreAPI.cc?rev=1060575&r1=1060574&r2=1060575&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt/api/CoreAPI.cc (original)
+++ trafficserver/traffic/trunk/proxy/mgmt/api/CoreAPI.cc Tue Jan 18 20:53:21 2011
@@ -58,13 +58,17 @@ CallbackTable *local_event_callbacks;
  * eg. set up global structures; called by the INKMgmtAPI::INKInit()
  */
 INKError
-Init(const char *socket_path)
+Init(const char *socket_path, TSInitOptionT options)
 {
   NOWARN_UNUSED(socket_path);
   // socket_path should be null; only applies to remote clients
-  local_event_callbacks = create_callback_table("local_callbacks");
-  if (!local_event_callbacks)
-    return INK_ERR_SYS_CALL;
+  if (0 == (options & TS_MGMT_OPT_NO_EVENTS)) {
+    local_event_callbacks = create_callback_table("local_callbacks");
+    if (!local_event_callbacks)
+      return INK_ERR_SYS_CALL;
+  } else {
+    local_event_callbacks = NULL;
+  }
 
   return INK_ERR_OKAY;
 }

Modified: trafficserver/traffic/trunk/proxy/mgmt/api/CoreAPI.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt/api/CoreAPI.h?rev=1060575&r1=1060574&r2=1060575&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt/api/CoreAPI.h (original)
+++ trafficserver/traffic/trunk/proxy/mgmt/api/CoreAPI.h Tue Jan 18 20:53:21 2011
@@ -40,7 +40,7 @@ extern "C"
 {
 #endif /* __cplusplus */
 
-INKError Init(const char *socket_path = NULL);
+INKError Init(const char *socket_path = NULL, TSInitOptionT options = TS_MGMT_OPT_DEFAULTS);
 INKError Terminate();
 
 void Diags(INKDiagsT mode, const char *fmt, va_list ap);

Modified: trafficserver/traffic/trunk/proxy/mgmt/api/INKMgmtAPI.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt/api/INKMgmtAPI.cc?rev=1060575&r1=1060574&r2=1060575&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt/api/INKMgmtAPI.cc (original)
+++ trafficserver/traffic/trunk/proxy/mgmt/api/INKMgmtAPI.cc Tue Jan 18 20:53:21 2011
@@ -1913,9 +1913,9 @@ INKRecordSetMlt(INKList rec_list, INKAct
 
 /*--- api initialization and shutdown -------------------------------------*/
 inkapi INKError
-INKInit(const char *socket_path)
+INKInit(const char *socket_path, TSInitOptionT options)
 {
-  return Init(socket_path);
+  return Init(socket_path, options);
 }
 
 inkapi INKError

Modified: trafficserver/traffic/trunk/proxy/mgmt/api/include/INKMgmtAPI.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt/api/include/INKMgmtAPI.h?rev=1060575&r1=1060574&r2=1060575&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt/api/include/INKMgmtAPI.h (original)
+++ trafficserver/traffic/trunk/proxy/mgmt/api/include/INKMgmtAPI.h Tue Jan 18 20:53:21 2011
@@ -202,15 +202,6 @@ extern "C"
   } INKDiagsT;
 
 /*--- event operations ----------------------------------------------------*/
-/*
-typedef enum
-{
-  INK_EVENT_TYPE_PREDEFINED,
-  INK_EVENT_TYPE_CONDITIONAL,
-  INK_EVENT_TYPE_UNDEFINED
-} INKEventTypeT;
-*/
-
   typedef enum
   {
     INK_EVENT_PRIORITY_WARNING,
@@ -316,6 +307,7 @@ typedef enum
     INK_LOG_MODE_UNDEFINED
   } INKLogModeT;
 
+  /* TODO: This should be removed */
   typedef enum                  /* access privileges to news articles cached by Traffic Server
 */
   {
     INK_MGMT_ALLOW_ALLOW,
@@ -456,6 +448,14 @@ typedef enum
     INK_TYPE_COMMENT            /* for internal use only */
   } INKRuleTypeT;
 
+  /* These are initialization options for the Init() function. */
+  typedef enum
+  {
+    TS_MGMT_OPT_DEFAULTS = 0,
+    TS_MGMT_OPT_NO_EVENTS,      /* No event callbacks and threads */
+    TS_MGMT_OPT_NO_SOCK_TESTS  /* No socket test thread */
+  } TSInitOptionT;
+
 
 /***************************************************************************
  * Structures
@@ -983,12 +983,13 @@ typedef enum
  * Input: socket_path - not applicable for local clients
  *                      for remote users, the path to the config directory
  *         (eg. run from bin, socket_path = "../etc/trafficserver")
+ *        options - Control some features of the APIs
  * Output: INK_ERR_xx
  * Note: If remote client successfully connects, returns INK_ERR_OKAY; but
  *       even if not successful connection (eg. client program is started
  *       before TM) then can still make API calls and will try connecting then
  */
-  inkapi INKError INKInit(const char *socket_path);
+  inkapi INKError INKInit(const char *socket_path, TSInitOptionT options );
 
 /* INKTerminate: does clean up for API clients
  * Input: <none>

Modified: trafficserver/traffic/trunk/proxy/mgmt/api/remote/APITestCliRemote.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt/api/remote/APITestCliRemote.cc?rev=1060575&r1=1060574&r2=1060575&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt/api/remote/APITestCliRemote.cc (original)
+++ trafficserver/traffic/trunk/proxy/mgmt/api/remote/APITestCliRemote.cc Tue Jan 18 20:53:21
2011
@@ -2551,30 +2551,14 @@ 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
-  // XXX: This was ../etc/trafficserver/
-  if ((ret = INKInit(Layout::get()->runtimedir)) != INK_ERR_OKAY)
-#else
-  // XXX: This was even more wired; ../../../../etc/trafficserver/
-  if ((ret = INKInit(Layout::get()->runtimedir)) != INK_ERR_OKAY)
-#endif
-  {
+  if ((ret = INKInit(Layout::get()->runtimedir, TS_MGMT_OPT_DEFAULTS)) == INK_ERR_OKAY)
{
+    runInteractive();
+    INKTerminate();
+    printf("END REMOTE API TEST\n");
+  } else {
     print_err("main", ret);
-
-    //return -1;
   }
-  // Interactive mode
-  runInteractive();
-
-  // clean-up
-  INKTerminate();               //ERROR:Causes infinite!!
-  printf("END REMOTE API TEST\n");
 
   return 0;
 }                               // end main()

Modified: trafficserver/traffic/trunk/proxy/mgmt/api/remote/CoreAPIRemote.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt/api/remote/CoreAPIRemote.cc?rev=1060575&r1=1060574&r2=1060575&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt/api/remote/CoreAPIRemote.cc (original)
+++ trafficserver/traffic/trunk/proxy/mgmt/api/remote/CoreAPIRemote.cc Tue Jan 18 20:53:21
2011
@@ -64,7 +64,9 @@ bool start_binary(const char *abs_bin_pa
 // global variables
 // need to store the thread id associated with socket_test_thread
 // in case we want to  explicitly stop/cancel the testing thread
-ink_thread ink_test_thread;
+ink_thread ts_test_thread;
+ink_thread ts_event_thread;
+TSInitOptionT ts_init_options;
 
 /***************************************************************************
  * Helper Functions
@@ -132,7 +134,6 @@ send_and_parse_list(OpType op, LLQ * lis
 
   if (list_str)
     xfree(list_str);
-
   return INK_ERR_OKAY;
 }
 
@@ -229,24 +230,13 @@ start_binary(const char *abs_bin_path)
 /***************************************************************************
  * SetUp Operations
  ***************************************************************************/
-
-// signal handler for SIGUSR1 - sent when cancelling the socket-test-thread
-// Doesn't really need to do anything since it's currently only called when
-// terminating the remote client api, so everything should close anyways
-void
-terminate_signal(int sig)
-{
-  NOWARN_UNUSED(sig);
-  //fprintf(stderr, "[terminate_signal] received SIGUSR1 signal\n");
-  return;
-}
-
-
 INKError
-Init(const char *socket_path)
+Init(const char *socket_path, TSInitOptionT options)
 {
   INKError err = INK_ERR_OKAY;
 
+  ts_init_options = options;
+
   // SOCKET setup
   ink_assert(socket_path);
   if (!socket_path)
@@ -257,12 +247,15 @@ Init(const char *socket_path)
 
   // need to ignore SIGPIPE signal; in the case that TM is restarted
   signal(SIGPIPE, SIG_IGN);
-  signal(SIGUSR1, terminate_signal);    // for cancelling socket_test_thread
 
   // EVENT setup - initialize callback queue
-  remote_event_callbacks = create_callback_table("remote_callbacks");
-  if (!remote_event_callbacks)
-    return INK_ERR_SYS_CALL;
+  if (0 == (ts_init_options & TS_MGMT_OPT_NO_EVENTS)) {
+    remote_event_callbacks = create_callback_table("remote_callbacks");
+    if (!remote_event_callbacks)
+      return INK_ERR_SYS_CALL;
+  } else {
+    remote_event_callbacks = NULL;
+  }
 
   // try to connect to traffic manager
   // do this last so that everything else on client side is set up even if
@@ -273,13 +266,22 @@ Init(const char *socket_path)
     goto END;
 
   // if connected, create event thread that listens for events from TM
-  ink_thread_create(event_poll_thread_main, &event_socket_fd);
+  if (0 == (ts_init_options & TS_MGMT_OPT_NO_EVENTS)) {
+    ts_event_thread = ink_thread_create(event_poll_thread_main, &event_socket_fd, 0,
DEFAULT_STACK_SIZE);
+  } else {
+    ts_event_thread = static_cast<ink_thread>(NULL);
+  }
 
 END:
 
   // create thread that periodically checks the socket connection
   // with TM alive - reconnects if not alive
-  ink_test_thread = ink_thread_create(socket_test_thread, NULL);
+  if (0 == (ts_init_options & TS_MGMT_OPT_NO_SOCK_TESTS)) {
+    ts_test_thread = ink_thread_create(socket_test_thread, NULL, 0, DEFAULT_STACK_SIZE);
+  } else {
+    ts_test_thread = static_cast<ink_thread>(NULL);
+  }
+
   return err;
 
 }
@@ -290,7 +292,8 @@ Terminate()
 {
   INKError err;
 
-  delete_callback_table(remote_event_callbacks);
+  if (remote_event_callbacks)
+    delete_callback_table(remote_event_callbacks);
 
   // be sure to do this before reset socket_fd's
   err = disconnect();
@@ -303,8 +306,13 @@ Terminate()
   // will seg fault if the socket paths are NULL while it is connecting;
   // the thread will be cancelled at a cancellation point in the
   // socket_test_thread, eg. sleep
-  ink_thread_cancel(ink_test_thread);
+  if (ts_test_thread)
+    ink_thread_cancel(ts_test_thread);
+  if (ts_event_thread)
+    ink_thread_cancel(ts_event_thread);
 
+  ts_test_thread = static_cast<ink_thread>(NULL);
+  ts_event_thread = static_cast<ink_thread>(NULL);
   set_socket_paths(NULL);       // clear the socket_path
 
   return INK_ERR_OKAY;
@@ -412,10 +420,8 @@ HardRestart()
   // determine the path of where start and stop TS scripts stored
   INKDiags(INK_DIAG_NOTE, "Root Directory: %s", Layout::get()->bindir);
 
-  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");
+  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);
@@ -708,6 +714,8 @@ EventSignalCbRegister(char *event_name, 
 
   if (func == NULL)
     return INK_ERR_PARAMS;
+  if (!remote_event_callbacks)
+    return INK_ERR_FAIL;
 
   err = cb_table_register(remote_event_callbacks, event_name, func, data, &first_time);
   if (err != INK_ERR_OKAY)
@@ -742,6 +750,9 @@ EventSignalCbUnregister(char *event_name
 {
   INKError err;
 
+  if (!remote_event_callbacks)
+    return INK_ERR_FAIL;
+
   // remove the callback function from the table
   err = cb_table_unregister(remote_event_callbacks, event_name, func);
   if (err != INK_ERR_OKAY)

Modified: trafficserver/traffic/trunk/proxy/mgmt/api/remote/EventRegistration.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt/api/remote/EventRegistration.cc?rev=1060575&r1=1060574&r2=1060575&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt/api/remote/EventRegistration.cc (original)
+++ trafficserver/traffic/trunk/proxy/mgmt/api/remote/EventRegistration.cc Tue Jan 18 20:53:21
2011
@@ -76,38 +76,32 @@ event_poll_thread_main(void *arg)
 {
   INKError err;
   int sock_fd;
-  INKEvent *event_notice;
+  INKEvent *event_notice = NULL;
 
   sock_fd = *((int *) arg);     // should be same as event_socket_fd
 
-  // Not use here.
-  //fd_set selectFDs;
-  //struct timeval timeout;
-
   // the sock_fd is going to be the one we listen for events on
   while (1) {
-
     // possible sock_fd is invalid if TM restarts and client reconnects
     if (sock_fd < 0) {
-      //fprintf(stderr, "[event_poll_thread_main] EXIT: invalid socket %d\n", sock_fd);
-      return NULL;              // exit thread
+      break;
     }
+
     // read the entire message, so create INKEvent for the callback
     event_notice = INKEventCreate();
     err = parse_event_notification(sock_fd, event_notice);
     if (err == INK_ERR_NET_READ || err == INK_ERR_NET_EOF) {
-      goto END;                 // socket connection error; kill the thread!
+      break;
     } else if (err != INK_ERR_OKAY) {
       INKEventDestroy(event_notice);
       continue;                 // skip the message
     }
     // got event notice; spawn new thread to handle the event's callback functions
-    ink_thread_create(event_callback_thread, (void *) event_notice);
-
-  }                             // end while(1)
+    ink_thread_create(event_callback_thread, (void *) event_notice, 0, DEFAULT_STACK_SIZE);
+  }
 
-END:
-  INKEventDestroy(event_notice);
+  if (event_notice)
+    INKEventDestroy(event_notice);
   ink_thread_exit(NULL);
   return NULL;
 }
@@ -134,20 +128,19 @@ event_callback_thread(void *arg)
 
   func_q = create_queue();
   if (!func_q) {
+    if (event_notice)
+      INKEventDestroy(event_notice);
     return NULL;
   }
+
   // obtain lock
   ink_mutex_acquire(&remote_event_callbacks->event_callback_lock);
 
   INKEventSignalFunc cb;
 
   // check if we have functions to call
-  if (remote_event_callbacks->event_callback_l[index] &&
-      (!queue_is_empty(remote_event_callbacks->event_callback_l[index]))) {
-
-    int queue_depth;
-
-    queue_depth = queue_len(remote_event_callbacks->event_callback_l[index]);
+  if (remote_event_callbacks->event_callback_l[index] && (!queue_is_empty(remote_event_callbacks->event_callback_l[index])))
{
+    int queue_depth = queue_len(remote_event_callbacks->event_callback_l[index]);
 
     for (int i = 0; i < queue_depth; i++) {
       event_cb = (EventCallbackT *) dequeue(remote_event_callbacks->event_callback_l[index]);

Modified: trafficserver/traffic/trunk/proxy/mgmt/api/remote/NetworkUtilsRemote.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt/api/remote/NetworkUtilsRemote.cc?rev=1060575&r1=1060574&r2=1060575&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt/api/remote/NetworkUtilsRemote.cc (original)
+++ trafficserver/traffic/trunk/proxy/mgmt/api/remote/NetworkUtilsRemote.cc Tue Jan 18 20:53:21
2011
@@ -51,6 +51,12 @@ int event_socket_fd = -1;
 char *main_socket_path = NULL;  // "<path>/mgmtapisocket"
 char *event_socket_path = NULL; // "<path>/eventapisocket"
 
+// From CoreAPIRemote.cc
+extern ink_thread ts_test_thread;
+extern ink_thread ts_event_thread;
+extern TSInitOptionT ts_init_options;
+
+
 /**********************************************************************
  * Socket Helper Functions
  **********************************************************************/
@@ -113,7 +119,6 @@ socket_test(int fd)
 
       return -1;
     }
-
     amount_read += ret;
   }
 
@@ -261,12 +266,17 @@ reconnect()
     return err;
 
   // relaunch a new event thread since socket_fd changed
-  ink_thread_create(event_poll_thread_main, &(event_socket_fd));
-
-  // reregister the callbacks on the TM side for this new client connection
-  err = send_register_all_callbacks(event_socket_fd, remote_event_callbacks);
-  if (err != INK_ERR_OKAY)      // problem establishing connection
-    return err;
+  if (0 == (ts_init_options & TS_MGMT_OPT_NO_EVENTS)) {
+    ts_event_thread = ink_thread_create(event_poll_thread_main, &event_socket_fd, 0,
DEFAULT_STACK_SIZE);
+    // reregister the callbacks on the TM side for this new client connection
+    if (remote_event_callbacks) {
+      err = send_register_all_callbacks(event_socket_fd, remote_event_callbacks);
+      if (err != INK_ERR_OKAY)      // problem establishing connection
+        return err;
+    }
+  } else {
+    ts_event_thread = static_cast<ink_thread>(NULL);
+  }
 
   return INK_ERR_OKAY;
 }

Modified: trafficserver/traffic/trunk/proxy/mgmt/api/remote/NetworkUtilsRemote.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt/api/remote/NetworkUtilsRemote.h?rev=1060575&r1=1060574&r2=1060575&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt/api/remote/NetworkUtilsRemote.h (original)
+++ trafficserver/traffic/trunk/proxy/mgmt/api/remote/NetworkUtilsRemote.h Tue Jan 18 20:53:21
2011
@@ -47,6 +47,8 @@ extern "C"
 {
 #endif /* __cplusplus */
 
+const int DEFAULT_STACK_SIZE = 1048576; // 1MB stack
+
 /**********************************************************************
  * Socket Helper Functions
  **********************************************************************/

Modified: trafficserver/traffic/trunk/proxy/mgmt/cli2/cliMain.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt/cli2/cliMain.cc?rev=1060575&r1=1060574&r2=1060575&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt/cli2/cliMain.cc (original)
+++ trafficserver/traffic/trunk/proxy/mgmt/cli2/cliMain.cc Tue Jan 18 20:53:21 2011
@@ -79,7 +79,7 @@ main(int argc, char *argv[])
   CliDisplayPrintf = 1;
 
   // initialize MgmtAPI using TS runtime directory
-  status = INKInit(Layout::get()->runtimedir);
+  status = INKInit(Layout::get()->runtimedir, TS_MGMT_OPT_DEFAULTS);
   if (status) {
     printf("INKInit %d: Failed to initialize MgmtAPI in %s\n",
            status, Layout::get()->runtimedir);

Modified: trafficserver/traffic/trunk/proxy/mgmt/cop/Makefile.am
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt/cop/Makefile.am?rev=1060575&r1=1060574&r2=1060575&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt/cop/Makefile.am (original)
+++ trafficserver/traffic/trunk/proxy/mgmt/cop/Makefile.am Tue Jan 18 20:53:21 2011
@@ -21,8 +21,8 @@ AM_CPPFLAGS = $(iocore_include_dirs) \
   -I$(top_srcdir)/lib/records \
   -I$(top_srcdir)/proxy/mgmt \
   -I$(top_srcdir)/proxy/mgmt/utils \
-  -I$(top_srcdir)/proxy/mgmt/cli \
-  -I$(top_srcdir)/proxy/mgmt/cluster
+  -I$(top_srcdir)/proxy/mgmt/cluster \
+  -I$(top_srcdir)/proxy/mgmt/api/include
 
 MGMT_DEFS = @MGMT_DEFS@
 DEFS += $(MGMT_DEFS)
@@ -32,9 +32,7 @@ bin_PROGRAMS = traffic_cop
 traffic_cop_SOURCES = TrafficCop.cc
 traffic_cop_LDFLAGS = @EXTRA_CXX_LDFLAGS@
 traffic_cop_LDADD = \
-  $(top_builddir)/proxy/mgmt/cli/libcli_tl.a \
-  $(top_builddir)/lib/ts/libts.a \
+  $(top_builddir)/proxy/mgmt/api/remote/libmgmtapiremote.a \
   $(top_builddir)/iocore/utils/libinkutils.a \
-  @LIBTCL@ \
-  @LIBSOCKET@ @LIBNSL@ @LIBRESOLV@ \
-  @LIBTHREAD@ @LIBDL@ @LIBRT@ @LIBICONV@ @LIBEXECINFO@
+  $(top_builddir)/lib/ts/libts.a \
+  @LIBTHREAD@ @LIBSOCKET@ @LIBTCL@ @LIBRT@ @LIBDL@ @LIBSSL@ 

Modified: trafficserver/traffic/trunk/proxy/mgmt/cop/TrafficCop.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/mgmt/cop/TrafficCop.cc?rev=1060575&r1=1060574&r2=1060575&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/mgmt/cop/TrafficCop.cc (original)
+++ trafficserver/traffic/trunk/proxy/mgmt/cop/TrafficCop.cc Tue Jan 18 20:53:21 2011
@@ -24,7 +24,7 @@
 #include "libts.h"
 #include "I_Layout.h"
 #include "I_Version.h"
-#include "clientCLI.h"
+#include "INKMgmtAPI.h"
 #include "ClusterCom.h"
 
 #if defined(linux)
@@ -1145,24 +1145,16 @@ read_manager_int(const char *variable, i
 }
 
 static int
-read_cli_int(ClientCLI *cli, const char *variable, int *value)
+read_mgmt_cli_int(const char *variable, int *value)
 {
-  char *resp = NULL;
-  int ret = 0;
+  INKInt val;
 
-  if (cli->connectToLM() != ClientCLI::err_none)
+  if (INKRecordGetInt(variable, &val) != INK_ERR_OKAY) {
+    cop_log(COP_WARNING, "(cli test) could not communicate with mgmt cli\n");
     return -1;
-
-  if ((cli->getVariable(variable, &resp) == ClientCLI::err_none) && resp)
{
-    *value = ink_atoi(resp);
-    xfree(resp);
-  } else {
-    ret = -1;
-    cop_log(COP_WARNING, "(cli test) could not communicate with cli\n");
   }
-
-  cli->disconnectFromLM();
-  return ret;
+  *value = val;
+  return 0;
 }
 
 
@@ -1187,25 +1179,22 @@ test_rs_port()
 
 
 static int
-test_cli_port(ClientCLI *cli)
+test_mgmt_cli_port()
 {
-  char *resp = NULL;
+  INKString val;
   int ret = 0;
 
-  if (cli->connectToLM() != ClientCLI::err_none)
-    return -1;
-
-  if ((cli->getVariable("proxy.config.manager_binary", &resp) == ClientCLI::err_none)
&& resp) {
-    if (strcmp(resp, manager_binary) != 0) {
-      cop_log(COP_WARNING, "(cli test) bad response value, got %s, expected %s\n", resp,
manager_binary);
+  if (INKRecordGetString("proxy.config.manager_binary", &val) !=  INK_ERR_OKAY) {
+    cop_log(COP_WARNING, "(cli test) unable to retrieve manager_binary\n");
+    ret = -1;
+  } else {
+    if (strcmp(val, manager_binary) != 0) {
+      cop_log(COP_WARNING, "(cli test) bad response value, got %s, expected %s\n", val, manager_binary);
       ret = -1;
     }
-    xfree(resp);
-  } else {
-    ret = -1;
   }
 
-  cli->disconnectFromLM();
+  INKfree(val);
   return ret;
 }
 
@@ -1299,7 +1288,7 @@ test_manager_http_port()
 
 
 static int
-heartbeat_manager(ClientCLI *cli)
+heartbeat_manager()
 {
   int err;
 
@@ -1307,7 +1296,7 @@ heartbeat_manager(ClientCLI *cli)
   cop_log(COP_DEBUG, "Entering heartbeat_manager()\n");
 #endif
   // the CLI, and the rsport if cluster is enabled.
-  err = test_cli_port(cli);
+  err = test_mgmt_cli_port();
   if ((0 == err) && (cluster_type != NO_CLUSTER))
     err = test_rs_port();
 
@@ -1406,7 +1395,7 @@ heartbeat_server()
 }
 
 static int
-server_up(ClientCLI *cli)
+server_up()
 {
   static int old_val = 0;
   int val = -1;
@@ -1425,8 +1414,7 @@ server_up(ClientCLI *cli)
       return 0;
     }
   } else {
-    err = read_cli_int(cli, "proxy.node.proxy_running", &val);
-    printf("GOT %d\n", val);
+    err = read_mgmt_cli_int("proxy.node.proxy_running", &val);
     if (err < 0) {
       cop_log(COP_WARNING, "could not contact manager, " "assuming server is down\n");
 #ifdef TRACE_LOG_COP
@@ -1472,7 +1460,7 @@ server_up(ClientCLI *cli)
 
 
 static void
-check_programs(ClientCLI *cli)
+check_programs()
 {
   int err;
   pid_t holding_pid;
@@ -1565,14 +1553,14 @@ check_programs(ClientCLI *cli)
     // running. If there is we test it.
 
     alarm(2 * manager_timeout);
-    err = heartbeat_manager(cli);
+    err = heartbeat_manager();
     alarm(0);
 
     if (err < 0) {
       return;
     }
 
-    if (server_up(cli) <= 0) {
+    if (server_up() <= 0) {
       return;
     }
 
@@ -1690,24 +1678,17 @@ check_no_run()
   return -1;
 }
 
-// 3/23/99 - elam
-//
 // Changed function from taking no argument and returning void
 // to taking a void* and returning a void*. The change was made
 // so that we can call ink_thread_create() on this function
 // in the case of running cop as a win32 service.
-static void *
+static void*
 check(void *arg)
 {
+  bool mgmt_init = false;
 #ifdef TRACE_LOG_COP
   cop_log(COP_DEBUG, "Entering check()\n");
 #endif
-  // Get a CLI
-  char sock_path[PATH_NAME_MAX + 1];
-  ClientCLI *cli = new ClientCLI();
-
-  Layout::relative_to(sock_path, sizeof(sock_path), Layout::get()->runtimedir, ClientCLI::defaultSockPath);
-  cli->setSockPath(sock_path);
 
   for (;;) {
     // problems with the ownership of this file as root Make sure it is
@@ -1737,11 +1718,12 @@ check(void *arg)
 
       child_pid = child_status = 0;
     }
+
     // Re-read the config file information
     read_config();
 
     // Check to make sure the programs are running
-    check_programs(cli);
+    check_programs();
 
     // Check to see if we're running out of free memory
     check_memory();
@@ -1750,10 +1732,16 @@ check(void *arg)
     // Use 'millisleep()' because normal 'sleep()' interferes with
     // the SIGALRM signal which we use to heartbeat the cop.
     millisleep(sleep_time * 1000);
+
+    // We do this after the first round of checks, since the first "check" will spawn traffic_manager
+    if (!mgmt_init) {
+      INKInit(Layout::get()->runtimedir, static_cast<TSInitOptionT>(TS_MGMT_OPT_NO_EVENTS
| TS_MGMT_OPT_NO_SOCK_TESTS));
+      mgmt_init = true;
+    }
   }
 
-  // Get rid of the CLI
-  delete cli;
+  // Done with the mgmt API.
+  INKTerminate();
 
 #ifdef TRACE_LOG_COP
   cop_log(COP_DEBUG, "Leaving check()\n");



Mime
View raw message