lttng-ctl: fix: lttng_data_pending confuses communication status
[lttng-tools.git] / src / lib / lttng-ctl / lttng-ctl.c
index 0f9378c2c5d82507df87d2b83a46a5d5f192d733..79b885467e27d4f258e44823231ae3da7a56fd2c 100644 (file)
@@ -208,15 +208,13 @@ end:
 LTTNG_HIDDEN
 int lttng_check_tracing_group(void)
 {
-       struct group *grp_tracing;      /* no free(). See getgrnam(3) */
-       gid_t *grp_list;
+       gid_t *grp_list, tracing_gid;
        int grp_list_size, grp_id, i;
        int ret = -1;
        const char *grp_name = tracing_group;
 
        /* Get GID of group 'tracing' */
-       grp_tracing = getgrnam(grp_name);
-       if (!grp_tracing) {
+       if (utils_get_group_id(grp_name, false, &tracing_gid)) {
                /* If grp_tracing is NULL, the group does not exist. */
                goto end;
        }
@@ -241,7 +239,7 @@ int lttng_check_tracing_group(void)
        }
 
        for (i = 0; i < grp_list_size; i++) {
-               if (grp_list[i] == grp_tracing->gr_gid) {
+               if (grp_list[i] == tracing_gid) {
                        ret = 1;
                        break;
                }
@@ -797,7 +795,7 @@ static char *set_agent_filter(const char *filter, struct lttng_event *ev)
        assert(ev);
 
        /* Don't add filter for the '*' event. */
-       if (ev->name[0] != '*') {
+       if (strcmp(ev->name, "*") != 0) {
                if (filter) {
                        err = asprintf(&agent_filter, "(%s) && (logger_name == \"%s\")", filter,
                                        ev->name);
@@ -920,12 +918,28 @@ static int generate_filter(char *filter_expression,
                ret = -LTTNG_ERR_FILTER_INVAL;
                goto parse_error;
        }
+
+       /* Normalize globbing patterns in the expression. */
+       ret = filter_visitor_ir_normalize_glob_patterns(ctx);
+       if (ret) {
+               ret = -LTTNG_ERR_FILTER_INVAL;
+               goto parse_error;
+       }
+
        /* Validate strings used as literals in the expression. */
        ret = filter_visitor_ir_validate_string(ctx);
        if (ret) {
                ret = -LTTNG_ERR_FILTER_INVAL;
                goto parse_error;
        }
+
+       /* Validate globbing patterns in the expression. */
+       ret = filter_visitor_ir_validate_globbing(ctx);
+       if (ret) {
+               ret = -LTTNG_ERR_FILTER_INVAL;
+               goto parse_error;
+       }
+
        dbg_printf("done\n");
 
        dbg_printf("Generating bytecode... ");
@@ -2031,14 +2045,14 @@ int lttng_calibrate(struct lttng_handle *handle,
 void lttng_channel_set_default_attr(struct lttng_domain *domain,
                struct lttng_channel_attr *attr)
 {
-       struct lttng_channel_extended *extended =
-                       (struct lttng_channel_extended *) attr->extended.ptr;
+       struct lttng_channel_extended *extended;
 
        /* Safety check */
        if (attr == NULL || domain == NULL) {
                return;
        }
 
+       extended = (struct lttng_channel_extended *) attr->extended.ptr;
        memset(attr, 0, sizeof(struct lttng_channel_attr));
 
        /* Same for all domains. */
@@ -2057,6 +2071,8 @@ void lttng_channel_set_default_attr(struct lttng_domain *domain,
                if (extended) {
                        extended->monitor_timer_interval =
                                        DEFAULT_KERNEL_CHANNEL_MONITOR_TIMER;
+                       extended->blocking_timeout =
+                                       DEFAULT_KERNEL_CHANNEL_BLOCKING_TIMEOUT;
                }
                break;
        case LTTNG_DOMAIN_UST:
@@ -2072,6 +2088,8 @@ void lttng_channel_set_default_attr(struct lttng_domain *domain,
                        if (extended) {
                                extended->monitor_timer_interval =
                                                DEFAULT_UST_UID_CHANNEL_MONITOR_TIMER;
+                               extended->blocking_timeout =
+                                               DEFAULT_UST_UID_CHANNEL_BLOCKING_TIMEOUT;
                        }
                        break;
                case LTTNG_BUFFER_PER_PID:
@@ -2086,6 +2104,8 @@ void lttng_channel_set_default_attr(struct lttng_domain *domain,
                        if (extended) {
                                extended->monitor_timer_interval =
                                                DEFAULT_UST_PID_CHANNEL_MONITOR_TIMER;
+                               extended->blocking_timeout =
+                                               DEFAULT_UST_PID_CHANNEL_BLOCKING_TIMEOUT;
                        }
                        break;
                }
@@ -2187,6 +2207,61 @@ end:
        return ret;
 }
 
+int lttng_channel_get_blocking_timeout(struct lttng_channel *chan,
+               int64_t *blocking_timeout)
+{
+       int ret = 0;
+
+       if (!chan || !blocking_timeout) {
+               ret = -LTTNG_ERR_INVALID;
+               goto end;
+       }
+
+       if (!chan->attr.extended.ptr) {
+               ret = -LTTNG_ERR_INVALID;
+               goto end;
+       }
+
+       *blocking_timeout = ((struct lttng_channel_extended *)
+                       chan->attr.extended.ptr)->blocking_timeout;
+end:
+       return ret;
+}
+
+int lttng_channel_set_blocking_timeout(struct lttng_channel *chan,
+               int64_t blocking_timeout)
+{
+       int ret = 0;
+       int64_t msec_timeout;
+
+       if (!chan || !chan->attr.extended.ptr) {
+               ret = -LTTNG_ERR_INVALID;
+               goto end;
+       }
+
+       if (blocking_timeout < 0 && blocking_timeout != -1) {
+               ret = -LTTNG_ERR_INVALID;
+               goto end;
+       }
+
+       /*
+        * LTTng-ust's use of poll() to implement this timeout mechanism forces
+        * us to accept a narrower range of values (msecs expressed as a signed
+        * 32-bit integer).
+        */
+       msec_timeout = blocking_timeout / 1000;
+       if (msec_timeout != (int32_t) msec_timeout) {
+               ret = -LTTNG_ERR_INVALID;
+               goto end;
+       }
+
+       ((struct lttng_channel_extended *)
+                       chan->attr.extended.ptr)->blocking_timeout =
+                       blocking_timeout;
+end:
+       return ret;
+}
+
 /*
  * Check if session daemon is alive.
  *
@@ -2372,6 +2447,10 @@ int lttng_data_pending(const char *session_name)
                /* Unexpected payload size */
                ret = -LTTNG_ERR_INVALID;
                goto end;
+       } else if (!pending) {
+               /* Internal error. */
+               ret = -LTTNG_ERR_UNK;
+               goto end;
        }
 
        ret = (int) *pending;
@@ -2481,7 +2560,7 @@ int lttng_list_tracker_pids(struct lttng_handle *handle,
        int enabled = 1;
        struct lttcomm_session_msg lsm;
        size_t nr_pids;
-       int32_t *pids;
+       int32_t *pids = NULL;
 
        if (handle == NULL) {
                return -LTTNG_ERR_INVALID;
@@ -2498,6 +2577,9 @@ int lttng_list_tracker_pids(struct lttng_handle *handle,
                return ret;
        }
        nr_pids = ret / sizeof(int32_t);
+       if (nr_pids > 0 && !pids) {
+               return -LTTNG_ERR_UNK;
+       }
        if (nr_pids == 1 && pids[0] == -1) {
                free(pids);
                pids = NULL;
@@ -2591,7 +2673,7 @@ int lttng_register_trigger(struct lttng_trigger *trigger)
        }
 
        if (!lttng_trigger_validate(trigger)) {
-               ret = -LTTNG_ERR_INVALID;
+               ret = -LTTNG_ERR_INVALID_TRIGGER;
                goto end;
        }
 
This page took 0.028294 seconds and 4 git commands to generate.