jobs.c
author viric <viriketo@gmail.com>
Sat, 26 May 2012 17:04:22 +0200
changeset 331 7e3b3663bb34
parent 317 290b5aa53061
child 333 4a2f6bdca101
permissions -rw-r--r--
Fixing the minimum of num_slots per job to zero.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49
09bb8a5583e9 Added the license.
lbatlle@npdl268.bpo.hp.com
parents: 44
diff changeset
     1
/*
09bb8a5583e9 Added the license.
lbatlle@npdl268.bpo.hp.com
parents: 44
diff changeset
     2
    Task Spooler - a task queue system for the unix user
267
11631dd11ff8 Updating copyright years in the source.
viric@mandarina
parents: 259
diff changeset
     3
    Copyright (C) 2007-2009  LluĂ­s Batlle i Rossell
49
09bb8a5583e9 Added the license.
lbatlle@npdl268.bpo.hp.com
parents: 44
diff changeset
     4
09bb8a5583e9 Added the license.
lbatlle@npdl268.bpo.hp.com
parents: 44
diff changeset
     5
    Please find the license in the provided COPYING file.
09bb8a5583e9 Added the license.
lbatlle@npdl268.bpo.hp.com
parents: 44
diff changeset
     6
*/
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
     7
#include <stdlib.h>
44
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
     8
#include <unistd.h>
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
     9
#include <stdio.h>
44
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
    10
#include <string.h>
146
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
    11
#include <sys/time.h>
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
    12
#include <time.h>
32
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
    13
#include "main.h"
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
    14
219
c24a1f5c1715 Adding hot-switchable amount of max_slots.
viric@mandarina
parents: 218
diff changeset
    15
/* The list will access them */
c24a1f5c1715 Adding hot-switchable amount of max_slots.
viric@mandarina
parents: 218
diff changeset
    16
int busy_slots = 0;
c24a1f5c1715 Adding hot-switchable amount of max_slots.
viric@mandarina
parents: 218
diff changeset
    17
int max_slots = 1;
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
    18
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
    19
struct Notify
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
    20
{
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
    21
    int socket;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
    22
    int jobid;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
    23
    struct Notify *next;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
    24
};
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
    25
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
    26
/* Globals */
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
    27
static struct Job *firstjob = 0;
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    28
static struct Job *first_finished_job = 0;
44
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
    29
static int jobids = 0;
221
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
    30
/* This is used for dependencies from jobs
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
    31
 * already out of the queue */
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
    32
static int last_errorlevel = 0; /* Before the first job, let's consider
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
    33
                                   a good previous result */
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
    34
/* We need this to handle well "-d" after a "-nf" run */
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
    35
static int last_finished_jobid;
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
    36
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
    37
static struct Notify *first_notify = 0;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
    38
287
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
    39
int max_jobs;
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
    40
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
    41
static struct Job * get_job(int jobid);
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
    42
void notify_errorlevel(struct Job *p);
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
    43
5
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 3
diff changeset
    44
static void send_list_line(int s, const char * str)
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 3
diff changeset
    45
{
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 3
diff changeset
    46
    struct msg m;
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 3
diff changeset
    47
21
a797f96a022f Lines for list doesn't have limit.
viric@llimona
parents: 20
diff changeset
    48
    /* Message */
5
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 3
diff changeset
    49
    m.type = LIST_LINE;
146
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
    50
    m.u.size = strlen(str) + 1;
5
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 3
diff changeset
    51
21
a797f96a022f Lines for list doesn't have limit.
viric@llimona
parents: 20
diff changeset
    52
    send_msg(s, &m);
a797f96a022f Lines for list doesn't have limit.
viric@llimona
parents: 20
diff changeset
    53
a797f96a022f Lines for list doesn't have limit.
viric@llimona
parents: 20
diff changeset
    54
    /* Send the line */
146
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
    55
    send_bytes(s, str, m.u.size);
5
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 3
diff changeset
    56
}
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 3
diff changeset
    57
53
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
    58
static void send_urgent_ok(int s)
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
    59
{
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
    60
    struct msg m;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
    61
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
    62
    /* Message */
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
    63
    m.type = URGENT_OK;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
    64
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
    65
    send_msg(s, &m);
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
    66
}
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
    67
66
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
    68
static void send_swap_jobs_ok(int s)
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
    69
{
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
    70
    struct msg m;
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
    71
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
    72
    /* Message */
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
    73
    m.type = SWAP_JOBS_OK;
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
    74
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
    75
    send_msg(s, &m);
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
    76
}
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
    77
120
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    78
static struct Job * find_previous_job(const struct Job *final)
53
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
    79
{
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
    80
    struct Job *p;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
    81
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
    82
    /* Show Queued or Running jobs */
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
    83
    p = firstjob;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
    84
    while(p != 0)
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
    85
    {
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
    86
        if (p->next == final)
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
    87
            return p;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
    88
        p = p->next;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
    89
    }
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
    90
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
    91
    return 0;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
    92
}
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
    93
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
    94
static struct Job * findjob(int jobid)
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
    95
{
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
    96
    struct Job *p;
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
    97
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
    98
    /* Show Queued or Running jobs */
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
    99
    p = firstjob;
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   100
    while(p != 0)
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   101
    {
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   102
        if (p->jobid == jobid)
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   103
            return p;
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   104
        p = p->next;
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   105
    }
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   106
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   107
    return 0;
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   108
}
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   109
287
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   110
static struct Job * findjob_holding_client()
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   111
{
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   112
    struct Job *p;
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   113
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   114
    /* Show Queued or Running jobs */
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   115
    p = firstjob;
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   116
    while(p != 0)
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   117
    {
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   118
        if (p->state == HOLDING_CLIENT)
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   119
            return p;
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   120
        p = p->next;
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   121
    }
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   122
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   123
    return 0;
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   124
}
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   125
32
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   126
static struct Job * find_finished_job(int jobid)
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   127
{
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   128
    struct Job *p;
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   129
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   130
    /* Show Queued or Running jobs */
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   131
    p = first_finished_job;
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   132
    while(p != 0)
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   133
    {
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   134
        if (p->jobid == jobid)
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   135
            return p;
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   136
        p = p->next;
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   137
    }
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   138
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   139
    return 0;
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   140
}
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   141
287
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   142
static int count_not_finished_jobs()
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   143
{
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   144
    int count=0;
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   145
    struct Job *p;
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   146
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   147
    /* Show Queued or Running jobs */
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   148
    p = firstjob;
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   149
    while(p != 0)
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   150
    {
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   151
        ++count;
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   152
        p = p->next;
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   153
    }
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   154
    return count;
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   155
}
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   156
259
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   157
static void add_notify_errorlevel_to(struct Job *job, int jobid)
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   158
{
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   159
    int *p;
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   160
    int newsize = (job->notify_errorlevel_to_size + 1)
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   161
        * sizeof(int);
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   162
    p = (int *) realloc(job->notify_errorlevel_to,
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   163
            newsize);
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   164
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   165
    if (p == 0)
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   166
        error("Cannot allocate more memory for notify_errorlist_to for jobid %i,"
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   167
                " having already %i elements",
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   168
                job->jobid, job->notify_errorlevel_to_size);
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   169
    
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   170
    job->notify_errorlevel_to = p;
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   171
    job->notify_errorlevel_to_size += 1;
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   172
    job->notify_errorlevel_to[job->notify_errorlevel_to_size - 1] = jobid;
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   173
}
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   174
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   175
void s_mark_job_running(int jobid)
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   176
{
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   177
    struct Job *p;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   178
    p = findjob(jobid);
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   179
    if (!p)
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   180
        error("Cannot mark the jobid %i RUNNING.", jobid);
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   181
    p->state = RUNNING;
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   182
}
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   183
287
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   184
/* -1 means nothing awaken, otherwise returns the jobid awaken */
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   185
int wake_hold_client()
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   186
{
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   187
    struct Job *p;
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   188
    p = findjob_holding_client();
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   189
    if (p)
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   190
    {
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   191
        p->state = QUEUED;
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   192
        return p->jobid;
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   193
    }
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   194
    return -1;
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   195
}
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   196
63
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
   197
const char * jstate2string(enum Jobstate s)
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   198
{
120
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
   199
    const char * jobstate;
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   200
    switch(s)
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   201
    {
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   202
        case QUEUED:
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   203
            jobstate = "queued";
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   204
            break;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   205
        case RUNNING:
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   206
            jobstate = "running";
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   207
            break;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   208
        case FINISHED:
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   209
            jobstate = "finished";
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   210
            break;
156
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
   211
        case SKIPPED:
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
   212
            jobstate = "skipped";
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
   213
            break;
287
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   214
        case HOLDING_CLIENT:
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   215
            jobstate = "skipped";
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   216
            break;
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   217
    }
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   218
    return jobstate;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   219
}
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   220
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   221
void s_list(int s)
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   222
{
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   223
    struct Job *p;
117
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents: 114
diff changeset
   224
    char *buffer;
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   225
114
bd123730295d times() reporting finished.
viric@mandarina
parents: 113
diff changeset
   226
    /* Times:   0.00/0.00/0.00 - 4+4+4+2 = 14*/ 
117
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents: 114
diff changeset
   227
    buffer = joblist_headers();
5
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 3
diff changeset
   228
    send_list_line(s,buffer);
117
db479ef293d3 Making "-l" not to trunc the commands.
viric@llimona
parents: 114
diff changeset
   229
    free(buffer);
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   230
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   231
    /* Show Queued or Running jobs */
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   232
    p = firstjob;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   233
    while(p != 0)
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   234
    {
287
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   235
        if (p->state != HOLDING_CLIENT)
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   236
        {
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   237
            buffer = joblist_line(p);
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   238
            send_list_line(s,buffer);
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   239
            free(buffer);
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   240
        }
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   241
        p = p->next;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   242
    }
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   243
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   244
    p = first_finished_job;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   245
120
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
   246
    /* Show Finished jobs */
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
   247
    while(p != 0)
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   248
    {
120
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
   249
        buffer = joblist_line(p);
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
   250
        send_list_line(s,buffer);
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
   251
        free(buffer);
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
   252
        p = p->next;
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   253
    }
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   254
}
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   255
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   256
static struct Job * newjobptr()
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   257
{
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   258
    struct Job *p;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   259
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   260
    if (firstjob == 0)
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   261
    {
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   262
        firstjob = (struct Job *) malloc(sizeof(*firstjob));
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   263
        firstjob->next = 0;
64
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   264
        firstjob->output_filename = 0;
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   265
        firstjob->command = 0;
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   266
        return firstjob;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   267
    }
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   268
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   269
    p = firstjob;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   270
    while(p->next != 0)
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   271
        p = p->next;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   272
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   273
    p->next = (struct Job *) malloc(sizeof(*p));
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   274
    p->next->next = 0;
64
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   275
    p->next->output_filename = 0;
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   276
    p->next->command = 0;
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   277
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   278
    return p->next;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   279
}
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   280
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   281
/* Returns -1 if no last job id found */
221
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
   282
static int find_last_jobid_in_queue(int neglect_jobid)
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   283
{
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   284
    struct Job *p;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   285
    int last_jobid = -1;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   286
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   287
    p = firstjob;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   288
    while(p != 0)
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   289
    {
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   290
        if (p->jobid != neglect_jobid &&
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   291
            p->jobid > last_jobid)
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   292
            last_jobid = p->jobid;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   293
        p = p->next;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   294
    }
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   295
221
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
   296
    return last_jobid;
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
   297
}
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
   298
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
   299
/* Returns -1 if no last job id found */
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
   300
static int find_last_stored_jobid_finished()
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
   301
{
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
   302
    struct Job *p;
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
   303
    int last_jobid = -1;
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
   304
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   305
    p = first_finished_job;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   306
    while(p != 0)
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   307
    {
221
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
   308
        if (p->jobid > last_jobid)
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   309
            last_jobid = p->jobid;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   310
        p = p->next;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   311
    }
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   312
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   313
    return last_jobid;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   314
}
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   315
259
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   316
/* Returns job id or -1 on error */
18
af4898956964 Now commands of any-length are accepted.
viric@llimona
parents: 9
diff changeset
   317
int s_newjob(int s, struct msg *m)
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   318
{
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   319
    struct Job *p;
18
af4898956964 Now commands of any-length are accepted.
viric@llimona
parents: 9
diff changeset
   320
    int res;
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   321
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   322
    p = newjobptr();
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   323
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   324
    p->jobid = jobids++;
287
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   325
    if (count_not_finished_jobs() < max_jobs)
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   326
        p->state = QUEUED;
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   327
    else
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   328
        p->state = HOLDING_CLIENT;
315
2b3ed8fdfb12 Implementing the num_slots for newjob in the messages, but the server still does
viric <viriketo@gmail.com>
parents: 289
diff changeset
   329
    p->num_slots = m->u.newjob.num_slots;
27
886bdb2f4632 Fixed the Output File information in the list.
viric@llimona
parents: 26
diff changeset
   330
    p->store_output = m->u.newjob.store_output;
55
678ca291d545 Now the '-nf' doesn't leave a job in 'finished' state.
viric@llimona
parents: 54
diff changeset
   331
    p->should_keep_finished = m->u.newjob.should_keep_finished;
259
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   332
    p->notify_errorlevel_to = 0;
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   333
    p->notify_errorlevel_to_size = 0;
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   334
    p->do_depend = m->u.newjob.do_depend;
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   335
    p->depend_on = -1; /* By default. May be overriden in the next conditions */
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   336
    if (m->u.newjob.do_depend == 1)
221
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
   337
    {
259
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   338
        /* Depend on the last queued job. */
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   339
221
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
   340
        /* As we already have 'p' in the queue,
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
   341
         * neglect it during the find_last_jobid_in_queue() */
259
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   342
        if (m->u.newjob.depend_on == -1)
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   343
        {
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   344
            p->depend_on = find_last_jobid_in_queue(p->jobid);
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   345
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   346
            /* We don't trust the last jobid in the queue (running or queued)
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   347
             * if it's not the last added job. In that case, let
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   348
             * the next control flow handle it as if it could not
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   349
             * do_depend on any still queued job. */
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   350
            if (last_finished_jobid > p->depend_on)
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   351
                p->depend_on = -1;
221
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
   352
259
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   353
            /* If it's queued still without result, let it know
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   354
             * its result to p when it finishes. */
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   355
            if (p->depend_on != -1)
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   356
            {
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   357
                struct Job *depended_job;
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   358
                depended_job = findjob(p->depend_on);
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   359
                if (depended_job != 0)
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   360
                    add_notify_errorlevel_to(depended_job, p->jobid);
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   361
                else
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   362
                    warning("The jobid %i is queued to do_depend on the jobid %i"
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   363
                        " suddenly non existant in the queue", p->jobid,
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   364
                        p->depend_on);
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   365
            }
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   366
            else /* Otherwise take the finished job, or the last_errorlevel */
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   367
            {
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   368
                if (m->u.newjob.depend_on == -1)
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   369
                {
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   370
                    int ljobid = find_last_stored_jobid_finished();
317
290b5aa53061 Making the number of slots appear on '-i'.
viric <viriketo@gmail.com>
parents: 316
diff changeset
   371
                    p->depend_on = ljobid;
290b5aa53061 Making the number of slots appear on '-i'.
viric <viriketo@gmail.com>
parents: 316
diff changeset
   372
259
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   373
                    /* If we have a newer result stored, use it */
317
290b5aa53061 Making the number of slots appear on '-i'.
viric <viriketo@gmail.com>
parents: 316
diff changeset
   374
                    /* NOTE:
290b5aa53061 Making the number of slots appear on '-i'.
viric <viriketo@gmail.com>
parents: 316
diff changeset
   375
                     *   Reading this now, I don't know how ljobid can be
290b5aa53061 Making the number of slots appear on '-i'.
viric <viriketo@gmail.com>
parents: 316
diff changeset
   376
                     *   greater than last_finished_jobid */
259
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   377
                    if (last_finished_jobid < ljobid)
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   378
                    {
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   379
                        struct Job *parent;
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   380
                        parent = find_finished_job(ljobid);
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   381
                        if (!parent)
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   382
                            error("jobid %i suddenly disappeared from the finished list",
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   383
                                ljobid);
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   384
                        p->dependency_errorlevel = parent->result.errorlevel;
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   385
                    }
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   386
                    else
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   387
                        p->dependency_errorlevel = last_errorlevel;
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   388
                }
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   389
            }
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   390
        }
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   391
        else
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   392
        {
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   393
            /* The user decided what's the job this new job depends on */
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   394
            struct Job *depended_job;
221
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
   395
259
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   396
            p->depend_on = m->u.newjob.depend_on;
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   397
221
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
   398
            depended_job = findjob(p->depend_on);
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
   399
            if (depended_job != 0)
259
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   400
                add_notify_errorlevel_to(depended_job, p->jobid);
221
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
   401
            else
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
   402
            {
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
   403
                struct Job *parent;
259
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   404
                parent = find_finished_job(p->depend_on);
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   405
                if (parent)
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   406
                {
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   407
                    p->dependency_errorlevel = parent->result.errorlevel;
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   408
                }
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   409
                else
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   410
                {
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   411
                    /* We consider as if the job not found
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   412
                       didn't finish well */
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   413
                    p->dependency_errorlevel = -1;
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   414
                }
221
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
   415
            }
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
   416
        }
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
   417
    }
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   418
18
af4898956964 Now commands of any-length are accepted.
viric@llimona
parents: 9
diff changeset
   419
147
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
   420
    pinfo_init(&p->info);
146
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   421
    pinfo_set_enqueue_time(&p->info);
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   422
18
af4898956964 Now commands of any-length are accepted.
viric@llimona
parents: 9
diff changeset
   423
    /* load the command */
af4898956964 Now commands of any-length are accepted.
viric@llimona
parents: 9
diff changeset
   424
    p->command = malloc(m->u.newjob.command_size);
147
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
   425
    if (p->command == 0)
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
   426
        error("Cannot allocate memory in s_newjob command_size (%i)",
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
   427
                m->u.newjob.command_size);
18
af4898956964 Now commands of any-length are accepted.
viric@llimona
parents: 9
diff changeset
   428
    res = recv_bytes(s, p->command, m->u.newjob.command_size);
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   429
    if (res == -1)
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   430
        error("wrong bytes received");
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   431
150
a615d7971bf6 Added -L (label)
viric@llimona
parents: 148
diff changeset
   432
    /* load the label */
a615d7971bf6 Added -L (label)
viric@llimona
parents: 148
diff changeset
   433
    p->label = 0;
a615d7971bf6 Added -L (label)
viric@llimona
parents: 148
diff changeset
   434
    if (m->u.newjob.label_size > 0)
a615d7971bf6 Added -L (label)
viric@llimona
parents: 148
diff changeset
   435
    {
a615d7971bf6 Added -L (label)
viric@llimona
parents: 148
diff changeset
   436
        char *ptr;
a615d7971bf6 Added -L (label)
viric@llimona
parents: 148
diff changeset
   437
        ptr = (char *) malloc(m->u.newjob.label_size);
a615d7971bf6 Added -L (label)
viric@llimona
parents: 148
diff changeset
   438
        if (ptr == 0)
a615d7971bf6 Added -L (label)
viric@llimona
parents: 148
diff changeset
   439
            error("Cannot allocate memory in s_newjob env_size(%i)",
a615d7971bf6 Added -L (label)
viric@llimona
parents: 148
diff changeset
   440
                    m->u.newjob.env_size);
a615d7971bf6 Added -L (label)
viric@llimona
parents: 148
diff changeset
   441
        res = recv_bytes(s, ptr, m->u.newjob.label_size);
a615d7971bf6 Added -L (label)
viric@llimona
parents: 148
diff changeset
   442
        if (res == -1)
a615d7971bf6 Added -L (label)
viric@llimona
parents: 148
diff changeset
   443
            error("wrong bytes received");
a615d7971bf6 Added -L (label)
viric@llimona
parents: 148
diff changeset
   444
        p->label = ptr;
a615d7971bf6 Added -L (label)
viric@llimona
parents: 148
diff changeset
   445
    }
a615d7971bf6 Added -L (label)
viric@llimona
parents: 148
diff changeset
   446
147
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
   447
    /* load the info */
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
   448
    if (m->u.newjob.env_size > 0)
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
   449
    {
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
   450
        char *ptr;
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
   451
        ptr = (char *) malloc(m->u.newjob.env_size);
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
   452
        if (ptr == 0)
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
   453
            error("Cannot allocate memory in s_newjob env_size(%i)",
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
   454
                    m->u.newjob.env_size);
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
   455
        res = recv_bytes(s, ptr, m->u.newjob.env_size);
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
   456
        if (res == -1)
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
   457
            error("wrong bytes received");
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
   458
        pinfo_addinfo(&p->info, m->u.newjob.env_size+100,
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
   459
                "Environment:\n%s", ptr);
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
   460
        free(ptr);
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
   461
    }
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
   462
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   463
    return p->jobid;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   464
}
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   465
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   466
/* This assumes the jobid exists */
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   467
void s_removejob(int jobid)
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   468
{
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   469
    struct Job *p;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   470
    struct Job *newnext;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   471
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   472
    if (firstjob->jobid == jobid)
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   473
    {
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   474
        struct Job *newfirst;
134
5a6b8bb1f7a8 Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents: 120
diff changeset
   475
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   476
        /* First job is to be removed */
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   477
        newfirst = firstjob->next;
18
af4898956964 Now commands of any-length are accepted.
viric@llimona
parents: 9
diff changeset
   478
        free(firstjob->command);
64
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   479
        free(firstjob->output_filename);
148
a8c5dac8f1e9 Fixing a memory leak in new pinfo.
viric@llimona
parents: 147
diff changeset
   480
        pinfo_free(&firstjob->info);
150
a615d7971bf6 Added -L (label)
viric@llimona
parents: 148
diff changeset
   481
        free(firstjob->label);
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   482
        free(firstjob);
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   483
        firstjob = newfirst;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   484
        return;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   485
    }
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   486
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   487
    p = firstjob;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   488
    /* Not first job */
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   489
    while (p->next != 0)
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   490
    {
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   491
        if (p->next->jobid == jobid)
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   492
            break;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   493
        p = p->next;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   494
    }
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   495
    if (p->next == 0)
134
5a6b8bb1f7a8 Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents: 120
diff changeset
   496
        error("Job to be removed not found. jobid=%i", jobid);
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   497
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   498
    newnext = p->next->next;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   499
18
af4898956964 Now commands of any-length are accepted.
viric@llimona
parents: 9
diff changeset
   500
    free(p->next->command);
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   501
    free(p->next);
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   502
    p->next = newnext;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   503
}
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   504
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   505
/* -1 if no one should be run. */
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   506
int next_run_job()
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   507
{
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   508
    struct Job *p;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   509
316
7ce3aeaf73b5 Making the option -N work fine; jobs get into running if there are free slots.
viric <viriketo@gmail.com>
parents: 315
diff changeset
   510
    const int free_slots = max_slots - busy_slots;
7ce3aeaf73b5 Making the option -N work fine; jobs get into running if there are free slots.
viric <viriketo@gmail.com>
parents: 315
diff changeset
   511
219
c24a1f5c1715 Adding hot-switchable amount of max_slots.
viric@mandarina
parents: 218
diff changeset
   512
    /* busy_slots may be bigger than the maximum slots,
c24a1f5c1715 Adding hot-switchable amount of max_slots.
viric@mandarina
parents: 218
diff changeset
   513
     * if the user was running many jobs, and suddenly
c24a1f5c1715 Adding hot-switchable amount of max_slots.
viric@mandarina
parents: 218
diff changeset
   514
     * trimmed the maximum slots down. */
316
7ce3aeaf73b5 Making the option -N work fine; jobs get into running if there are free slots.
viric <viriketo@gmail.com>
parents: 315
diff changeset
   515
    if (free_slots <= 0)
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   516
        return -1;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   517
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   518
    /* If there are no jobs to run... */
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   519
    if (firstjob == 0)
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   520
        return -1;
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   521
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   522
    /* Look for a runnable task */
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   523
    p = firstjob;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   524
    while(p != 0)
9
9acd8ae3190c First usable version!
lbatlle@npdl268.bpo.hp.com
parents: 8
diff changeset
   525
    {
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   526
        if (p->state == QUEUED)
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   527
        {
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   528
            if (p->depend_on >= 0)
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   529
            {
259
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   530
                struct Job *do_depend_job = get_job(p->depend_on);
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   531
                /* We won't try to run any job do_depending on an unfinished
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   532
                 * job */
259
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   533
                if (do_depend_job != NULL &&
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   534
                    (do_depend_job->state == QUEUED || do_depend_job->state == RUNNING))
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   535
                {
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   536
                    /* Next try */
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   537
                    p = p->next;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   538
                    continue;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   539
                }
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   540
            }
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   541
316
7ce3aeaf73b5 Making the option -N work fine; jobs get into running if there are free slots.
viric <viriketo@gmail.com>
parents: 315
diff changeset
   542
            if (free_slots >= p->num_slots)
7ce3aeaf73b5 Making the option -N work fine; jobs get into running if there are free slots.
viric <viriketo@gmail.com>
parents: 315
diff changeset
   543
            {
7ce3aeaf73b5 Making the option -N work fine; jobs get into running if there are free slots.
viric <viriketo@gmail.com>
parents: 315
diff changeset
   544
                busy_slots = busy_slots + p->num_slots;
7ce3aeaf73b5 Making the option -N work fine; jobs get into running if there are free slots.
viric <viriketo@gmail.com>
parents: 315
diff changeset
   545
                return p->jobid;
7ce3aeaf73b5 Making the option -N work fine; jobs get into running if there are free slots.
viric <viriketo@gmail.com>
parents: 315
diff changeset
   546
            }
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   547
        }
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   548
        p = p->next;
9
9acd8ae3190c First usable version!
lbatlle@npdl268.bpo.hp.com
parents: 8
diff changeset
   549
    }
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   550
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   551
    return -1;
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   552
}
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   553
64
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   554
/* Returns 1000 if no limit, The limit otherwise. */
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   555
static int get_max_finished_jobs()
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   556
{
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   557
    char *limit;
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   558
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   559
    limit = getenv("TS_MAXFINISHED");
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   560
    if (limit == NULL)
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   561
        return 1000;
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   562
    return abs(atoi(limit));
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   563
}
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   564
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   565
/* Add the job to the finished queue. */
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   566
static void new_finished_job(struct Job *j)
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   567
{
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   568
    struct Job *p;
64
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   569
    int count, max;
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   570
64
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   571
    max = get_max_finished_jobs();
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   572
    count = 0;
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   573
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   574
    if (first_finished_job == 0 && count < max)
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   575
    {
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   576
        first_finished_job = j;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   577
        first_finished_job->next = 0;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   578
        return;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   579
    }
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   580
64
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   581
    ++count;
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   582
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   583
    p = first_finished_job;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   584
    while(p->next != 0)
64
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   585
    {
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   586
        p = p->next;
64
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   587
        ++count;
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   588
    }
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   589
64
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   590
    /* If too many jobs, wipe out the first */
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   591
    if (count >= max)
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   592
    {
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   593
        struct Job *tmp;
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   594
        tmp = first_finished_job;
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   595
        first_finished_job = first_finished_job->next;
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   596
        free(tmp->command);
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   597
        free(tmp->output_filename);
148
a8c5dac8f1e9 Fixing a memory leak in new pinfo.
viric@llimona
parents: 147
diff changeset
   598
        pinfo_free(&tmp->info);
150
a615d7971bf6 Added -L (label)
viric@llimona
parents: 148
diff changeset
   599
        free(tmp->label);
64
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   600
        free(tmp);
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   601
    }
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   602
    p->next = j;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   603
    p->next->next = 0;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   604
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   605
    return;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   606
}
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   607
287
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   608
static int job_is_in_state(int jobid, enum Jobstate state)
252
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 246
diff changeset
   609
{
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 246
diff changeset
   610
    struct Job *p;
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 246
diff changeset
   611
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 246
diff changeset
   612
    p = findjob(jobid);
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 246
diff changeset
   613
    if (p == 0)
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 246
diff changeset
   614
        return 0;
287
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   615
    if (p->state == state)
252
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 246
diff changeset
   616
        return 1;
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 246
diff changeset
   617
    return 0;
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 246
diff changeset
   618
}
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 246
diff changeset
   619
287
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   620
int job_is_running(int jobid)
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   621
{
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   622
    return job_is_in_state(jobid, RUNNING);
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   623
}
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   624
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   625
int job_is_holding_client(int jobid)
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   626
{
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   627
    return job_is_in_state(jobid, HOLDING_CLIENT);
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   628
}
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 267
diff changeset
   629
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   630
void job_finished(const struct Result *result, int jobid)
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   631
{
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   632
    struct Job *p;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   633
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   634
    if (busy_slots <= 0)
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   635
        error("Wrong state in the server. busy_slots = %i instead of greater than 0", busy_slots);
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   636
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   637
    p = findjob(jobid);
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   638
    if (p == 0)
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   639
        error("on jobid %i finished, it doesn't exist", jobid);
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   640
288
8459747e1a73 Fixing the cleaning of the job list in case of ctrl-c on a blocked client
viric <viriketo@gmail.com>
parents: 287
diff changeset
   641
    /* The job may be not only in running state, but also in other states, as
8459747e1a73 Fixing the cleaning of the job list in case of ctrl-c on a blocked client
viric <viriketo@gmail.com>
parents: 287
diff changeset
   642
     * we call this to clean up the jobs list in case of the client closing the
8459747e1a73 Fixing the cleaning of the job list in case of ctrl-c on a blocked client
viric <viriketo@gmail.com>
parents: 287
diff changeset
   643
     * connection. */
8459747e1a73 Fixing the cleaning of the job list in case of ctrl-c on a blocked client
viric <viriketo@gmail.com>
parents: 287
diff changeset
   644
    if (p->state == RUNNING)
316
7ce3aeaf73b5 Making the option -N work fine; jobs get into running if there are free slots.
viric <viriketo@gmail.com>
parents: 315
diff changeset
   645
        busy_slots = busy_slots - p->num_slots;
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   646
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   647
    /* Mark state */
156
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
   648
    if (result->skipped)
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   649
        p->state = SKIPPED;
156
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
   650
    else
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   651
        p->state = FINISHED;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   652
    p->result = *result;
221
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
   653
    last_finished_jobid = p->jobid;
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   654
    notify_errorlevel(p);
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   655
    pinfo_set_end_time(&p->info);
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   656
246
239b28c0cca9 Adding information on the exit status (signal/exit code).
viric@mandarina
parents: 231
diff changeset
   657
    if (p->result.died_by_signal)
239b28c0cca9 Adding information on the exit status (signal/exit code).
viric@mandarina
parents: 231
diff changeset
   658
        pinfo_addinfo(&p->info, 100, "Exit status: killed by signal %i\n", p->result.signal);
239b28c0cca9 Adding information on the exit status (signal/exit code).
viric@mandarina
parents: 231
diff changeset
   659
    else
239b28c0cca9 Adding information on the exit status (signal/exit code).
viric@mandarina
parents: 231
diff changeset
   660
        pinfo_addinfo(&p->info, 100, "Exit status: died with exit code %i\n", p->result.errorlevel);
239b28c0cca9 Adding information on the exit status (signal/exit code).
viric@mandarina
parents: 231
diff changeset
   661
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   662
    /* Find the pointing node, to
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   663
     * update it removing the finished job. */
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   664
    {
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   665
        struct Job **jpointer = 0;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   666
        struct Job *newfirst = p->next;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   667
        if (firstjob == p)
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   668
            jpointer = &firstjob;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   669
        else
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   670
        {
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   671
            struct Job *p2;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   672
            p2 = firstjob;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   673
            while(p2 != 0)
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   674
            {
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   675
                if (p2->next == p)
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   676
                {
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   677
                    jpointer = &(p2->next);
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   678
                    break;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   679
                }
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   680
                p2 = p2->next;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   681
            }
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   682
        }
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   683
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   684
        /* Add it to the finished queue */
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   685
        if (p->should_keep_finished)
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   686
            new_finished_job(p);
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   687
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   688
        /* Remove it from the run queue */
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   689
        if (jpointer == 0)
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   690
            error("Cannot remove a finished job from the "
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   691
                "queue list (jobid=%i)", p->jobid);
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   692
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   693
        *jpointer = newfirst;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   694
    }
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   695
}
20
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   696
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   697
void s_clear_finished()
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   698
{
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   699
    struct Job *p;
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   700
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   701
    if (first_finished_job == 0)
20
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   702
        return;
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   703
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   704
    p = first_finished_job;
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   705
    first_finished_job = 0;
20
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   706
64
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
   707
    while (p != 0)
20
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   708
    {
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   709
        struct Job *tmp;
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   710
        tmp = p->next;
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   711
        free(p->command);
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   712
        free(p->output_filename);
148
a8c5dac8f1e9 Fixing a memory leak in new pinfo.
viric@llimona
parents: 147
diff changeset
   713
        pinfo_free(&p->info);
150
a615d7971bf6 Added -L (label)
viric@llimona
parents: 148
diff changeset
   714
        free(p->label);
20
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   715
        free(p);
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   716
        p = tmp;
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   717
    }
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   718
}
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   719
35
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 32
diff changeset
   720
void s_process_runjob_ok(int jobid, char *oname, int pid)
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   721
{
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   722
    struct Job *p;
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   723
    p = findjob(jobid);
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   724
    if (p == 0)
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   725
        error("Job %i already run not found on runjob_ok", jobid);
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   726
    if (p->state != RUNNING)
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   727
        error("Job %i not running, but %i on runjob_ok", jobid,
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   728
                p->state);
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   729
35
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 32
diff changeset
   730
    p->pid = pid;
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   731
    p->output_filename = oname;
146
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   732
    pinfo_set_start_time(&p->info);
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   733
}
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   734
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   735
void s_send_runjob(int s, int jobid)
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   736
{
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   737
    struct msg m;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   738
    struct Job *p;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   739
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   740
    p = findjob(jobid);
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   741
    if (p == 0) 
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   742
        error("Job %i was expected to run", jobid);
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   743
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   744
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   745
    m.type = RUNJOB;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   746
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   747
    /* TODO
259
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   748
     * We should make the dependencies update the jobids they're do_depending on.
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   749
     * Then, on finish, these could set the errorlevel to send to its dependency childs.
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   750
     * We cannot consider that the jobs will leave traces in the finished job list (-nf?) . */
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   751
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   752
    m.u.last_errorlevel = p->dependency_errorlevel;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   753
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   754
    send_msg(s, &m);
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   755
}
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   756
146
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   757
void s_job_info(int s, int jobid)
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   758
{
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   759
    struct Job *p = 0;
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   760
    struct msg m;
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   761
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   762
    if (jobid == -1)
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   763
    {
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   764
        /* This means that we want the job info of the running task, or that
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   765
         * of the last job run */
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   766
        if (busy_slots > 0)
146
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   767
        {
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   768
            p = firstjob;
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   769
            if (p == 0)
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   770
                error("Internal state WAITING, but job not run."
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   771
                        "firstjob = %x", firstjob);
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   772
        }
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   773
        else
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   774
        {
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   775
            p = first_finished_job;
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   776
            if (p == 0)
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   777
            {
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   778
                send_list_line(s, "No jobs.\n");
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   779
                return;
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   780
            }
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   781
            while(p->next != 0)
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   782
                p = p->next;
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   783
        }
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   784
    } else
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   785
    {
154
b1618fe033aa Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents: 153
diff changeset
   786
        p = firstjob;
b1618fe033aa Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents: 153
diff changeset
   787
        while (p != 0 && p->jobid != jobid)
b1618fe033aa Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents: 153
diff changeset
   788
            p = p->next;
b1618fe033aa Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents: 153
diff changeset
   789
b1618fe033aa Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents: 153
diff changeset
   790
        /* Look in finished jobs if needed */
b1618fe033aa Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents: 153
diff changeset
   791
        if (p == 0)
b1618fe033aa Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents: 153
diff changeset
   792
        {
b1618fe033aa Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents: 153
diff changeset
   793
            p = first_finished_job;
b1618fe033aa Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents: 153
diff changeset
   794
            while (p != 0 && p->jobid != jobid)
b1618fe033aa Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents: 153
diff changeset
   795
                p = p->next;
b1618fe033aa Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents: 153
diff changeset
   796
        }
146
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   797
    }
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   798
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   799
    if (p == 0)
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   800
    {
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   801
        char tmp[50];
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   802
        sprintf(tmp, "Job %i not finished or not running.\n", jobid);
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   803
        send_list_line(s, tmp);
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   804
        return;
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   805
    }
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   806
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   807
    m.type = INFO_DATA;
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   808
    send_msg(s, &m);
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   809
    pinfo_dump(&p->info, s);
317
290b5aa53061 Making the number of slots appear on '-i'.
viric <viriketo@gmail.com>
parents: 316
diff changeset
   810
    fd_nprintf(s, 100, "Command: ");
290b5aa53061 Making the number of slots appear on '-i'.
viric <viriketo@gmail.com>
parents: 316
diff changeset
   811
    if (p->depend_on != -1)
290b5aa53061 Making the number of slots appear on '-i'.
viric <viriketo@gmail.com>
parents: 316
diff changeset
   812
        fd_nprintf(s, 100, "[%i]&& ", p->depend_on);
154
b1618fe033aa Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents: 153
diff changeset
   813
    write(s, p->command, strlen(p->command));
b1618fe033aa Fixed a bug on -i, when the job was not running or run. Added Command: in -i.
viric@llimona
parents: 153
diff changeset
   814
    fd_nprintf(s, 100, "\n");
317
290b5aa53061 Making the number of slots appear on '-i'.
viric <viriketo@gmail.com>
parents: 316
diff changeset
   815
    fd_nprintf(s, 100, "Slots required: %i\n", p->num_slots);
146
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   816
    fd_nprintf(s, 100, "Enqueue time: %s",
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   817
            ctime(&p->info.enqueue_time.tv_sec));
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   818
    if (p->state == RUNNING)
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   819
    {
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   820
        fd_nprintf(s, 100, "Start time: %s",
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   821
                ctime(&p->info.start_time.tv_sec));
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   822
        fd_nprintf(s, 100, "Time running: %fs\n",
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   823
                pinfo_time_until_now(&p->info));
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   824
    } else if (p->state == FINISHED)
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   825
    {
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   826
        fd_nprintf(s, 100, "Start time: %s",
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   827
                ctime(&p->info.start_time.tv_sec));
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   828
        fd_nprintf(s, 100, "End time: %s",
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   829
                ctime(&p->info.end_time.tv_sec));
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   830
        fd_nprintf(s, 100, "Time run: %fs\n",
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   831
                pinfo_time_run(&p->info));
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   832
    }
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   833
}
32
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   834
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   835
void s_send_output(int s, int jobid)
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   836
{
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   837
    struct Job *p = 0;
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   838
    struct msg m;
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   839
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   840
    if (jobid == -1)
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   841
    {
146
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
   842
        /* This means that we want the output info of the running task, or that
32
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   843
         * of the last job run */
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   844
        if (busy_slots > 0)
32
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   845
        {
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   846
            p = firstjob;
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   847
            if (p == 0)
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   848
                error("Internal state WAITING, but job not run."
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   849
                        "firstjob = %x", firstjob);
32
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   850
        }
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   851
        else
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   852
        {
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   853
            p = first_finished_job;
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   854
            if (p == 0)
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   855
            {
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   856
                send_list_line(s, "No jobs.\n");
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   857
                return;
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   858
            }
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   859
            while(p->next != 0)
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   860
                p = p->next;
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   861
        }
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   862
    } else
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   863
    {
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   864
        p = get_job(jobid);
225
6c2583ea71eb Bugfix: Improving the parent bugfix, so it displays a nicer message on SKIPPED
viric@mandarina
parents: 224
diff changeset
   865
        if (p != 0 && p->state != RUNNING
6c2583ea71eb Bugfix: Improving the parent bugfix, so it displays a nicer message on SKIPPED
viric@mandarina
parents: 224
diff changeset
   866
            && p->state != FINISHED
6c2583ea71eb Bugfix: Improving the parent bugfix, so it displays a nicer message on SKIPPED
viric@mandarina
parents: 224
diff changeset
   867
            && p->state != SKIPPED)
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   868
            p = 0;
32
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   869
    }
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   870
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   871
    if (p == 0)
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   872
    {
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   873
        char tmp[50];
196
bca29e2a1a86 Fixing a bug related to a message on -t on last job, when it was skipped.
viric@llimona
parents: 190
diff changeset
   874
        if (jobid == -1)
bca29e2a1a86 Fixing a bug related to a message on -t on last job, when it was skipped.
viric@llimona
parents: 190
diff changeset
   875
            sprintf(tmp, "The last job has not finished or is not running.\n");
bca29e2a1a86 Fixing a bug related to a message on -t on last job, when it was skipped.
viric@llimona
parents: 190
diff changeset
   876
        else
bca29e2a1a86 Fixing a bug related to a message on -t on last job, when it was skipped.
viric@llimona
parents: 190
diff changeset
   877
            sprintf(tmp, "Job %i not finished or not running.\n", jobid);
32
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   878
        send_list_line(s, tmp);
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   879
        return;
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   880
    }
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   881
157
c4909531282e Fixed a bug on new skipped state and -o.
viric@mandarina
parents: 156
diff changeset
   882
    if (p->state == SKIPPED)
156
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
   883
    {
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
   884
        char tmp[50];
196
bca29e2a1a86 Fixing a bug related to a message on -t on last job, when it was skipped.
viric@llimona
parents: 190
diff changeset
   885
        if (jobid == -1)
bca29e2a1a86 Fixing a bug related to a message on -t on last job, when it was skipped.
viric@llimona
parents: 190
diff changeset
   886
            sprintf(tmp,  "The last job was skipped due to a dependency.\n");
bca29e2a1a86 Fixing a bug related to a message on -t on last job, when it was skipped.
viric@llimona
parents: 190
diff changeset
   887
                    
bca29e2a1a86 Fixing a bug related to a message on -t on last job, when it was skipped.
viric@llimona
parents: 190
diff changeset
   888
        else
bca29e2a1a86 Fixing a bug related to a message on -t on last job, when it was skipped.
viric@llimona
parents: 190
diff changeset
   889
            sprintf(tmp, "Job %i was skipped due to a dependency.\n", jobid);
156
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
   890
        send_list_line(s, tmp);
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
   891
        return;
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
   892
    }
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
   893
32
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   894
    m.type = ANSWER_OUTPUT;
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   895
    m.u.output.store_output = p->store_output;
35
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 32
diff changeset
   896
    m.u.output.pid = p->pid;
289
f331d05328b3 Fixing a bug in the server, that made the server crash if the output file was
viric <viriketo@gmail.com>
parents: 288
diff changeset
   897
    if (m.u.output.store_output && p->output_filename)
153
3cc22be1ab95 Fixed a bug with -n and -p.
viric@llimona
parents: 150
diff changeset
   898
        m.u.output.ofilename_size = strlen(p->output_filename) + 1;
3cc22be1ab95 Fixed a bug with -n and -p.
viric@llimona
parents: 150
diff changeset
   899
    else
3cc22be1ab95 Fixed a bug with -n and -p.
viric@llimona
parents: 150
diff changeset
   900
        m.u.output.ofilename_size = 0;
32
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   901
    send_msg(s, &m);
289
f331d05328b3 Fixing a bug in the server, that made the server crash if the output file was
viric <viriketo@gmail.com>
parents: 288
diff changeset
   902
    if (m.u.output.ofilename_size > 0)
f331d05328b3 Fixing a bug in the server, that made the server crash if the output file was
viric <viriketo@gmail.com>
parents: 288
diff changeset
   903
        send_bytes(s, p->output_filename, m.u.output.ofilename_size);
32
3531439f2770 Tail works.
viric@llimona
parents: 27
diff changeset
   904
}
41
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   905
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   906
void notify_errorlevel(struct Job *p)
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   907
{
259
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   908
    int i;
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   909
221
fed80bc73128 Updating the "-d" behaviour, so it now works well also with "-nf" submitted
viric@mandarina
parents: 219
diff changeset
   910
    last_errorlevel = p->result.errorlevel;
259
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   911
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   912
    for(i = 0; i < p->notify_errorlevel_to_size; ++i)
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   913
    {
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   914
        struct Job *notified;
259
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
   915
        notified = get_job(p->notify_errorlevel_to[i]);
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   916
        if (notified)
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   917
        {
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   918
            notified->dependency_errorlevel = p->result.errorlevel;
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   919
        }
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   920
    }
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   921
}
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   922
134
5a6b8bb1f7a8 Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents: 120
diff changeset
   923
int s_remove_job(int s, int jobid)
41
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   924
{
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   925
    struct Job *p = 0;
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   926
    struct msg m;
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   927
    struct Job *before_p = 0;
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   928
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   929
    if (jobid == -1)
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   930
    {
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   931
        /* Find the last job added */
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   932
        p = firstjob;
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   933
        if (p != 0)
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   934
        {
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   935
            while (p->next != 0)
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   936
            {
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   937
                before_p = p;
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   938
                p = p->next;
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   939
            }
180
a35159b7009a Finished jobs can also be removed now.
viric@llimona
parents: 178
diff changeset
   940
        } else
a35159b7009a Finished jobs can also be removed now.
viric@llimona
parents: 178
diff changeset
   941
        {
a35159b7009a Finished jobs can also be removed now.
viric@llimona
parents: 178
diff changeset
   942
            /* last 'finished' */
a35159b7009a Finished jobs can also be removed now.
viric@llimona
parents: 178
diff changeset
   943
            p = first_finished_job;
190
a1d9f881740e Fixed "-r" without jobid.
lbatlle@npdl268.bpo.hp.com
parents: 182
diff changeset
   944
            if (p)
180
a35159b7009a Finished jobs can also be removed now.
viric@llimona
parents: 178
diff changeset
   945
            {
190
a1d9f881740e Fixed "-r" without jobid.
lbatlle@npdl268.bpo.hp.com
parents: 182
diff changeset
   946
                while (p->next != 0)
a1d9f881740e Fixed "-r" without jobid.
lbatlle@npdl268.bpo.hp.com
parents: 182
diff changeset
   947
                {
a1d9f881740e Fixed "-r" without jobid.
lbatlle@npdl268.bpo.hp.com
parents: 182
diff changeset
   948
                    before_p = p;
a1d9f881740e Fixed "-r" without jobid.
lbatlle@npdl268.bpo.hp.com
parents: 182
diff changeset
   949
                    p = p->next;
a1d9f881740e Fixed "-r" without jobid.
lbatlle@npdl268.bpo.hp.com
parents: 182
diff changeset
   950
                }
180
a35159b7009a Finished jobs can also be removed now.
viric@llimona
parents: 178
diff changeset
   951
            }
41
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   952
        }
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   953
    }
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   954
    else
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   955
    {
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   956
        p = firstjob;
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   957
        if (p != 0)
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   958
        {
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   959
            while (p->next != 0 && p->jobid != jobid)
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   960
            {
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   961
                before_p = p;
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   962
                p = p->next;
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   963
            }
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   964
        }
180
a35159b7009a Finished jobs can also be removed now.
viric@llimona
parents: 178
diff changeset
   965
a35159b7009a Finished jobs can also be removed now.
viric@llimona
parents: 178
diff changeset
   966
        /* If not found, look in the 'finished' list */
a35159b7009a Finished jobs can also be removed now.
viric@llimona
parents: 178
diff changeset
   967
        if (p == 0 || p->jobid != jobid)
a35159b7009a Finished jobs can also be removed now.
viric@llimona
parents: 178
diff changeset
   968
        {
a35159b7009a Finished jobs can also be removed now.
viric@llimona
parents: 178
diff changeset
   969
            p = first_finished_job;
a35159b7009a Finished jobs can also be removed now.
viric@llimona
parents: 178
diff changeset
   970
            if (p != 0)
a35159b7009a Finished jobs can also be removed now.
viric@llimona
parents: 178
diff changeset
   971
            {
a35159b7009a Finished jobs can also be removed now.
viric@llimona
parents: 178
diff changeset
   972
                while (p->next != 0 && p->jobid != jobid)
a35159b7009a Finished jobs can also be removed now.
viric@llimona
parents: 178
diff changeset
   973
                {
a35159b7009a Finished jobs can also be removed now.
viric@llimona
parents: 178
diff changeset
   974
                    before_p = p;
a35159b7009a Finished jobs can also be removed now.
viric@llimona
parents: 178
diff changeset
   975
                    p = p->next;
a35159b7009a Finished jobs can also be removed now.
viric@llimona
parents: 178
diff changeset
   976
                }
227
3570252beade Bugfix: '-r' has a better behaviour when all the jobs finished.
viric@mandarina
parents: 226
diff changeset
   977
                if (p->jobid != jobid)
3570252beade Bugfix: '-r' has a better behaviour when all the jobs finished.
viric@mandarina
parents: 226
diff changeset
   978
                    p = 0;
180
a35159b7009a Finished jobs can also be removed now.
viric@llimona
parents: 178
diff changeset
   979
            }
a35159b7009a Finished jobs can also be removed now.
viric@llimona
parents: 178
diff changeset
   980
        }
41
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   981
    }
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   982
227
3570252beade Bugfix: '-r' has a better behaviour when all the jobs finished.
viric@mandarina
parents: 226
diff changeset
   983
    if (p == 0 || p->state == RUNNING || p == firstjob)
41
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   984
    {
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   985
        char tmp[50];
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   986
        if (jobid == -1)
44
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
   987
            sprintf(tmp, "The last job cannot be removed.\n");
41
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   988
        else
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   989
            sprintf(tmp, "The job %i cannot be removed.\n", jobid);
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   990
        send_list_line(s, tmp);
134
5a6b8bb1f7a8 Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents: 120
diff changeset
   991
        return 0;
41
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   992
    }
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
   993
178
5b64d66a8d89 Fixed awaking the wait_job clients on job removal.
viric@llimona
parents: 176
diff changeset
   994
    /* Tricks for the check_notify_list */
5b64d66a8d89 Fixed awaking the wait_job clients on job removal.
viric@llimona
parents: 176
diff changeset
   995
    p->state = FINISHED;
5b64d66a8d89 Fixed awaking the wait_job clients on job removal.
viric@llimona
parents: 176
diff changeset
   996
    p->result.errorlevel = -1;
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   997
    notify_errorlevel(p);
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 209
diff changeset
   998
        
178
5b64d66a8d89 Fixed awaking the wait_job clients on job removal.
viric@llimona
parents: 176
diff changeset
   999
    /* Notify the clients in wait_job */
5b64d66a8d89 Fixed awaking the wait_job clients on job removal.
viric@llimona
parents: 176
diff changeset
  1000
    check_notify_list(m.u.jobid);
5b64d66a8d89 Fixed awaking the wait_job clients on job removal.
viric@llimona
parents: 176
diff changeset
  1001
180
a35159b7009a Finished jobs can also be removed now.
viric@llimona
parents: 178
diff changeset
  1002
    /* Update the list pointers */
a35159b7009a Finished jobs can also be removed now.
viric@llimona
parents: 178
diff changeset
  1003
    if (p == first_finished_job)
a35159b7009a Finished jobs can also be removed now.
viric@llimona
parents: 178
diff changeset
  1004
        first_finished_job = p->next;
a35159b7009a Finished jobs can also be removed now.
viric@llimona
parents: 178
diff changeset
  1005
    else
a35159b7009a Finished jobs can also be removed now.
viric@llimona
parents: 178
diff changeset
  1006
        before_p->next = p->next;
a35159b7009a Finished jobs can also be removed now.
viric@llimona
parents: 178
diff changeset
  1007
259
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 254
diff changeset
  1008
    free(p->notify_errorlevel_to);
64
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
  1009
    free(p->command);
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
  1010
    free(p->output_filename);
146
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 134
diff changeset
  1011
    pinfo_free(&p->info);
150
a615d7971bf6 Added -L (label)
viric@llimona
parents: 148
diff changeset
  1012
    free(p->label);
41
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
  1013
    free(p);
180
a35159b7009a Finished jobs can also be removed now.
viric@llimona
parents: 178
diff changeset
  1014
41
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
  1015
    m.type = REMOVEJOB_OK;
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
  1016
    send_msg(s, &m);
134
5a6b8bb1f7a8 Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents: 120
diff changeset
  1017
    return 1;
41
cad41574feda Added 'remove job'.
viric@llimona
parents: 39
diff changeset
  1018
}
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1019
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1020
static void add_to_notify_list(int s, int jobid)
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1021
{
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1022
    struct Notify *n;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1023
    struct Notify *new;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1024
195
cbe64953fa1f Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents: 190
diff changeset
  1025
    new = (struct Notify *) malloc(sizeof(*new));
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1026
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1027
    new->socket = s;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1028
    new->jobid = jobid;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1029
    new->next = 0;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1030
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1031
    n = first_notify;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1032
    if (n == 0)
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1033
    {
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1034
        first_notify = new;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1035
        return;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1036
    }
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1037
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1038
    while(n->next != 0)
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1039
        n = n->next;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1040
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1041
    n->next = new;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1042
}
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1043
51
aa6e05d77537 '-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents: 49
diff changeset
  1044
static void send_waitjob_ok(int s, int errorlevel)
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1045
{
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1046
    struct msg m;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1047
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1048
    m.type = WAITJOB_OK;
112
303834d55e99 More code on times()
viric@mandarina
parents: 104
diff changeset
  1049
    m.u.result.errorlevel = errorlevel;
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1050
    send_msg(s, &m);
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1051
}
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1052
51
aa6e05d77537 '-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents: 49
diff changeset
  1053
static struct Job *
aa6e05d77537 '-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents: 49
diff changeset
  1054
get_job(int jobid)
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1055
{
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1056
    struct Job *j;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1057
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1058
    j = findjob(jobid);
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1059
    if (j != NULL)
51
aa6e05d77537 '-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents: 49
diff changeset
  1060
        return j;
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1061
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1062
    j = find_finished_job(jobid);
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1063
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1064
    if (j != NULL)
51
aa6e05d77537 '-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents: 49
diff changeset
  1065
        return j;
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1066
51
aa6e05d77537 '-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents: 49
diff changeset
  1067
    return 0;
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1068
}
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1069
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1070
/* Don't complain, if the socket doesn't exist */
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1071
void s_remove_notification(int s)
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1072
{
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1073
    struct Notify *n;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1074
    struct Notify *previous;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1075
    n = first_notify;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1076
    while (n != 0 && n->socket != s)
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1077
        n = n->next;
176
306890eeeffa Fixing a bug on s_remove_job, related to -w and dying with signals
viric@llimona
parents: 166
diff changeset
  1078
    if (n == 0 || n->socket != s)
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1079
        return;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1080
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1081
    /* Remove the notification */
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1082
    previous = first_notify;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1083
    if (n == previous)
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1084
    {
254
41252d5e85f5 Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents: 253
diff changeset
  1085
        first_notify = n->next;
41252d5e85f5 Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents: 253
diff changeset
  1086
        free(n);
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1087
        return;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1088
    }
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1089
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1090
    /* if not the first... */
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1091
    while(previous->next != n)
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1092
        previous = previous->next;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1093
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1094
    previous->next = n->next;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1095
    free(n);
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1096
}
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1097
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1098
/* This is called when a job finishes */
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1099
void check_notify_list(int jobid)
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1100
{
206
7acb031b40b8 Better managing of notifications on job finish.
viric@llimona
parents: 198
diff changeset
  1101
    struct Notify *n, *tmp;
51
aa6e05d77537 '-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents: 49
diff changeset
  1102
    struct Job *j;
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1103
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1104
    n = first_notify;
195
cbe64953fa1f Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents: 190
diff changeset
  1105
    while (n != 0)
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1106
    {
206
7acb031b40b8 Better managing of notifications on job finish.
viric@llimona
parents: 198
diff changeset
  1107
        tmp = n;
7acb031b40b8 Better managing of notifications on job finish.
viric@llimona
parents: 198
diff changeset
  1108
        n = n->next;
7acb031b40b8 Better managing of notifications on job finish.
viric@llimona
parents: 198
diff changeset
  1109
        if (tmp->jobid == jobid)
195
cbe64953fa1f Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents: 190
diff changeset
  1110
        {
cbe64953fa1f Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents: 190
diff changeset
  1111
            j = get_job(jobid);
cbe64953fa1f Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents: 190
diff changeset
  1112
            /* If the job finishes, notify the waiter */
cbe64953fa1f Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents: 190
diff changeset
  1113
            if (j->state == FINISHED || j->state == SKIPPED)
cbe64953fa1f Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents: 190
diff changeset
  1114
            {
209
507bd37ab1d3 Bug resolving a pointer when notifying job_ends.
lbatlle@npdl268.bpo.hp.com
parents: 206
diff changeset
  1115
                send_waitjob_ok(tmp->socket, j->result.errorlevel);
195
cbe64953fa1f Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents: 190
diff changeset
  1116
                /* We want to get the next Nofity* before we remove
cbe64953fa1f Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents: 190
diff changeset
  1117
                 * the actual 'n'. As s_remove_notification() simply
cbe64953fa1f Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents: 190
diff changeset
  1118
                 * removes the element from the linked list, we can
cbe64953fa1f Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents: 190
diff changeset
  1119
                 * safely follow on the list from n->next. */
cbe64953fa1f Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents: 190
diff changeset
  1120
                s_remove_notification(tmp->socket);
cbe64953fa1f Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents: 190
diff changeset
  1121
            }
cbe64953fa1f Bugfix: the -w and -t only worked if there was a *single* ts process waiting.
viric@mandarina
parents: 190
diff changeset
  1122
        }
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1123
    }
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1124
}
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1125
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1126
void s_wait_job(int s, int jobid)
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1127
{
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1128
    struct Job *p = 0;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1129
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1130
    if (jobid == -1)
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1131
    {
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1132
        /* Find the last job added */
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1133
        p = firstjob;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1134
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1135
        if (p != 0)
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1136
            while (p->next != 0)
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1137
                p = p->next;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1138
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1139
        /* Look in finished jobs if needed */
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1140
        if (p == 0)
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1141
        {
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1142
            p = first_finished_job;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1143
            if (p != 0)
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1144
                while (p->next != 0)
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1145
                    p = p->next;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1146
        }
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1147
    }
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1148
    else
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1149
    {
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1150
        p = firstjob;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1151
        while (p != 0 && p->jobid != jobid)
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1152
            p = p->next;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1153
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1154
        /* Look in finished jobs if needed */
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1155
        if (p == 0)
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1156
        {
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1157
            p = first_finished_job;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1158
            while (p != 0 && p->jobid != jobid)
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1159
                p = p->next;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1160
        }
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1161
    }
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1162
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1163
    if (p == 0)
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1164
    {
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1165
        char tmp[50];
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1166
        if (jobid == -1)
44
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
  1167
            sprintf(tmp, "The last job cannot be waited.\n");
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1168
        else
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1169
            sprintf(tmp, "The job %i cannot be waited.\n", jobid);
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1170
        send_list_line(s, tmp);
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1171
        return;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1172
    }
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1173
166
8c19a66b5407 Fixing a bug on wait_job on skipped jobs. Moving vnumber to 0.5
viric@vicerveza
parents: 157
diff changeset
  1174
    if (p->state == FINISHED || p->state == SKIPPED)
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1175
    {
112
303834d55e99 More code on times()
viric@mandarina
parents: 104
diff changeset
  1176
        send_waitjob_ok(s, p->result.errorlevel);
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1177
    }
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1178
    else
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1179
        add_to_notify_list(s, p->jobid);
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
  1180
}
53
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1181
226
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1182
void s_wait_running_job(int s, int jobid)
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1183
{
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1184
    struct Job *p = 0;
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1185
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1186
    /* The job finding algorithm should be similar to that of
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1187
     * s_send_output, because this will be used by "-t" and "-c" */
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1188
    if (jobid == -1)
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1189
    {
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1190
        /* This means that we want the output info of the running task, or that
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1191
         * of the last job run */
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1192
        if (busy_slots > 0)
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1193
        {
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1194
            p = firstjob;
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1195
            if (p == 0)
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1196
                error("Internal state WAITING, but job not run."
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1197
                        "firstjob = %x", firstjob);
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1198
        }
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1199
        else
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1200
        {
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1201
            p = first_finished_job;
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1202
            if (p == 0)
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1203
            {
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1204
                send_list_line(s, "No jobs.\n");
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1205
                return;
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1206
            }
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1207
            while(p->next != 0)
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1208
                p = p->next;
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1209
        }
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1210
    }
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1211
    else
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1212
    {
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1213
        p = firstjob;
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1214
        while (p != 0 && p->jobid != jobid)
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1215
            p = p->next;
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1216
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1217
        /* Look in finished jobs if needed */
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1218
        if (p == 0)
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1219
        {
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1220
            p = first_finished_job;
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1221
            while (p != 0 && p->jobid != jobid)
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1222
                p = p->next;
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1223
        }
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1224
    }
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1225
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1226
    if (p == 0)
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1227
    {
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1228
        char tmp[50];
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1229
        if (jobid == -1)
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1230
            sprintf(tmp, "The last job cannot be waited.\n");
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1231
        else
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1232
            sprintf(tmp, "The job %i cannot be waited.\n", jobid);
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1233
        send_list_line(s, tmp);
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1234
        return;
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1235
    }
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1236
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1237
    if (p->state == FINISHED || p->state == SKIPPED)
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1238
    {
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1239
        send_waitjob_ok(s, p->result.errorlevel);
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1240
    }
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1241
    else
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1242
        add_to_notify_list(s, p->jobid);
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1243
}
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 225
diff changeset
  1244
219
c24a1f5c1715 Adding hot-switchable amount of max_slots.
viric@mandarina
parents: 218
diff changeset
  1245
void s_set_max_slots(int new_max_slots)
c24a1f5c1715 Adding hot-switchable amount of max_slots.
viric@mandarina
parents: 218
diff changeset
  1246
{
c24a1f5c1715 Adding hot-switchable amount of max_slots.
viric@mandarina
parents: 218
diff changeset
  1247
    if (new_max_slots > 0)
c24a1f5c1715 Adding hot-switchable amount of max_slots.
viric@mandarina
parents: 218
diff changeset
  1248
        max_slots = new_max_slots;
c24a1f5c1715 Adding hot-switchable amount of max_slots.
viric@mandarina
parents: 218
diff changeset
  1249
    else
c24a1f5c1715 Adding hot-switchable amount of max_slots.
viric@mandarina
parents: 218
diff changeset
  1250
        warning("Received new_max_slots=%i", new_max_slots);
c24a1f5c1715 Adding hot-switchable amount of max_slots.
viric@mandarina
parents: 218
diff changeset
  1251
}
c24a1f5c1715 Adding hot-switchable amount of max_slots.
viric@mandarina
parents: 218
diff changeset
  1252
253
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 252
diff changeset
  1253
void s_get_max_slots(int s)
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 252
diff changeset
  1254
{
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 252
diff changeset
  1255
    struct msg m;
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 252
diff changeset
  1256
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 252
diff changeset
  1257
    /* Message */
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 252
diff changeset
  1258
    m.type = GET_MAX_SLOTS_OK;
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 252
diff changeset
  1259
    m.u.max_slots = max_slots;
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 252
diff changeset
  1260
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 252
diff changeset
  1261
    send_msg(s, &m);
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 252
diff changeset
  1262
}
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 252
diff changeset
  1263
53
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1264
void s_move_urgent(int s, int jobid)
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1265
{
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1266
    struct Job *p = 0;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1267
    struct Job *tmp1;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1268
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1269
    if (jobid == -1)
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1270
    {
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1271
        /* Find the last job added */
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1272
        p = firstjob;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1273
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1274
        if (p != 0)
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1275
            while (p->next != 0)
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1276
                p = p->next;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1277
    }
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1278
    else
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1279
    {
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1280
        p = firstjob;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1281
        while (p != 0 && p->jobid != jobid)
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1282
            p = p->next;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1283
    }
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1284
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1285
    if (p == 0 || firstjob->next == 0)
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1286
    {
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1287
        char tmp[50];
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1288
        if (jobid == -1)
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1289
            sprintf(tmp, "The last job cannot be urged.\n");
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1290
        else
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1291
            sprintf(tmp, "The job %i cannot be urged.\n", jobid);
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1292
        send_list_line(s, tmp);
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1293
        return;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1294
    }
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1295
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1296
    /* Interchange the pointers */
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1297
    tmp1 = find_previous_job(p);
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1298
    tmp1->next = p->next;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1299
    p->next = firstjob->next;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1300
    firstjob->next = p;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1301
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1302
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1303
    send_urgent_ok(s);
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
  1304
}
63
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1305
66
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1306
void s_swap_jobs(int s, int jobid1, int jobid2)
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1307
{
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1308
    struct Job *p1, *p2;
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1309
    struct Job *prev1, *prev2;
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1310
    struct Job *tmp;
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1311
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1312
    p1 = findjob(jobid1);
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1313
    p2 = findjob(jobid2);
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1314
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1315
    if (p1 == 0 || p2 == 0 || p1 == firstjob || p2 == firstjob)
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1316
    {
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1317
        char prev[60];
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1318
        sprintf(prev, "The jobs %i and %i cannot be swapped.\n", jobid1, jobid2);
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1319
        send_list_line(s, prev);
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1320
        return;
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1321
    }
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1322
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1323
    /* Interchange the pointers */
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1324
    prev1 = find_previous_job(p1);
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1325
    prev2 = find_previous_job(p2);
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1326
    prev1->next = p2;
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1327
    prev2->next = p1;
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1328
    tmp = p1->next;
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1329
    p1->next = p2->next;
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1330
    p2->next = tmp;
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1331
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1332
    send_swap_jobs_ok(s);
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1333
}
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
  1334
63
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1335
static void send_state(int s, enum Jobstate state)
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1336
{
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1337
    struct msg m;
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1338
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1339
    m.type = ANSWER_STATE;
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1340
    m.u.state = state;
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1341
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1342
    send_msg(s, &m);
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1343
}
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1344
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1345
void s_send_state(int s, int jobid)
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1346
{
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1347
    struct Job *p = 0;
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1348
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1349
    if (jobid == -1)
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1350
    {
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1351
        /* Find the last job added */
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1352
        p = firstjob;
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1353
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1354
        if (p != 0)
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1355
            while (p->next != 0)
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1356
                p = p->next;
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1357
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1358
        /* Look in finished jobs if needed */
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1359
        if (p == 0)
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1360
        {
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1361
            p = first_finished_job;
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1362
            if (p != 0)
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1363
                while (p->next != 0)
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1364
                    p = p->next;
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1365
        }
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1366
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1367
    }
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1368
    else
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1369
    {
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1370
        p = get_job(jobid);
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1371
    }
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1372
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1373
    if (p == 0)
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1374
    {
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1375
        char tmp[50];
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1376
        if (jobid == -1)
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1377
            sprintf(tmp, "The last job cannot be stated.\n");
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1378
        else
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1379
            sprintf(tmp, "The job %i cannot be stated.\n", jobid);
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1380
        send_list_line(s, tmp);
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1381
        return;
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1382
    }
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1383
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1384
    /* Interchange the pointers */
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1385
    send_state(s, p->state);
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 55
diff changeset
  1386
}
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1387
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1388
static void dump_job_struct(FILE *out, const struct Job *p)
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1389
{
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1390
    fprintf(out, "  new_job\n");
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1391
    fprintf(out, "    jobid %i\n", p->jobid);
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1392
    fprintf(out, "    command \"%s\"\n", p->command);
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1393
    fprintf(out, "    state %s\n",
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1394
            jstate2string(p->state));
112
303834d55e99 More code on times()
viric@mandarina
parents: 104
diff changeset
  1395
    fprintf(out, "    result.errorlevel %i\n", p->result.errorlevel);
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1396
    fprintf(out, "    output_filename \"%s\"\n",
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1397
            p->output_filename ? p->output_filename : "NULL");
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1398
    fprintf(out, "    store_output %i\n", p->store_output);
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1399
    fprintf(out, "    pid %i\n", p->pid);
252
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 246
diff changeset
  1400
    fprintf(out, "    should_keep_finished %i\n", p->should_keep_finished);
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1401
}
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1402
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1403
void dump_jobs_struct(FILE *out)
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1404
{
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1405
    const struct Job *p;
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1406
104
dc4dd9939238 Fixed error reporting.
viric@llimona
parents: 92
diff changeset
  1407
    fprintf(out, "New_jobs\n");
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1408
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1409
    p = firstjob;
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1410
    while (p != 0)
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1411
    {
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1412
        dump_job_struct(out, p);
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1413
        p = p->next;
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1414
    }
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1415
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1416
    p = first_finished_job;
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1417
    while (p != 0)
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1418
    {
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1419
        dump_job_struct(out, p);
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1420
        p = p->next;
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1421
    }
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
  1422
}
120
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1423
254
41252d5e85f5 Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents: 253
diff changeset
  1424
static void dump_notify_struct(FILE *out, const struct Notify *n)
41252d5e85f5 Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents: 253
diff changeset
  1425
{
41252d5e85f5 Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents: 253
diff changeset
  1426
    fprintf(out, "  notify\n");
41252d5e85f5 Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents: 253
diff changeset
  1427
    fprintf(out, "    jobid %i\n", n->jobid);
41252d5e85f5 Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents: 253
diff changeset
  1428
    fprintf(out, "    socket \"%i\"\n", n->socket);
41252d5e85f5 Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents: 253
diff changeset
  1429
}
41252d5e85f5 Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents: 253
diff changeset
  1430
41252d5e85f5 Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents: 253
diff changeset
  1431
void dump_notifies_struct(FILE *out)
41252d5e85f5 Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents: 253
diff changeset
  1432
{
41252d5e85f5 Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents: 253
diff changeset
  1433
    const struct Notify *n;
41252d5e85f5 Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents: 253
diff changeset
  1434
41252d5e85f5 Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents: 253
diff changeset
  1435
    fprintf(out, "New_notifies\n");
41252d5e85f5 Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents: 253
diff changeset
  1436
41252d5e85f5 Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents: 253
diff changeset
  1437
    n = first_notify;
41252d5e85f5 Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents: 253
diff changeset
  1438
    while (n != 0)
41252d5e85f5 Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents: 253
diff changeset
  1439
    {
41252d5e85f5 Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents: 253
diff changeset
  1440
        dump_notify_struct(out, n);
41252d5e85f5 Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents: 253
diff changeset
  1441
        n = n->next;
41252d5e85f5 Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents: 253
diff changeset
  1442
    }
41252d5e85f5 Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents: 253
diff changeset
  1443
}
41252d5e85f5 Fixed a bug in the notify list, reported by mark meissonnier.
viric@mandarina
parents: 253
diff changeset
  1444
120
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1445
void joblist_dump(int fd)
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1446
{
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1447
    struct Job *p;
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1448
    char *buffer;
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1449
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1450
    buffer = joblistdump_headers();
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1451
    write(fd,buffer, strlen(buffer));
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1452
    free(buffer);
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1453
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1454
    /* We reuse the headers from the list */
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1455
    buffer = joblist_headers();
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1456
    write(fd, "# ", 2);
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1457
    write(fd, buffer, strlen(buffer));
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1458
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1459
    /* Show Finished jobs */
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1460
    p = first_finished_job;
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1461
    while(p != 0)
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1462
    {
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1463
        buffer = joblist_line(p);
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1464
        write(fd, "# ", 2);
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1465
        write(fd,buffer, strlen(buffer));
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1466
        free(buffer);
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1467
        p = p->next;
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1468
    }
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1469
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1470
    write(fd, "\n", 1);
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1471
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1472
    /* Show Queued or Running jobs */
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1473
    p = firstjob;
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1474
    while(p != 0)
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1475
    {
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1476
        buffer = joblistdump_torun(p);
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1477
        write(fd,buffer,strlen(buffer));
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1478
        free(buffer);
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1479
        p = p->next;
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1480
    }
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
  1481
}