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

Processes can now be added/removed to jobs

parent 6f7d59cd
Loading
Loading
Loading
Loading
+10 −11
Original line number Diff line number Diff line
@@ -89,29 +89,28 @@ int main(int argc, char* argv[]) {

    // register a job with ID 42
    if((rv = norns_register_job(&cred, 42, &job)) != NORNS_SUCCESS) {
            fprintf(stderr, "ERROR: norns_register_job failed!\n");
            fprintf(stderr, "ERROR: norns_register_job failed: %s\n", norns_strerror(rv));
    }

    // register processes with access to this job
    for(int i=0; i<1; ++i) {
        if((rv = norns_add_process(&cred, 42, (pid_t) i, (gid_t) i)) != NORNS_SUCCESS) {
            fprintf(stderr, "norns_add_process failed: %s\n", norns_strerror(rv));
        }
    else {
        fprintf(stdout, "norns_register_job succeded!\n");
    }


    // update the job description
    job.jb_hosts = hosts2;
    job.jb_nhosts = num_hosts2;

    if((rv = norns_update_job(&cred, 42, &job)) != NORNS_SUCCESS) {
        fprintf(stderr, "norns_update_job failed!\n");
    }
    else {
        fprintf(stdout, "norns_update_job succeded!\n");
        fprintf(stderr, "norns_update_job failed: %s\n", norns_strerror(rv));
    }

    // unregister the job
    if((rv = norns_unregister_job(&cred, 42)) != NORNS_SUCCESS) {
        fprintf(stderr, "norns_unregister_job failed!\n");
    }
    else {
        fprintf(stdout, "norns_unregister_job succeded!\n");
        fprintf(stderr, "norns_unregister_job failed: %s\n", norns_strerror(rv));
    }

    NORNS_PLIST_FREE(hosts1);
+5 −14
Original line number Diff line number Diff line
@@ -35,18 +35,6 @@
extern "C" {
#endif

/* Error codes */
#define NORNS_SUCCESS           0
#define NORNS_EBADPARAMS        -1
#define NORNS_ENOMEM            -2
#define NORNS_ECONNFAILED       -3
#define NORNS_ERPCSENDFAILED    -4
#define NORNS_ERPCRECVFAILED    -5
#define NORNS_EJOBEXISTS        -6
#define NORNS_ENOJOBEXISTS      -7

typedef uint32_t jobid_t;

/* Process credentials */
struct norns_cred {
    // TODO: to be completed, but at least...
@@ -189,17 +177,20 @@ int norns_command(struct norns_cred* auth);
int norns_register_job(struct norns_cred* auth, uint32_t jobid, struct norns_job* job);

/* Update an existing batch job */
/* XXX: At the moment this invalidates all registered processes for this job */
int norns_update_job(struct norns_cred* auth, uint32_t jobid, struct norns_job* job);

/* Remove a batch job from the system */
int norns_unregister_job(struct norns_cred* auth, uint32_t jobid);

/* Add a process to a registered batch job */
int norns_add_process(struct norns_cred* auth, uint32_t jobid, pid_t pid);
int norns_add_process(struct norns_cred* auth, uint32_t jobid, pid_t pid, gid_t gid);

/* Remove a process from a registered batch job */
int norns_remove_process(struct norns_cred* auth, uint32_t jobid, pid_t pid);
int norns_remove_process(struct norns_cred* auth, uint32_t jobid, pid_t pid, gid_t gid);


char* norns_strerror(int errnum);

#ifdef __cplusplus
}
+10 −6
Original line number Diff line number Diff line
@@ -33,15 +33,19 @@
extern "C" {
#endif

#define NORNS_ERRMAX 512

/** Error codes */
#define NORNS_SUCCESS           0
#define NORNS_EBADPARAMS        -1
#define NORNS_ENOMEM            -2
#define NORNS_ECONNFAILED       -3
#define NORNS_ERPCSENDFAILED    -4
#define NORNS_ERPCRECVFAILED    -5
#define NORNS_EJOBEXISTS        -6
#define NORNS_ENOJOBEXISTS      -7
#define NORNS_EBADREQUEST       -2
#define NORNS_ENOMEM            -3
#define NORNS_ECONNFAILED       -4
#define NORNS_ERPCSENDFAILED    -5
#define NORNS_ERPCRECVFAILED    -6
#define NORNS_EJOBEXISTS        -7
#define NORNS_ENOSUCHJOB        -8
#define NORNS_ENOSUCHPROCESS    -9

#ifdef __cplusplus
}
+1 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ AM_CPPFLAGS = \

libnorns_la_SOURCES = 	\
	norns.c				\
	errors.c            \
	$(top_srcdir)/include/norns.h \
	$(top_srcdir)/rpc/norns-rpc.h \
	messages.pb-c.c \

lib/errors.c

0 → 100644
+29 −0
Original line number Diff line number Diff line
#include <norns.h>

#define ERR_REMAP(n) ((n) < 0 ? -(n) : (n))

const char* const norns_errlist[NORNS_ERRMAX + 1] = {
    [ERR_REMAP(NORNS_SUCCESS)] = "Success",
    [ERR_REMAP(NORNS_EBADREQUEST)] = "Bad request",
    [ERR_REMAP(NORNS_EBADPARAMS)] = "Bad parameters",
    [ERR_REMAP(NORNS_ENOMEM)] = "Cannot allocate memory",
    [ERR_REMAP(NORNS_ECONNFAILED)] = "Cannot connect to daemon",
    [ERR_REMAP(NORNS_ERPCSENDFAILED)] = "Cannot send requests to daemon",
    [ERR_REMAP(NORNS_ERPCRECVFAILED)] = "Cannot receive responses from daemon",
    [ERR_REMAP(NORNS_EJOBEXISTS)] = "Job already exists",
    [ERR_REMAP(NORNS_ENOSUCHJOB)] = "Job does not exist",
    [ERR_REMAP(NORNS_ENOSUCHPROCESS)] = "Process does not exist",

    [ERR_REMAP(NORNS_ERRMAX)] = "Unknown error",

};

char*
norns_strerror(int errnum) {

    if(errnum > NORNS_ERRMAX) {
        errnum = NORNS_ERRMAX;
    }

    return (char*) norns_errlist[ERR_REMAP(errnum)];
}
Loading