-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjobs.c
1568 lines (1343 loc) · 35.6 KB
/
jobs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Task Spooler - a task queue system for the unix user
Copyright (C) 2007-2013 Lluís Batlle i Rossell
Please find the license in the provided COPYING file.
*/
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include "main.h"
/* The list will access them */
int busy_slots = 0;
int max_slots = 1;
int used_ram = 0;
int max_ram = 1;
struct Notify
{
int socket;
int jobid;
struct Notify *next;
};
/* Globals */
static struct Job *firstjob = 0;
static struct Job *first_finished_job = 0;
static int jobids = 0;
/* This is used for dependencies from jobs
* already out of the queue */
static int last_errorlevel = 0; /* Before the first job, let's consider
a good previous result */
/* We need this to handle well "-d" after a "-nf" run */
static int last_finished_jobid;
static struct Notify *first_notify = 0;
int max_jobs;
static struct Job * get_job(int jobid);
void notify_errorlevel(struct Job *p);
static void send_list_line(int s, const char * str)
{
struct msg m;
/* Message */
m.type = LIST_LINE;
m.u.size = strlen(str) + 1;
send_msg(s, &m);
/* Send the line */
send_bytes(s, str, m.u.size);
}
static void send_urgent_ok(int s)
{
struct msg m;
/* Message */
m.type = URGENT_OK;
send_msg(s, &m);
}
static void send_swap_jobs_ok(int s)
{
struct msg m;
/* Message */
m.type = SWAP_JOBS_OK;
send_msg(s, &m);
}
static struct Job * find_previous_job(const struct Job *final)
{
struct Job *p;
/* Show Queued or Running jobs */
p = firstjob;
while(p != 0)
{
if (p->next == final)
return p;
p = p->next;
}
return 0;
}
static struct Job * findjob(int jobid)
{
struct Job *p;
/* Show Queued or Running jobs */
p = firstjob;
while(p != 0)
{
if (p->jobid == jobid)
return p;
p = p->next;
}
return 0;
}
static struct Job * findjob_holding_client()
{
struct Job *p;
/* Show Queued or Running jobs */
p = firstjob;
while(p != 0)
{
if (p->state == HOLDING_CLIENT)
return p;
p = p->next;
}
return 0;
}
static struct Job * find_finished_job(int jobid)
{
struct Job *p;
/* Show Queued or Running jobs */
p = first_finished_job;
while(p != 0)
{
if (p->jobid == jobid)
return p;
p = p->next;
}
return 0;
}
static int count_not_finished_jobs()
{
int count=0;
struct Job *p;
/* Show Queued or Running jobs */
p = firstjob;
while(p != 0)
{
++count;
p = p->next;
}
return count;
}
static void add_notify_errorlevel_to(struct Job *job, int jobid)
{
int *p;
int newsize = (job->notify_errorlevel_to_size + 1)
* sizeof(int);
p = (int *) realloc(job->notify_errorlevel_to,
newsize);
if (p == 0)
error("Cannot allocate more memory for notify_errorlist_to for jobid %i,"
" having already %i elements",
job->jobid, job->notify_errorlevel_to_size);
job->notify_errorlevel_to = p;
job->notify_errorlevel_to_size += 1;
job->notify_errorlevel_to[job->notify_errorlevel_to_size - 1] = jobid;
}
void s_mark_job_running(int jobid)
{
struct Job *p;
p = findjob(jobid);
if (!p)
error("Cannot mark the jobid %i RUNNING.", jobid);
p->state = RUNNING;
}
/* -1 means nothing awaken, otherwise returns the jobid awaken */
int wake_hold_client()
{
struct Job *p;
p = findjob_holding_client();
if (p)
{
p->state = QUEUED;
return p->jobid;
}
return -1;
}
const char * jstate2string(enum Jobstate s)
{
const char * jobstate;
switch(s)
{
case QUEUED:
jobstate = "queued";
break;
case RUNNING:
jobstate = "running";
break;
case FINISHED:
jobstate = "finished";
break;
case SKIPPED:
jobstate = "skipped";
break;
case HOLDING_CLIENT:
jobstate = "skipped";
break;
}
return jobstate;
}
void s_list(int s)
{
struct Job *p;
char *buffer;
/* Times: 0.00/0.00/0.00 - 4+4+4+2 = 14*/
buffer = joblist_headers();
send_list_line(s,buffer);
free(buffer);
/* Show Queued or Running jobs */
p = firstjob;
while(p != 0)
{
if (p->state != HOLDING_CLIENT)
{
buffer = joblist_line(p);
send_list_line(s,buffer);
free(buffer);
}
p = p->next;
}
p = first_finished_job;
/* Show Finished jobs */
while(p != 0)
{
buffer = joblist_line(p);
send_list_line(s,buffer);
free(buffer);
p = p->next;
}
}
static struct Job * newjobptr()
{
struct Job *p;
if (firstjob == 0)
{
firstjob = (struct Job *) malloc(sizeof(*firstjob));
firstjob->next = 0;
firstjob->output_filename = 0;
firstjob->command = 0;
return firstjob;
}
p = firstjob;
while(p->next != 0)
p = p->next;
p->next = (struct Job *) malloc(sizeof(*p));
p->next->next = 0;
p->next->output_filename = 0;
p->next->command = 0;
return p->next;
}
/* Returns -1 if no last job id found */
static int find_last_jobid_in_queue(int neglect_jobid)
{
struct Job *p;
int last_jobid = -1;
p = firstjob;
while(p != 0)
{
if (p->jobid != neglect_jobid &&
p->jobid > last_jobid)
last_jobid = p->jobid;
p = p->next;
}
return last_jobid;
}
/* Returns -1 if no last job id found */
static int find_last_stored_jobid_finished()
{
struct Job *p;
int last_jobid = -1;
p = first_finished_job;
while(p != 0)
{
if (p->jobid > last_jobid)
last_jobid = p->jobid;
p = p->next;
}
return last_jobid;
}
/* Returns job id or -1 on error */
int s_newjob(int s, struct msg *m)
{
struct Job *p;
int res;
p = newjobptr();
p->jobid = jobids++;
if (count_not_finished_jobs() < max_jobs)
p->state = QUEUED;
else
p->state = HOLDING_CLIENT;
p->num_slots = m->u.newjob.num_slots;
p->amt_ram = m->u.newjob.amt_ram;
p->store_output = m->u.newjob.store_output;
p->should_keep_finished = m->u.newjob.should_keep_finished;
p->notify_errorlevel_to = 0;
p->notify_errorlevel_to_size = 0;
p->do_depend = m->u.newjob.do_depend;
p->depend_on = -1; /* By default. May be overriden in the next conditions */
if (m->u.newjob.do_depend == 1)
{
/* Depend on the last queued job. */
/* As we already have 'p' in the queue,
* neglect it during the find_last_jobid_in_queue() */
if (m->u.newjob.depend_on == -1)
{
p->depend_on = find_last_jobid_in_queue(p->jobid);
/* We don't trust the last jobid in the queue (running or queued)
* if it's not the last added job. In that case, let
* the next control flow handle it as if it could not
* do_depend on any still queued job. */
if (last_finished_jobid > p->depend_on)
p->depend_on = -1;
/* If it's queued still without result, let it know
* its result to p when it finishes. */
if (p->depend_on != -1)
{
struct Job *depended_job;
depended_job = findjob(p->depend_on);
if (depended_job != 0)
add_notify_errorlevel_to(depended_job, p->jobid);
else
warning("The jobid %i is queued to do_depend on the jobid %i"
" suddenly non existent in the queue", p->jobid,
p->depend_on);
}
else /* Otherwise take the finished job, or the last_errorlevel */
{
if (m->u.newjob.depend_on == -1)
{
int ljobid = find_last_stored_jobid_finished();
p->depend_on = ljobid;
/* If we have a newer result stored, use it */
/* NOTE:
* Reading this now, I don't know how ljobid can be
* greater than last_finished_jobid */
if (last_finished_jobid < ljobid)
{
struct Job *parent;
parent = find_finished_job(ljobid);
if (!parent)
error("jobid %i suddenly disappeared from the finished list",
ljobid);
p->dependency_errorlevel = parent->result.errorlevel;
}
else
p->dependency_errorlevel = last_errorlevel;
}
}
}
else
{
/* The user decided what's the job this new job depends on */
struct Job *depended_job;
p->depend_on = m->u.newjob.depend_on;
depended_job = findjob(p->depend_on);
if (depended_job != 0)
add_notify_errorlevel_to(depended_job, p->jobid);
else
{
struct Job *parent;
parent = find_finished_job(p->depend_on);
if (parent)
{
p->dependency_errorlevel = parent->result.errorlevel;
}
else
{
/* We consider as if the job not found
didn't finish well */
p->dependency_errorlevel = -1;
}
}
}
}
pinfo_init(&p->info);
pinfo_set_enqueue_time(&p->info);
/* load the command */
p->command = malloc(m->u.newjob.command_size);
if (p->command == 0)
error("Cannot allocate memory in s_newjob command_size (%i)",
m->u.newjob.command_size);
res = recv_bytes(s, p->command, m->u.newjob.command_size);
if (res == -1)
error("wrong bytes received");
/* load the label */
p->label = 0;
if (m->u.newjob.label_size > 0)
{
char *ptr;
ptr = (char *) malloc(m->u.newjob.label_size);
if (ptr == 0)
error("Cannot allocate memory in s_newjob env_size(%i)",
m->u.newjob.env_size);
res = recv_bytes(s, ptr, m->u.newjob.label_size);
if (res == -1)
error("wrong bytes received");
p->label = ptr;
}
/* load the info */
if (m->u.newjob.env_size > 0)
{
char *ptr;
ptr = (char *) malloc(m->u.newjob.env_size);
if (ptr == 0)
error("Cannot allocate memory in s_newjob env_size(%i)",
m->u.newjob.env_size);
res = recv_bytes(s, ptr, m->u.newjob.env_size);
if (res == -1)
error("wrong bytes received");
pinfo_addinfo(&p->info, m->u.newjob.env_size+100,
"Environment:\n%s", ptr);
free(ptr);
}
return p->jobid;
}
/* This assumes the jobid exists */
void s_removejob(int jobid)
{
struct Job *p;
struct Job *newnext;
if (firstjob->jobid == jobid)
{
struct Job *newfirst;
/* First job is to be removed */
newfirst = firstjob->next;
free(firstjob->command);
free(firstjob->output_filename);
pinfo_free(&firstjob->info);
free(firstjob->label);
free(firstjob);
firstjob = newfirst;
return;
}
p = firstjob;
/* Not first job */
while (p->next != 0)
{
if (p->next->jobid == jobid)
break;
p = p->next;
}
if (p->next == 0)
error("Job to be removed not found. jobid=%i", jobid);
newnext = p->next->next;
free(p->next->command);
free(p->next);
p->next = newnext;
}
/* -1 if no one should be run. */
int next_run_job()
{
struct Job *p;
const int free_slots = max_slots - busy_slots;
const int free_ram = max_ram - used_ram;
/* busy_slots may be bigger than the maximum slots,
* if the user was running many jobs, and suddenly
* trimmed the maximum slots down. */
if (free_slots <= 0)
return -1;
if (free_ram <= 0)
return -1;
/* If there are no jobs to run... */
if (firstjob == 0)
return -1;
/* Look for a runnable task */
p = firstjob;
while(p != 0)
{
if (p->state == QUEUED)
{
if (p->depend_on >= 0)
{
struct Job *do_depend_job = get_job(p->depend_on);
/* We won't try to run any job do_depending on an unfinished
* job */
if (do_depend_job != NULL &&
(do_depend_job->state == QUEUED || do_depend_job->state == RUNNING))
{
/* Next try */
p = p->next;
continue;
}
}
if (free_slots >= p->num_slots && free_ram >= p->amt_ram)
{
busy_slots = busy_slots + p->num_slots;
used_ram = used_ram + p->amt_ram;
return p->jobid;
}
}
p = p->next;
}
return -1;
}
/* Returns 1000 if no limit, The limit otherwise. */
static int get_max_finished_jobs()
{
char *limit;
limit = getenv("TS_MAXFINISHED");
if (limit == NULL)
return 1000;
return abs(atoi(limit));
}
/* Add the job to the finished queue. */
static void new_finished_job(struct Job *j)
{
struct Job *p;
int count, max;
max = get_max_finished_jobs();
count = 0;
if (first_finished_job == 0 && count < max)
{
first_finished_job = j;
first_finished_job->next = 0;
return;
}
++count;
p = first_finished_job;
while(p->next != 0)
{
p = p->next;
++count;
}
/* If too many jobs, wipe out the first */
if (count >= max)
{
struct Job *tmp;
tmp = first_finished_job;
first_finished_job = first_finished_job->next;
free(tmp->command);
free(tmp->output_filename);
pinfo_free(&tmp->info);
free(tmp->label);
free(tmp);
}
p->next = j;
p->next->next = 0;
return;
}
static int job_is_in_state(int jobid, enum Jobstate state)
{
struct Job *p;
p = findjob(jobid);
if (p == 0)
return 0;
if (p->state == state)
return 1;
return 0;
}
int job_is_running(int jobid)
{
return job_is_in_state(jobid, RUNNING);
}
int job_is_holding_client(int jobid)
{
return job_is_in_state(jobid, HOLDING_CLIENT);
}
static int in_notify_list(int jobid)
{
struct Notify *n, *tmp;
n = first_notify;
while (n != 0)
{
tmp = n;
n = n->next;
if (tmp->jobid == jobid)
return 1;
}
return 0;
}
void job_finished(const struct Result *result, int jobid)
{
struct Job *p;
if (busy_slots <= 0)
error("Wrong state in the server. busy_slots = %i instead of greater than 0", busy_slots);
p = findjob(jobid);
if (p == 0)
error("on jobid %i finished, it doesn't exist", jobid);
/* The job may be not only in running state, but also in other states, as
* we call this to clean up the jobs list in case of the client closing the
* connection. */
if (p->state == RUNNING)
{
busy_slots = busy_slots - p->num_slots;
used_ram = used_ram - p->amt_ram;
}
/* Mark state */
if (result->skipped)
p->state = SKIPPED;
else
p->state = FINISHED;
p->result = *result;
last_finished_jobid = p->jobid;
notify_errorlevel(p);
pinfo_set_end_time(&p->info);
if (p->result.died_by_signal)
pinfo_addinfo(&p->info, 100, "Exit status: killed by signal %i\n", p->result.signal);
else
pinfo_addinfo(&p->info, 100, "Exit status: died with exit code %i\n", p->result.errorlevel);
/* Find the pointing node, to
* update it removing the finished job. */
{
struct Job **jpointer = 0;
struct Job *newfirst = p->next;
if (firstjob == p)
jpointer = &firstjob;
else
{
struct Job *p2;
p2 = firstjob;
while(p2 != 0)
{
if (p2->next == p)
{
jpointer = &(p2->next);
break;
}
p2 = p2->next;
}
}
/* Add it to the finished queue (maybe temporarily) */
if (p->should_keep_finished || in_notify_list(p->jobid))
new_finished_job(p);
/* Remove it from the run queue */
if (jpointer == 0)
error("Cannot remove a finished job from the "
"queue list (jobid=%i)", p->jobid);
*jpointer = newfirst;
}
}
void s_clear_finished()
{
struct Job *p;
if (first_finished_job == 0)
return;
p = first_finished_job;
first_finished_job = 0;
while (p != 0)
{
struct Job *tmp;
tmp = p->next;
free(p->command);
free(p->output_filename);
pinfo_free(&p->info);
free(p->label);
free(p);
p = tmp;
}
}
void s_process_runjob_ok(int jobid, char *oname, int pid)
{
struct Job *p;
p = findjob(jobid);
if (p == 0)
error("Job %i already run not found on runjob_ok", jobid);
if (p->state != RUNNING)
error("Job %i not running, but %i on runjob_ok", jobid,
p->state);
p->pid = pid;
p->output_filename = oname;
pinfo_set_start_time(&p->info);
}
void s_send_runjob(int s, int jobid)
{
struct msg m;
struct Job *p;
p = findjob(jobid);
if (p == 0)
error("Job %i was expected to run", jobid);
m.type = RUNJOB;
/* TODO
* We should make the dependencies update the jobids they're do_depending on.
* Then, on finish, these could set the errorlevel to send to its dependency childs.
* We cannot consider that the jobs will leave traces in the finished job list (-nf?) . */
m.u.last_errorlevel = p->dependency_errorlevel;
send_msg(s, &m);
}
void s_job_info(int s, int jobid)
{
struct Job *p = 0;
struct msg m;
if (jobid == -1)
{
/* This means that we want the job info of the running task, or that
* of the last job run */
if (busy_slots > 0)
{
p = firstjob;
if (p == 0)
error("Internal state WAITING, but job not run."
"firstjob = %x", firstjob);
}
else
{
p = first_finished_job;
if (p == 0)
{
send_list_line(s, "No jobs.\n");
return;
}
while(p->next != 0)
p = p->next;
}
} else
{
p = firstjob;
while (p != 0 && p->jobid != jobid)
p = p->next;
/* Look in finished jobs if needed */
if (p == 0)
{
p = first_finished_job;
while (p != 0 && p->jobid != jobid)
p = p->next;
}
}
if (p == 0)
{
char tmp[50];
sprintf(tmp, "Job %i not finished or not running.\n", jobid);
send_list_line(s, tmp);
return;
}
m.type = INFO_DATA;
send_msg(s, &m);
pinfo_dump(&p->info, s);
fd_nprintf(s, 100, "Command: ");
if (p->depend_on != -1)
fd_nprintf(s, 100, "[%i]&& ", p->depend_on);
write(s, p->command, strlen(p->command));
fd_nprintf(s, 100, "\n");
fd_nprintf(s, 100, "Slots required: %i\n", p->num_slots);
fd_nprintf(s, 100, "RAM (GB) required: %i\n", p->amt_ram);
fd_nprintf(s, 100, "Enqueue time: %s",
ctime(&p->info.enqueue_time.tv_sec));
if (p->state == RUNNING)
{
fd_nprintf(s, 100, "Start time: %s",
ctime(&p->info.start_time.tv_sec));
fd_nprintf(s, 100, "Time running: %fs\n",
pinfo_time_until_now(&p->info));
} else if (p->state == FINISHED)
{
fd_nprintf(s, 100, "Start time: %s",
ctime(&p->info.start_time.tv_sec));
fd_nprintf(s, 100, "End time: %s",
ctime(&p->info.end_time.tv_sec));
fd_nprintf(s, 100, "Time run: %fs\n",
pinfo_time_run(&p->info));
}
}
void s_send_output(int s, int jobid)
{
struct Job *p = 0;
struct msg m;
if (jobid == -1)
{
/* This means that we want the output info of the running task, or that
* of the last job run */
if (busy_slots > 0)
{
p = firstjob;
if (p == 0)
error("Internal state WAITING, but job not run."
"firstjob = %x", firstjob);
}
else
{
p = first_finished_job;
if (p == 0)
{
send_list_line(s, "No jobs.\n");
return;
}
while(p->next != 0)
p = p->next;
}
} else
{
p = get_job(jobid);
if (p != 0 && p->state != RUNNING
&& p->state != FINISHED
&& p->state != SKIPPED)
p = 0;
}
if (p == 0)
{
char tmp[50];
if (jobid == -1)
sprintf(tmp, "The last job has not finished or is not running.\n");
else
sprintf(tmp, "Job %i not finished or not running.\n", jobid);
send_list_line(s, tmp);
return;
}
if (p->state == SKIPPED)
{
char tmp[50];
if (jobid == -1)
sprintf(tmp, "The last job was skipped due to a dependency.\n");
else
sprintf(tmp, "Job %i was skipped due to a dependency.\n", jobid);
send_list_line(s, tmp);
return;
}
m.type = ANSWER_OUTPUT;
m.u.output.store_output = p->store_output;
m.u.output.pid = p->pid;
if (m.u.output.store_output && p->output_filename)
m.u.output.ofilename_size = strlen(p->output_filename) + 1;
else
m.u.output.ofilename_size = 0;
send_msg(s, &m);
if (m.u.output.ofilename_size > 0)
send_bytes(s, p->output_filename, m.u.output.ofilename_size);
}
void notify_errorlevel(struct Job *p)
{
int i;
last_errorlevel = p->result.errorlevel;
for(i = 0; i < p->notify_errorlevel_to_size; ++i)
{
struct Job *notified;
notified = get_job(p->notify_errorlevel_to[i]);
if (notified)
{
notified->dependency_errorlevel = p->result.errorlevel;
}
}
}
/* jobid is input/output. If the input is -1, it's changed to the jobid
* removed */
int s_remove_job(int s, int *jobid)
{
struct Job *p = 0;
struct msg m;
struct Job *before_p = 0;
if (*jobid == -1)
{
/* Find the last job added */
p = firstjob;
if (p != 0)
{
while (p->next != 0)
{
before_p = p;
p = p->next;
}
} else
{
/* last 'finished' */
p = first_finished_job;
if (p)
{
while (p->next != 0)
{
before_p = p;
p = p->next;
}
}
}
}
else
{
p = firstjob;
if (p != 0)
{
while (p->next != 0 && p->jobid != *jobid)
{
before_p = p;
p = p->next;
}
}
/* If not found, look in the 'finished' list */
if (p == 0 || p->jobid != *jobid)
{
p = first_finished_job;
if (p != 0)