client.c
author viric@llimona
Mon, 02 Apr 2007 17:53:52 +0200
changeset 74 bb1b20d79acf
parent 71 531666e297d7
child 92 05004c52ecff
permissions -rw-r--r--
Marking the TODO for 0.3
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
09bb8a5583e9 Added the license.
lbatlle@npdl268.bpo.hp.com
parents: 44
diff changeset
     3
    Copyright (C) 2007  LluĂ­s Batlle i Rossell
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
*/
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
     7
#include <assert.h>
9
9acd8ae3190c First usable version!
lbatlle@npdl268.bpo.hp.com
parents: 8
diff changeset
     8
#include <stdio.h>
44
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
     9
#include <string.h>
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
    10
#include <stdlib.h>
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
    11
#include <sys/types.h>
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
    12
#include <sys/socket.h>
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
    13
#include "msg.h"
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    14
#include "main.h"
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
    15
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
    16
static void c_end_of_job(int errorlevel);
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
    17
71
531666e297d7 Send e-letter implemented.
viric@llimona
parents: 69
diff changeset
    18
char *build_command_string()
68
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    19
{
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    20
    int size;
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    21
    int i;
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    22
    int num;
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    23
    char **array;
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    24
    char *commandstring;
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    25
    
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    26
    size = 0;
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    27
    num = command_line.command.num;
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    28
    array = command_line.command.array;
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    29
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    30
    /* Count bytes needed */
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    31
    for (i = 0; i < num; ++i)
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    32
    {
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    33
        /* The '1' is for spaces, and at the last i,
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    34
         * for the null character */
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    35
        size = size + strlen(array[i]) + 1;
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    36
    }
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    37
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    38
    /* Alloc */
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    39
    commandstring = (char *) malloc(size);
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    40
    assert(commandstring != NULL);
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    41
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    42
    /* Build the command */
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    43
    strcpy(commandstring, array[0]);
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    44
    for (i = 1; i < num; ++i)
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    45
    {
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    46
        strcat(commandstring, " ");
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    47
        strcat(commandstring, array[i]);
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    48
    }
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    49
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    50
    return commandstring;
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    51
}
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    52
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    53
void c_new_job()
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    54
{
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    55
    struct msg m;
68
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    56
    char *new_command;
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    57
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    58
    m.type = NEWJOB;
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    59
68
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    60
    new_command = build_command_string();
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    61
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
    62
    /* global */
68
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    63
    m.u.newjob.command_size = strlen(new_command) + 1; /* add null */
30
ab88478a7e9b The commandline parameters are centered in a struct.
viric@llimona
parents: 27
diff changeset
    64
    m.u.newjob.store_output = command_line.store_output;
55
678ca291d545 Now the '-nf' doesn't leave a job in 'finished' state.
viric@llimona
parents: 53
diff changeset
    65
    m.u.newjob.should_keep_finished = command_line.should_keep_finished;
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    66
18
af4898956964 Now commands of any-length are accepted.
viric@llimona
parents: 11
diff changeset
    67
    /* Send the message */
af4898956964 Now commands of any-length are accepted.
viric@llimona
parents: 11
diff changeset
    68
    send_msg(server_socket, &m);
af4898956964 Now commands of any-length are accepted.
viric@llimona
parents: 11
diff changeset
    69
af4898956964 Now commands of any-length are accepted.
viric@llimona
parents: 11
diff changeset
    70
    /* Send the command */
68
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    71
    send_bytes(server_socket, new_command, m.u.newjob.command_size);
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    72
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    73
    free(new_command);
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    74
}
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    75
62
2b29d4666f6c Return the jobid in stdout.
viric@llimona
parents: 55
diff changeset
    76
int c_wait_newjob_ok()
2b29d4666f6c Return the jobid in stdout.
viric@llimona
parents: 55
diff changeset
    77
{
2b29d4666f6c Return the jobid in stdout.
viric@llimona
parents: 55
diff changeset
    78
    struct msg m;
2b29d4666f6c Return the jobid in stdout.
viric@llimona
parents: 55
diff changeset
    79
    int res;
2b29d4666f6c Return the jobid in stdout.
viric@llimona
parents: 55
diff changeset
    80
2b29d4666f6c Return the jobid in stdout.
viric@llimona
parents: 55
diff changeset
    81
    res = recv_msg(server_socket, &m);
2b29d4666f6c Return the jobid in stdout.
viric@llimona
parents: 55
diff changeset
    82
    if(res == -1)
2b29d4666f6c Return the jobid in stdout.
viric@llimona
parents: 55
diff changeset
    83
    {
2b29d4666f6c Return the jobid in stdout.
viric@llimona
parents: 55
diff changeset
    84
        perror("read");
2b29d4666f6c Return the jobid in stdout.
viric@llimona
parents: 55
diff changeset
    85
        exit(-1);
2b29d4666f6c Return the jobid in stdout.
viric@llimona
parents: 55
diff changeset
    86
    }
2b29d4666f6c Return the jobid in stdout.
viric@llimona
parents: 55
diff changeset
    87
    assert(m.type = NEWJOB_OK);
2b29d4666f6c Return the jobid in stdout.
viric@llimona
parents: 55
diff changeset
    88
2b29d4666f6c Return the jobid in stdout.
viric@llimona
parents: 55
diff changeset
    89
    return m.u.jobid;
2b29d4666f6c Return the jobid in stdout.
viric@llimona
parents: 55
diff changeset
    90
}
2b29d4666f6c Return the jobid in stdout.
viric@llimona
parents: 55
diff changeset
    91
68
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    92
int c_wait_server_commands()
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    93
{
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    94
    struct msg m;
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    95
    int res;
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    96
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    97
    while (1)
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    98
    {
9
9acd8ae3190c First usable version!
lbatlle@npdl268.bpo.hp.com
parents: 8
diff changeset
    99
        res = recv(server_socket, &m, sizeof(m), 0);
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   100
        if(res == -1)
9
9acd8ae3190c First usable version!
lbatlle@npdl268.bpo.hp.com
parents: 8
diff changeset
   101
        {
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   102
            perror("read");
9
9acd8ae3190c First usable version!
lbatlle@npdl268.bpo.hp.com
parents: 8
diff changeset
   103
            exit(-1);
9acd8ae3190c First usable version!
lbatlle@npdl268.bpo.hp.com
parents: 8
diff changeset
   104
        }
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   105
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   106
        if (res == 0)
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   107
            break;
9
9acd8ae3190c First usable version!
lbatlle@npdl268.bpo.hp.com
parents: 8
diff changeset
   108
        if (res != sizeof(m))
9acd8ae3190c First usable version!
lbatlle@npdl268.bpo.hp.com
parents: 8
diff changeset
   109
        {
9acd8ae3190c First usable version!
lbatlle@npdl268.bpo.hp.com
parents: 8
diff changeset
   110
            fprintf(stderr, "c: recv() message size wrong: %i instead of %i\n",
9acd8ae3190c First usable version!
lbatlle@npdl268.bpo.hp.com
parents: 8
diff changeset
   111
                res, (int) sizeof(m));
9acd8ae3190c First usable version!
lbatlle@npdl268.bpo.hp.com
parents: 8
diff changeset
   112
        }
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   113
        assert(res == sizeof(m));
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   114
        if (m.type == RUNJOB)
5
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   115
        {
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   116
            int errorlevel;
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   117
            /* This will send RUNJOB_OK */
68
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
   118
            errorlevel = run_job();
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   119
            c_end_of_job(errorlevel);
38
768d009604b3 The program returns the errorlevel of the job, if it doesn't go to background.
viric@llimona
parents: 35
diff changeset
   120
            return errorlevel;
5
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   121
        }
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   122
    }
38
768d009604b3 The program returns the errorlevel of the job, if it doesn't go to background.
viric@llimona
parents: 35
diff changeset
   123
    return -1;
5
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   124
}
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   125
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   126
void c_wait_server_lines()
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   127
{
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   128
    struct msg m;
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   129
    int res;
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   130
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   131
    while (1)
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   132
    {
21
a797f96a022f Lines for list doesn't have limit.
viric@llimona
parents: 20
diff changeset
   133
        res = recv_msg(server_socket, &m);
5
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   134
        if(res == -1)
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   135
        {
5
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   136
            perror("read");
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   137
            exit(-1);
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   138
        }
5
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   139
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   140
        if (res == 0)
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   141
            break;
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   142
        assert(res == sizeof(m));
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   143
        if (m.type == LIST_LINE)
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   144
        {
21
a797f96a022f Lines for list doesn't have limit.
viric@llimona
parents: 20
diff changeset
   145
            char * buffer;
a797f96a022f Lines for list doesn't have limit.
viric@llimona
parents: 20
diff changeset
   146
            buffer = (char *) malloc(m.u.line_size);
a797f96a022f Lines for list doesn't have limit.
viric@llimona
parents: 20
diff changeset
   147
            recv_bytes(server_socket, buffer, m.u.line_size);
a797f96a022f Lines for list doesn't have limit.
viric@llimona
parents: 20
diff changeset
   148
            printf("%s", buffer);
a797f96a022f Lines for list doesn't have limit.
viric@llimona
parents: 20
diff changeset
   149
            free(buffer);
5
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   150
        }
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   151
    }
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   152
}
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   153
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   154
void c_list_jobs()
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   155
{
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   156
    struct msg m;
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   157
    int res;
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   158
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   159
    m.type = LIST;
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   160
9
9acd8ae3190c First usable version!
lbatlle@npdl268.bpo.hp.com
parents: 8
diff changeset
   161
    res = send(server_socket, &m, sizeof(m), 0);
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   162
    if(res == -1)
9
9acd8ae3190c First usable version!
lbatlle@npdl268.bpo.hp.com
parents: 8
diff changeset
   163
        perror("send");
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   164
}
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   165
35
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   166
void c_send_runjob_ok(const char *ofname, int pid)
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   167
{
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   168
    struct msg m;
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   169
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   170
    /* Prepare the message */
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   171
    m.type = RUNJOB_OK;
32
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   172
    m.u.output.store_output = command_line.store_output;
35
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   173
    m.u.output.pid = pid;
30
ab88478a7e9b The commandline parameters are centered in a struct.
viric@llimona
parents: 27
diff changeset
   174
    if (command_line.store_output)
32
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   175
        m.u.output.ofilename_size = strlen(ofname) + 1;
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   176
    else
32
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   177
        m.u.output.ofilename_size = 0;
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   178
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   179
    send_msg(server_socket, &m);
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   180
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   181
    /* Send the filename */
30
ab88478a7e9b The commandline parameters are centered in a struct.
viric@llimona
parents: 27
diff changeset
   182
    if (command_line.store_output)
32
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   183
        send_bytes(server_socket, ofname, m.u.output.ofilename_size);
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   184
}
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   185
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   186
static void c_end_of_job(int errorlevel)
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   187
{
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   188
    struct msg m;
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   189
    int res;
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   190
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   191
    m.type = ENDJOB;
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   192
    m.u.errorlevel = errorlevel;
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   193
9
9acd8ae3190c First usable version!
lbatlle@npdl268.bpo.hp.com
parents: 8
diff changeset
   194
    res = send(server_socket, &m, sizeof(m),0);
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   195
    if(res == -1)
9
9acd8ae3190c First usable version!
lbatlle@npdl268.bpo.hp.com
parents: 8
diff changeset
   196
        perror("send");
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   197
}
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   198
44
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
   199
void c_shutdown_server()
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   200
{
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   201
    struct msg m;
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   202
31
1a6c732b0b71 The command line parsing has been simplified.
viric@llimona
parents: 30
diff changeset
   203
    m.type = KILL_SERVER;
32
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   204
    send_msg(server_socket, &m);
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   205
}
20
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   206
44
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
   207
void c_clear_finished()
20
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   208
{
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   209
    struct msg m;
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   210
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   211
    m.type = CLEAR_FINISHED;
32
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   212
    send_msg(server_socket, &m);
20
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   213
}
32
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   214
35
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   215
static char * get_output_file(int *pid)
32
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   216
{
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   217
    struct msg m;
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   218
    int res;
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   219
    char *string = 0;
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   220
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   221
    /* Send the request */
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   222
    m.type = ASK_OUTPUT;
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   223
    m.u.jobid = command_line.jobid;
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   224
    send_msg(server_socket, &m);
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   225
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   226
    /* Receive the answer */
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   227
    res = recv_msg(server_socket, &m);
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   228
    assert(res == sizeof(m));
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   229
    switch(m.type)
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   230
    {
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   231
    case ANSWER_OUTPUT:
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   232
        if (m.u.output.store_output)
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   233
        {
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   234
            /* Receive the output file name */
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   235
            string = (char *) malloc(m.u.output.ofilename_size);
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   236
            recv_bytes(server_socket, string, m.u.output.ofilename_size);
35
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   237
            *pid = m.u.output.pid;
33
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   238
            return string;
32
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   239
        }
35
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   240
        *pid = m.u.output.pid;
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   241
        return 0;
32
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   242
        /* WILL NOT GO FURTHER */
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   243
    case LIST_LINE: /* Only ONE line accepted */
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   244
        string = (char *) malloc(m.u.line_size);
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   245
        res = recv_bytes(server_socket, string, m.u.line_size);
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   246
        assert(res == m.u.line_size);
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   247
        fprintf(stderr, "Error in the request: %s", 
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   248
                string);
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   249
        exit(-1);
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   250
        /* WILL NOT GO FURTHER */
44
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
   251
    default:
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
   252
        fprintf(stderr, "Wrong internal message\n");
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
   253
        exit(-1);
32
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   254
    }
33
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   255
    /* This will never be reached */
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   256
    return 0;
32
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   257
}
33
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   258
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   259
void c_tail()
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   260
{
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   261
    char *str;
35
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   262
    int pid;
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   263
    str = get_output_file(&pid);
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   264
    if (str == 0)
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   265
    {
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   266
        fprintf(stderr, "The output is not stored. Cannot tail.\n");
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   267
        exit(-1);
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   268
    }
33
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   269
    c_run_tail(str);
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   270
}
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   271
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   272
void c_cat()
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   273
{
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   274
    char *str;
35
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   275
    int pid;
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   276
    str = get_output_file(&pid);
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   277
    if (str == 0)
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   278
    {
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   279
        fprintf(stderr, "The output is not stored. Cannot tail.\n");
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   280
        exit(-1);
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   281
    }
33
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   282
    c_run_cat(str);
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   283
}
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   284
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   285
void c_show_output_file()
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   286
{
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   287
    char *str;
35
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   288
    int pid;
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   289
    /* This will exit if there is any error */
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   290
    str = get_output_file(&pid);
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   291
    if (str == 0)
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   292
    {
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   293
        fprintf(stderr, "The output is not stored. Cannot tail.\n");
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   294
        exit(-1);
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   295
    }
33
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   296
    printf("%s\n", str);
35
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   297
    free(str);
33
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   298
}
35
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   299
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   300
void c_show_pid()
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   301
{
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   302
    char *str;
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   303
    int pid;
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   304
    /* This will exit if there is any error */
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   305
    str = get_output_file(&pid);
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   306
    printf("%i\n", pid);
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   307
}
41
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   308
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   309
void c_remove_job()
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   310
{
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   311
    struct msg m;
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   312
    int res;
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   313
    char *string = 0;
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   314
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   315
    /* Send the request */
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   316
    m.type = REMOVEJOB;
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   317
    m.u.jobid = command_line.jobid;
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   318
    send_msg(server_socket, &m);
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   319
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   320
    /* Receive the answer */
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   321
    res = recv_msg(server_socket, &m);
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   322
    assert(res == sizeof(m));
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   323
    switch(m.type)
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   324
    {
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   325
    case REMOVEJOB_OK:
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   326
        return;
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   327
        /* WILL NOT GO FURTHER */
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   328
    case LIST_LINE: /* Only ONE line accepted */
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   329
        string = (char *) malloc(m.u.line_size);
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   330
        res = recv_bytes(server_socket, string, m.u.line_size);
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   331
        assert(res == m.u.line_size);
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   332
        fprintf(stderr, "Error in the request: %s", 
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   333
                string);
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   334
        exit(-1);
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   335
        /* WILL NOT GO FURTHER */
44
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
   336
    default:
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
   337
        fprintf(stderr, "Wrong internal message\n");
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
   338
        exit(-1);
41
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   339
    }
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   340
    /* This will never be reached */
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   341
}
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   342
51
aa6e05d77537 '-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents: 49
diff changeset
   343
/* Returns the errorlevel */
aa6e05d77537 '-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents: 49
diff changeset
   344
int c_wait_job()
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   345
{
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   346
    struct msg m;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   347
    int res;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   348
    char *string = 0;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   349
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   350
    /* Send the request */
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   351
    m.type = WAITJOB;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   352
    m.u.jobid = command_line.jobid;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   353
    send_msg(server_socket, &m);
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   354
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   355
    /* Receive the answer */
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   356
    res = recv_msg(server_socket, &m);
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   357
    assert(res == sizeof(m));
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   358
    switch(m.type)
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   359
    {
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   360
    case WAITJOB_OK:
51
aa6e05d77537 '-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents: 49
diff changeset
   361
        return m.u.errorlevel;
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   362
        /* WILL NOT GO FURTHER */
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   363
    case LIST_LINE: /* Only ONE line accepted */
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   364
        string = (char *) malloc(m.u.line_size);
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   365
        res = recv_bytes(server_socket, string, m.u.line_size);
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   366
        assert(res == m.u.line_size);
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   367
        fprintf(stderr, "Error in the request: %s", 
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   368
                string);
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   369
        exit(-1);
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   370
        /* WILL NOT GO FURTHER */
44
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
   371
    default:
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
   372
        fprintf(stderr, "Wrong internal message\n");
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
   373
        exit(-1);
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   374
    }
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   375
    /* This will never be reached */
51
aa6e05d77537 '-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents: 49
diff changeset
   376
    return -1;
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   377
}
53
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   378
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   379
void c_move_urgent()
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   380
{
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   381
    struct msg m;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   382
    int res;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   383
    char *string = 0;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   384
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   385
    /* Send the request */
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   386
    m.type = URGENT;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   387
    m.u.jobid = command_line.jobid;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   388
    send_msg(server_socket, &m);
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   389
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   390
    /* Receive the answer */
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   391
    res = recv_msg(server_socket, &m);
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   392
    assert(res == sizeof(m));
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   393
    switch(m.type)
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   394
    {
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   395
    case URGENT_OK:
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   396
        return;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   397
        /* WILL NOT GO FURTHER */
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   398
    case LIST_LINE: /* Only ONE line accepted */
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   399
        string = (char *) malloc(m.u.line_size);
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   400
        res = recv_bytes(server_socket, string, m.u.line_size);
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   401
        assert(res == m.u.line_size);
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   402
        fprintf(stderr, "Error in the request: %s", 
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   403
                string);
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   404
        exit(-1);
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   405
        /* WILL NOT GO FURTHER */
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   406
    default:
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   407
        fprintf(stderr, "Wrong internal message\n");
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   408
        exit(-1);
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   409
    }
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   410
    /* This will never be reached */
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   411
    return;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   412
}
63
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   413
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   414
void c_get_state()
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   415
{
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   416
    struct msg m;
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   417
    int res;
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   418
    char *string = 0;
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   419
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   420
    /* Send the request */
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   421
    m.type = GET_STATE;
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   422
    m.u.jobid = command_line.jobid;
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   423
    send_msg(server_socket, &m);
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   424
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   425
    /* Receive the answer */
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   426
    res = recv_msg(server_socket, &m);
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   427
    assert(res == sizeof(m));
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   428
    switch(m.type)
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   429
    {
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   430
    case ANSWER_STATE:
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   431
        printf("%s\n", jstate2string(m.u.state));
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   432
        return;
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   433
        /* WILL NOT GO FURTHER */
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   434
    case LIST_LINE: /* Only ONE line accepted */
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   435
        string = (char *) malloc(m.u.line_size);
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   436
        res = recv_bytes(server_socket, string, m.u.line_size);
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   437
        assert(res == m.u.line_size);
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   438
        fprintf(stderr, "Error in the request: %s", 
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   439
                string);
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   440
        exit(-1);
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   441
        /* WILL NOT GO FURTHER */
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   442
    default:
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   443
        fprintf(stderr, "Wrong internal message\n");
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   444
        exit(-1);
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   445
    }
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   446
    /* This will never be reached */
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   447
    return;
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   448
}
66
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   449
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   450
void c_swap_jobs()
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   451
{
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   452
    struct msg m;
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   453
    int res;
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   454
    char *string = 0;
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   455
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   456
    /* Send the request */
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   457
    m.type = SWAP_JOBS;
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   458
    m.u.swap.jobid1 = command_line.jobid;
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   459
    m.u.swap.jobid2 = command_line.jobid2;
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   460
    send_msg(server_socket, &m);
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   461
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   462
    /* Receive the answer */
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   463
    res = recv_msg(server_socket, &m);
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   464
    assert(res == sizeof(m));
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   465
    switch(m.type)
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   466
    {
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   467
    case SWAP_JOBS_OK:
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   468
        return;
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   469
        /* WILL NOT GO FURTHER */
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   470
    case LIST_LINE: /* Only ONE line accepted */
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   471
        string = (char *) malloc(m.u.line_size);
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   472
        res = recv_bytes(server_socket, string, m.u.line_size);
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   473
        assert(res == m.u.line_size);
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   474
        fprintf(stderr, "Error in the request: %s", 
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   475
                string);
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   476
        exit(-1);
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   477
        /* WILL NOT GO FURTHER */
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   478
    default:
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   479
        fprintf(stderr, "Wrong internal message\n");
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   480
        exit(-1);
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   481
    }
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   482
    /* This will never be reached */
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   483
    return;
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   484
}