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]

Re: script compilation fails at 'Pass 4'


Mehul_Choube wrote:

> http://pastebin.com/vyKHBGd0

sockname() can't work like that.  Systemtap embedded-C code runs
within the kernel, and can't call userspace glibc functions or
system calls like that.

Try instead: 

########################################################################
function print_fd(fd) {
         task = task_current()
         sock = task_file_handle_socket(task,fd)
	 if (sock) {
            fam = socket_family(sock)
            if (fam == %{ AF_INET %}) {
	       printf("%s[%d] fd %d: %s\n", execname(), tid(), fd,
                      socket_ipv4_sockname(sock))
               return 0
            } /* other cases as per pfiles.stp */
         }
}

probe syscall.connect.return {
      if ($return >= 0) print_fd($return)
}


/* the rest verbatim from pfiles.stp */

%{
#include <linux/file.h>
#include <net/sock.h>
#include <linux/un.h>
#include <linux/tcp.h>
#include <linux/in.h>
%}

function task_file_handle_socket:long (task:long, fd:long) %{ /* pure */
        struct task_struct *p = (struct task_struct *)((long)STAP_ARG_task);
	struct files_struct *files;
        struct file *filp;
        struct dentry *dentry;
        struct inode *inode;

        rcu_read_lock();
        if ((files = kread(&p->files)) &&
            (filp = fcheck_files(files, STAP_ARG_fd)) &&
            (dentry = kread(&filp->f_dentry)) &&
            (inode = kread(&filp->f_dentry->d_inode))) {
                if (S_ISSOCK(kread(&inode->i_mode)))
                        STAP_RETVALUE = (long)SOCKET_I(inode);
        }

        CATCH_DEREF_FAULT();
        rcu_read_unlock();
%}

function socket_family:long (sock:long) %{ /* pure */
	struct socket *sock = (struct socket *)((long)STAP_ARG_sock);
        const struct proto_ops *ops = kread(&sock->ops);
        STAP_RETVALUE = (long)kread(&ops->family);
        CATCH_DEREF_FAULT();
%}

function socket_ipv4_sockname:string (sock:long) %{ /* pure */
        struct socket *sock = (struct socket *)((long)STAP_ARG_sock);
        const struct proto_ops *ops = kread(&sock->ops);
        struct sockaddr_in in_addr;
        __be32 addr, port;
        int err, len;

	err = ops->getname (sock, (struct sockaddr*)(&in_addr), &len, 0);
        if (!err) {
                addr = in_addr.sin_addr.s_addr;
                port = htons(in_addr.sin_port);
		snprintf(STAP_RETVALUE, MAXSTRINGLEN,
                        "        sockname: AF_INET " NIPQUAD_FMT "  port: %d",
	                NIPQUAD(addr), port);
        }
        CATCH_DEREF_FAULT();
%}


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