liblttctl: switch_timer for all channels fix
[ltt-control.git] / liblttctl / liblttctl.c
index 6ee37a479797d7f5f70d65446035c9c69588e354..1032f15660019608b5682e4e41180591db31a5d2 100644 (file)
@@ -1,23 +1,25 @@
-/* libltt
+/*
+ * liblttctl
  *
- * Linux Trace Toolkit Netlink Control Library
+ * Linux Trace Toolkit Control Library
  *
  * Controls the ltt-control kernel module through debugfs.
  *
- * Copyright 2005 -
- *     Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
- *
+ * Copyright (c) 2005-2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
  *
- * This program is distributed in the hope that it will be useful,
+ * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.        See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
  *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #ifdef HAVE_CONFIG_H
@@ -162,6 +164,7 @@ static int lttctl_check_trace(const char *name, int expect)
        dir = opendir(tracedirname);
        if (dir) {
                exist = 1;
+               closedir(dir);
        } else {
                if (errno != ENOENT) {
                        fprintf(stderr, "%s: %s\n", __func__, strerror(errno));
@@ -170,8 +173,6 @@ static int lttctl_check_trace(const char *name, int expect)
                exist = 0;
        }
 
-       closedir(dir);
-
        if (!expect != !exist) {
                if (exist)
                {
@@ -444,6 +445,7 @@ static int __lttctl_set_channel_enable(const char *name, const char *channel,
 
        return ret;
 }
+
 int lttctl_set_channel_enable(const char *name, const char *channel,
                int enable)
 {
@@ -640,7 +642,9 @@ static int __lttctl_set_channel_subbuf_size(const char *name,
        ret = lttctl_sendop(ctlfname, opstr);
        if (ret)
                fprintf(stderr, "Set channel's subbuf size failed\n");
+       return ret;
 }
+
 int lttctl_set_channel_subbuf_size(const char *name, const char *channel,
                unsigned subbuf_size)
 {
@@ -691,6 +695,74 @@ arg_error:
        return ret;
 }
 
+static int __lttctl_set_channel_switch_timer(const char *name,
+               const char *channel, unsigned switch_timer)
+{
+       int ret;
+       char ctlfname[PATH_MAX];
+       char opstr[32];
+
+       sprintf(ctlfname, "%s/ltt/control/%s/channel/%s/switch_timer",
+               debugfsmntdir, name, channel);
+
+       sprintf(opstr, "%u", switch_timer);
+
+       ret = lttctl_sendop(ctlfname, opstr);
+       if (ret)
+               fprintf(stderr, "Set channel's switch timer failed\n");
+       return ret;
+}
+
+int lttctl_set_channel_switch_timer(const char *name, const char *channel,
+               unsigned switch_timer)
+{
+       int ret;
+       char **channellist;
+       int n_channel;
+
+       if (!name || !channel) {
+               fprintf(stderr, "%s: args invalid\n", __func__);
+               ret = -EINVAL;
+               goto arg_error;
+       }
+
+       ret = lttctl_check_trace(name, 1);
+       if (ret)
+               goto arg_error;
+
+       if (strcmp(channel, "all")) {
+               ret = __lttctl_set_channel_switch_timer(name, channel,
+                       switch_timer);
+               if (ret)
+                       goto op_err;
+       } else {
+               /* allow set subbuf_size for metadata channel */
+               n_channel = lttctl_get_channellist(name, &channellist, 1);
+               if (n_channel < 0) {
+                       fprintf(stderr, "%s: lttctl_get_channellist failed\n",
+                               __func__);
+                       ret = -ENOENT;
+                       goto op_err;
+               }
+
+               for (; n_channel > 0; n_channel--) {
+                       ret = __lttctl_set_channel_switch_timer(name,
+                               channellist[n_channel - 1], switch_timer);
+                       if (ret)
+                               goto op_err_clean;
+               }
+               lttctl_free_channellist(channellist, n_channel);
+       }
+
+       return 0;
+
+op_err_clean:
+       lttctl_free_channellist(channellist, n_channel);
+op_err:
+arg_error:
+       return ret;
+}
+
 int getdebugfsmntdir(char *mntdir)
 {
        char mnt_dir[PATH_MAX];
This page took 0.023961 seconds and 4 git commands to generate.