Commit 119084c6 authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

Fake tasks can now be created for testing

- task_manager is now a full-fledged class rather than
inheriting from std::unordered_map
- changes to handlers to reflect the new interface
in task_manager
- new dry_run option for enabling "fake task mode"
- in libraries, log errors to stderr only if env var
NORNS_DBG_LOG_TO_STDERR is defined.
parent 786e42ed
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ extern "C" {
/* errors about tasks */
#define NORNS_ETASKEXISTS        -40
#define NORNS_ENOSUCHTASK        -41
#define NORNS_ETOOMANYTASKS      -42

/* task status */
#define NORNS_EPENDING          -100
+16 −3
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#include "log.h"

@@ -57,6 +58,7 @@ static void
log_error_helper(const char* file, int line, const char* func, 
                 const char* suffix, const char* fmt, va_list ap) {

    FILE* outfp = stderr;
    int saved_errno = errno;
    char buffer[MAX_LOG_MSG];
    char errstr[MAX_ERROR_MSG] = "";
@@ -64,6 +66,17 @@ log_error_helper(const char* file, int line, const char* func,
    const char* sep = "";
    int ret;

    if(getenv("NORNS_DBG_LOG_TO_STDERR") == NULL) {
        outfp = fopen("/dev/null", "w");

        if(outfp == NULL) {
            strerror_r(errno, errstr, MAX_ERROR_MSG);
            fprintf(stderr, "unable to open /dev/null: %s", errstr);

            return;
        }
    }

    if(file != NULL) {

        char* f;
@@ -76,7 +89,7 @@ log_error_helper(const char* file, int line, const char* func,
                "<%s>: [%s:%d %s] ", log_prefix, file, line, func);

        if(ret < 0) {
            fprintf(stderr, "vsnprintf failed");
            fprintf(outfp, "vsnprintf failed");
            goto end;
        }

@@ -95,7 +108,7 @@ log_error_helper(const char* file, int line, const char* func,
        ret = vsnprintf(&buffer[cc], MAX_LOG_MSG - cc, fmt, ap);

        if(ret < 0) {
            fprintf(stderr, "vsnprintf failed");
            fprintf(outfp, "vsnprintf failed");
            goto end;
        }

@@ -104,7 +117,7 @@ log_error_helper(const char* file, int line, const char* func,

    snprintf(&buffer[cc], MAX_LOG_MSG - cc, "%s%s%s", sep, errstr, suffix);

    fprintf(stderr, "%s", buffer);
    fprintf(outfp, "%s", buffer);

end:
	errno = saved_errno;
+12 −6
Original line number Diff line number Diff line
@@ -70,10 +70,15 @@ liburd_aux_la_SOURCES = \
	common/types.hpp \
	common/unique-ptr-cast.hpp \
	defaults.hpp \
	io-task.cpp \
	io-task.hpp \
	io-task-stats.cpp \
	io-task-stats.hpp \
	io.hpp \
	io/fake-task.cpp \
	io/fake-task.hpp \
	io/task.cpp \
	io/task.hpp \
	io/task-manager.cpp \
	io/task-manager.hpp \
	io/task-stats.cpp \
	io/task-stats.hpp \
	job.hpp \
	logger.hpp \
	resources.hpp \
@@ -91,7 +96,6 @@ liburd_aux_la_SOURCES = \
	settings.cpp \
	settings.hpp \
	signal-listener.hpp \
	task-manager.hpp \
	thread-pool.hpp \
	thread-pool/thread-pool.hpp \
	thread-pool/thread-pool-queue.hpp \
@@ -142,7 +146,9 @@ defaults.cpp: Makefile
	   echo "    const char* progname           = \"urd\";"; \
	   echo "    const bool  daemonize          = true;"; \
	   echo "    const bool  use_syslog         = false;"; \
	   echo "    const char* running_dir        = \"/tmp\";"; \
	   echo ""; \
\
	   echo "    const bool dry_run             = false;"; \
\
	   echo "    const char* global_socket      = \"$(localstatedir)/urd/global.socket.2\";"; \
	   echo "    const char* control_socket     = \"$(localstatedir)/urd/control.socket.2\";"; \
+1 −1
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@
 *************************************************************************/

#include "messages.pb.h"
#include "io-task-stats.hpp"
#include "io.hpp"
#include "response.hpp"

namespace {
+2 −0
Original line number Diff line number Diff line
@@ -95,6 +95,8 @@ std::string to_string(urd_error ecode) {
            return "NORNS_ETASKEXISTS";
        case urd_error::no_such_task:
            return "NORNS_ENOSUCHTASK";
        case urd_error::too_many_tasks:
            return "NORNS_ETOOMANYTASKS";
        default:
            return "UNKNOWN_ERROR";
    }
Loading