From 0a325e56466f37caacb783c7f0774a4809ce700e Mon Sep 17 00:00:00 2001 From: Tom Balzer Date: Mon, 31 Dec 2018 00:36:00 -0600 Subject: [PATCH] Added compile flag for guile features --- src/common/guile_helpers.c | 203 +++++++++++++++++++------------------ 1 file changed, 102 insertions(+), 101 deletions(-) diff --git a/src/common/guile_helpers.c b/src/common/guile_helpers.c index fb9471f..5c1198d 100644 --- a/src/common/guile_helpers.c +++ b/src/common/guile_helpers.c @@ -46,111 +46,118 @@ static struct job jobs[MAX_JOBS]= {} }; -/* static struct job load_job(SCM job_list, int index) */ -/* { */ -/* struct job ret = { NULL }; */ -/* SCM scm_cur_job = SCM_ARR(job_list, index); */ - -/* if(scm_is_false(job_predicate(scm_cur_job))){ */ -/* tomd_p("job %d wasn't a real job type.", index); */ -/* return ret; */ -/* } */ - -/* SCM scm_name = get_name(scm_cur_job); */ -/* SCM scm_cmd = get_cmd(scm_cur_job); */ -/* SCM scm_args = get_args(scm_cur_job); */ - -/* /\* TODO > Handle these. *\/ */ -/* /\* planned is to be able to run at different points, and at *\/ */ -/* /\* the request of a user. for testing we do things all at *\/ */ -/* /\* boot up. *\/ */ -/* SCM scm_start_trigger = get_start_trigger(scm_cur_job); */ -/* SCM scm_end_trigger = get_end_trigger(scm_cur_job); */ - -/* char *job_name = scm_to_locale_string(scm_name); */ -/* char *job_cmd = scm_to_locale_string(scm_cmd); */ -/* char *real_args[10]; */ -/* int jlen = scm_to_int(scm_length(scm_args)); */ -/* for(int j = 0; */ -/* j < jlen; */ -/* j++){ */ -/* real_args[j] = */ -/* scm_to_locale_string(SCM_ARR(scm_args, j)); */ -/* } */ - -/* ret.name = job_name; */ -/* ret.cmd = job_cmd; */ - -/* for(int j = 1; */ -/* j <= jlen; */ -/* j++){ */ -/* ret.args[j] = real_args[j - 1]; */ -/* } */ -/* ret.args[jlen + 1] = NULL; */ -/* ret.args[0] = ret.cmd; */ - -/* return ret; */ -/* } */ - -/* static void *load_manifest(void *args) */ -/* { */ -/* char *manifest_loc; */ -/* if(!args){ */ -/* tomd_p("arg to load_manifest is NULL"); */ -/* exit(EXIT_FAILURE); */ -/* } */ -/* manifest_loc = (char *)args; */ - -/* scm_c_primitive_load(args); */ - -/* SCM scm_job_list = */ -/* scm_c_public_ref("tomd manifest", "job-list"); */ - -/* if(scm_is_false(scm_job_list)){ */ -/* tomd_p("no job-list found in manifest.scm"); */ -/* return NULL; */ -/* } */ - -/* if(scm_is_false(scm_list_p(scm_job_list))){ */ -/* tomd_p("job-list found, but isn't a list."); */ -/* return NULL; */ -/* } */ - -/* int i; */ -/* int len = SCM_LIST_LEN(scm_job_list); */ -/* tomd_p("len=%d, max=%d", len, MAX_JOBS); */ -/* for(i = 0; */ -/* i < len && i < MAX_JOBS; */ -/* i++){ */ -/* jobs[i] = load_job(scm_job_list, i); */ -/* } */ -/* tomd_p("looked at %d jobs.", i); */ -/* jobs[i].cmd = NULL; */ -/* } */ +#ifdef GUILE_CAPABLE +static struct job load_job(SCM job_list, int index) +{ + struct job ret = { NULL }; + SCM scm_cur_job = SCM_ARR(job_list, index); + + if(scm_is_false(job_predicate(scm_cur_job))){ + tomd_p("job %d wasn't a real job type.", index); + return ret; + } + + SCM scm_name = get_name(scm_cur_job); + SCM scm_cmd = get_cmd(scm_cur_job); + SCM scm_args = get_args(scm_cur_job); + + /* TODO > Handle these. */ + /* planned is to be able to run at different points, and at */ + /* the request of a user. for testing we do things all at */ + /* boot up. */ + SCM scm_start_trigger = get_start_trigger(scm_cur_job); + SCM scm_end_trigger = get_end_trigger(scm_cur_job); + + char *job_name = scm_to_locale_string(scm_name); + char *job_cmd = scm_to_locale_string(scm_cmd); + char *real_args[10]; + int jlen = scm_to_int(scm_length(scm_args)); + for(int j = 0; + j < jlen; + j++){ + real_args[j] = + scm_to_locale_string(SCM_ARR(scm_args, j)); + } + + ret.name = job_name; + ret.cmd = job_cmd; + + for(int j = 1; + j <= jlen; + j++){ + ret.args[j] = real_args[j - 1]; + } + ret.args[jlen + 1] = NULL; + ret.args[0] = ret.cmd; + + return ret; +} + +static void *load_manifest(void *args) +{ + char *manifest_loc; + if(!args){ + tomd_p("arg to load_manifest is NULL"); + exit(EXIT_FAILURE); + } + manifest_loc = (char *)args; + + scm_c_primitive_load(args); + + SCM scm_job_list = + scm_c_public_ref("tomd manifest", "job-list"); + + if(scm_is_false(scm_job_list)){ + tomd_p("no job-list found in manifest.scm"); + return NULL; + } + + if(scm_is_false(scm_list_p(scm_job_list))){ + tomd_p("job-list found, but isn't a list."); + return NULL; + } + + int i; + int len = SCM_LIST_LEN(scm_job_list); + tomd_p("len=%d, max=%d", len, MAX_JOBS); + for(i = 0; + i < len && i < MAX_JOBS; + i++){ + jobs[i] = load_job(scm_job_list, i); + } + tomd_p("looked at %d jobs.", i); + jobs[i].cmd = NULL; +} +#endif static char *lookup_user_folder(void) { +#ifdef GUILE_CAPABLE + uid_t user = getuid(); + struct passwd *userpasswd = + getpwuid(user); + + /* take the manifest location and sub ~ for pw_dir */ + char *buffer = (char *)malloc(sizeof(char) * 300); + strcpy(buffer, userpasswd->pw_dir); + int len = strlen(userpasswd->pw_dir); + strcpy(buffer + len, MANIFEST_LOC); + return buffer; +#else return NULL; - /* uid_t user = getuid(); */ - /* struct passwd *userpasswd = */ - /* getpwuid(user); */ - - /* /\* take the manifest location and sub ~ for pw_dir *\/ */ - /* char *buffer = (char *)malloc(sizeof(char) * 300); */ - /* strcpy(buffer, userpasswd->pw_dir); */ - /* int len = strlen(userpasswd->pw_dir); */ - /* strcpy(buffer + len, MANIFEST_LOC); */ - /* return buffer; */ +#endif } void load_jobs(void) { char *manifest = lookup_user_folder(); - /* tomd_p("Loading jobs from '%s'", manifest); */ +#ifdef GUILE_CAPABLE + tomd_p("Loading jobs from '%s'", manifest); - /* void *res = */ - /* scm_with_guile(load_manifest, */ - /* (void *) manifest); */ + void *res = + scm_with_guile(load_manifest, + (void *) manifest); +#endif tomd_p("Stubbed job loading."); tomd_p("Finished loading."); @@ -284,10 +291,8 @@ void check_root_job(void) delay = 0; } if(root_job != -1){ - /* tomd_p("checking root job pid %d", jobs[root_job].pid); */ int n_pid = waitpid(jobs[root_job].pid, &jobs[root_job].last_status, WNOHANG); if(n_pid != jobs[root_job].pid){ - /* tomd_p("status of root not available."); */ return; } @@ -297,9 +302,5 @@ void check_root_job(void) jobs[root_job].pid, jobs[root_job].last_status); run_job(root_job); } - /* else { */ - /* tomd_p("checking root job pid %d", jobs[root_job].pid); */ - /* int n_pid = waitpid(jobs[root_job].pid, &jobs[root_job].last_status, WNOHANG); */ - /* } */ } } -- 2.20.1