1 /* Copyright (C) 2018 Thomas Balzer */
3 /* This file is part of tomd. */
5 /* tomd is free software: you can redistribute it and/or modify */
6 /* it under the terms of the GNU General Public License as published by */
7 /* the Free Software Foundation, either version 3 of the License, or */
8 /* (at your option) any later version. */
10 /* tomd is distributed in the hope that it will be useful, */
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
13 /* GNU General Public License for more details. */
15 /* You should have received a copy of the GNU General Public License */
16 /* along with tomd. If not, see <http://www.gnu.org/licenses/>. */
21 #include "../../include/macros.h"
23 #define MANIFEST_LOC "/.config/tomd/init/manifest.scm"
25 static void load_job(void)
30 static void *load_manifest(void *args
)
34 tomd_p("arg to load_manifest is NULL");
37 manifest_loc
= (char *)args
;
39 /* tomd_p("load_manifest called with arg '%s'", args); */
41 scm_c_primitive_load(args
);
43 /* now that we have the file in memory, lets grab the value of job-list */
45 scm_c_public_ref("tomd manifest", "job-list");
47 if(scm_is_false(scm_job_list
)){
48 tomd_p("no job-list found in manifest.scm");
52 if(scm_is_false(scm_list_p(scm_job_list
))){
53 tomd_p("job-list found, but isn't a list.");
57 SCM scm_job_predicate
=
58 scm_c_public_ref("tomd job", "c-check-job");
61 scm_c_public_ref("tomd job", "c-job-cmd");
64 scm_c_public_ref("tomd job", "c-job-args");
66 SCM scm_job_start_trigger
=
67 scm_c_public_ref("tomd job", "c-job-start-trigger");
69 SCM scm_job_end_trigger
=
70 scm_c_public_ref("tomd job", "c-job-end-trigger");
73 SCM scm_len
= scm_length(scm_job_list
);
74 int len
= scm_to_int(scm_len
);
80 scm_from_signed_integer(i
);
82 SCM_ARR(scm_job_list
, i
);
84 /* scm_cur_job should be a job */
85 if(scm_is_false(scm_call(scm_job_predicate
, scm_cur_job
, SCM_UNDEFINED
))){
86 tomd_p("job %d wasn't a real job type.", i
);
95 scm_call(scm_job_args
,
98 SCM scm_start_trigger
=
99 scm_call(scm_job_start_trigger
,
102 SCM scm_end_trigger
=
103 scm_call(scm_job_end_trigger
,
108 scm_to_locale_string(scm_cmd
);
111 int jlen
= scm_to_int(scm_length(scm_args
));
116 scm_to_locale_string(SCM_ARR(scm_args
, j
));
119 tomd_p("JOB <%d>:", i
);
120 tomd_p(" cmd:'%s'", job_cmd
);
124 tomd_p(" arg [%d]:'%s'", j
, real_args
[j
]);
127 tomd_p("looked at %d jobs.", i
);
130 static char *lookup_user_folder(void)
132 uid_t user
= getuid();
133 struct passwd
*userpasswd
=
135 /* tomd_p("pw_name='%s'", userpasswd->pw_name); */
136 /* tomd_p("pw_passwd='%s'", userpasswd->pw_passwd); */
137 /* tomd_p("pw_uid='%d'", userpasswd->pw_uid); */
138 /* tomd_p("pw_gid='%d'", userpasswd->pw_gid); */
139 /* tomd_p("pw_gecos='%s'", userpasswd->pw_gecos); */
140 /* tomd_p("pw_dir='%s'", userpasswd->pw_dir); */
141 /* tomd_p("pw_shell='%s'", userpasswd->pw_shell); */
143 /* take the manifest location and sub ~ for pw_dir */
144 char *buffer
= (char *)malloc(sizeof(char) * 300);
145 strcpy(buffer
, userpasswd
->pw_dir
);
146 int len
= strlen(userpasswd
->pw_dir
);
147 strcpy(buffer
+ len
, MANIFEST_LOC
);
148 /* tomd_p("full config path:'%s'", buffer); */
154 char *manifest
= lookup_user_folder();
155 tomd_p("Loading jobs from '%s'", manifest
);
157 /* get into the manifest.scm file */
159 scm_with_guile(load_manifest
,
161 /* check if the variable 'job-list' is defined */
163 tomd_p("Finished loading.");