apply zhaolei updates
authorcompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Thu, 15 Jan 2009 01:19:39 +0000 (01:19 +0000)
committercompudj <compudj@04897980-b3bd-0310-b5e0-8ef037075253>
Thu, 15 Jan 2009 01:19:39 +0000 (01:19 +0000)
git-svn-id: http://ltt.polymtl.ca/svn@3212 04897980-b3bd-0310-b5e0-8ef037075253

trunk/ltt-control/configure.in
trunk/ltt-control/liblttctl/liblttctl.c
trunk/ltt-control/liblttctl/lttctl.h
trunk/ltt-control/lttctl/lttctl.c

index fe7b6e1b63cd96d609bf2b256cf659a0f2b3a272..55feebfb1cc96be6a809a317bfe5c00376980341 100644 (file)
@@ -23,7 +23,7 @@
 AC_PREREQ(2.57)
 AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
 #AC_WITH_LTDL  # not needed ?
-AM_INIT_AUTOMAKE(ltt-control,0.63-03012009)
+AM_INIT_AUTOMAKE(ltt-control,0.64-14012009)
 AM_CONFIG_HEADER(config.h)
 AM_PROG_LIBTOOL
 
index ca5ba08b153717ba6cee872505f5af91a08200b6..e866d73be9758fd37826ecfb7570e2fdea0cadc8 100644 (file)
@@ -39,53 +39,60 @@ static char debugfsmntdir[PATH_MAX];
 
 static int initdebugfsmntdir(void)
 {
-       char mnt_dir[PATH_MAX];
-       char mnt_type[PATH_MAX];
+       return getdebugfsmntdir(debugfsmntdir);
+}
 
-       FILE *fp = fopen("/proc/mounts", "r");
-       if (!fp) {
-               fprintf(stderr, "%s: Can't open /proc/mounts\n", __func__);
-               return 1;
+/*
+ * This function must called posterior to initdebugfsmntdir(),
+ * because it need to use debugfsmntdir[] which is inited in initdebugfsmntdir()
+ */
+static int initmodule(void)
+{
+       char controldirname[PATH_MAX];
+       DIR *dir;
+       int tryload_done = 0;
+
+       sprintf(controldirname, "%s/ltt/control/", debugfsmntdir);
+
+check_again:
+       /*
+        * Check ltt control's debugfs dir
+        *
+        * We don't check is ltt-trace-control module exist, because it maybe
+        * compiled into kernel.
+        */
+       dir = opendir(controldirname);
+       if (dir) {
+               closedir(dir);
+               return 0;
        }
 
-       while (1) {
-               if (fscanf(fp, "%*s %s %s %*s %*s %*s", mnt_dir, mnt_type)
-                       <= 0) {
-                       fprintf(stderr, "%s: debugfs mountpoint not found\n",
-                               __func__);
-                       return 1;
-               }
-               if (!strcmp(mnt_type, "debugfs")) {
-                       strcpy(debugfsmntdir, mnt_dir);
-                       return 0;
-               }
+       if (!tryload_done) {
+               system("modprobe ltt-trace-control");
+               tryload_done = 1;
+               goto check_again;
        }
+
+       return -ENOENT;
 }
 
 int lttctl_init(void)
 {
        int ret;
-       DIR *dir;
-       char controldirname[PATH_MAX];
+
 
        ret = initdebugfsmntdir();
        if (ret) {
-               fprintf(stderr, "Debugfs mount point not found\n");
+               fprintf(stderr, "Get debugfs mount point failed\n");
                return 1;
        }
 
-       /* check ltt control's debugfs dir */
-       sprintf(controldirname, "%s/ltt/control/", debugfsmntdir);
-
-       dir = opendir(controldirname);
-       if (!dir) {
-               fprintf(stderr, "ltt-trace-control's debugfs dir not found\n");
-               closedir(dir);
-               return -errno;
+       ret = initmodule();
+       if (ret) {
+               fprintf(stderr, "Control module seems not work\n");
+               return 1;
        }
 
-       closedir(dir);
-
        return 0;
 }
 
@@ -664,3 +671,33 @@ op_err:
 arg_error:
        return ret;
 }
+
+int getdebugfsmntdir(char *mntdir)
+{
+       char mnt_dir[PATH_MAX];
+       char mnt_type[PATH_MAX];
+       int trymount_done = 0;
+
+       FILE *fp = fopen("/proc/mounts", "r");
+       if (!fp)
+               return -EINVAL;
+
+find_again:
+       while (1) {
+               if (fscanf(fp, "%*s %s %s %*s %*s %*s", mnt_dir, mnt_type) <= 0)
+                       break;
+
+               if (!strcmp(mnt_type, "debugfs")) {
+                       strcpy(mntdir, mnt_dir);
+                       return 0;
+               }
+       }
+
+       if (!trymount_done) {
+               mount("debugfs", "/sys/kernel/debug/", "debugfs", 0, NULL);
+               trymount_done = 1;
+               goto find_again;
+       }
+
+       return -ENOENT;
+}
index 31fd7cb564912ba5e2b60ff53ef3707d807f4927..facc8f05f0b4ada702e936f0d6bc8970f49f4e8e 100644 (file)
@@ -36,4 +36,7 @@ int lttctl_set_channel_subbuf_num(const char *name, const char *channel,
 int lttctl_set_channel_subbuf_size(const char *name, const char *channel,
                unsigned subbuf_size);
 
+/* Helper functions */
+int getdebugfsmntdir(char *mntdir);
+
 #endif /*_LIBLTT_H */
index c1a49cd4f8dff16179e6ad03436cc98376885ed8..eeb810053e1b5634c9800727611b1e9abc5443ea 100644 (file)
@@ -142,26 +142,6 @@ static void show_arguments(void)
        printf("\n");
 }
 
-static int getdebugfsmntdir(char *mntdir)
-{
-       char mnt_dir[PATH_MAX];
-       char mnt_type[PATH_MAX];
-
-       FILE *fp = fopen("/proc/mounts", "r");
-       if (!fp)
-               return -EINVAL;
-
-       while (1) {
-               if (fscanf(fp, "%*s %s %s %*s %*s %*s", mnt_dir, mnt_type) <= 0)
-                       return -ENOENT;
-
-               if (!strcmp(mnt_type, "debugfs")) {
-                       strcpy(mntdir, mnt_dir);
-                       return 0;
-               }
-       }
-}
-
 /*
  * Separate option name to 3 fields
  * Ex:
@@ -559,19 +539,15 @@ static int parse_arguments(int argc, char **argv)
                        if (getdebugfsmntdir(channel_root_default) == 0) {
                                strcat(channel_root_default, "/ltt");
                                opt_channel_root = channel_root_default;
+                       } else {
+                               fprintf(stderr,
+                                       "Channel_root is necessary for -w"
+                                       " option, but neither --channel_root"
+                                       " option\n"
+                                       "specified, nor debugfs's mount dir"
+                                       " found, mount debugfs also failed\n");
+                               return -EINVAL;
                        }
-               /* Todo:
-                * if (!opt_channel_root)
-                *      if (auto_mount_debugfs_dir(channel_root_default) == 0)
-                *              opt_channel_root = debugfs_dir_mnt_point;
-                */
-               if (!opt_channel_root) {
-                       fprintf(stderr,
-                               "Channel_root is necessary for -w option,"
-                               " but neither --channel_root option\n"
-                               "specified, nor debugfs's mount dir found.\n");
-                       return -EINVAL;
-               }
 
                if (opt_dump_threads == 0)
                        opt_dump_threads = 1;
This page took 0.026708 seconds and 4 git commands to generate.