From 354b34fd3862bb86f74ecfdcca471d6c66238b61 Mon Sep 17 00:00:00 2001 From: compudj Date: Thu, 15 Jan 2009 01:19:39 +0000 Subject: [PATCH] apply zhaolei updates git-svn-id: http://ltt.polymtl.ca/svn@3212 04897980-b3bd-0310-b5e0-8ef037075253 --- trunk/ltt-control/configure.in | 2 +- trunk/ltt-control/liblttctl/liblttctl.c | 97 +++++++++++++++++-------- trunk/ltt-control/liblttctl/lttctl.h | 3 + trunk/ltt-control/lttctl/lttctl.c | 40 ++-------- 4 files changed, 79 insertions(+), 63 deletions(-) diff --git a/trunk/ltt-control/configure.in b/trunk/ltt-control/configure.in index fe7b6e1..55feebf 100644 --- a/trunk/ltt-control/configure.in +++ b/trunk/ltt-control/configure.in @@ -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 diff --git a/trunk/ltt-control/liblttctl/liblttctl.c b/trunk/ltt-control/liblttctl/liblttctl.c index ca5ba08..e866d73 100644 --- a/trunk/ltt-control/liblttctl/liblttctl.c +++ b/trunk/ltt-control/liblttctl/liblttctl.c @@ -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; +} diff --git a/trunk/ltt-control/liblttctl/lttctl.h b/trunk/ltt-control/liblttctl/lttctl.h index 31fd7cb..facc8f0 100644 --- a/trunk/ltt-control/liblttctl/lttctl.h +++ b/trunk/ltt-control/liblttctl/lttctl.h @@ -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 */ diff --git a/trunk/ltt-control/lttctl/lttctl.c b/trunk/ltt-control/lttctl/lttctl.c index c1a49cd..eeb8100 100644 --- a/trunk/ltt-control/lttctl/lttctl.c +++ b/trunk/ltt-control/lttctl/lttctl.c @@ -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; -- 2.34.1