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

ifs: daemon configurations and bugfix

parent ba4577e3
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -9,6 +9,11 @@
#define LOG_INFO
//#define LOG_DEBUG
//#define LOG_TRACE
#define LOG_PATH "/tmp/adafs.log"

// Enable logging for daemon
#define LOG_DAEMON_DEBUG 1
#define LOG_DAEMON_PATH "/tmp/adafs_daemon.log"

// If ACM time should be considered
#define ACMtime
+8 −1
Original line number Diff line number Diff line
@@ -10,10 +10,12 @@
#include <stdint.h>
#include <fcntl.h>

#include "../../configure.hpp"

#include <preload/open_file_map.hpp>
#include <preload/preload_util.hpp>

//

void* libc;

void* libc_open;
@@ -75,7 +77,12 @@ static OpenFileMap file_map{};
#define ld_dup dup
#define ld_dup2 dup2

bool is_lib_initialized = false;

FILE* debug_fd;

#define DAEMON_DEBUG(fd, fmt, ...) \
            do { if (LOG_DAEMON_DEBUG) fprintf(fd, fmt, ##__VA_ARGS__); } while (0)

void init_preload(void) __attribute__((constructor));

+2 −2
Original line number Diff line number Diff line
@@ -9,8 +9,8 @@ namespace po = boost::program_options;
int main(int argc, const char* argv[]) {


//    //set the spdlogger and initialize it with spdlog
    ADAFS_DATA->spdlogger(spdlog::basic_logger_mt("basic_logger", "adafs.log"));
    //set the spdlogger and initialize it with spdlog
    ADAFS_DATA->spdlogger(spdlog::basic_logger_mt("basic_logger", LOG_PATH));
#if defined(LOG_TRACE)
    spdlog::set_level(spdlog::level::trace);
    ADAFS_DATA->spdlogger()->flush_on(spdlog::level::trace);
+2 −2
Original line number Diff line number Diff line
@@ -20,8 +20,8 @@
#include <boost/program_options.hpp>
#include <boost/tokenizer.hpp>
// third party libs
#include "extern/spdlog/spdlog.h"
#include "extern/spdlog/fmt/fmt.h"
#include <extern/spdlog/spdlog.h>
#include <extern/spdlog/fmt/fmt.h>
// rocksdb
#include <rocksdb/db.h>
#include <rocksdb/slice.h>
+22 −30
Original line number Diff line number Diff line
@@ -5,35 +5,12 @@
//#define _GNU_SOURCE
#include <preload/preload.hpp>
#include <dlfcn.h>
#include <string.h>

//#include <dlfcn.h>
//#include <sys/types.h>
//#include <sys/uio.h>
//#include <stdio.h>
#include <stdarg.h>
//#include <stdlib.h>
//#include <inttypes.h>
//#include <string.h>
//#include <assert.h>
//#include <errno.h>
//#include <utime.h>
//#include <sys/statvfs.h>
//#include <fcntl.h>
//#include <sys/stat.h>
//#include <dirent.h>
//#include <sys/param.h>
//#include <sys/mount.h>
//#include <sys/time.h>
#include <unistd.h>
//#include <dirent.h>
//#include <sys/xattr.h>
//#include <string>
//#include <iostream>


int ld_open(const char* path, int flags, ...) {
    printf("opening up the path: %s\n", path);
    mode_t mode;
    if (flags & O_CREAT) {
        va_list vl;
@@ -60,7 +37,7 @@ int ld_open64(__const char* path, int flags, ...) {
}

FILE* ld_fopen(const char* path, const char* mode) {
    printf("FILE opening up the path: %s\n", path);
    printf("test\n");
    return (reinterpret_cast<decltype(&fopen)>(libc_fopen))(path, mode);
}

@@ -72,13 +49,11 @@ int ld_close(int fd) {
    if (file_map.exist(fd)) {
        // TODO call daemon and return (do we even need to)
        file_map.remove(fd);
    } else
        printf("closing fd: %d\n", fd);
    }
    return (reinterpret_cast<decltype(&close)>(libc_close))(fd);
}

int ld___close(int fd) {
    printf("___closing fd: %d\n", fd);
    return ld_close(fd);
}

@@ -91,7 +66,6 @@ int ld_stat(const char* path, struct stat* buf) {
}

int ld_fstat(int fd, struct stat* buf) {
    \
    if (file_map.exist(fd)) {
        auto path = file_map.get(fd)->path(); // TODO use this to send to the daemon (call directly)
        // TODO call daemon and return
@@ -100,7 +74,6 @@ int ld_fstat(int fd, struct stat* buf) {
}

int ld_puts(const char* str) {
    printf("puts:chars#:%lu\n", strlen(str));
    return (reinterpret_cast<decltype(&puts)>(libc_puts))(str);
}

@@ -153,14 +126,27 @@ int ld_ftruncate(int fd, off_t length) __THROW {
}

int ld_dup(int oldfd) __THROW {
    if (file_map.exist(oldfd)) {
        // Not implemented
        return -1;
    }
    return (reinterpret_cast<decltype(&dup)>(libc_dup))(oldfd);
}

int ld_dup2(int oldfd, int newfd) __THROW {
    if (file_map.exist(oldfd) || file_map.exist(newfd)) {
        // Not implemented
        return -1;
    }
    return (reinterpret_cast<decltype(&dup2)>(libc_dup2))(oldfd, newfd);
}


void init_preload(void) {

    // just a security measure
    if (is_lib_initialized)
        return;
    libc = dlopen("libc.so.6", RTLD_LAZY);
    libc_open = dlsym(libc, "open");
    libc_fopen = dlsym(libc, "fopen");
@@ -183,9 +169,15 @@ void init_preload(void) {
    libc_truncate = dlsym(libc, "truncate");
    libc_ftruncate = dlsym(libc, "ftruncate");

    printf("HELLLO\n");
    libc_dup = dlsym(libc, "dup");
    libc_dup2 = dlsym(libc, "dup2");

    debug_fd = fopen(LOG_DAEMON_PATH, "a+");
    DAEMON_DEBUG(debug_fd, "Preload initialized.\n");
    is_lib_initialized = true;
}

void destroy_preload(void) {

    fclose(debug_fd);
}
 No newline at end of file
Loading