72
73
static int setup_batch_wrapper(const char *sysname)
75
char wrapperfile[BATCH_JOB_LINE_MAX];
77
sprintf(wrapperfile, "%s.wrapper", sysname);
75
char *wrapperfile = string_format("%s.wrapper", sysname);
79
77
if(access(wrapperfile, R_OK | X_OK) == 0)
82
file = fopen(wrapperfile, "w");
80
FILE *file = fopen(wrapperfile, "w");
86
86
fprintf(file, "#!/bin/sh\n");
87
87
fprintf(file, "logfile=%s.status.${JOB_ID}\n", sysname);
100
100
chmod(wrapperfile, 0755);
106
108
batch_job_id_t batch_job_submit_simple_cluster(struct batch_queue * q, const char *cmd, const char *extra_input_files, const char *extra_output_files)
108
char line[BATCH_JOB_LINE_MAX];
109
char name[BATCH_JOB_LINE_MAX];
110
110
batch_job_id_t jobid;
111
111
struct batch_job_info *info;
115
113
if(setup_batch_wrapper(cluster_name) < 0)
119
char *s = strchr(name, ' ');
123
sprintf(line, "%s %s '%s' %s %s.wrapper \"%s\"", cluster_submit_cmd, cluster_options, string_basename(name), q->options_text ? q->options_text : "", cluster_name, cmd);
125
debug(D_DEBUG, "%s", line);
127
file = popen(line, "r");
116
char *name = xstrdup(cmd);
118
char *s = strchr(name, ' ');
122
char *command = string_format("%s %s '%s' %s %s.wrapper \"%s\"", cluster_submit_cmd, cluster_options, string_basename(name), q->options_text ? q->options_text : "", cluster_name, cmd);
125
debug(D_DEBUG, "%s", command);
127
FILE *file = popen(command, "r");
129
130
debug(D_DEBUG, "couldn't submit job: %s", strerror(errno));
134
char line[BATCH_JOB_LINE_MAX] = "";
134
135
while(fgets(line, sizeof(line), file)) {
135
136
if(sscanf(line, "Your job %d", &jobid) == 1) {
136
137
debug(D_DEBUG, "job %d submitted", jobid);
155
156
batch_job_id_t batch_job_submit_cluster(struct batch_queue * q, const char *cmd, const char *args, const char *infile, const char *outfile, const char *errfile, const char *extra_input_files, const char *extra_output_files)
157
char command[BATCH_JOB_LINE_MAX];
159
sprintf(command, "%s %s", cmd, args);
162
sprintf(&command[strlen(command)], " <%s", infile);
164
sprintf(&command[strlen(command)], " >%s", outfile);
166
sprintf(&command[strlen(command)], " 2>%s", errfile);
168
return batch_job_submit_simple_cluster(q, command, extra_input_files, extra_output_files);
158
char *command = string_format("%s %s", cmd, args);
160
char *new = string_format("%s <%s", command, infile);
165
char *new = string_format("%s >%s", command, outfile);
170
char *new = string_format("%s 2>%s", command, errfile);
175
batch_job_id_t status = batch_job_submit_simple_cluster(q, command, extra_input_files, extra_output_files);
171
180
batch_job_id_t batch_job_wait_cluster(struct batch_queue * q, struct batch_job_info * info_out, time_t stoptime)
173
182
struct batch_job_info *info;
174
183
batch_job_id_t jobid;
176
char statusfile[BATCH_JOB_LINE_MAX];
177
char line[BATCH_JOB_LINE_MAX];
182
188
itable_firstkey(q->job_table);
183
189
while(itable_nextkey(q->job_table, &ujobid, (void **) &info)) {
185
sprintf(statusfile, "%s.status.%d", cluster_name, jobid);
186
file = fopen(statusfile, "r");
191
char *statusfile = string_format("%s.status.%d", cluster_name, jobid);
192
FILE *file = fopen(statusfile, "r");
194
char line[BATCH_JOB_LINE_MAX];
188
195
while(fgets(line, sizeof(line), file)) {
189
196
if(sscanf(line, "start %d", &t)) {
190
197
info->started = t;
227
236
int batch_job_remove_cluster(struct batch_queue *q, batch_job_id_t jobid)
229
char line[BATCH_JOB_LINE_MAX];
230
238
struct batch_job_info *info;
232
240
info = itable_lookup(q->job_table, jobid);
240
248
info->exited_normally = 0;
241
249
info->exit_signal = 1;
243
sprintf(line, "%s %d", cluster_remove_cmd, jobid);
251
char *command = string_format("%s %d", cluster_remove_cmd, jobid);