fix: if tracing group does not exist, do not report a client error
[lttng-tools.git] / src / lib / lttng-ctl / lttng-ctl.c
index dfaa47f7d7d3efb49aa109b9d05dc4dfc53af857..c5887fe65ead21a41f637aafa3adc10d60e0eb45 100644 (file)
@@ -74,6 +74,7 @@ static void copy_lttng_domain(struct lttng_domain *dst, struct lttng_domain *src
                                memcpy(dst, src, sizeof(struct lttng_domain));
                                break;
                        default:
+                               memset(dst, 0, sizeof(struct lttng_domain));
                                dst->type = LTTNG_DOMAIN_KERNEL;
                                break;
                }
@@ -137,11 +138,8 @@ static int check_tracing_group(const char *grp_name)
 
        /* Get GID of group 'tracing' */
        grp_tracing = getgrnam(grp_name);
-       if (grp_tracing == NULL) {
-               /* NULL means not found also. getgrnam(3) */
-               if (errno != 0) {
-                       perror("getgrnam");
-               }
+       if (!grp_tracing) {
+               /* If grp_tracing is NULL, the group does not exist. */
                goto end;
        }
 
@@ -466,7 +464,10 @@ int lttng_stop_tracing(const char *session_name)
 }
 
 /*
- * Add context to event or/and channel.
+ * Add context to event and/or channel.
+ * If event_name is NULL, the context is applied to all events of the channel.
+ * If channel_name is NULL, a lookup of the event's channel is done.
+ * If both are NULL, the context is applied to all events of all channels.
  *
  * Returns the size of the returned payload data or a negative error code.
  */
@@ -481,6 +482,8 @@ int lttng_add_context(struct lttng_handle *handle,
                return -1;
        }
 
+       memset(&lsm, 0, sizeof(lsm));
+
        lsm.cmd_type = LTTNG_ADD_CONTEXT;
 
        /* Copy channel name */
@@ -515,6 +518,8 @@ int lttng_enable_event(struct lttng_handle *handle,
                return -1;
        }
 
+       memset(&lsm, 0, sizeof(lsm));
+
        /* If no channel name, we put the default name */
        if (channel_name == NULL) {
                copy_string(lsm.u.enable.channel_name, DEFAULT_CHANNEL_NAME,
@@ -554,6 +559,8 @@ int lttng_disable_event(struct lttng_handle *handle, const char *name,
                return -1;
        }
 
+       memset(&lsm, 0, sizeof(lsm));
+
        if (channel_name) {
                copy_string(lsm.u.disable.channel_name, channel_name,
                                sizeof(lsm.u.disable.channel_name));
@@ -593,6 +600,8 @@ int lttng_enable_channel(struct lttng_handle *handle,
                return -1;
        }
 
+       memset(&lsm, 0, sizeof(lsm));
+
        memcpy(&lsm.u.channel.chan, chan, sizeof(lsm.u.channel.chan));
 
        lsm.cmd_type = LTTNG_ENABLE_CHANNEL;
@@ -618,6 +627,8 @@ int lttng_disable_channel(struct lttng_handle *handle, const char *name)
                return -1;
        }
 
+       memset(&lsm, 0, sizeof(lsm));
+
        lsm.cmd_type = LTTNG_DISABLE_CHANNEL;
 
        copy_string(lsm.u.disable.channel_name, name,
@@ -858,11 +869,13 @@ int lttng_calibrate(struct lttng_handle *handle,
 
 /*
  * Set default channel attributes.
- * If either or both of the arguments are null, nothing happens.
+ * If either or both of the arguments are null, attr content is zeroe'd.
  */
 void lttng_channel_set_default_attr(struct lttng_domain *domain,
                struct lttng_channel_attr *attr)
 {
+       memset(attr, 0, sizeof(struct lttng_channel_attr));
+
        /* Safety check */
        if (attr == NULL || domain == NULL) {
                return;
@@ -893,8 +906,7 @@ void lttng_channel_set_default_attr(struct lttng_domain *domain,
                attr->output = DEFAULT_UST_CHANNEL_OUTPUT;
                break;
        default:
-               /* Default behavior */
-               memset(attr, 0, sizeof(struct lttng_channel_attr));
+               /* Default behavior: leave set to 0. */
                break;
        }
 }
This page took 0.02447 seconds and 4 git commands to generate.