Permalink
Browse files

Move code that was duplicated in opensnoop.c and opensnoop.py into op…

…ensnoop.h.
  • Loading branch information...
bolinfest committed Sep 27, 2018
1 parent 97303f8 commit f528a8ad9b7305f482623b1b94448df035a58e18
Showing with 29 additions and 38 deletions.
  1. +1 −24 opensnoop/opensnoop.c
  2. +27 −0 opensnoop/opensnoop.h
  3. +1 −14 opensnoop/opensnoop.py
View
@@ -1,4 +1,5 @@
#include "generated_bytecode.h"
#include "opensnoop.h"
#include <bcc/libbpf.h>
#include <bcc/perf_reader.h>
#include <errno.h>
@@ -12,35 +13,11 @@
#include <time.h>
#include <unistd.h>
// This seems like it should be in <linux/sched.h>,
// but I don't have it there on Ubuntu 18.04.
#ifndef TASK_COMM_LEN
// Task command name length:
#define TASK_COMM_LEN 16
#endif
// These constants and structs must match those
// used in the source in opensnoop.py.
#define LOG_BUF_SIZE 65536
#define NAME_MAX 255
char bpf_log_buf[LOG_BUF_SIZE];
struct val_t {
__u64 id;
char comm[TASK_COMM_LEN];
const char *fname;
};
struct data_t {
__u64 id;
__u64 ts;
int ret;
char comm[TASK_COMM_LEN];
char fname[NAME_MAX];
};
/**
* If a positive integer is parsed successfully, returns the value.
* If not, returns -1 and errno is set.
View
@@ -0,0 +1,27 @@
/**
* This header contains definitions that are shared with
* opensnoop.c and opensnoop.py.
*/
// This seems like it should be in <linux/sched.h>,
// but I don't have it there on Ubuntu 18.04.
#ifndef TASK_COMM_LEN
// Task command name length:
#define TASK_COMM_LEN 16
#endif
#define NAME_MAX 255
struct val_t {
__u64 id;
char comm[TASK_COMM_LEN];
const char *fname;
};
struct data_t {
__u64 id;
__u64 ts;
int ret;
char comm[TASK_COMM_LEN];
char fname[NAME_MAX];
};
View
@@ -14,20 +14,7 @@
#include <uapi/linux/ptrace.h>
#include <uapi/linux/limits.h>
#include <linux/sched.h>
struct val_t {
u64 id;
char comm[TASK_COMM_LEN];
const char *fname;
};
struct data_t {
u64 id;
u64 ts;
int ret;
char comm[TASK_COMM_LEN];
char fname[NAME_MAX];
};
#include "opensnoop.h"
BPF_HASH(infotmp, u64, struct val_t);
BPF_PERF_OUTPUT(events);

0 comments on commit f528a8a

Please sign in to comment.