diff options
author | Clark Williams <williams@redhat.com> | 2011-09-07 16:25:02 -0500 |
---|---|---|
committer | Clark Williams <williams@redhat.com> | 2011-09-07 16:25:02 -0500 |
commit | 3209d3c634db739605c6d3fbd9ad55cb50d1f2df (patch) | |
tree | 9c7a205bc23b858f2e9510c920962ed629c6af7c | |
parent | aca74c66e53b884ecd9638a2be286794e0d43c40 (diff) | |
download | cyclictest-3209d3c634db739605c6d3fbd9ad55cb50d1f2df.tar.gz |
add stat(2) shortcuts to mount_debugfs()
Before trying to parse /proc/mount, check for existance of directories
/sys/kernel/debug/tracing and /debug/tracing using stat(2).
Signed-off-by: Clark Williams <williams@redhat.com>
-rw-r--r-- | src/include/rt-utils.h | 1 | ||||
-rw-r--r-- | src/lib/rt-utils.c | 45 |
2 files changed, 36 insertions, 10 deletions
diff --git a/src/include/rt-utils.h b/src/include/rt-utils.h index 730344e..316b09c 100644 --- a/src/include/rt-utils.h +++ b/src/include/rt-utils.h @@ -20,5 +20,6 @@ int event_disable_all(void); void warn(char *fmt, ...); void fatal(char *fmt, ...); +void info(char *fmt, ...); #endif /* __RT_UTILS.H */ diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c index 4776c00..ec71dbd 100644 --- a/src/lib/rt-utils.c +++ b/src/lib/rt-utils.c @@ -13,6 +13,9 @@ #include <stdarg.h> #include <errno.h> #include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> #include "rt-utils.h" static char debugfileprefix[MAX_PATH]; @@ -26,12 +29,26 @@ char *get_debugfileprefix(void) FILE *fp; int size; int found = 0; + struct stat s; if (debugfileprefix[0] != '\0') - return debugfileprefix; + goto out; + /* look in the "standard" mount point first */ + if ((stat("/sys/kernel/debug/tracing", &s) == 0) && S_ISDIR(s.st_mode)) { + strcpy(debugfileprefix, "/sys/kernel/debug/tracing/"); + goto out; + } + + /* now look in the "other standard" place */ + if ((stat("/debug/tracing", &s) == 0) && S_ISDIR(s.st_mode)) { + strcpy(debugfileprefix, "/debug/tracing/"); + goto out; + } + + /* oh well, parse /proc/mounts and see if it's there */ if ((fp = fopen("/proc/mounts","r")) == NULL) - return debugfileprefix; + goto out; while (fscanf(fp, "%*s %" STR(MAX_PATH) @@ -41,6 +58,7 @@ char *get_debugfileprefix(void) found = 1; break; } + /* stupid check for systemd-style autofs mount */ if ((strcmp(debugfileprefix, "/sys/kernel/debug") == 0) && (strcmp(type, "systemd") == 0)) { found = 1; @@ -51,12 +69,13 @@ char *get_debugfileprefix(void) if (!found) { debugfileprefix[0] = '\0'; - return debugfileprefix; + goto out; } size = sizeof(debugfileprefix) - strlen(debugfileprefix); strncat(debugfileprefix, "/tracing/", size); +out: return debugfileprefix; } @@ -67,20 +86,16 @@ int mount_debugfs(char *path) char *prefix; int ret; - if (!path) - printf("mount_debugfs: null input\n"); - + /* if it's already mounted just return */ prefix = get_debugfileprefix(); - if (strlen(prefix)) { - printf("mount_debugfs: current debug fileprefix: %s\n", prefix); + if (strlen(prefix) != 0) { + info("debugfs mountpoint: %s\n", prefix); return 0; } - if (!mountpoint) mountpoint = "/sys/kernel/debug"; sprintf(cmd, "mount -t debugfs debugfs %s", mountpoint); - printf("running: %s\n", cmd); ret = system(cmd); if (ret != 0) { fprintf(stderr, "Error mounting debugfs at %s: %s\n", mountpoint, strerror(errno)); @@ -257,6 +272,16 @@ int check_privs(void) return sched_setscheduler(0, policy, &old_param); } +void info(char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + fputs("INFO: ", stderr); + vfprintf(stderr, fmt, ap); + va_end(ap); +} + void warn(char *fmt, ...) { va_list ap; |