Commit ca12fe03 authored by Marc Vef's avatar Marc Vef
Browse files

ifs: added daemon Signal handlers + added unlink and access libc interceptor fncts

parent 074eec5c
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ extern "C" {
#define ld_fopen fopen

#define ld_creat creat
#define ld_unlink unlink

#define ld_close close
#define ld___close __close
@@ -35,6 +36,8 @@ extern "C" {
#define ld_stat stat
#define ld_fstat fstat

#define ld_access access

#define ld_puts puts

#define ld_write write
+14 −1
Original line number Diff line number Diff line
@@ -2,10 +2,18 @@

#include "daemon/adafs_daemon.hpp"

#include <csignal>


using namespace std;
namespace po = boost::program_options;

static bool shutdown_please = false;

void shutdown_handler(int dummy) {
    shutdown_please = true;
}

int main(int argc, const char* argv[]) {


@@ -97,12 +105,17 @@ int main(int argc, const char* argv[]) {
#ifndef MARGOIPC
    run_daemon(); // blocks here until application loop is exited TODO don't know yet how it'll be closed :D
#else
    bool shutdown_please = false;

    signal(SIGINT, shutdown_handler);
    signal(SIGTERM, shutdown_handler);
    signal(SIGKILL, shutdown_handler);

    while (!shutdown_please) {
        sleep(1);
    }

    ADAFS_DATA->spdlogger()->info("Shutting done signal encountered. Shutting down ...");

#endif
    destroy_enviroment();

+31 −1
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ void* libc_open;
void* libc_fopen;

//void* libc_creat; //unused
void* libc_unlink;

void* libc_close;
//void* libc___close; //unused
@@ -40,6 +41,8 @@ void* libc_close;
void* libc_stat;
void* libc_fstat;

void* libc_access;

void* libc_puts;

void* libc_write;
@@ -82,7 +85,6 @@ int ld_open(const char* path, int flags, ...) {
            return -1;
        }
    }
    ipc_send_open(path, flags, mode, ipc_open_id);
    return (reinterpret_cast<decltype(&open)>(libc_open))(path, flags, mode);
}

@@ -102,9 +104,22 @@ FILE* ld_fopen(const char* path, const char* mode) {
}

int ld_creat(const char* path, mode_t mode) {
//    DAEMON_DEBUG(debug_fd, "ld_creat called with path %s with mode %d\n", path, mode);
    return ld_open(path, O_CREAT | O_WRONLY | O_TRUNC, mode);
}

int ld_unlink(const char* path) __THROW {
//    DAEMON_DEBUG(debug_fd, "ld_unlink called with path %s\n", path);
    if (is_fs_path(path)) {
#ifndef MARGOIPC

#else

#endif
    }
    return (reinterpret_cast<decltype(&unlink)>(libc_unlink))(path);
}

int ld_close(int fd) {
    if (file_map.exist(fd)) {
        // TODO call daemon and return (do we even need to)
@@ -150,6 +165,17 @@ int ld_fstat(int fd, struct stat* buf) {
    return (reinterpret_cast<decltype(&fstat)>(libc_fstat))(fd, buf);
}

int ld_access(const char* path, int mode) __THROW {
    if (is_fs_path(path)) {
#ifndef MARGOIPC

#else

#endif
    }
    return (reinterpret_cast<decltype(&access)>(libc_access))(path, mode);
}

int ld_puts(const char* str) {
    return (reinterpret_cast<decltype(&puts)>(libc_puts))(str);
}
@@ -349,12 +375,16 @@ void init_preload(void) {
    libc_open = dlsym(libc, "open");
    libc_fopen = dlsym(libc, "fopen");

    libc_unlink = dlsym(libc, "unlink");

    libc_close = dlsym(libc, "close");
//    libc___close = dlsym(libc, "__close");

    libc_stat = dlsym(libc, "stat");
    libc_fstat = dlsym(libc, "fstat");

    libc_access = dlsym(libc, "access");

    libc_puts = dlsym(libc, "puts");

    libc_write = dlsym(libc, "write");