diff options
Diffstat (limited to 'runtime/staprun/ctl.c')
-rw-r--r-- | runtime/staprun/ctl.c | 56 |
1 files changed, 11 insertions, 45 deletions
diff --git a/runtime/staprun/ctl.c b/runtime/staprun/ctl.c index 53c27190..72592bdf 100644 --- a/runtime/staprun/ctl.c +++ b/runtime/staprun/ctl.c @@ -12,62 +12,28 @@ #include "staprun.h" -/* This is only used in the old relayfs code */ -static void read_buffer_info(void) -{ - char buf[PATH_MAX]; - struct statfs st; - int fd, len, ret; - - if (!use_old_transport) - return; - - if (statfs("/sys/kernel/debug", &st) == 0 && (int) st.f_type == (int) DEBUGFS_MAGIC) - return; - - sprintf (buf, "/proc/systemtap/%s/bufsize", modname); - fd = open(buf, O_RDONLY); - if (fd < 0) - return; - - len = read(fd, buf, sizeof(buf)); - if (len <= 0) { - fprintf (stderr, "ERROR: couldn't read bufsize.\n"); - close(fd); - return; - } - ret = sscanf(buf, "%u,%u", &n_subbufs, &subbuf_size); - if (ret != 2) - fprintf (stderr, "ERROR: couldn't read bufsize.\n"); - - dbug(2, "n_subbufs= %u, size=%u\n", n_subbufs, subbuf_size); - close(fd); - return; -} - - int init_ctl_channel(void) { char buf[PATH_MAX]; struct statfs st; - if (statfs("/sys/kernel/debug", &st) == 0 && (int) st.f_type == (int) DEBUGFS_MAGIC) - sprintf (buf, "/sys/kernel/debug/systemtap/%s/cmd", modname); - else - sprintf (buf, "/proc/systemtap/%s/cmd", modname); - + if (statfs("/sys/kernel/debug", &st) == 0 && (int) st.f_type == (int) DEBUGFS_MAGIC) { + if (sprintf_chk(buf, "/sys/kernel/debug/systemtap/%s/cmd", modname)) + return -1; + } else { + if (sprintf_chk(buf, "/proc/systemtap/%s/cmd", modname)) + return -1; + } + dbug(2, "Opening %s\n", buf); control_channel = open(buf, O_RDWR); if (control_channel < 0) { - if (attach_mod) - fprintf (stderr, "ERROR: Cannot connect to module \"%s\".\n", modname); + if (attach_mod && errno == ENOENT) + err("ERROR: Can not attach. Module %s not running.\n", modname); else - fprintf (stderr, "ERROR: couldn't open control channel %s\n", buf); - fprintf (stderr, "errcode = %s\n", strerror(errno)); + perr("Couldn't open control channel '%s'", buf); return -1; } - - read_buffer_info(); return 0; } |