Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
* [ltt-dev] [PATCH 1/2] Make lttctl mount debugfs automatically
@ 2009-01-07  8:04 Zhaolei
  2009-01-07  8:09 ` [ltt-dev] [PATCH 2/2] Make lttctl load ltt-trace-control module automatically Zhaolei
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Zhaolei @ 2009-01-07  8:04 UTC (permalink / raw)


lttctl need debugfs mounted,
This patch make lttctl mount debugfs automatically when it is not mounted.

Little cleanup also done(combile 2 getdebugfsmntdir() into one).

Applies on top of ltt-control-0.63-03012009.

Signed-off-by: Zhao lei <zhaolei at cn.fujitsu.com>
---
 liblttctl/liblttctl.c |   54 +++++++++++++++++++++++++++++---------------------
 liblttctl/lttctl.h    |    3 ++
 lttctl/lttctl.c       |   40 +++++++------------------------------
 3 files changed, 43 insertions(+), 54 deletions(-)
diff -Nur ltt-control-0.63-03012009.org/liblttctl/liblttctl.c ltt-control-0.63-03012009.new/liblttctl/liblttctl.c
--- ltt-control-0.63-03012009.org/liblttctl/liblttctl.c	2009-01-07 09:52:05.000000000 +0800
+++ ltt-control-0.63-03012009.new/liblttctl/liblttctl.c	2009-01-07 14:48:18.000000000 +0800
@@ -39,27 +39,7 @@
 
 static int initdebugfsmntdir(void)
 {
-	char mnt_dir[PATH_MAX];
-	char mnt_type[PATH_MAX];
-
-	FILE *fp = fopen("/proc/mounts", "r");
-	if (!fp) {
-		fprintf(stderr, "%s: Can't open /proc/mounts\n", __func__);
-		return 1;
-	}
-
-	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;
-		}
-	}
+	return getdebugfsmntdir(debugfsmntdir);
 }
 
 int lttctl_init(void)
@@ -70,7 +50,7 @@
 
 	ret = initdebugfsmntdir();
 	if (ret) {
-		fprintf(stderr, "Debugfs mount point not found\n");
+		fprintf(stderr, "Get debugfs mount point failed\n");
 		return 1;
 	}
 
@@ -664,3 +644,33 @@
 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 -Nur ltt-control-0.63-03012009.org/liblttctl/lttctl.h ltt-control-0.63-03012009.new/liblttctl/lttctl.h
--- ltt-control-0.63-03012009.org/liblttctl/lttctl.h	2009-01-07 09:52:05.000000000 +0800
+++ ltt-control-0.63-03012009.new/liblttctl/lttctl.h	2009-01-07 14:48:18.000000000 +0800
@@ -36,4 +36,7 @@
 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 -Nur ltt-control-0.63-03012009.org/lttctl/lttctl.c ltt-control-0.63-03012009.new/lttctl/lttctl.c
--- ltt-control-0.63-03012009.org/lttctl/lttctl.c	2009-01-07 09:52:05.000000000 +0800
+++ ltt-control-0.63-03012009.new/lttctl/lttctl.c	2009-01-07 14:48:18.000000000 +0800
@@ -142,26 +142,6 @@
 	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 @@
 			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;




^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2009-01-15  1:41 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-07  8:04 [ltt-dev] [PATCH 1/2] Make lttctl mount debugfs automatically Zhaolei
2009-01-07  8:09 ` [ltt-dev] [PATCH 2/2] Make lttctl load ltt-trace-control module automatically Zhaolei
2009-01-15  1:20   ` Mathieu Desnoyers
2009-01-07 14:20 ` [ltt-dev] [PATCH 1/2] Make lttctl mount debugfs automatically Pierre-Marc Fournier
2009-01-08  0:40   ` Zhaolei
2009-01-08 14:44     ` Mathieu Desnoyers
2009-01-09  1:57       ` Zhaolei
2009-01-09  3:30         ` Mathieu Desnoyers
2009-01-13 23:54           ` Greg KH
2009-01-14  2:02             ` Josh Boyer
2009-01-14  5:16             ` Mathieu Desnoyers
2009-01-14  5:54               ` Greg KH
2009-01-15  1:41                 ` Mathieu Desnoyers
2009-01-15  1:20 ` Mathieu Desnoyers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox