[faultd],
[http://review.tizen.org/git/])
AC_CONFIG_SRCDIR([src/faultd.c])
+AC_CONFIG_SRCDIR([src/audit.c])
AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([
check-news
AS_IF([test "x$have_libsystemd" = "xno"],
AC_MSG_ERROR([libsystemd version 221 or newer not found]))
+PKG_CHECK_MODULES(AUDIT,
+ [audit],
+ have_audit=yes,
+ have_audit=no)
+AS_IF([test "x$have_audit" = "xno"],
+ AC_MSG_ERROR([audit not found]))
+
AC_CHECK_FUNCS([ \
printf\
])
--- /dev/null
+#include <libaudit.h>
+#include <systemd/sd-event.h>
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include "audit.h"
+
+static struct audit_rule_data rule_data = {
+ .flags = AUDIT_FILTER_EXIT, /* trigger on exit from syscall */
+ .action = AUDIT_ALWAYS, /* always catch matching syscall */
+ .field_count = 1,
+ .fields = {AUDIT_EXIT}, /* watch exit code */
+ .values = {-EMFILE},
+ .fieldflags = {AUDIT_EQUAL}, /* trigger if equal to value*/
+};
+
+static int audit_handler(sd_event_source *s, int fd, uint32_t revents, void *userdata)
+{
+ struct audit_reply reply;
+ int ret;
+
+ ret = audit_get_reply(fd, &reply, GET_REPLY_NONBLOCKING, 0);
+ if (ret < 0) {
+ fprintf(stderr, "Could not get reply\n");
+ return ret;
+ }
+
+ if (reply.type == AUDIT_SYSCALL)
+ printf("syscall: data = %.*s\n", reply.len, (char *)reply.message);
+
+ return 0;
+}
+
+int faultd_audit_init(sd_event *event)
+{
+ int fd;
+ int ret;
+
+ fd = audit_open();
+ if (fd < 0) {
+ fprintf(stderr, "Could not open audit socket (%d)\n", fd);
+ return fd;
+ }
+
+ ret = audit_set_pid(fd, getpid(), WAIT_YES);
+ if (ret < 0) {
+ fprintf(stderr, "Could not set pid (%d)\n", ret);
+ return ret;
+ }
+
+ ret = sd_event_add_io(event, NULL, fd, EPOLLIN, audit_handler, NULL);
+ if (ret < 0) {
+ fprintf(stderr, "Could not add event io (%d)\n", ret);
+ return ret;
+ }
+
+ /* TODO: select only relevant syscalls */
+ audit_rule_syscallbyname_data(&rule_data, "all");
+
+ ret = audit_add_rule_data(fd, &rule_data, AUDIT_FILTER_EXIT, AUDIT_ALWAYS);
+ if (ret < 0 && ret != -EEXIST) {
+ fprintf(stderr, "Could not add rule: %d\n", ret);
+ return ret;
+ }
+
+ return fd;
+}
+
+int faultd_audit_close(int fd)
+{
+ int ret;
+
+ ret = audit_delete_rule_data(fd, &rule_data, AUDIT_FILTER_EXIT, AUDIT_ALWAYS);
+ if (ret < 0 && ret != -EEXIST) {
+ fprintf(stderr, "Could not add rule: %d\n", ret);
+ return ret;
+ }
+
+ ret = audit_set_pid(fd, 0, WAIT_YES);
+ if (ret < 0) {
+ fprintf(stderr, "Could not set pid (%d)\n", ret);
+ return ret;
+ }
+
+ audit_close(fd);
+ return 0;
+}
#include <stdio.h>
#include <systemd/sd-bus.h>
+#include <systemd/sd-event.h>
+#include <signal.h>
+#include "audit.h"
+
+static int terminate = 0;
+
+int sigint_handler(sd_event_source *s,
+ const struct signalfd_siginfo *si,
+ void *userdata)
+{
+ terminate = 1;
+ return 0;
+}
int dbus_handler(sd_event_source *s, int fd, uint32_t revents, void *userdata);
sd_bus *bus = NULL;
/* const char *path; */
int rc;
-
+ int aufd;
+ sigset_t ss;
rc = sd_bus_new(&bus);
if (rc < 0) {
return -1;
}
- sd_event_add_io(loop, NULL, sd_bus_get_fd(bus), EPOLLIN | EPOLLOUT, dbus_handler, (void*)bus);
+ sigemptyset(&ss);
+ sigaddset(&ss, SIGINT);
+ rc = sigprocmask(SIG_BLOCK, &ss, NULL);
+ rc = sd_event_add_signal(loop, NULL, SIGINT, sigint_handler, NULL);
+
+
+// sd_event_add_io(loop, NULL, sd_bus_get_fd(bus), EPOLLIN | EPOLLOUT, dbus_handler, (void*)bus);
+ aufd = faultd_audit_init(loop);
printf("Hello world!\n");
for (;;) {
fprintf(stderr, "Failed to wait on the bus.\n");
break;
}
+
+ if (terminate) {
+ printf("Closing...\n");
+ break;
+ }
}
sd_bus_close(bus);
+ faultd_audit_close(aufd);
return 0;
}