Relayd: disallow-clear option parsing
[lttng-tools.git] / src / bin / lttng-relayd / main.c
index cd4f058bf0243df63dd78e573e97fca202b751d3..705b5d6c52247be9e1d318b7a8dd94ec39123129 100644 (file)
@@ -83,6 +83,7 @@ NULL
 /* command line options */
 char *opt_output_path;
 static int opt_daemon, opt_background;
+static int opt_allow_clear = 1;
 
 /*
  * We need to wait for listener and live listener threads, as well as
@@ -171,6 +172,7 @@ static struct option long_options[] = {
        { "verbose", 0, 0, 'v', },
        { "config", 1, 0, 'f' },
        { "version", 0, 0, 'V' },
+       { "disallow-clear", 0, 0, 'x' },
        { NULL, 0, 0, 0, },
 };
 
@@ -292,6 +294,10 @@ static int set_option(int opt, const char *arg, const char *optname)
                        }
                }
                break;
+       case 'x':
+               /* Disallow clear */
+               opt_allow_clear = 0;
+               break;
        default:
                /* Unknown option or other error.
                 * Error is printed by getopt, just return */
@@ -367,6 +373,7 @@ static int set_options(int argc, char **argv)
        int orig_optopt = optopt, orig_optind = optind;
        char *default_address, *optstring;
        const char *config_path = NULL;
+       const char *value = NULL;
 
        optstring = utils_generate_optstring(long_options,
                        sizeof(long_options) / sizeof(struct option));
@@ -479,6 +486,20 @@ static int set_options(int argc, char **argv)
                }
        }
 
+       if (opt_allow_clear) {
+               /* Check if env variable exists. */
+               value = lttng_secure_getenv(DEFAULT_LTTNG_RELAYD_DISALLOW_CLEAR_ENV);
+               if (value) {
+                       ret = config_parse_value(value);
+                       if (ret < 0) {
+                               ERR("Invalid value for %s specified", DEFAULT_LTTNG_RELAYD_DISALLOW_CLEAR_ENV);
+                               retval = -1;
+                               goto exit;
+                       }
+                       opt_allow_clear = !ret;
+               }
+       }
+
 exit:
        free(optstring);
        return retval;
@@ -749,6 +770,7 @@ static struct lttcomm_sock *relay_socket_create(struct lttng_uri *uri)
 
        ret = sock->ops->bind(sock);
        if (ret < 0) {
+               PERROR("Failed to bind socket");
                goto error;
        }
 
@@ -2053,8 +2075,13 @@ static int relay_recv_index(struct lttcomm_relayd_hdr *recv_hdr,
                /* no flush. */
                ret = 0;
        } else {
+               /*
+                * ret < 0
+                *
+                * relay_index_try_flush is responsible for the self-reference
+                * put of the index object on error.
+                */
                ERR("relay_index_try_flush error %d", ret);
-               relay_index_put(index);
                ret = -1;
        }
 
@@ -2254,9 +2281,13 @@ static int handle_index_data(struct relay_stream *stream, uint64_t net_seq_num,
                /* No flush. */
                ret = 0;
        } else {
-               /* Put self-ref for this index due to error. */
-               relay_index_put(index);
-               index = NULL;
+               /*
+                * ret < 0
+                *
+                * relay_index_try_flush is responsible for the self-reference
+                * put of the index object on error.
+                */
+               ERR("relay_index_try_flush error %d", ret);
                ret = -1;
        }
 end:
@@ -2774,6 +2805,10 @@ int main(int argc, char **argv)
                goto exit_options;
        }
 
+       if (!opt_allow_clear) {
+               DBG("Clear command disallowed.");
+       }
+
        /* Try to create directory if -o, --output is specified. */
        if (opt_output_path) {
                if (*opt_output_path != '/') {
This page took 0.032907 seconds and 5 git commands to generate.