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"
22 #include "../../include/scm_interface.h"
24 #define MANIFEST_LOC "/.config/tomd/init/manifest.scm"
26 static void load_job(SCM job_list
, int index
)
29 scm_from_signed_integer(index
);
31 SCM_ARR(job_list
, index
);
33 /* scm_cur_job should be a job */
34 if(scm_is_false(job_predicate(scm_cur_job
))){
35 tomd_p("job %d wasn't a real job type.", index
);
42 get_args(scm_cur_job
);
43 SCM scm_start_trigger
=
44 get_start_trigger(scm_cur_job
);
46 get_end_trigger(scm_cur_job
);
49 scm_to_locale_string(scm_cmd
);
52 int jlen
= scm_to_int(scm_length(scm_args
));
57 scm_to_locale_string(SCM_ARR(scm_args
, j
));
60 tomd_p("JOB <%d>:", index
);
61 tomd_p(" cmd:'%s'", job_cmd
);
65 tomd_p(" arg [%d]:'%s'", j
, real_args
[j
]);
69 static void *load_manifest(void *args
)
73 tomd_p("arg to load_manifest is NULL");
76 manifest_loc
= (char *)args
;
78 /* tomd_p("load_manifest called with arg '%s'", args); */
80 scm_c_primitive_load(args
);
82 /* now that we have the file in memory, lets grab the value of job-list */
84 scm_c_public_ref("tomd manifest", "job-list");
86 if(scm_is_false(scm_job_list
)){
87 tomd_p("no job-list found in manifest.scm");
91 if(scm_is_false(scm_list_p(scm_job_list
))){
92 tomd_p("job-list found, but isn't a list.");
97 int len
= SCM_LIST_LEN(scm_job_list
);
101 load_job(scm_job_list
, i
);
103 tomd_p("looked at %d jobs.", i
);
106 static char *lookup_user_folder(void)
108 uid_t user
= getuid();
109 struct passwd
*userpasswd
=
111 /* tomd_p("pw_name='%s'", userpasswd->pw_name); */
112 /* tomd_p("pw_passwd='%s'", userpasswd->pw_passwd); */
113 /* tomd_p("pw_uid='%d'", userpasswd->pw_uid); */
114 /* tomd_p("pw_gid='%d'", userpasswd->pw_gid); */
115 /* tomd_p("pw_gecos='%s'", userpasswd->pw_gecos); */
116 /* tomd_p("pw_dir='%s'", userpasswd->pw_dir); */
117 /* tomd_p("pw_shell='%s'", userpasswd->pw_shell); */
119 /* take the manifest location and sub ~ for pw_dir */
120 char *buffer
= (char *)malloc(sizeof(char) * 300);
121 strcpy(buffer
, userpasswd
->pw_dir
);
122 int len
= strlen(userpasswd
->pw_dir
);
123 strcpy(buffer
+ len
, MANIFEST_LOC
);
124 /* tomd_p("full config path:'%s'", buffer); */
130 char *manifest
= lookup_user_folder();
131 tomd_p("Loading jobs from '%s'", manifest
);
133 /* get into the manifest.scm file */
135 scm_with_guile(load_manifest
,
137 /* check if the variable 'job-list' is defined */
139 tomd_p("Finished loading.");