From ad6787967f4156c5a2d4b513cfd535eb3d62c95b Mon Sep 17 00:00:00 2001 From: Grazvydas Ignotas Date: Fri, 21 Aug 2015 03:38:05 +0300 Subject: [PATCH] fatrace: add 0.10 with old glibc compat stuff --- recipes/fatrace/fatrace_0.10.bb | 28 ++++++ recipes/fatrace/files/linux_fanotify.h | 123 +++++++++++++++++++++++++ recipes/fatrace/files/old_glibc.patch | 40 ++++++++ recipes/fatrace/files/sys_fanotify.h | 38 ++++++++ 4 files changed, 229 insertions(+) create mode 100644 recipes/fatrace/fatrace_0.10.bb create mode 100644 recipes/fatrace/files/linux_fanotify.h create mode 100644 recipes/fatrace/files/old_glibc.patch create mode 100644 recipes/fatrace/files/sys_fanotify.h diff --git a/recipes/fatrace/fatrace_0.10.bb b/recipes/fatrace/fatrace_0.10.bb new file mode 100644 index 0000000..94ec469 --- /dev/null +++ b/recipes/fatrace/fatrace_0.10.bb @@ -0,0 +1,28 @@ +DESCRIPTION = "fatrace reports file access events from all running processes." +LICENSE = "GPLv3" + +PR = "r0" + +SRC_URI = " \ + https://launchpad.net/fatrace/trunk/0.10/+download/fatrace-${PV}.tar.bz2 \ + file://old_glibc.patch;patch=1 \ + file://sys_fanotify.h \ + file://linux_fanotify.h \ +" + +CFLAGS += "-I." + +do_compile() { + mkdir -p ${S}/sys/ + cp ${WORKDIR}/sys_fanotify.h ${S}/sys/fanotify.h + mkdir -p ${S}/linux/ + cp ${WORKDIR}/linux_fanotify.h ${S}/linux/fanotify.h + + oe_runmake +} + +do_install() { + oe_runmake install PREFIX=${prefix} DESTDIR=${D} +} + +SRC_URI[md5sum] = "b8b101fa3e2e18bac048a3240a5dbdab" diff --git a/recipes/fatrace/files/linux_fanotify.h b/recipes/fatrace/files/linux_fanotify.h new file mode 100644 index 0000000..4d5647e --- /dev/null +++ b/recipes/fatrace/files/linux_fanotify.h @@ -0,0 +1,123 @@ +#ifndef _LINUX_FANOTIFY_H +#define _LINUX_FANOTIFY_H + +#include + +#ifndef __aligned_u64 +#define __aligned_u64 __u64 __attribute__((aligned(8))) +#endif +#ifndef AT_FDCWD +#define AT_FDCWD -100 +#endif + +/* the following events that user-space can register for */ +#define FAN_ACCESS 0x00000001 /* File was accessed */ +#define FAN_MODIFY 0x00000002 /* File was modified */ +#define FAN_CLOSE_WRITE 0x00000008 /* Writtable file closed */ +#define FAN_CLOSE_NOWRITE 0x00000010 /* Unwrittable file closed */ +#define FAN_OPEN 0x00000020 /* File was opened */ + +#define FAN_Q_OVERFLOW 0x00004000 /* Event queued overflowed */ + +#define FAN_OPEN_PERM 0x00010000 /* File open in perm check */ +#define FAN_ACCESS_PERM 0x00020000 /* File accessed in perm check */ + +#define FAN_ONDIR 0x40000000 /* event occurred against dir */ + +#define FAN_EVENT_ON_CHILD 0x08000000 /* interested in child events */ + +/* helper events */ +#define FAN_CLOSE (FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE) /* close */ + +/* flags used for fanotify_init() */ +#define FAN_CLOEXEC 0x00000001 +#define FAN_NONBLOCK 0x00000002 + +/* These are NOT bitwise flags. Both bits are used togther. */ +#define FAN_CLASS_NOTIF 0x00000000 +#define FAN_CLASS_CONTENT 0x00000004 +#define FAN_CLASS_PRE_CONTENT 0x00000008 +#define FAN_ALL_CLASS_BITS (FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | \ + FAN_CLASS_PRE_CONTENT) + +#define FAN_UNLIMITED_QUEUE 0x00000010 +#define FAN_UNLIMITED_MARKS 0x00000020 + +#define FAN_ALL_INIT_FLAGS (FAN_CLOEXEC | FAN_NONBLOCK | \ + FAN_ALL_CLASS_BITS | FAN_UNLIMITED_QUEUE |\ + FAN_UNLIMITED_MARKS) + +/* flags used for fanotify_modify_mark() */ +#define FAN_MARK_ADD 0x00000001 +#define FAN_MARK_REMOVE 0x00000002 +#define FAN_MARK_DONT_FOLLOW 0x00000004 +#define FAN_MARK_ONLYDIR 0x00000008 +#define FAN_MARK_MOUNT 0x00000010 +#define FAN_MARK_IGNORED_MASK 0x00000020 +#define FAN_MARK_IGNORED_SURV_MODIFY 0x00000040 +#define FAN_MARK_FLUSH 0x00000080 + +#define FAN_ALL_MARK_FLAGS (FAN_MARK_ADD |\ + FAN_MARK_REMOVE |\ + FAN_MARK_DONT_FOLLOW |\ + FAN_MARK_ONLYDIR |\ + FAN_MARK_MOUNT |\ + FAN_MARK_IGNORED_MASK |\ + FAN_MARK_IGNORED_SURV_MODIFY |\ + FAN_MARK_FLUSH) + +/* + * All of the events - we build the list by hand so that we can add flags in + * the future and not break backward compatibility. Apps will get only the + * events that they originally wanted. Be sure to add new events here! + */ +#define FAN_ALL_EVENTS (FAN_ACCESS |\ + FAN_MODIFY |\ + FAN_CLOSE |\ + FAN_OPEN) + +/* + * All events which require a permission response from userspace + */ +#define FAN_ALL_PERM_EVENTS (FAN_OPEN_PERM |\ + FAN_ACCESS_PERM) + +#define FAN_ALL_OUTGOING_EVENTS (FAN_ALL_EVENTS |\ + FAN_ALL_PERM_EVENTS |\ + FAN_Q_OVERFLOW) + +#define FANOTIFY_METADATA_VERSION 3 + +struct fanotify_event_metadata { + __u32 event_len; + __u8 vers; + __u8 reserved; + __u16 metadata_len; + __aligned_u64 mask; + __s32 fd; + __s32 pid; +}; + +struct fanotify_response { + __s32 fd; + __u32 response; +}; + +/* Legit userspace responses to a _PERM event */ +#define FAN_ALLOW 0x01 +#define FAN_DENY 0x02 +/* No fd set in event */ +#define FAN_NOFD -1 + +/* Helper functions to deal with fanotify_event_metadata buffers */ +#define FAN_EVENT_METADATA_LEN (sizeof(struct fanotify_event_metadata)) + +#define FAN_EVENT_NEXT(meta, len) ((len) -= (meta)->event_len, \ + (struct fanotify_event_metadata*)(((char *)(meta)) + \ + (meta)->event_len)) + +#define FAN_EVENT_OK(meta, len) ((long)(len) >= (long)FAN_EVENT_METADATA_LEN && \ + (long)(meta)->event_len >= (long)FAN_EVENT_METADATA_LEN && \ + (long)(meta)->event_len <= (long)(len)) + +#endif /* _LINUX_FANOTIFY_H */ diff --git a/recipes/fatrace/files/old_glibc.patch b/recipes/fatrace/files/old_glibc.patch new file mode 100644 index 0000000..fb77497 --- /dev/null +++ b/recipes/fatrace/files/old_glibc.patch @@ -0,0 +1,40 @@ +diff -Nur fatrace-0.10_/Makefile fatrace-0.10/Makefile +--- fatrace-0.10_/Makefile 2015-04-29 11:36:49.000000000 +0300 ++++ fatrace-0.10/Makefile 2015-08-21 03:15:38.318377923 +0300 +@@ -3,8 +3,8 @@ + CFLAGS ?= -O2 -g -Wall -Wextra -Werror + PREFIX ?= /usr/local + +-fatrace: fatrace.o +- $(CC) $(LDFLAGS) -o $@ $< ++fatrace: fatrace.o syscalls.o ++ $(CC) $(LDFLAGS) -o $@ $^ + + clean: + rm -f *.o fatrace +diff -Nur fatrace-0.10_/syscalls.c fatrace-0.10/syscalls.c +--- fatrace-0.10_/syscalls.c 1970-01-01 03:00:00.000000000 +0300 ++++ fatrace-0.10/syscalls.c 2015-08-21 03:14:28.930375341 +0300 +@@ -0,0 +1,22 @@ ++#include ++#include ++#include ++ ++#ifndef __NR_fanotify_init ++#define __NR_fanotify_init (__NR_SYSCALL_BASE+367) ++#endif ++#ifndef __NR_fanotify_mark ++#define __NR_fanotify_mark (__NR_SYSCALL_BASE+368) ++#endif ++ ++int fanotify_init(unsigned int __flags, unsigned int __event_f_flags) ++{ ++ return syscall(__NR_fanotify_init, __flags, __event_f_flags); ++} ++ ++int fanotify_mark (int __fanotify_fd, unsigned int __flags, ++ uint64_t __mask, int __dfd, const char *__pathname) ++{ ++ return syscall(__NR_fanotify_mark, __fanotify_fd, __flags, ++ (int)__mask, (int)(__mask >> 32), __dfd, __pathname); ++} diff --git a/recipes/fatrace/files/sys_fanotify.h b/recipes/fatrace/files/sys_fanotify.h new file mode 100644 index 0000000..480e912 --- /dev/null +++ b/recipes/fatrace/files/sys_fanotify.h @@ -0,0 +1,38 @@ +/* Copyright (C) 2010-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _SYS_FANOTIFY_H +#define _SYS_FANOTIFY_H 1 + +#include +#include + + +__BEGIN_DECLS + +/* Create and initialize fanotify group. */ +extern int fanotify_init (unsigned int __flags, unsigned int __event_f_flags) + __THROW; + +/* Add, remove, or modify an fanotify mark on a filesystem object. */ +extern int fanotify_mark (int __fanotify_fd, unsigned int __flags, + uint64_t __mask, int __dfd, const char *__pathname) + __THROW; + +__END_DECLS + +#endif /* sys/fanotify.h */ -- 2.39.2