Loading examples/job_registration.c +10 −11 Original line number Diff line number Diff line Loading @@ -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); Loading include/norns/norns.h +5 −14 Original line number Diff line number Diff line Loading @@ -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... Loading Loading @@ -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 } Loading include/norns/norns_error.h +10 −6 Original line number Diff line number Diff line Loading @@ -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 } Loading lib/Makefile.am +1 −0 Original line number Diff line number Diff line Loading @@ -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 \ Loading 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
examples/job_registration.c +10 −11 Original line number Diff line number Diff line Loading @@ -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); Loading
include/norns/norns.h +5 −14 Original line number Diff line number Diff line Loading @@ -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... Loading Loading @@ -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 } Loading
include/norns/norns_error.h +10 −6 Original line number Diff line number Diff line Loading @@ -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 } Loading
lib/Makefile.am +1 −0 Original line number Diff line number Diff line Loading @@ -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 \ Loading
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)]; }