You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by so...@apache.org on 2016/11/02 16:59:57 UTC

[trafficserver] branch 6.2.x updated: TS-3245: Allow multiple plugins to safely use getopt(3).

This is an automated email from the ASF dual-hosted git repository.

sorber pushed a commit to branch 6.2.x
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

The following commit(s) were added to refs/heads/6.2.x by this push:
       new  72b9fdc   TS-3245: Allow multiple plugins to safely use getopt(3).
72b9fdc is described below

commit 72b9fdce011e5ccde2b3a1d48a4b80e0e6055928
Author: Peter Chou <pb...@labs.att.com>
AuthorDate: Mon Jun 6 16:31:43 2016 -0700

    TS-3245: Allow multiple plugins to safely use getopt(3).
    
    Allow multiple global plugins to co-exist in the plugin.config
    file. Also, made the same changes to allow remap plugins
    to co-exist with each other in the remap.config file.
    
    Specifically, on freebsd and darwin platforms we use 'optreset =
    1' to reset the getopt_long() command line parser.  On Linux/glibc
    we use 'optind = 0' to reset the parser.  The parser must be reset
    between uses such as first loading one plugin and then another.
    
    The setting of these variables is now performed in ATS core before
    the plugin initialization functions are called. The setting of these
    variables inside of the individual plugins has been removed. If a
    plugin needs to call getopt_long() outside of the plugin global or
    remap intializations, it should use the code in proxy/Plugin.cc as
    an example.
    
    (cherry picked from commit 590edf6a9c0577b1109d8d061b2b96356b9d4de1)
    
    Conflicts:
    	plugins/experimental/cachekey/configs.cc
    	plugins/experimental/esi/esi.cc
    	plugins/experimental/regex_revalidate/regex_revalidate.c
    	plugins/experimental/remap_stats/remap_stats.c
    	plugins/experimental/stale_while_revalidate/stale_while_revalidate.c
---
 plugins/experimental/acme/acme.c                              |  1 -
 plugins/experimental/authproxy/authproxy.cc                   |  5 -----
 plugins/experimental/background_fetch/background_fetch.cc     |  1 -
 plugins/experimental/balancer/balancer.cc                     |  1 -
 plugins/experimental/cache_promote/cache_promote.cc           |  1 -
 plugins/experimental/cachekey/configs.cc                      |  1 -
 plugins/experimental/esi/esi.cc                               |  4 +---
 plugins/experimental/regex_revalidate/regex_revalidate.c      |  1 -
 plugins/experimental/remap_stats/remap_stats.c                |  1 -
 plugins/experimental/s3_auth/s3_auth.cc                       |  1 -
 plugins/experimental/sslheaders/sslheaders.cc                 |  5 -----
 .../stale_while_revalidate/stale_while_revalidate.c           |  1 -
 plugins/experimental/xdebug/xdebug.cc                         |  2 --
 plugins/stats_over_http/stats_over_http.c                     |  1 -
 plugins/tcpinfo/tcpinfo.cc                                    |  1 -
 proxy/Plugin.cc                                               | 10 ++++++++++
 proxy/http/remap/RemapConfig.cc                               | 11 +++++++++++
 17 files changed, 22 insertions(+), 26 deletions(-)

diff --git a/plugins/experimental/acme/acme.c b/plugins/experimental/acme/acme.c
index ec547e8..c9c7729 100644
--- a/plugins/experimental/acme/acme.c
+++ b/plugins/experimental/acme/acme.c
@@ -307,7 +307,6 @@ TSPluginInit(int argc, const char *argv[])
   };
 
   memset(&gConfig, 0, sizeof(gConfig));
-  optind = 0;
   while (true) {
     int opt = getopt_long(argc, (char *const *)argv, "", longopt, NULL);
 
diff --git a/plugins/experimental/authproxy/authproxy.cc b/plugins/experimental/authproxy/authproxy.cc
index 315ee5c..a99a8fa 100644
--- a/plugins/experimental/authproxy/authproxy.cc
+++ b/plugins/experimental/authproxy/authproxy.cc
@@ -692,11 +692,6 @@ AuthParseOptions(int argc, const char **argv)
 
   options->transform = AuthWriteRedirectedRequest;
 
-  // We might parse arguments multiple times if we are loaded as a global
-  // plugin and a remap plugin. Reset optind so that getopt_long() does the
-  // right thing (ie. work instead of crash).
-  optind = 0;
-
   for (;;) {
     int opt;
 
diff --git a/plugins/experimental/background_fetch/background_fetch.cc b/plugins/experimental/background_fetch/background_fetch.cc
index ccb7995..db69839 100644
--- a/plugins/experimental/background_fetch/background_fetch.cc
+++ b/plugins/experimental/background_fetch/background_fetch.cc
@@ -568,7 +568,6 @@ TSPluginInit(int argc, const char *argv[])
   gConfig = new BgFetchConfig(cont);
   gConfig->acquire(); // Inc refcount, although this global config should never go out of scope
 
-  optind = 1;
   while (true) {
     int opt = getopt_long(argc, (char *const *)argv, "lc", longopt, NULL);
 
diff --git a/plugins/experimental/balancer/balancer.cc b/plugins/experimental/balancer/balancer.cc
index 4d3bee2..5a7b0ed 100644
--- a/plugins/experimental/balancer/balancer.cc
+++ b/plugins/experimental/balancer/balancer.cc
@@ -111,7 +111,6 @@ TSRemapNewInstance(int argc, char *argv[], void **instance, char *errbuf, int er
   argc--;
   argv++;
 
-  optind = 0;
   for (;;) {
     int opt;
 
diff --git a/plugins/experimental/cache_promote/cache_promote.cc b/plugins/experimental/cache_promote/cache_promote.cc
index c35c570..66bca1c 100644
--- a/plugins/experimental/cache_promote/cache_promote.cc
+++ b/plugins/experimental/cache_promote/cache_promote.cc
@@ -349,7 +349,6 @@ public:
   bool
   factory(int argc, char *argv[])
   {
-    optind = 0;
     while (true) {
       int opt = getopt_long(argc, (char *const *)argv, "psbh", longopt, NULL);
 
diff --git a/plugins/experimental/cachekey/configs.cc b/plugins/experimental/cachekey/configs.cc
index e2666e8..544461f 100644
--- a/plugins/experimental/cachekey/configs.cc
+++ b/plugins/experimental/cachekey/configs.cc
@@ -343,7 +343,6 @@ Configs::init(int argc, char *argv[])
                                           {0, 0, 0, 0}};
 
   bool status = true;
-  optind      = 0;
 
   /* argv contains the "to" and "from" URLs. Skip the first so that the second one poses as the program name. */
   argc--;
diff --git a/plugins/experimental/esi/esi.cc b/plugins/experimental/esi/esi.cc
index 40c6f29..a2a5483 100644
--- a/plugins/experimental/esi/esi.cc
+++ b/plugins/experimental/esi/esi.cc
@@ -1604,9 +1604,7 @@ esiPluginInit(int argc, const char *argv[], struct OptionInfo *pOptionInfo)
                                              {const_cast<char *>("handler-filename"), required_argument, NULL, 'f'},
                                              {NULL, 0, NULL, 0}};
 
-    optarg = NULL;
-    optind = opterr = optopt = 0;
-    int longindex            = 0;
+    int longindex = 0;
     while ((c = getopt_long(argc, (char *const *)argv, "npzbf:", longopts, &longindex)) != -1) {
       switch (c) {
       case 'n':
diff --git a/plugins/experimental/regex_revalidate/regex_revalidate.c b/plugins/experimental/regex_revalidate/regex_revalidate.c
index 2782924..0ff10ff 100644
--- a/plugins/experimental/regex_revalidate/regex_revalidate.c
+++ b/plugins/experimental/regex_revalidate/regex_revalidate.c
@@ -466,7 +466,6 @@ TSPluginInit(int argc, const char *argv[])
   init_plugin_state_t(pstate);
 
   int c;
-  optind                                = 1;
   static const struct option longopts[] = {
     {"config", required_argument, NULL, 'c'}, {"log", required_argument, NULL, 'l'}, {NULL, 0, NULL, 0}};
 
diff --git a/plugins/experimental/remap_stats/remap_stats.c b/plugins/experimental/remap_stats/remap_stats.c
index d5d3f9a..16d1a35 100644
--- a/plugins/experimental/remap_stats/remap_stats.c
+++ b/plugins/experimental/remap_stats/remap_stats.c
@@ -251,7 +251,6 @@ TSPluginInit(int argc, const char *argv[])
 
   if (argc > 1) {
     int c;
-    optind                                = 1;
     static const struct option longopts[] = {
       {"post-remap-host", no_argument, NULL, 'P'}, {"persistent", no_argument, NULL, 'p'}, {NULL, 0, NULL, 0}};
 
diff --git a/plugins/experimental/s3_auth/s3_auth.cc b/plugins/experimental/s3_auth/s3_auth.cc
index 48e4df2..cd17a9d 100644
--- a/plugins/experimental/s3_auth/s3_auth.cc
+++ b/plugins/experimental/s3_auth/s3_auth.cc
@@ -524,7 +524,6 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char * /* errbuf ATS_UNUSE
   // second one poses as the program name.
   --argc;
   ++argv;
-  optind = 0;
 
   while (true) {
     int opt = getopt_long(argc, static_cast<char *const *>(argv), "", longopt, NULL);
diff --git a/plugins/experimental/sslheaders/sslheaders.cc b/plugins/experimental/sslheaders/sslheaders.cc
index f2c7d56..dfcd7fb 100644
--- a/plugins/experimental/sslheaders/sslheaders.cc
+++ b/plugins/experimental/sslheaders/sslheaders.cc
@@ -170,11 +170,6 @@ SslHdrParseOptions(int argc, const char **argv)
 
   ats_scoped_obj<SslHdrInstance> hdr(new SslHdrInstance());
 
-  // We might parse arguments multiple times if we are loaded as a global
-  // plugin and a remap plugin. Reset optind so that getopt_long() does the
-  // right thing (ie. work instead of crash).
-  optind = 0;
-
   for (;;) {
     int opt;
 
diff --git a/plugins/experimental/stale_while_revalidate/stale_while_revalidate.c b/plugins/experimental/stale_while_revalidate/stale_while_revalidate.c
index 2e0f9fb..81279c8 100644
--- a/plugins/experimental/stale_while_revalidate/stale_while_revalidate.c
+++ b/plugins/experimental/stale_while_revalidate/stale_while_revalidate.c
@@ -637,7 +637,6 @@ TSPluginInit(int argc, const char *argv[])
 
   if (argc > 1) {
     int c;
-    optind                                = 1;
     static const struct option longopts[] = {{"log-all", no_argument, NULL, 'a'},
                                              {"log-stale-while-revalidate", no_argument, NULL, 'r'},
                                              {"log-stale-if-error", no_argument, NULL, 'e'},
diff --git a/plugins/experimental/xdebug/xdebug.cc b/plugins/experimental/xdebug/xdebug.cc
index e0cd61d..fa4ee93 100644
--- a/plugins/experimental/xdebug/xdebug.cc
+++ b/plugins/experimental/xdebug/xdebug.cc
@@ -369,8 +369,6 @@ TSPluginInit(int argc, const char *argv[])
     TSError("[xdebug] Plugin registration failed");
   }
 
-  optind = 0;
-
   // Parse the arguments
   while (true) {
     int opt = getopt_long(argc, (char *const *)argv, "", longopt, NULL);
diff --git a/plugins/stats_over_http/stats_over_http.c b/plugins/stats_over_http/stats_over_http.c
index 48733c2..f557cd6 100644
--- a/plugins/stats_over_http/stats_over_http.c
+++ b/plugins/stats_over_http/stats_over_http.c
@@ -299,7 +299,6 @@ TSPluginInit(int argc, const char *argv[])
     TSError("[%s] registration failed", PLUGIN_NAME);
   }
 
-  optind = 0;
   for (;;) {
     switch (getopt_long(argc, (char *const *)argv, "iw", longopts, NULL)) {
     case 'i':
diff --git a/plugins/tcpinfo/tcpinfo.cc b/plugins/tcpinfo/tcpinfo.cc
index 2002973..125d310 100644
--- a/plugins/tcpinfo/tcpinfo.cc
+++ b/plugins/tcpinfo/tcpinfo.cc
@@ -319,7 +319,6 @@ TSPluginInit(int argc, const char *argv[])
     TSError("[tcpinfo] plugin registration failed");
   }
 
-  optind = 0;
   for (;;) {
     unsigned long lval;
 
diff --git a/proxy/Plugin.cc b/proxy/Plugin.cc
index f434fa2..5dad0d4 100644
--- a/proxy/Plugin.cc
+++ b/proxy/Plugin.cc
@@ -123,6 +123,16 @@ plugin_load(int argc, char *argv[], bool validateOnly)
       return false; // this line won't get called since Fatal brings down ATS
     }
 
+#if defined(freebsd) || defined(darwin)
+    optreset = 1;
+#endif
+#if defined(__GLIBC__)
+    optind = 0;
+#else
+    optind = 1;
+#endif
+    opterr = 0;
+    optarg = NULL;
     init(argc, argv);
   } // done elevating access
 
diff --git a/proxy/http/remap/RemapConfig.cc b/proxy/http/remap/RemapConfig.cc
index fd50297..db567d3 100644
--- a/proxy/http/remap/RemapConfig.cc
+++ b/proxy/http/remap/RemapConfig.cc
@@ -859,6 +859,17 @@ remap_load_plugin(const char **argv, int argc, url_mapping *mp, char *errbuf, in
   void *ih         = NULL;
   TSReturnCode res = TS_SUCCESS;
   if (pi->fp_tsremap_new_instance) {
+#if defined(freebsd) || defined(darwin)
+    optreset = 1;
+#endif
+#if defined(__GLIBC__)
+    optind = 0;
+#else
+    optind = 1;
+#endif
+    opterr = 0;
+    optarg = NULL;
+
     res = pi->fp_tsremap_new_instance(parc, parv, &ih, tmpbuf, sizeof(tmpbuf) - 1);
   }
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].