This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
[PATCH] bugfix: fix some bugs about combination of -b and -S on old kernel
- From: Masami Hiramatsu <mhiramat at redhat dot com>
- To: systemtap at sources dot redhat dot com
- Date: Fri, 19 Jun 2009 17:14:58 -0400
- Subject: [PATCH] bugfix: fix some bugs about combination of -b and -S on old kernel
Hi,
Here is a patch which fixes some bugs when we give stap
-b (bulk mode) and -S (file-switching) on old kernel(e.g. RHEL4)
This fixes staprun to pass flightrec3.exp testcase.
Thank you,
--
Masami Hiramatsu
Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division
e-mail: mhiramat@redhat.com
Fix on-file flight recorder mode bugs on old kernel.
From: Masami Hiramatsu <mhiramat@redhat.com>
* runtime/staprun/common.c (make_outfile_name): Moved from relay.c, fix not to
open /dev/null.XXX output files, and add 'bulk' argument for bulkmode.
* runtime/staprun/relay.c (make_outfile_name): Moved to common.c.
* runtime/staprun/relay_old.c (open_oldoutfile): Fix to use fopen() and store
FILE * to percpu_tmpfile[cpu].
---
runtime/staprun/common.c | 27 +++++++++++++++++++++++++++
runtime/staprun/relay.c | 30 +++---------------------------
runtime/staprun/relay_old.c | 17 ++++++++++-------
runtime/staprun/staprun.h | 3 ++-
4 files changed, 42 insertions(+), 35 deletions(-)
diff --git a/runtime/staprun/common.c b/runtime/staprun/common.c
index c67ce34..5c4a843 100644
--- a/runtime/staprun/common.c
+++ b/runtime/staprun/common.c
@@ -66,6 +66,33 @@ int stap_strfloctime(char *buf, size_t max, const char *fmt, time_t t)
return (int)ret;
}
+int make_outfile_name(char *buf, int max, int fnum, int cpu, time_t t, int bulk)
+{
+ int len;
+ if (PATH_MAX < max)
+ max = PATH_MAX;
+ len = stap_strfloctime(buf, max, outfile_name, t);
+ if (len < 0) {
+ err("Invalid FILE name format\n");
+ return -1;
+ }
+ /* special case: for testing we sometimes want to write to /dev/null */
+ if (strcmp(outfile_name, "/dev/null") == 0) {
+ strcpy(buf, "/dev/null");
+ } else {
+ if (bulk) {
+ if (snprintf_chk(&buf[len], max - len, "_cpu%d.%d",
+ cpu, fnum))
+ return -1;
+ } else {
+ /* stream mode */
+ if (snprintf_chk(&buf[len], max - len, ".%d", fnum))
+ return -1;
+ }
+ }
+ return 0;
+}
+
void parse_args(int argc, char **argv)
{
int c;
diff --git a/runtime/staprun/relay.c b/runtime/staprun/relay.c
index b979624..f4aa139 100644
--- a/runtime/staprun/relay.c
+++ b/runtime/staprun/relay.c
@@ -73,31 +73,6 @@ time_t read_backlog(int cpu, int fnum)
return time_backlog[cpu][fnum & BACKLOG_MASK];
}
-int make_outfile_name(char *buf, int max, int fnum, int cpu, time_t t)
-{
- int len;
- len = stap_strfloctime(buf, max, outfile_name, t);
- if (len < 0) {
- err("Invalid FILE name format\n");
- return -1;
- }
- if (bulkmode) {
- /* special case: for testing we sometimes want to write to /dev/null */
- if (strcmp(outfile_name, "/dev/null") == 0) {
- strcpy(buf, "/dev/null");
- } else {
- if (snprintf_chk(&buf[len], PATH_MAX - len,
- "_cpu%d.%d", cpu, fnum))
- return -1;
- }
- } else {
- /* stream mode */
- if (snprintf_chk(&buf[len], PATH_MAX - len, ".%d", fnum))
- return -1;
- }
- return 0;
-}
-
static int open_outfile(int fnum, int cpu, int remove_file)
{
char buf[PATH_MAX];
@@ -112,14 +87,15 @@ static int open_outfile(int fnum, int cpu, int remove_file)
if (remove_file) {
/* remove oldest file */
if (make_outfile_name(buf, PATH_MAX, fnum - fnum_max,
- cpu, read_backlog(cpu, fnum - fnum_max)) < 0)
+ cpu, read_backlog(cpu, fnum - fnum_max),
+ bulkmode) < 0)
return -1;
remove(buf); /* don't care */
}
write_backlog(cpu, fnum, t);
}
- if (make_outfile_name(buf, PATH_MAX, fnum, cpu, t) < 0)
+ if (make_outfile_name(buf, PATH_MAX, fnum, cpu, t, bulkmode) < 0)
return -1;
out_fd[cpu] = open (buf, O_CREAT|O_TRUNC|O_WRONLY, 0666);
if (out_fd[cpu] < 0) {
diff --git a/runtime/staprun/relay_old.c b/runtime/staprun/relay_old.c
index 33d2daf..71d8ace 100644
--- a/runtime/staprun/relay_old.c
+++ b/runtime/staprun/relay_old.c
@@ -87,30 +87,33 @@ static int open_oldoutfile(int fnum, int cpu, int remove_file)
if (fnum_max) {
if (remove_file) {
/* remove oldest file */
- if (make_outfile_name(buf, PATH_MAX, fnum - fnum_max,
- cpu, read_backlog(cpu, fnum - fnum_max)) < 0)
+ if (make_outfile_name(buf, PATH_MAX,
+ fnum - fnum_max, cpu,
+ read_backlog(cpu, fnum - fnum_max),
+ bulkmode) < 0)
return -1;
remove(buf); /* don't care */
}
write_backlog(cpu, fnum, t);
}
- if (make_outfile_name(buf, PATH_MAX, fnum, cpu, t) < 0)
+ if (make_outfile_name(buf, PATH_MAX, fnum, cpu, t, bulkmode) < 0)
return -1;
} else if (bulkmode) {
if (sprintf_chk(buf, "stpd_cpu%d.%d", cpu, fnum))
return -1;
} else { /* stream mode */
- out_fd[cpu] = STDOUT_FILENO;
+ percpu_tmpfile[cpu] = stdout;
return 0;
}
- out_fd[cpu] = open (buf, O_CREAT|O_TRUNC|O_WRONLY, 0666);
- if (out_fd[cpu] < 0) {
+ if((percpu_tmpfile[cpu] = fopen(buf, "w+")) == NULL) {
perr("Couldn't open output file %s", buf);
return -1;
}
- if (set_clexec(out_fd[cpu]) < 0)
+ if (set_clexec(fileno(percpu_tmpfile[cpu])) < 0) {
+ perr("Couldn't clear exec bit of open output file %s", buf);
return -1;
+ }
return 0;
}
/**
diff --git a/runtime/staprun/staprun.h b/runtime/staprun/staprun.h
index bd6402e..3c9dab3 100644
--- a/runtime/staprun/staprun.h
+++ b/runtime/staprun/staprun.h
@@ -120,7 +120,8 @@ int init_oldrelayfs(void);
void close_oldrelayfs(int);
int write_realtime_data(void *data, ssize_t nb);
void setup_signals(void);
-int make_outfile_name(char *buf, int max, int fnum, int cpu, time_t t);
+int make_outfile_name(char *buf, int max, int fnum, int cpu,
+ time_t t, int bulk);
int init_backlog(int cpu);
void write_backlog(int cpu, int fnum, time_t t);
time_t read_backlog(int cpu, int fnum);