ret = initdebugfsmntdir();
if (ret) {
fprintf(stderr, "Get debugfs mount point failed\n");
- return 1;
+ return ret;
}
ret = initmodule();
if (ret) {
fprintf(stderr, "Control module seems not work\n");
- return 1;
+ return ret;
}
return 0;
}
if (write(fd, op, strlen(op)) == -1) {
+ int ret = errno;
fprintf(stderr, "%s: write %s to %s failed: %s\n", __func__, op,
fname, strerror(errno));
close(fd);
- return 1;
+ return ret;
}
close(fd);
*
* ret:
* 0: check pass
- * 1: check failed
+ * -(EEXIST | ENOENT): check failed
* -ERRNO: error happened (no check)
*/
static int lttctl_check_trace(const char *name, int expect)
if (!expect != !exist) {
if (exist)
+ {
fprintf(stderr, "Trace %s already exist\n", name);
+ return -EEXIST;
+ }
else
+ {
fprintf(stderr, "Trace %s not exist\n", name);
- return 1;
+ return -ENOENT;
+ }
+
}
return 0;
return nr_chan;
}
+static void lttctl_free_channellist(char **channellist, int n_channel)
+{
+ int i = 0;
+ for(; i < n_channel; ++i)
+ free(channellist[i]);
+ free(channellist);
+}
+
int lttctl_setup_trace(const char *name)
{
int ret;
int enable)
{
int ret;
+ char **channellist;
+ int n_channel;
if (!name || !channel) {
fprintf(stderr, "%s: args invalid\n", __func__);
if (ret)
goto op_err;
} else {
- char **channellist;
- int n_channel;
-
/* Don't allow set enable state for metadata channel */
n_channel = lttctl_get_channellist(name, &channellist, 0);
if (n_channel < 0) {
ret = __lttctl_set_channel_enable(name,
channellist[n_channel - 1], enable);
if (ret)
- goto op_err;
+ goto op_err_clean;
}
- free(channellist);
+ lttctl_free_channellist(channellist, n_channel);
}
return 0;
+op_err_clean:
+ lttctl_free_channellist(channellist, n_channel);
op_err:
arg_error:
return ret;
int overwrite)
{
int ret;
+ char **channellist;
+ int n_channel;
if (!name || !channel) {
fprintf(stderr, "%s: args invalid\n", __func__);
if (ret)
goto op_err;
} else {
- char **channellist;
- int n_channel;
-
/* Don't allow set overwrite for metadata channel */
n_channel = lttctl_get_channellist(name, &channellist, 0);
if (n_channel < 0) {
ret = __lttctl_set_channel_overwrite(name,
channellist[n_channel - 1], overwrite);
if (ret)
- goto op_err;
+ goto op_err_clean;
}
- free(channellist);
+ lttctl_free_channellist(channellist, n_channel);
}
return 0;
+op_err_clean:
+ lttctl_free_channellist(channellist, n_channel);
op_err:
arg_error:
return ret;
unsigned subbuf_num)
{
int ret;
+ char **channellist;
+ int n_channel;
if (!name || !channel) {
fprintf(stderr, "%s: args invalid\n", __func__);
if (ret)
goto op_err;
} else {
- char **channellist;
- int n_channel;
-
/* allow set subbuf_num for metadata channel */
n_channel = lttctl_get_channellist(name, &channellist, 1);
if (n_channel < 0) {
ret = __lttctl_set_channel_subbuf_num(name,
channellist[n_channel - 1], subbuf_num);
if (ret)
- goto op_err;
+ goto op_err_clean;
}
- free(channellist);
+ lttctl_free_channellist(channellist, n_channel);
}
return 0;
+op_err_clean:
+ lttctl_free_channellist(channellist, n_channel);
op_err:
arg_error:
return ret;
unsigned subbuf_size)
{
int ret;
+ char **channellist;
+ int n_channel;
if (!name || !channel) {
fprintf(stderr, "%s: args invalid\n", __func__);
if (ret)
goto op_err;
} else {
- char **channellist;
- int n_channel;
-
/* allow set subbuf_size for metadata channel */
n_channel = lttctl_get_channellist(name, &channellist, 1);
if (n_channel < 0) {
ret = __lttctl_set_channel_subbuf_size(name,
channellist[n_channel - 1], subbuf_size);
if (ret)
- goto op_err;
+ goto op_err_clean;
}
- free(channellist);
+ lttctl_free_channellist(channellist, n_channel);
}
return 0;
+op_err_clean:
+ lttctl_free_channellist(channellist, n_channel);
op_err:
arg_error:
return ret;