client.c
author viric <viriketo@gmail.com>
Sat, 19 Nov 2011 10:11:48 +0100
changeset 309 de0a7720dbc2
parent 295 a63f43a17fd7
child 315 2b3ed8fdfb12
permissions -rw-r--r--
Updating the man page, for 0.7.2, describing the new option -E. (Reminded by Jan Šmydke)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49
09bb8a5583e9 Added the license.
lbatlle@npdl268.bpo.hp.com
parents: 44
diff changeset
     1
/*
09bb8a5583e9 Added the license.
lbatlle@npdl268.bpo.hp.com
parents: 44
diff changeset
     2
    Task Spooler - a task queue system for the unix user
267
11631dd11ff8 Updating copyright years in the source.
viric@mandarina
parents: 265
diff changeset
     3
    Copyright (C) 2007-2009  Lluís Batlle i Rossell
49
09bb8a5583e9 Added the license.
lbatlle@npdl268.bpo.hp.com
parents: 44
diff changeset
     4
09bb8a5583e9 Added the license.
lbatlle@npdl268.bpo.hp.com
parents: 44
diff changeset
     5
    Please find the license in the provided COPYING file.
09bb8a5583e9 Added the license.
lbatlle@npdl268.bpo.hp.com
parents: 44
diff changeset
     6
*/
9
9acd8ae3190c First usable version!
lbatlle@npdl268.bpo.hp.com
parents: 8
diff changeset
     7
#include <stdio.h>
44
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
     8
#include <string.h>
147
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
     9
#include <unistd.h>
44
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>
146
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
    13
#include <sys/time.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
110
2726c92a5cb3 Half-code for 'times'
viric@mandarina
parents: 92
diff changeset
    16
static void c_end_of_job(const struct Result *res);
226
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 219
diff changeset
    17
static void c_wait_job_send();
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 219
diff changeset
    18
static void c_wait_running_job_send();
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
    19
71
531666e297d7 Send e-letter implemented.
viric@llimona
parents: 69
diff changeset
    20
char *build_command_string()
68
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    21
{
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    22
    int size;
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    23
    int i;
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    24
    int num;
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    25
    char **array;
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    26
    char *commandstring;
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    27
    
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    28
    size = 0;
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    29
    num = command_line.command.num;
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    30
    array = command_line.command.array;
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    31
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    32
    /* Count bytes needed */
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    33
    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
    34
    {
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    35
        /* 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
    36
         * for the null character */
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    37
        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
    38
    }
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    39
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    40
    /* Alloc */
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    41
    commandstring = (char *) malloc(size);
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
    42
    if(commandstring == NULL)
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
    43
        error("Error in malloc for commandstring");
68
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    44
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    45
    /* Build the command */
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    46
    strcpy(commandstring, array[0]);
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    47
    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
    48
    {
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    49
        strcat(commandstring, " ");
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    50
        strcat(commandstring, array[i]);
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
    return commandstring;
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    54
}
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    55
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    56
void c_new_job()
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    57
{
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    58
    struct msg m;
68
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    59
    char *new_command;
147
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
    60
    char *myenv;
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    61
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    62
    m.type = NEWJOB;
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    63
68
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    64
    new_command = build_command_string();
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    65
147
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
    66
    myenv = get_environment();
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
    67
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
    68
    /* global */
68
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    69
    m.u.newjob.command_size = strlen(new_command) + 1; /* add null */
147
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
    70
    if (myenv)
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
    71
        m.u.newjob.env_size = strlen(myenv) + 1; /* add null */
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
    72
    else
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
    73
        m.u.newjob.env_size = 0;
150
a615d7971bf6 Added -L (label)
viric@llimona
parents: 147
diff changeset
    74
    if (command_line.label)
a615d7971bf6 Added -L (label)
viric@llimona
parents: 147
diff changeset
    75
        m.u.newjob.label_size = strlen(command_line.label) + 1; /* add null */
a615d7971bf6 Added -L (label)
viric@llimona
parents: 147
diff changeset
    76
    else
a615d7971bf6 Added -L (label)
viric@llimona
parents: 147
diff changeset
    77
        m.u.newjob.label_size = 0;
30
ab88478a7e9b The commandline parameters are centered in a struct.
viric@llimona
parents: 27
diff changeset
    78
    m.u.newjob.store_output = command_line.store_output;
259
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 253
diff changeset
    79
    m.u.newjob.do_depend = command_line.do_depend;
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 253
diff changeset
    80
    m.u.newjob.depend_on = command_line.depend_on;
55
678ca291d545 Now the '-nf' doesn't leave a job in 'finished' state.
viric@llimona
parents: 53
diff changeset
    81
    m.u.newjob.should_keep_finished = command_line.should_keep_finished;
147
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
    82
    m.u.newjob.command_size = strlen(new_command) + 1; /* add null */
295
a63f43a17fd7 Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents: 282
diff changeset
    83
    m.u.newjob.wait_enqueuing = command_line.wait_enqueuing;
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    84
18
af4898956964 Now commands of any-length are accepted.
viric@llimona
parents: 11
diff changeset
    85
    /* Send the message */
af4898956964 Now commands of any-length are accepted.
viric@llimona
parents: 11
diff changeset
    86
    send_msg(server_socket, &m);
af4898956964 Now commands of any-length are accepted.
viric@llimona
parents: 11
diff changeset
    87
af4898956964 Now commands of any-length are accepted.
viric@llimona
parents: 11
diff changeset
    88
    /* Send the command */
68
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    89
    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
    90
150
a615d7971bf6 Added -L (label)
viric@llimona
parents: 147
diff changeset
    91
    /* Send the label */
a615d7971bf6 Added -L (label)
viric@llimona
parents: 147
diff changeset
    92
    send_bytes(server_socket, command_line.label, m.u.newjob.label_size);
a615d7971bf6 Added -L (label)
viric@llimona
parents: 147
diff changeset
    93
147
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
    94
    /* Send the environment */
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
    95
    send_bytes(server_socket, myenv, m.u.newjob.env_size);
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
    96
68
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
    97
    free(new_command);
147
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
    98
    free(myenv);
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    99
}
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   100
62
2b29d4666f6c Return the jobid in stdout.
viric@llimona
parents: 55
diff changeset
   101
int c_wait_newjob_ok()
2b29d4666f6c Return the jobid in stdout.
viric@llimona
parents: 55
diff changeset
   102
{
2b29d4666f6c Return the jobid in stdout.
viric@llimona
parents: 55
diff changeset
   103
    struct msg m;
2b29d4666f6c Return the jobid in stdout.
viric@llimona
parents: 55
diff changeset
   104
    int res;
2b29d4666f6c Return the jobid in stdout.
viric@llimona
parents: 55
diff changeset
   105
2b29d4666f6c Return the jobid in stdout.
viric@llimona
parents: 55
diff changeset
   106
    res = recv_msg(server_socket, &m);
2b29d4666f6c Return the jobid in stdout.
viric@llimona
parents: 55
diff changeset
   107
    if(res == -1)
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   108
        error("Error in wait_newjob_ok");
295
a63f43a17fd7 Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents: 282
diff changeset
   109
    if(m.type == NEWJOB_NOK)
a63f43a17fd7 Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents: 282
diff changeset
   110
    {
a63f43a17fd7 Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents: 282
diff changeset
   111
        fprintf(stderr, "Error, queue full\n");
a63f43a17fd7 Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents: 282
diff changeset
   112
        exit(EXITCODE_QUEUE_FULL);
a63f43a17fd7 Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents: 282
diff changeset
   113
    }
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   114
    if(m.type != NEWJOB_OK)
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   115
        error("Error getting the newjob_ok");
62
2b29d4666f6c Return the jobid in stdout.
viric@llimona
parents: 55
diff changeset
   116
2b29d4666f6c Return the jobid in stdout.
viric@llimona
parents: 55
diff changeset
   117
    return m.u.jobid;
2b29d4666f6c Return the jobid in stdout.
viric@llimona
parents: 55
diff changeset
   118
}
2b29d4666f6c Return the jobid in stdout.
viric@llimona
parents: 55
diff changeset
   119
68
3ae9b38d7d30 Now the orders don't run under 'bash'. They run as is.
viric@llimona
parents: 63
diff changeset
   120
int c_wait_server_commands()
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   121
{
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   122
    struct msg m;
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   123
    int res;
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   124
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   125
    while (1)
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   126
    {
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   127
        res = recv_msg(server_socket, &m);
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   128
        if(res == -1)
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   129
            error("Error in wait_server_commands");
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   130
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   131
        if (res == 0)
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   132
            break;
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   133
        if(res != sizeof(m))
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   134
            error("Error in wait_server_commands");
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   135
        if (m.type == RUNJOB)
5
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   136
        {
110
2726c92a5cb3 Half-code for 'times'
viric@mandarina
parents: 92
diff changeset
   137
            struct Result res;
156
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
   138
            res.skipped = 0;
155
55515f9eac77 Added 'depend' -d
viric@vicerveza
parents: 153
diff changeset
   139
            /* These will send RUNJOB_OK */
259
ba3827aa8f25 Adding -D. Forward to 0.6.3.
viric@mandarina
parents: 253
diff changeset
   140
            if (command_line.do_depend && m.u.last_errorlevel != 0)
156
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
   141
            {
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
   142
                res.errorlevel = -1;
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
   143
                res.user_ms = 0.;
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
   144
                res.system_ms = 0.;
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
   145
                res.real_ms = 0.;
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
   146
                res.skipped = 1;
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
   147
                c_send_runjob_ok(0, -1);
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
   148
            }
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
   149
            else
9ac3bd570159 Improved -d (depend) information.
viric@mandarina
parents: 155
diff changeset
   150
                run_job(&res);
110
2726c92a5cb3 Half-code for 'times'
viric@mandarina
parents: 92
diff changeset
   151
            c_end_of_job(&res);
2726c92a5cb3 Half-code for 'times'
viric@mandarina
parents: 92
diff changeset
   152
            return res.errorlevel;
5
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   153
        }
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   154
    }
38
768d009604b3 The program returns the errorlevel of the job, if it doesn't go to background.
viric@llimona
parents: 35
diff changeset
   155
    return -1;
5
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   156
}
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   157
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   158
void c_wait_server_lines()
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   159
{
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   160
    struct msg m;
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   161
    int res;
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   162
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   163
    while (1)
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   164
    {
21
a797f96a022f Lines for list doesn't have limit.
viric@llimona
parents: 20
diff changeset
   165
        res = recv_msg(server_socket, &m);
5
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   166
        if(res == -1)
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   167
            error("Error in wait_server_lines");
5
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   168
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   169
        if (res == 0)
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   170
            break;
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   171
        if(res != sizeof(m))
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   172
            error("Error in wait_server_lines 2");
5
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   173
        if (m.type == LIST_LINE)
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   174
        {
21
a797f96a022f Lines for list doesn't have limit.
viric@llimona
parents: 20
diff changeset
   175
            char * buffer;
146
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   176
            buffer = (char *) malloc(m.u.size);
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   177
            recv_bytes(server_socket, buffer, m.u.size);
21
a797f96a022f Lines for list doesn't have limit.
viric@llimona
parents: 20
diff changeset
   178
            printf("%s", buffer);
a797f96a022f Lines for list doesn't have limit.
viric@llimona
parents: 20
diff changeset
   179
            free(buffer);
5
bc5e251418f3 The LIST_LINEs are outputed by the client.
viric@llimona
parents: 4
diff changeset
   180
        }
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   181
    }
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   182
}
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   183
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   184
void c_list_jobs()
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   185
{
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   186
    struct msg m;
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   187
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   188
    m.type = LIST;
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   189
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   190
    send_msg(server_socket, &m);
260
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 259
diff changeset
   191
}
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 259
diff changeset
   192
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 259
diff changeset
   193
/* Exits if wrong */
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 259
diff changeset
   194
void c_check_version()
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 259
diff changeset
   195
{
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 259
diff changeset
   196
    struct msg m;
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 259
diff changeset
   197
    int res;
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 259
diff changeset
   198
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 259
diff changeset
   199
    m.type = GET_VERSION;
282
835551fcecb7 Improving the detection of ts version, without timeout. This way TS_MAXCONN helps.
viric@mandarina
parents: 276
diff changeset
   200
    /* Double send, so an old ts will answer for sure at least once */
835551fcecb7 Improving the detection of ts version, without timeout. This way TS_MAXCONN helps.
viric@mandarina
parents: 276
diff changeset
   201
    send_msg(server_socket, &m);
260
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 259
diff changeset
   202
    send_msg(server_socket, &m);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 259
diff changeset
   203
265
8c16cd53f772 Making the check_version coep well with old ts servers.
viric@mandarina
parents: 260
diff changeset
   204
    /* Set up a 2 second timeout to receive the
8c16cd53f772 Making the check_version coep well with old ts servers.
viric@mandarina
parents: 260
diff changeset
   205
    version msg. */
8c16cd53f772 Making the check_version coep well with old ts servers.
viric@mandarina
parents: 260
diff changeset
   206
260
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 259
diff changeset
   207
    res = recv_msg(server_socket, &m);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 259
diff changeset
   208
    if (m.type != VERSION || m.u.version != PROTOCOL_VERSION)
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 259
diff changeset
   209
    {
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 259
diff changeset
   210
        printf("Wrong server version. Received %i, expecting %i\n",
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 259
diff changeset
   211
            m.u.version, PROTOCOL_VERSION);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 259
diff changeset
   212
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 259
diff changeset
   213
        error("Wrong server version. Received %i, expecting %i",
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 259
diff changeset
   214
            m.u.version, PROTOCOL_VERSION);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 259
diff changeset
   215
    }
282
835551fcecb7 Improving the detection of ts version, without timeout. This way TS_MAXCONN helps.
viric@mandarina
parents: 276
diff changeset
   216
835551fcecb7 Improving the detection of ts version, without timeout. This way TS_MAXCONN helps.
viric@mandarina
parents: 276
diff changeset
   217
    /* Receive also the 2nd send_msg if we got the right version */
835551fcecb7 Improving the detection of ts version, without timeout. This way TS_MAXCONN helps.
viric@mandarina
parents: 276
diff changeset
   218
    res = recv_msg(server_socket, &m);
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   219
}
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   220
146
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   221
void c_show_info()
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   222
{
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   223
    struct msg m;
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   224
    int res;
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   225
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   226
    m.type = INFO;
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   227
    m.u.jobid = command_line.jobid;
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   228
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   229
    send_msg(server_socket, &m);
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   230
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   231
    while (1)
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   232
    {
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   233
        res = recv_msg(server_socket, &m);
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   234
        if(res == -1)
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   235
            error("Error in wait_server_lines");
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   236
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   237
        if (res == 0)
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   238
            break;
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   239
        if(res != sizeof(m))
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   240
            error("Error in wait_server_lines 2");
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   241
        if (m.type == INFO_DATA)
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   242
        {
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   243
            char * buffer;
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   244
            enum { DSIZE = 1000 };
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   245
147
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
   246
            /* We're going to output data using the stdout fd */
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
   247
            fflush(stdout);
146
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   248
            buffer = (char *) malloc(DSIZE);
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   249
            do
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   250
            {
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   251
                res = recv(server_socket, buffer, DSIZE, 0);
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   252
                if (res > 0)
147
e173645f5221 Added environment info through TS_ENV
viric@llimona
parents: 146
diff changeset
   253
                    write(1, buffer, res);
146
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   254
            } while(res > 0);
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   255
            free(buffer);
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   256
        }
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   257
    }
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   258
}
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   259
35
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   260
void c_send_runjob_ok(const char *ofname, int pid)
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   261
{
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   262
    struct msg m;
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   263
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   264
    /* Prepare the message */
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   265
    m.type = RUNJOB_OK;
155
55515f9eac77 Added 'depend' -d
viric@vicerveza
parents: 153
diff changeset
   266
    if (ofname) /* ofname == 0, skipped execution */
55515f9eac77 Added 'depend' -d
viric@vicerveza
parents: 153
diff changeset
   267
	m.u.output.store_output = command_line.store_output;
55515f9eac77 Added 'depend' -d
viric@vicerveza
parents: 153
diff changeset
   268
    else
55515f9eac77 Added 'depend' -d
viric@vicerveza
parents: 153
diff changeset
   269
	m.u.output.store_output = 0;
35
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   270
    m.u.output.pid = pid;
155
55515f9eac77 Added 'depend' -d
viric@vicerveza
parents: 153
diff changeset
   271
    if (m.u.output.store_output)
32
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   272
        m.u.output.ofilename_size = strlen(ofname) + 1;
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   273
    else
32
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   274
        m.u.output.ofilename_size = 0;
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   275
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   276
    send_msg(server_socket, &m);
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   277
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 21
diff changeset
   278
    /* Send the filename */
30
ab88478a7e9b The commandline parameters are centered in a struct.
viric@llimona
parents: 27
diff changeset
   279
    if (command_line.store_output)
32
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   280
        send_bytes(server_socket, ofname, m.u.output.ofilename_size);
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
110
2726c92a5cb3 Half-code for 'times'
viric@mandarina
parents: 92
diff changeset
   283
static void c_end_of_job(const struct Result *res)
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   284
{
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   285
    struct msg m;
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   286
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   287
    m.type = ENDJOB;
110
2726c92a5cb3 Half-code for 'times'
viric@mandarina
parents: 92
diff changeset
   288
    m.u.result = *res; /* struct copy */
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   289
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   290
    send_msg(server_socket, &m);
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   291
}
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   292
44
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
   293
void c_shutdown_server()
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   294
{
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   295
    struct msg m;
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   296
31
1a6c732b0b71 The command line parsing has been simplified.
viric@llimona
parents: 30
diff changeset
   297
    m.type = KILL_SERVER;
32
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   298
    send_msg(server_socket, &m);
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   299
}
20
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   300
44
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
   301
void c_clear_finished()
20
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   302
{
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   303
    struct msg m;
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   304
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   305
    m.type = CLEAR_FINISHED;
32
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   306
    send_msg(server_socket, &m);
20
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   307
}
32
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   308
35
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   309
static char * get_output_file(int *pid)
32
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   310
{
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   311
    struct msg m;
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   312
    int res;
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   313
    char *string = 0;
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   314
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   315
    /* Send the request */
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   316
    m.type = ASK_OUTPUT;
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   317
    m.u.jobid = command_line.jobid;
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   318
    send_msg(server_socket, &m);
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   319
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   320
    /* Receive the answer */
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   321
    res = recv_msg(server_socket, &m);
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   322
    if(res != sizeof(m))
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   323
        error("Error in get_output_file");
32
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   324
    switch(m.type)
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   325
    {
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   326
    case ANSWER_OUTPUT:
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   327
        if (m.u.output.store_output)
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   328
        {
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   329
            /* Receive the output file name */
146
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   330
            string = 0;
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   331
            if (m.u.output.ofilename_size > 0)
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   332
            {
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   333
                string = (char *) malloc(m.u.output.ofilename_size);
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   334
                recv_bytes(server_socket, string, m.u.output.ofilename_size);
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   335
            }
35
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   336
            *pid = m.u.output.pid;
33
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   337
            return string;
32
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   338
        }
35
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   339
        *pid = m.u.output.pid;
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   340
        return 0;
32
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   341
        /* WILL NOT GO FURTHER */
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   342
    case LIST_LINE: /* Only ONE line accepted */
146
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   343
        string = (char *) malloc(m.u.size);
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   344
        res = recv_bytes(server_socket, string, m.u.size);
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   345
        if(res != m.u.size)
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   346
            error("Error in get_output_file line size");
32
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   347
        fprintf(stderr, "Error in the request: %s", 
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   348
                string);
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   349
        exit(-1);
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   350
        /* WILL NOT GO FURTHER */
44
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
   351
    default:
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   352
        warning("Wrong internal message in get_output_file line size");
32
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   353
    }
33
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   354
    /* This will never be reached */
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   355
    return 0;
32
3531439f2770 Tail works.
viric@llimona
parents: 31
diff changeset
   356
}
33
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   357
174
c112f67965fb Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents: 156
diff changeset
   358
int c_tail()
33
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   359
{
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   360
    char *str;
35
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   361
    int pid;
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   362
    str = get_output_file(&pid);
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   363
    if (str == 0)
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   364
    {
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   365
        fprintf(stderr, "The output is not stored. Cannot tail.\n");
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   366
        exit(-1);
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   367
    }
174
c112f67965fb Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents: 156
diff changeset
   368
226
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 219
diff changeset
   369
    c_wait_running_job_send();
174
c112f67965fb Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents: 156
diff changeset
   370
203
664044b1de73 Making '-c' to behave as 'tail -f', but showing *all* the file.
lbatlle@npdl268.bpo.hp.com
parents: 180
diff changeset
   371
    return tail_file(str, 10 /* Last lines to show */);
33
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   372
}
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   373
203
664044b1de73 Making '-c' to behave as 'tail -f', but showing *all* the file.
lbatlle@npdl268.bpo.hp.com
parents: 180
diff changeset
   374
int c_cat()
33
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   375
{
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   376
    char *str;
35
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   377
    int pid;
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   378
    str = get_output_file(&pid);
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   379
    if (str == 0)
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   380
    {
153
3cc22be1ab95 Fixed a bug with -n and -p.
viric@llimona
parents: 150
diff changeset
   381
        fprintf(stderr, "The output is not stored. Cannot cat.\n");
35
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   382
        exit(-1);
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   383
    }
226
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 219
diff changeset
   384
    c_wait_running_job_send();
203
664044b1de73 Making '-c' to behave as 'tail -f', but showing *all* the file.
lbatlle@npdl268.bpo.hp.com
parents: 180
diff changeset
   385
664044b1de73 Making '-c' to behave as 'tail -f', but showing *all* the file.
lbatlle@npdl268.bpo.hp.com
parents: 180
diff changeset
   386
    return tail_file(str, -1 /* All the lines */);
33
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   387
}
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   388
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   389
void c_show_output_file()
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   390
{
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   391
    char *str;
35
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   392
    int pid;
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   393
    /* This will exit if there is any error */
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   394
    str = get_output_file(&pid);
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   395
    if (str == 0)
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   396
    {
146
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   397
        fprintf(stderr, "The output is not stored.\n");
35
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   398
        exit(-1);
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   399
    }
33
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   400
    printf("%s\n", str);
35
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   401
    free(str);
33
5c2d981f2f8e Added 'cat' and 'show output filename'
viric@llimona
parents: 32
diff changeset
   402
}
35
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   403
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   404
void c_show_pid()
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   405
{
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   406
    char *str;
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   407
    int pid;
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   408
    /* This will exit if there is any error */
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   409
    str = get_output_file(&pid);
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   410
    printf("%i\n", pid);
83d0da612dc4 Kill the running job works fine.
viric@llimona
parents: 33
diff changeset
   411
}
41
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   412
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   413
void c_remove_job()
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   414
{
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   415
    struct msg m;
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   416
    int res;
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   417
    char *string = 0;
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   418
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   419
    /* Send the request */
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   420
    m.type = REMOVEJOB;
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   421
    m.u.jobid = command_line.jobid;
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   422
    send_msg(server_socket, &m);
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   423
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   424
    /* Receive the answer */
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   425
    res = recv_msg(server_socket, &m);
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   426
    if(res != sizeof(m))
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   427
        error("Error in remove_job");
41
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   428
    switch(m.type)
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   429
    {
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   430
    case REMOVEJOB_OK:
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   431
        return;
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   432
        /* WILL NOT GO FURTHER */
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   433
    case LIST_LINE: /* Only ONE line accepted */
146
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   434
        string = (char *) malloc(m.u.size);
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   435
        res = recv_bytes(server_socket, string, m.u.size);
41
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   436
        fprintf(stderr, "Error in the request: %s", 
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   437
                string);
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   438
        exit(-1);
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   439
        /* WILL NOT GO FURTHER */
44
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
   440
    default:
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   441
        warning("Wrong internal message in remove_job");
41
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   442
    }
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   443
    /* This will never be reached */
cad41574feda Added 'remove job'.
viric@llimona
parents: 38
diff changeset
   444
}
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   445
174
c112f67965fb Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents: 156
diff changeset
   446
int c_wait_job_recv()
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   447
{
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   448
    struct msg m;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   449
    int res;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   450
    char *string = 0;
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   451
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   452
    /* Receive the answer */
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   453
    res = recv_msg(server_socket, &m);
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   454
    if(res != sizeof(m))
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   455
        error("Error in wait_job");
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   456
    switch(m.type)
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   457
    {
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   458
    case WAITJOB_OK:
110
2726c92a5cb3 Half-code for 'times'
viric@mandarina
parents: 92
diff changeset
   459
        return m.u.result.errorlevel;
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   460
        /* WILL NOT GO FURTHER */
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   461
    case LIST_LINE: /* Only ONE line accepted */
146
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   462
        string = (char *) malloc(m.u.size);
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   463
        res = recv_bytes(server_socket, string, m.u.size);
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   464
        if(res != m.u.size)
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   465
            error("Error in wait_job - line size");
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   466
        fprintf(stderr, "Error in the request: %s", 
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   467
                string);
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   468
        exit(-1);
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   469
        /* WILL NOT GO FURTHER */
44
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
   470
    default:
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   471
        warning("Wrong internal message in c_wait_job");
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   472
    }
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   473
    /* This will never be reached */
51
aa6e05d77537 '-w' returns the waited errorlevel. Added a testbench.
viric@llimona
parents: 49
diff changeset
   474
    return -1;
42
f093d0964cf5 Added wait for jobs.
viric@llimona
parents: 41
diff changeset
   475
}
53
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   476
226
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 219
diff changeset
   477
static void c_wait_job_send()
174
c112f67965fb Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents: 156
diff changeset
   478
{
c112f67965fb Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents: 156
diff changeset
   479
    struct msg m;
c112f67965fb Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents: 156
diff changeset
   480
c112f67965fb Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents: 156
diff changeset
   481
    /* Send the request */
c112f67965fb Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents: 156
diff changeset
   482
    m.type = WAITJOB;
c112f67965fb Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents: 156
diff changeset
   483
    m.u.jobid = command_line.jobid;
c112f67965fb Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents: 156
diff changeset
   484
    send_msg(server_socket, &m);
c112f67965fb Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents: 156
diff changeset
   485
}
c112f67965fb Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents: 156
diff changeset
   486
226
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 219
diff changeset
   487
static void c_wait_running_job_send()
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 219
diff changeset
   488
{
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 219
diff changeset
   489
    struct msg m;
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 219
diff changeset
   490
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 219
diff changeset
   491
    /* Send the request */
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 219
diff changeset
   492
    m.type = WAIT_RUNNING_JOB;
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 219
diff changeset
   493
    m.u.jobid = command_line.jobid;
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 219
diff changeset
   494
    send_msg(server_socket, &m);
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 219
diff changeset
   495
}
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 219
diff changeset
   496
174
c112f67965fb Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents: 156
diff changeset
   497
/* Returns the errorlevel */
c112f67965fb Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents: 156
diff changeset
   498
int c_wait_job()
c112f67965fb Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents: 156
diff changeset
   499
{
c112f67965fb Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents: 156
diff changeset
   500
    c_wait_job_send();
c112f67965fb Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents: 156
diff changeset
   501
    return c_wait_job_recv();
c112f67965fb Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents: 156
diff changeset
   502
}
c112f67965fb Our implementation of -t (equivalent tail -f), which now
viric@llimona
parents: 156
diff changeset
   503
226
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 219
diff changeset
   504
/* Returns the errorlevel */
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 219
diff changeset
   505
int c_wait_running_job()
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 219
diff changeset
   506
{
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 219
diff changeset
   507
    c_wait_running_job_send();
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 219
diff changeset
   508
    return c_wait_job_recv();
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 219
diff changeset
   509
}
472ab90fd6a1 Bugfix: some "-t" and "-c" were not notified at end of job.
viric@mandarina
parents: 219
diff changeset
   510
219
c24a1f5c1715 Adding hot-switchable amount of max_slots.
viric@mandarina
parents: 203
diff changeset
   511
void c_send_max_slots(int max_slots)
c24a1f5c1715 Adding hot-switchable amount of max_slots.
viric@mandarina
parents: 203
diff changeset
   512
{
c24a1f5c1715 Adding hot-switchable amount of max_slots.
viric@mandarina
parents: 203
diff changeset
   513
    struct msg m;
c24a1f5c1715 Adding hot-switchable amount of max_slots.
viric@mandarina
parents: 203
diff changeset
   514
c24a1f5c1715 Adding hot-switchable amount of max_slots.
viric@mandarina
parents: 203
diff changeset
   515
    /* Send the request */
c24a1f5c1715 Adding hot-switchable amount of max_slots.
viric@mandarina
parents: 203
diff changeset
   516
    m.type = SET_MAX_SLOTS;
c24a1f5c1715 Adding hot-switchable amount of max_slots.
viric@mandarina
parents: 203
diff changeset
   517
    m.u.max_slots = command_line.max_slots;
c24a1f5c1715 Adding hot-switchable amount of max_slots.
viric@mandarina
parents: 203
diff changeset
   518
    send_msg(server_socket, &m);
c24a1f5c1715 Adding hot-switchable amount of max_slots.
viric@mandarina
parents: 203
diff changeset
   519
}
c24a1f5c1715 Adding hot-switchable amount of max_slots.
viric@mandarina
parents: 203
diff changeset
   520
253
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 231
diff changeset
   521
void c_get_max_slots()
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 231
diff changeset
   522
{
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 231
diff changeset
   523
    struct msg m;
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 231
diff changeset
   524
    int res;
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 231
diff changeset
   525
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 231
diff changeset
   526
    /* Send the request */
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 231
diff changeset
   527
    m.type = GET_MAX_SLOTS;
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 231
diff changeset
   528
    m.u.max_slots = command_line.max_slots;
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 231
diff changeset
   529
    send_msg(server_socket, &m);
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 231
diff changeset
   530
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 231
diff changeset
   531
    /* Receive the answer */
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 231
diff changeset
   532
    res = recv_msg(server_socket, &m);
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 231
diff changeset
   533
    if(res != sizeof(m))
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 231
diff changeset
   534
        error("Error in move_urgent");
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 231
diff changeset
   535
    switch(m.type)
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 231
diff changeset
   536
    {
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 231
diff changeset
   537
        case GET_MAX_SLOTS_OK:
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 231
diff changeset
   538
            printf("%i\n", m.u.max_slots);
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 231
diff changeset
   539
            return;
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 231
diff changeset
   540
        default:
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 231
diff changeset
   541
            warning("Wrong internal message in get_max_slots");
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 231
diff changeset
   542
    }
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 231
diff changeset
   543
}
e9b153f4ae40 Making "-S" to return the number of slots set, if without additional argument.
viric@mandarina
parents: 231
diff changeset
   544
53
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   545
void c_move_urgent()
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   546
{
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   547
    struct msg m;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   548
    int res;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   549
    char *string = 0;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   550
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   551
    /* Send the request */
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   552
    m.type = URGENT;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   553
    m.u.jobid = command_line.jobid;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   554
    send_msg(server_socket, &m);
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   555
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   556
    /* Receive the answer */
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   557
    res = recv_msg(server_socket, &m);
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   558
    if(res != sizeof(m))
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   559
        error("Error in move_urgent");
53
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   560
    switch(m.type)
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   561
    {
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   562
    case URGENT_OK:
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   563
        return;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   564
        /* WILL NOT GO FURTHER */
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   565
    case LIST_LINE: /* Only ONE line accepted */
146
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   566
        string = (char *) malloc(m.u.size);
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   567
        res = recv_bytes(server_socket, string, m.u.size);
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   568
        if(res != m.u.size)
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   569
            error("Error in move_urgent - line size");
53
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   570
        fprintf(stderr, "Error in the request: %s", 
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   571
                string);
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   572
        exit(-1);
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   573
        /* WILL NOT GO FURTHER */
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   574
    default:
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   575
        warning("Wrong internal message in move_urgent");
53
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   576
    }
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   577
    /* This will never be reached */
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   578
    return;
731c41817842 '-u' (urgency) implemented.
viric@llimona
parents: 51
diff changeset
   579
}
63
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   580
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   581
void c_get_state()
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   582
{
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   583
    struct msg m;
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   584
    int res;
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   585
    char *string = 0;
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   586
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   587
    /* Send the request */
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   588
    m.type = GET_STATE;
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   589
    m.u.jobid = command_line.jobid;
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   590
    send_msg(server_socket, &m);
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   591
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   592
    /* Receive the answer */
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   593
    res = recv_msg(server_socket, &m);
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   594
    if(res != sizeof(m))
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   595
        error("Error in get_state - line size");
63
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   596
    switch(m.type)
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   597
    {
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   598
    case ANSWER_STATE:
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   599
        printf("%s\n", jstate2string(m.u.state));
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   600
        return;
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   601
        /* WILL NOT GO FURTHER */
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   602
    case LIST_LINE: /* Only ONE line accepted */
146
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   603
        string = (char *) malloc(m.u.size);
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   604
        res = recv_bytes(server_socket, string, m.u.size);
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   605
        if(res != m.u.size)
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   606
            error("Error in get_state - line size");
63
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   607
        fprintf(stderr, "Error in the request: %s", 
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   608
                string);
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   609
        exit(-1);
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   610
        /* WILL NOT GO FURTHER */
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   611
    default:
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   612
        warning("Wrong internal message in get_state");
63
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   613
    }
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   614
    /* This will never be reached */
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   615
    return;
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 62
diff changeset
   616
}
66
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   617
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   618
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
   619
{
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   620
    struct msg m;
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   621
    int res;
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   622
    char *string = 0;
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   623
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   624
    /* Send the request */
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   625
    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
   626
    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
   627
    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
   628
    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
   629
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   630
    /* Receive the answer */
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   631
    res = recv_msg(server_socket, &m);
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   632
    if(res != sizeof(m))
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   633
        error("Error in swap_jobs");
66
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   634
    switch(m.type)
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   635
    {
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   636
    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
   637
        return;
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   638
        /* 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
   639
    case LIST_LINE: /* Only ONE line accepted */
146
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   640
        string = (char *) malloc(m.u.size);
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   641
        res = recv_bytes(server_socket, string, m.u.size);
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 117
diff changeset
   642
        if(res != m.u.size)
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   643
            error("Error in swap_jobs - line size");
66
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   644
        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
   645
                string);
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   646
        exit(-1);
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   647
        /* 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
   648
    default:
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 71
diff changeset
   649
        warning("Wrong internal message in swap_jobs");
66
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   650
    }
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   651
    /* 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
   652
    return;
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 63
diff changeset
   653
}