This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC][PATCH 1/5][flight-recorder] Background mode


Hi,
Here is a series of patches for flight recorder mode.

This patch adds a function to run the stpd in background.
I use daemon() function to do that. In the background mode,
stpd is seperated from console, but still run at current
working directory. This means the logfile is saved in
the working directory.

There are some future works should be implemented.
- lketb2a has to support new temporary file format.
- on memory flight recorder mode
- retrieve logs from kdump file
  (This would be crash enhancement)

Best regards,

-- 
Masami HIRAMATSU
2nd Research Dept.
Hitachi, Ltd., Systems Development Laboratory
E-mail: masami.hiramatsu.pt@hitachi.com

 runtime/stpd/librelay.c |    8 +++++---
 runtime/stpd/stpd.c     |   27 +++++++++++++++++++++++++--
 2 files changed, 30 insertions(+), 5 deletions(-)
Index: src/runtime/stpd/librelay.c
===================================================================
--- src.orig/runtime/stpd/librelay.c	2006-07-21 03:13:46.000000000 +0900
+++ src/runtime/stpd/librelay.c	2006-08-25 19:11:59.000000000 +0900
@@ -81,7 +81,7 @@
 static int control_channel;

 /* flags */
-extern int print_only, quiet, merge, verbose;
+extern int print_only, quiet, merge, verbose, background;
 extern unsigned int buffer_size;
 extern char *modname;
 extern char *modpath;
@@ -724,7 +724,7 @@
 	signal(SIGCHLD, sigproc);
 	signal(SIGHUP, sigproc);

-        if (driver_pid)
+        if (driver_pid && !background)
           driver_poll(0); // And by the way, I'm also the signal handler.

 	dbug("in main loop\n");
@@ -769,7 +769,9 @@
 					/* FIXME. Need to cleanup properly */
 					exit(1);
 				}
-			} else if (outfile_name) {
+			} else if (background || outfile_name) {
+				if (!outfile_name)
+					outfile_name = DEFAULT_RELAYFS_OUTFILE_NAME;
 				ofp = fopen (outfile_name, "w");
 				if (!ofp) {
 					fprintf (stderr, "ERROR: couldn't open output file %s: errcode = %s\n",
Index: src/runtime/stpd/stpd.c
===================================================================
--- src.orig/runtime/stpd/stpd.c	2006-08-02 23:06:35.000000000 +0900
+++ src/runtime/stpd/stpd.c	2006-08-25 19:11:59.000000000 +0900
@@ -40,6 +40,7 @@
 int enable_relayfs = 1;
 int target_pid = 0;
 int driver_pid = 0;
+int background = 0;
 unsigned int buffer_size = 0;
 char *modname = NULL;
 char *modpath = NULL;
@@ -64,8 +65,9 @@

 static void usage(char *prog)
 {
-	fprintf(stderr, "\n%s [-m] [-p] [-q] [-r] [-c cmd ] [-t pid]\n"
+	fprintf(stderr, "\n%s [-B] [-m] [-p] [-q] [-r] [-c cmd ] [-t pid]\n"
                 "\t[-b bufsize] [-o FILE] kmod-name [kmod-options]\n", prog);
+	fprintf(stderr, "-B  Execute in background. (be seperated from console)\n");
 	fprintf(stderr, "-m  Don't merge per-cpu files.\n");
 	fprintf(stderr, "-p  Print only.  Don't log to files.\n");
 	fprintf(stderr, "-q  Quiet. Don't display trace to stdout.\n");
@@ -89,9 +91,12 @@
 	pid_t pid;
 	struct statfs st;
 	
-	while ((c = getopt(argc, argv, "mpqrb:n:t:d:c:vo:u:")) != EOF)
+	while ((c = getopt(argc, argv, "Bmpqrb:n:t:d:c:vo:u:")) != EOF)
 	{
 		switch (c) {
+		case 'B':
+			background = 1;
+			break;
 		case 'm':
 			merge = 0;
 			break;
@@ -170,6 +175,17 @@
 		usage(argv[0]);
 	}

+	if (background) {
+		if (print_only) {
+			fprintf (stderr, "Cannot do \"-p\" and \"-B\" both.\n");
+			usage(argv[0]);
+		}
+		if ((!quiet) && !(merge == 0 && enable_relayfs)) {
+			fprintf (stderr, "Cannot do \"-B\" with console output.\n Please specify \"-q\" or \"-m\"\n");
+			usage(argv[0]);
+		}
+	}
+
 	if (print_only && quiet) {
 		fprintf (stderr, "Cannot do \"-p\" and \"-q\" both.\n");
 		usage(argv[0]);
@@ -225,6 +241,13 @@
 		exit(1);
 	}

+	if (background) {
+		if (daemon(1,0)){
+			perror("Couldn't be a daemon.");
+			exit(1);
+		}
+	}
+
 	if (stp_main_loop()) {
 		fprintf(stderr,"Couldn't enter main loop. Exiting.\n");
 		exit(1);




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]