jobs.c
author viric@llimona
Sun, 25 Mar 2007 04:55:18 +0200
changeset 23 96fcebb68510
parent 22 afdc8410633f
child 26 19d1bfdaa885
permissions -rw-r--r--
More TODO for the next versions.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
     1
#include <stdlib.h>
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
     2
#include <stdio.h>
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
     3
#include <assert.h>
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
     4
#include "msg.h"
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
     5
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
     6
static enum
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
     7
{
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
     8
    FREE, /* No task is running */
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
     9
    WAITING /* A task is running, and the server is waiting */
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
    10
} state = FREE;
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
    11
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
    12
struct Job
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
    13
{
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
    14
    int jobid;
18
af4898956964 Now commands of any-length are accepted.
viric@llimona
parents: 9
diff changeset
    15
    char *command;
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
    16
    enum Jobstate state;
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    17
    int errorlevel;
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
    18
    struct Job *next;
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
    19
    char *output_filename;
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
    20
};
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
    21
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
    22
/* Globals */
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
    23
static struct Job *firstjob = 0;
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    24
static struct Job *first_finished_job = 0;
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
    25
static jobids = 0;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
    26
5
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 3
diff changeset
    27
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
    28
{
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 3
diff changeset
    29
    struct msg m;
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 3
diff changeset
    30
    int res;
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 3
diff changeset
    31
21
a797f96a022f Lines for list doesn't have limit.
viric@llimona
parents: 20
diff changeset
    32
    /* Message */
5
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 3
diff changeset
    33
    m.type = LIST_LINE;
21
a797f96a022f Lines for list doesn't have limit.
viric@llimona
parents: 20
diff changeset
    34
    m.u.line_size = strlen(str) + 1;
5
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 3
diff changeset
    35
21
a797f96a022f Lines for list doesn't have limit.
viric@llimona
parents: 20
diff changeset
    36
    send_msg(s, &m);
a797f96a022f Lines for list doesn't have limit.
viric@llimona
parents: 20
diff changeset
    37
a797f96a022f Lines for list doesn't have limit.
viric@llimona
parents: 20
diff changeset
    38
    /* Send the line */
a797f96a022f Lines for list doesn't have limit.
viric@llimona
parents: 20
diff changeset
    39
    send_bytes(s, str, m.u.line_size);
5
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 3
diff changeset
    40
}
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 3
diff changeset
    41
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
    42
static struct Job * findjob(int jobid)
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
    43
{
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
    44
    struct Job *p;
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
    45
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
    46
    /* Show Queued or Running jobs */
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
    47
    p = firstjob;
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
    48
    while(p != 0)
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
    49
    {
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
    50
        if (p->jobid == jobid)
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
    51
            return p;
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
    52
        p = p->next;
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
    53
    }
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
    54
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
    55
    return 0;
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
    56
}
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
    57
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    58
void s_mark_job_running()
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    59
{
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    60
    firstjob->state = RUNNING;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    61
}
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    62
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    63
static const char * jstate2string(enum Jobstate s)
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    64
{
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    65
    char * jobstate;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    66
    switch(s)
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    67
    {
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    68
        case QUEUED:
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    69
            jobstate = "queued";
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    70
            break;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    71
        case RUNNING:
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    72
            jobstate = "running";
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    73
            break;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    74
        case FINISHED:
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    75
            jobstate = "finished";
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    76
            break;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    77
    }
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    78
    return jobstate;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    79
}
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    80
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
    81
void s_list(int s)
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
    82
{
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
    83
    int i;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
    84
    struct Job *p;
5
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 3
diff changeset
    85
    char buffer[LINE_LEN];
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
    86
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
    87
    sprintf(buffer, " ID\tState\tOutput\tCommand\n");
5
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 3
diff changeset
    88
    send_list_line(s,buffer);
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
    89
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    90
    /* Show Queued or Running jobs */
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
    91
    p = firstjob;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
    92
    while(p != 0)
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
    93
    {
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    94
        const char * jobstate;
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
    95
        const char * output_filename;
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    96
        jobstate = jstate2string(p->state);
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
    97
        if (p->output_filename == 0)
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
    98
            output_filename = "stdout";
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
    99
        else
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   100
            output_filename = p->output_filename;
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   101
        sprintf(buffer, "%i\t%s\t%s\t%s\n",
5
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 3
diff changeset
   102
                p->jobid,
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   103
                jobstate,
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   104
                output_filename,
5
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 3
diff changeset
   105
                p->command);
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 3
diff changeset
   106
        send_list_line(s,buffer);
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   107
        p = p->next;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   108
    }
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   109
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   110
    p = first_finished_job;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   111
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   112
    if (p != 0)
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   113
    {
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   114
        sprintf(buffer, "Finsihed jobs:\n");
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   115
        send_list_line(s,buffer);
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   116
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   117
        sprintf(buffer, " ID\tState\tOutput\tE-level\tCommand\n");
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   118
        send_list_line(s,buffer);
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   119
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   120
        /* Show Finished jobs */
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   121
        while(p != 0)
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   122
        {
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   123
            const char * jobstate;
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   124
            const char * output_filename;
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   125
            jobstate = jstate2string(p->state);
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   126
            if (p->output_filename == 0)
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   127
                output_filename = "stdout";
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   128
            else
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   129
                output_filename = p->output_filename;
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   130
            sprintf(buffer, "%i\t%s\t%s\t%i\t%s\n",
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   131
                    p->jobid,
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   132
                    jobstate,
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   133
                    output_filename,
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   134
                    p->errorlevel,
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   135
                    p->command);
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   136
            send_list_line(s,buffer);
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   137
            p = p->next;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   138
        }
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   139
    }
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   140
}
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   141
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   142
static struct Job * newjobptr()
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   143
{
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   144
    struct Job *p;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   145
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   146
    if (firstjob == 0)
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   147
    {
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   148
        firstjob = (struct Job *) malloc(sizeof(*firstjob));
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   149
        firstjob->next = 0;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   150
        return firstjob;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   151
    }
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   152
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   153
    p = firstjob;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   154
    while(p->next != 0)
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   155
        p = p->next;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   156
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   157
    p->next = (struct Job *) malloc(sizeof(*p));
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   158
    p->next->next = 0;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   159
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   160
    return p->next;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   161
}
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   162
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   163
/* Returns job id */
18
af4898956964 Now commands of any-length are accepted.
viric@llimona
parents: 9
diff changeset
   164
int s_newjob(int s, struct msg *m)
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   165
{
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   166
    struct Job *p;
18
af4898956964 Now commands of any-length are accepted.
viric@llimona
parents: 9
diff changeset
   167
    int res;
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   168
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   169
    p = newjobptr();
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   170
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   171
    p->jobid = jobids++;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   172
    p->state = QUEUED;
18
af4898956964 Now commands of any-length are accepted.
viric@llimona
parents: 9
diff changeset
   173
af4898956964 Now commands of any-length are accepted.
viric@llimona
parents: 9
diff changeset
   174
    /* load the command */
af4898956964 Now commands of any-length are accepted.
viric@llimona
parents: 9
diff changeset
   175
    p->command = malloc(m->u.newjob.command_size);
af4898956964 Now commands of any-length are accepted.
viric@llimona
parents: 9
diff changeset
   176
    /* !!! Check retval */
af4898956964 Now commands of any-length are accepted.
viric@llimona
parents: 9
diff changeset
   177
    res = recv_bytes(s, p->command, m->u.newjob.command_size);
af4898956964 Now commands of any-length are accepted.
viric@llimona
parents: 9
diff changeset
   178
    assert(res != -1);
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   179
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   180
    return p->jobid;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   181
}
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   182
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   183
void s_removejob(int jobid)
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   184
{
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   185
    struct Job *p;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   186
    struct Job *newnext;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   187
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   188
    if (firstjob->jobid == jobid)
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   189
    {
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   190
        struct Job *newfirst;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   191
        /* First job is to be removed */
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   192
        newfirst = firstjob->next;
18
af4898956964 Now commands of any-length are accepted.
viric@llimona
parents: 9
diff changeset
   193
        free(firstjob->command);
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   194
        free(firstjob);
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   195
        firstjob = newfirst;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   196
        return;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   197
    }
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   198
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   199
    p = firstjob;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   200
    /* Not first job */
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   201
    while (p->next != 0)
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   202
    {
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   203
        if (p->next->jobid == jobid)
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   204
            break;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   205
        p = p->next;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   206
    }
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   207
    assert(p->next != 0);
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   208
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   209
    newnext = p->next->next;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   210
18
af4898956964 Now commands of any-length are accepted.
viric@llimona
parents: 9
diff changeset
   211
    free(p->next->command);
3
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   212
    free(p->next);
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   213
    p->next = newnext;
2fb8a6bdd024 More code.
viric@llimona
parents:
diff changeset
   214
}
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   215
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   216
/* -1 if no one should be run. */
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   217
int next_run_job()
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   218
{
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   219
    if (state == WAITING)
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   220
        return -1;
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   221
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   222
    if (firstjob != 0)
9
9acd8ae3190c First usable version!
lbatlle@npdl268.bpo.hp.com
parents: 8
diff changeset
   223
    {
9acd8ae3190c First usable version!
lbatlle@npdl268.bpo.hp.com
parents: 8
diff changeset
   224
        state = WAITING;
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   225
        return firstjob->jobid;
9
9acd8ae3190c First usable version!
lbatlle@npdl268.bpo.hp.com
parents: 8
diff changeset
   226
    }
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   227
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   228
    return -1;
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   229
}
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   230
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   231
/* Add the job to the finished queue. */
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   232
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
   233
{
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   234
    struct Job *p;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   235
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   236
    if (first_finished_job == 0)
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   237
    {
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   238
        first_finished_job = j;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   239
        first_finished_job->next = 0;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   240
        return;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   241
    }
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   242
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   243
    p = first_finished_job;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   244
    while(p->next != 0)
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   245
        p = p->next;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   246
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   247
    p->next = j;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   248
    p->next->next = 0;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   249
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   250
    return;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   251
}
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   252
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   253
void job_finished(int errorlevel)
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   254
{
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   255
    struct Job *newfirst;
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   256
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   257
    assert(state == WAITING);
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   258
    assert(firstjob != 0);
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   259
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   260
    assert(firstjob->state == RUNNING);
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   261
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   262
    /* Mark state */
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   263
    firstjob->state = FINISHED;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   264
    firstjob->errorlevel = errorlevel;
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   265
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   266
    /* Add it to the finished queue */
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   267
    new_finished_job(firstjob);
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   268
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   269
    /* Remove it from the run queue */
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   270
    firstjob = firstjob->next;
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   271
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   272
    state = FREE;
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   273
}
20
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   274
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   275
void s_clear_finished()
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   276
{
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   277
    struct Job *p;
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   278
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   279
    if (first_finished_job == 0)
20
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   280
        return;
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   281
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   282
    p = first_finished_job;
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   283
    first_finished_job = 0;
20
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   284
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   285
    while (p->next != 0)
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   286
    {
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   287
        struct Job *tmp;
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   288
        tmp = p->next;
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   289
        free(p->command);
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   290
        free(p->output_filename);
20
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   291
        free(p);
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   292
        p = tmp;
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   293
    }
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   294
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   295
    free(p->next);
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   296
}
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   297
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   298
void s_process_runjob_ok(int jobid, char *oname)
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   299
{
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   300
    struct Job *p;
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   301
    p = findjob(jobid);
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   302
    assert(p != 0);
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   303
    assert(p->state == RUNNING);
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   304
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   305
    p->output_filename = oname;
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   306
}