server.c
author viric <viriketo@gmail.com>
Wed, 19 Oct 2016 22:09:43 +0200
changeset 353 cee48819d7e4
parent 336 5ddb2f6fc452
child 369 040912c941e4
permissions -rw-r--r--
Added tag v1.0.0 for changeset 387687433b1e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49
09bb8a5583e9 Added the license.
lbatlle@npdl268.bpo.hp.com
parents: 45
diff changeset
     1
/*
09bb8a5583e9 Added the license.
lbatlle@npdl268.bpo.hp.com
parents: 45
diff changeset
     2
    Task Spooler - a task queue system for the unix user
335
b4a5d9544836 Updating messages to 0.7.4.
viric
parents: 334
diff changeset
     3
    Copyright (C) 2007-2013  LluĂ­s Batlle i Rossell
49
09bb8a5583e9 Added the license.
lbatlle@npdl268.bpo.hp.com
parents: 45
diff changeset
     4
09bb8a5583e9 Added the license.
lbatlle@npdl268.bpo.hp.com
parents: 45
diff changeset
     5
    Please find the license in the provided COPYING file.
09bb8a5583e9 Added the license.
lbatlle@npdl268.bpo.hp.com
parents: 45
diff changeset
     6
*/
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
     7
#include <sys/types.h>
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
     8
#include <sys/socket.h>
44
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
     9
#include <sys/select.h>
134
5a6b8bb1f7a8 Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents: 129
diff changeset
    10
#ifdef linux
5a6b8bb1f7a8 Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents: 129
diff changeset
    11
  #include <sys/time.h>
5a6b8bb1f7a8 Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents: 129
diff changeset
    12
#endif
94
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
    13
#include <sys/resource.h>
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
    14
#include <sys/un.h>
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
    15
#include <errno.h>
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    16
#include <string.h>
28
107abb4ec98a Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents: 26
diff changeset
    17
#include <stdlib.h>
44
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
    18
#include <unistd.h>
94
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
    19
#include <limits.h>
99
88d96be4e0e9 Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents: 94
diff changeset
    20
#include <signal.h>
120
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    21
#include <fcntl.h>
263
0d831e6cf8ef Making ts chdir to the socket directory.
viric@mandarina
parents: 260
diff changeset
    22
#include <libgen.h>
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
    23
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
    24
#include <stdio.h>
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
    25
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    26
#include "main.h"
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
    27
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
    28
enum
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
    29
{
64
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 63
diff changeset
    30
    MAXCONN=1000
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
    31
};
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
    32
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
    33
enum Break
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
    34
{
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
    35
    BREAK,
260
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
    36
    NOBREAK,
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
    37
    CLOSE
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
    38
};
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
    39
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    40
/* Prototypes */
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    41
static void server_loop(int ls);
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    42
static enum Break
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    43
    client_read(int index);
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    44
static void end_server(int ls);
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
    45
static void s_newjob_ok(int index);
295
a63f43a17fd7 Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents: 290
diff changeset
    46
static void s_newjob_nok(int index);
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 178
diff changeset
    47
static void s_runjob(int jobid, int index);
260
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
    48
static void clean_after_client_disappeared(int socket, int index);
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    49
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    50
struct Client_conn
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    51
{
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    52
    int socket;
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    53
    int hasjob;
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    54
    int jobid;
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    55
};
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    56
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    57
/* Globals */
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    58
static struct Client_conn client_cs[MAXCONN];
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    59
static int nconnections;
28
107abb4ec98a Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents: 26
diff changeset
    60
static char *path;
94
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
    61
static int max_descriptors;
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
    62
287
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 278
diff changeset
    63
/* in jobs.c */
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 278
diff changeset
    64
extern int max_jobs;
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 278
diff changeset
    65
260
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
    66
static void s_send_version(int s)
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
    67
{
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
    68
    struct msg m;
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
    69
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
    70
    m.type = VERSION;
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
    71
    m.u.version = PROTOCOL_VERSION;
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
    72
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
    73
    send_msg(s, &m);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
    74
}
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
    75
99
88d96be4e0e9 Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents: 94
diff changeset
    76
static void sigterm_handler(int n)
88d96be4e0e9 Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents: 94
diff changeset
    77
{
120
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    78
    const char *dumpfilename;
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    79
    int fd;
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    80
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    81
    /* Dump the job list if we should to */
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    82
    dumpfilename = getenv("TS_SAVELIST");
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    83
    if (dumpfilename != NULL)
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    84
    {
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    85
        fd = open(dumpfilename, O_WRONLY | O_APPEND | O_CREAT, 0600);
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    86
        if (fd != -1)
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    87
        {
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    88
            joblist_dump(fd);
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    89
            close(fd);
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    90
        } else
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    91
            warning("The TS_SAVELIST file \"%s\" cannot be opened",
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    92
                    dumpfilename);
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    93
    }
790bc4cecd3b Added TS_SAVELIST.
viric@llimona
parents: 117
diff changeset
    94
99
88d96be4e0e9 Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents: 94
diff changeset
    95
    /* path will be initialized for sure, before installing the handler */
88d96be4e0e9 Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents: 94
diff changeset
    96
    unlink(path);
88d96be4e0e9 Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents: 94
diff changeset
    97
    exit(1);
88d96be4e0e9 Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents: 94
diff changeset
    98
}
88d96be4e0e9 Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents: 94
diff changeset
    99
239
18301d7a56d4 As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents: 231
diff changeset
   100
static void set_default_maxslots()
18301d7a56d4 As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents: 231
diff changeset
   101
{
18301d7a56d4 As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents: 231
diff changeset
   102
    char *str;
18301d7a56d4 As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents: 231
diff changeset
   103
18301d7a56d4 As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents: 231
diff changeset
   104
    str = getenv("TS_SLOTS");
18301d7a56d4 As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents: 231
diff changeset
   105
    if (str != NULL)
18301d7a56d4 As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents: 231
diff changeset
   106
    {
18301d7a56d4 As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents: 231
diff changeset
   107
        int slots;
18301d7a56d4 As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents: 231
diff changeset
   108
        slots = abs(atoi(str));
18301d7a56d4 As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents: 231
diff changeset
   109
        s_set_max_slots(slots);
18301d7a56d4 As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents: 231
diff changeset
   110
    }
18301d7a56d4 As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents: 231
diff changeset
   111
}
18301d7a56d4 As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents: 231
diff changeset
   112
99
88d96be4e0e9 Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents: 94
diff changeset
   113
static void install_sigterm_handler()
88d96be4e0e9 Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents: 94
diff changeset
   114
{
88d96be4e0e9 Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents: 94
diff changeset
   115
  struct sigaction act;
88d96be4e0e9 Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents: 94
diff changeset
   116
88d96be4e0e9 Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents: 94
diff changeset
   117
  act.sa_handler = sigterm_handler;
88d96be4e0e9 Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents: 94
diff changeset
   118
  /* Reset the mask */
88d96be4e0e9 Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents: 94
diff changeset
   119
  memset(&act.sa_mask,0,sizeof(act.sa_mask));
88d96be4e0e9 Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents: 94
diff changeset
   120
  act.sa_flags = 0;
88d96be4e0e9 Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents: 94
diff changeset
   121
88d96be4e0e9 Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents: 94
diff changeset
   122
  sigaction(SIGTERM, &act, NULL);
88d96be4e0e9 Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents: 94
diff changeset
   123
}
88d96be4e0e9 Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents: 94
diff changeset
   124
94
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   125
static int get_max_descriptors()
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   126
{
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   127
    const int MARGIN = 5; /* stdin, stderr, listen socket, and whatever */
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   128
    int max;
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   129
    struct rlimit rlim;
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   130
    int res;
278
1698b327528d Adding the limit of ts connections
viric@mandarina
parents: 267
diff changeset
   131
    const char *str;
94
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   132
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   133
    max = MAXCONN;
278
1698b327528d Adding the limit of ts connections
viric@mandarina
parents: 267
diff changeset
   134
1698b327528d Adding the limit of ts connections
viric@mandarina
parents: 267
diff changeset
   135
    str = getenv("TS_MAXCONN");
1698b327528d Adding the limit of ts connections
viric@mandarina
parents: 267
diff changeset
   136
    if (str != NULL)
1698b327528d Adding the limit of ts connections
viric@mandarina
parents: 267
diff changeset
   137
    {
1698b327528d Adding the limit of ts connections
viric@mandarina
parents: 267
diff changeset
   138
        int user_maxconn;
1698b327528d Adding the limit of ts connections
viric@mandarina
parents: 267
diff changeset
   139
        user_maxconn = abs(atoi(str));
1698b327528d Adding the limit of ts connections
viric@mandarina
parents: 267
diff changeset
   140
        if (max > user_maxconn)
1698b327528d Adding the limit of ts connections
viric@mandarina
parents: 267
diff changeset
   141
            max = user_maxconn;
1698b327528d Adding the limit of ts connections
viric@mandarina
parents: 267
diff changeset
   142
    }
1698b327528d Adding the limit of ts connections
viric@mandarina
parents: 267
diff changeset
   143
94
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   144
    if (max > FD_SETSIZE)
278
1698b327528d Adding the limit of ts connections
viric@mandarina
parents: 267
diff changeset
   145
        max = FD_SETSIZE - MARGIN;
94
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   146
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   147
    /* I'd like to use OPEN_MAX or NR_OPEN, but I don't know if any
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   148
     * of them is POSIX compliant */
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   149
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   150
    res = getrlimit(RLIMIT_NOFILE, &rlim);
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   151
    if (res != 0)
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   152
        warning("getrlimit for open files");
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   153
    else
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   154
    {
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   155
        if (max > rlim.rlim_cur)
278
1698b327528d Adding the limit of ts connections
viric@mandarina
parents: 267
diff changeset
   156
            max = rlim.rlim_cur - MARGIN;
94
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   157
    }
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   158
278
1698b327528d Adding the limit of ts connections
viric@mandarina
parents: 267
diff changeset
   159
    if (max < 1)
94
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   160
        error("Too few opened descriptors available");
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   161
278
1698b327528d Adding the limit of ts connections
viric@mandarina
parents: 267
diff changeset
   162
    return max;
94
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   163
}
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   164
28
107abb4ec98a Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents: 26
diff changeset
   165
void server_main(int notify_fd, char *_path)
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   166
{
44
4dcf05746ece Better include files.
viric@llimona
parents: 42
diff changeset
   167
    int ls;
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   168
    struct sockaddr_un addr;
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   169
    int res;
263
0d831e6cf8ef Making ts chdir to the socket directory.
viric@mandarina
parents: 260
diff changeset
   170
    char *dirpath;
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   171
104
dc4dd9939238 Fixed error reporting.
viric@llimona
parents: 99
diff changeset
   172
    process_type = SERVER;
94
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   173
    max_descriptors = get_max_descriptors();
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   174
287
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 278
diff changeset
   175
    /* Arbitrary limit, that will block the enqueuing, but should allow space
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 278
diff changeset
   176
     * for usual ts queries */
290
eefb37e0a8fe Restoring the max_jobs to a reasonable value, not only for testing.
viric <viriketo@gmail.com>
parents: 288
diff changeset
   177
    max_jobs = max_descriptors - 5;
287
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 278
diff changeset
   178
28
107abb4ec98a Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents: 26
diff changeset
   179
    path = _path;
107abb4ec98a Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents: 26
diff changeset
   180
263
0d831e6cf8ef Making ts chdir to the socket directory.
viric@mandarina
parents: 260
diff changeset
   181
    /* Move the server to the socket directory */
336
5ddb2f6fc452 Patch for MacOSX: remove strdup
Lluís Batlle <viric@viric.name>
parents: 335
diff changeset
   182
    dirpath = malloc(strlen(path)+1);
5ddb2f6fc452 Patch for MacOSX: remove strdup
Lluís Batlle <viric@viric.name>
parents: 335
diff changeset
   183
    strcpy(dirpath, path);
263
0d831e6cf8ef Making ts chdir to the socket directory.
viric@mandarina
parents: 260
diff changeset
   184
    chdir(dirname(dirpath));
0d831e6cf8ef Making ts chdir to the socket directory.
viric@mandarina
parents: 260
diff changeset
   185
    free(dirpath);
0d831e6cf8ef Making ts chdir to the socket directory.
viric@mandarina
parents: 260
diff changeset
   186
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   187
    nconnections = 0;
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   188
129
312083fb8899 Change PF_UNIX to AF_UNIX. According to socket(2), this is better.
viric@llimona
parents: 120
diff changeset
   189
    ls = socket(AF_UNIX, SOCK_STREAM, 0);
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   190
    if(ls == -1)
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   191
        error("cannot create the listen socket in the server");
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   192
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   193
    addr.sun_family = AF_UNIX;
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   194
    strcpy(addr.sun_path, path);
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   195
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   196
    res = bind(ls, (struct sockaddr *) &addr, sizeof(addr));
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   197
    if (res == -1)
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   198
        error("Error binding.");
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   199
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   200
    res = listen(ls, 0);
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   201
    if (res == -1)
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   202
        error("Error listening.");
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   203
99
88d96be4e0e9 Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents: 94
diff changeset
   204
    install_sigterm_handler();
88d96be4e0e9 Never leave the socket if the server dies by SIGTERM.
viric@llimona
parents: 94
diff changeset
   205
239
18301d7a56d4 As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents: 231
diff changeset
   206
    set_default_maxslots();
18301d7a56d4 As asked by Sergio Ballestreros, adding TS_SLOTS to set the default amount of
viric@vicerveza
parents: 231
diff changeset
   207
25
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 22
diff changeset
   208
    notify_parent(notify_fd);
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 22
diff changeset
   209
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   210
    server_loop(ls);
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   211
}
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   212
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   213
static int get_conn_of_jobid(int jobid)
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   214
{
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   215
    int i;
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   216
    for(i=0; i< nconnections; ++i)
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   217
        if (client_cs[i].hasjob && client_cs[i].jobid == jobid)
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   218
            return i;
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   219
    return -1;
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   220
}
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   221
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   222
static void server_loop(int ls)
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   223
{
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   224
    fd_set readset;
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   225
    int i;
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   226
    int maxfd;
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   227
    int keep_loop = 1;
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   228
    int newjob;
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   229
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   230
    while (keep_loop)
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   231
    {
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   232
        FD_ZERO(&readset);
94
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   233
        maxfd = 0;
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   234
        /* If we can accept more connections, go on.
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   235
         * Otherwise, the system block them (no accept will be done). */
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   236
        if (nconnections < max_descriptors)
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   237
        {
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   238
            FD_SET(ls,&readset);
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   239
            maxfd = ls;
aefdd4d9cbab Server won't die for out of handles.
viric@llimona
parents: 92
diff changeset
   240
        }
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   241
        for(i=0; i< nconnections; ++i)
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   242
        {
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   243
            FD_SET(client_cs[i].socket, &readset);
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   244
            if (client_cs[i].socket > maxfd)
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   245
                maxfd = client_cs[i].socket;
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   246
        }
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   247
        select(maxfd + 1, &readset, NULL, NULL, NULL);
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   248
        if (FD_ISSET(ls,&readset))
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   249
        {
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   250
            int cs;
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   251
            cs = accept(ls, NULL, NULL);
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   252
            if (cs == -1)
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   253
                error("Accepting from %i", ls);
134
5a6b8bb1f7a8 Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents: 129
diff changeset
   254
            client_cs[nconnections].hasjob = 0;
5a6b8bb1f7a8 Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents: 129
diff changeset
   255
            client_cs[nconnections].socket = cs;
5a6b8bb1f7a8 Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents: 129
diff changeset
   256
            ++nconnections;
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   257
        }
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   258
        for(i=0; i< nconnections; ++i)
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   259
            if (FD_ISSET(client_cs[i].socket, &readset))
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   260
            {
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   261
                enum Break b;
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   262
                b = client_read(i);
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   263
                /* Check if we should break */
260
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   264
                if (b == CLOSE)
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   265
                {
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   266
                    warning("Closing");
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   267
                    /* On unknown message, we close the client,
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   268
                       or it may hang waiting for an answer */
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   269
                    clean_after_client_disappeared(client_cs[i].socket, i);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   270
                }
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   271
                else if (b == BREAK)
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   272
                    keep_loop = 0;
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   273
            }
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   274
        /* This will return firstjob->jobid or -1 */
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   275
        newjob = next_run_job();
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   276
        if (newjob != -1)
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   277
        {
287
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 278
diff changeset
   278
            int conn, awaken_job;
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   279
            conn = get_conn_of_jobid(newjob);
19
5efc347cca8d The finished jobs store the errorlevel, and can be listed.
viric@llimona
parents: 18
diff changeset
   280
            /* This next marks the firstjob state to RUNNING */
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 178
diff changeset
   281
            s_mark_job_running(newjob);
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 178
diff changeset
   282
            s_runjob(newjob, conn);
287
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 278
diff changeset
   283
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 278
diff changeset
   284
            while ((awaken_job = wake_hold_client()) != -1)
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 278
diff changeset
   285
            {
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 278
diff changeset
   286
                int wake_conn = get_conn_of_jobid(awaken_job);
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 278
diff changeset
   287
                if (wake_conn == -1)
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 278
diff changeset
   288
                    error("The job awaken does not have a connection open");
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 278
diff changeset
   289
                s_newjob_ok(wake_conn);
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 278
diff changeset
   290
            }
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   291
        }
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   292
    }
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   293
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   294
    end_server(ls);
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   295
}
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   296
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   297
static void end_server(int ls)
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   298
{
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   299
    close(ls);
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   300
    unlink(path);
28
107abb4ec98a Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents: 26
diff changeset
   301
    /* This comes from the parent, in the fork after server_main.
107abb4ec98a Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents: 26
diff changeset
   302
     * This is the last use of path in this process.*/
107abb4ec98a Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents: 26
diff changeset
   303
    free(path); 
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   304
}
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   305
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   306
static void remove_connection(int index)
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   307
{
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   308
    int i;
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   309
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   310
    if(client_cs[index].hasjob)
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   311
    {
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   312
        s_removejob(client_cs[index].jobid);
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   313
    }
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   314
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   315
    for(i=index; i<(nconnections-1); ++i)
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   316
    {
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   317
        memcpy(&client_cs[i], &client_cs[i+1], sizeof(client_cs[0]));
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   318
    }
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   319
    nconnections--;
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   320
}
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   321
252
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   322
static void
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   323
clean_after_client_disappeared(int socket, int index)
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   324
{
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   325
    /* Act as if the job ended. */
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   326
    int jobid = client_cs[index].jobid;
288
8459747e1a73 Fixing the cleaning of the job list in case of ctrl-c on a blocked client
viric <viriketo@gmail.com>
parents: 287
diff changeset
   327
    if (client_cs[index].hasjob)
252
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   328
    {
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   329
        struct Result r;
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   330
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   331
        r.errorlevel = -1;
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   332
        r.died_by_signal = 1;
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   333
        r.signal = SIGKILL;
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   334
        r.user_ms = 0;
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   335
        r.system_ms = 0;
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   336
        r.real_ms = 0;
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   337
        r.skipped = 0;
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   338
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   339
        warning("JobID %i quit while running.", jobid);
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   340
        job_finished(&r, jobid);
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   341
        /* For the dependencies */
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   342
        check_notify_list(jobid);
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   343
        /* We don't want this connection to do anything
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   344
         * more related to the jobid, secially on remove_connection
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   345
         * when we receive the EOC. */
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   346
        client_cs[index].hasjob = 0;
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   347
    }
256
638fcfee37c6 In 254 I introduced an important bug: ts -t marked the running job as
viric@mandarina
parents: 253
diff changeset
   348
    else
638fcfee37c6 In 254 I introduced an important bug: ts -t marked the running job as
viric@mandarina
parents: 253
diff changeset
   349
        /* If it doesn't have a running job,
638fcfee37c6 In 254 I introduced an important bug: ts -t marked the running job as
viric@mandarina
parents: 253
diff changeset
   350
         * it may well be a notification */
638fcfee37c6 In 254 I introduced an important bug: ts -t marked the running job as
viric@mandarina
parents: 253
diff changeset
   351
        s_remove_notification(socket);
252
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   352
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   353
    close(socket);
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   354
    remove_connection(index);
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   355
}
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   356
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   357
static enum Break
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   358
    client_read(int index)
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   359
{
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   360
    struct msg m;
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   361
    int s;
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   362
    int res;
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   363
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   364
    s = client_cs[index].socket;
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   365
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   366
    /* Read the message */
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   367
    res = recv_msg(s, &m);
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   368
    if (res == -1)
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   369
    {
134
5a6b8bb1f7a8 Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents: 129
diff changeset
   370
        warning("client recv failed");
252
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   371
        clean_after_client_disappeared(s, index);
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   372
        return NOBREAK;
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   373
    }
134
5a6b8bb1f7a8 Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents: 129
diff changeset
   374
    else if (res == 0)
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   375
    {
252
f0af96f58947 Fixing the problem of ts clients being killed. The queue should be reusable
viric@mandarina
parents: 239
diff changeset
   376
        clean_after_client_disappeared(s, index);
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   377
        return NOBREAK;
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   378
    }
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   379
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   380
    /* Process message */
260
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   381
    switch(m.type)
22
afdc8410633f Now output can go to filenames.
viric@llimona
parents: 20
diff changeset
   382
    {
260
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   383
        case KILL_SERVER:
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   384
            return BREAK; /* break in the parent*/
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   385
            break;
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   386
        case NEWJOB:
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   387
            client_cs[index].jobid = s_newjob(s, &m);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   388
            client_cs[index].hasjob = 1;
287
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 278
diff changeset
   389
            if (!job_is_holding_client(client_cs[index].jobid))
b3c38ff8f41a An implementation that looks like working for the queue limit and client
viric <viriketo@gmail.com>
parents: 278
diff changeset
   390
                s_newjob_ok(index);
295
a63f43a17fd7 Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents: 290
diff changeset
   391
            else if (!m.u.newjob.wait_enqueuing)
a63f43a17fd7 Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents: 290
diff changeset
   392
            {
a63f43a17fd7 Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents: 290
diff changeset
   393
                s_newjob_nok(index);
a63f43a17fd7 Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents: 290
diff changeset
   394
                clean_after_client_disappeared(s, index);
a63f43a17fd7 Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents: 290
diff changeset
   395
            }
260
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   396
            break;
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   397
        case RUNJOB_OK:
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   398
            {
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   399
                char *buffer = 0;
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   400
                if (m.u.output.store_output)
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   401
                {
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   402
                    /* Receive the output filename */
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   403
                    buffer = (char *) malloc(m.u.output.ofilename_size);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   404
                    res = recv_bytes(s, buffer,
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   405
                        m.u.output.ofilename_size);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   406
                    if (res != m.u.output.ofilename_size)
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   407
                        error("Reading the ofilename");
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   408
                }
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   409
                s_process_runjob_ok(client_cs[index].jobid, buffer,
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   410
                        m.u.output.pid);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   411
            }
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   412
            break;
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   413
        case LIST:
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   414
            s_list(s);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   415
            /* We must actively close, meaning End of Lines */
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   416
            close(s);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   417
            remove_connection(index);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   418
            break;
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   419
        case INFO:
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   420
            s_job_info(s, m.u.jobid);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   421
            close(s);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   422
            remove_connection(index);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   423
            break;
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   424
        case ENDJOB:
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   425
            job_finished(&m.u.result, client_cs[index].jobid);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   426
            /* For the dependencies */
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   427
            check_notify_list(client_cs[index].jobid);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   428
            /* We don't want this connection to do anything
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   429
             * more related to the jobid, secially on remove_connection
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   430
             * when we receive the EOC. */
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   431
            client_cs[index].hasjob = 0;
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   432
            break;
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   433
        case CLEAR_FINISHED:
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   434
            s_clear_finished();
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   435
            break;
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   436
        case ASK_OUTPUT:
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   437
            s_send_output(s, m.u.jobid);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   438
            break;
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   439
        case REMOVEJOB:
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   440
            {
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   441
                int went_ok;
334
e9e212846a89 Fixing a process left, when "-r" is used without jobid.
viric
parents: 295
diff changeset
   442
                /* Will update the jobid. If it's -1, will set the jobid found */
e9e212846a89 Fixing a process left, when "-r" is used without jobid.
viric
parents: 295
diff changeset
   443
                went_ok = s_remove_job(s, &m.u.jobid);
260
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   444
                if (went_ok)
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   445
                {
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   446
                    int i;
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   447
                    for(i = 0; i < nconnections; ++i)
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   448
                    {
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   449
                        if (client_cs[i].hasjob && client_cs[i].jobid == m.u.jobid)
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   450
                        {
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   451
                            close(client_cs[i].socket);
146
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 136
diff changeset
   452
260
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   453
                            /* So remove_connection doesn't call s_removejob again */
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   454
                            client_cs[i].hasjob = 0;
20
d85b4c0745fa "-c" added, for clearing the finished tasks' list.
viric@llimona
parents: 19
diff changeset
   455
260
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   456
                            /* We don't try to remove any notification related to
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   457
                             * 'i', because it will be for sure a ts client for a job */
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   458
                            remove_connection(i);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   459
                        }
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   460
                    }
134
5a6b8bb1f7a8 Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents: 129
diff changeset
   461
                }
5a6b8bb1f7a8 Fixing two bugs noted in buglist.bug (ts clients not dying on removejob, queue
viric@llimona
parents: 129
diff changeset
   462
            }
260
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   463
            break;
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   464
        case WAITJOB:
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   465
            s_wait_job(s, m.u.jobid);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   466
            break;
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   467
        case WAIT_RUNNING_JOB:
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   468
            s_wait_running_job(s, m.u.jobid);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   469
            break;
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   470
        case URGENT:
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   471
            s_move_urgent(s, m.u.jobid);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   472
            break;
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   473
        case SET_MAX_SLOTS:
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   474
            s_set_max_slots(m.u.max_slots);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   475
            break;
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   476
        case GET_MAX_SLOTS:
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   477
            s_get_max_slots(s);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   478
            break;
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   479
        case SWAP_JOBS:
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   480
            s_swap_jobs(s, m.u.swap.jobid1,
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   481
                    m.u.swap.jobid2);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   482
            break;
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   483
        case GET_STATE:
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   484
            s_send_state(s, m.u.jobid);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   485
            break;
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   486
        case GET_VERSION:
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   487
            s_send_version(s);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   488
            break;
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   489
        default:
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   490
            /* Command not supported */
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   491
            /* On unknown message, we close the client,
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   492
               or it may hang waiting for an answer */
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   493
            warning("Unknown message: %i", m.type);
ecd09b351170 Adding version control in the protocol. It can't check with older versions.
viric@mandarina
parents: 256
diff changeset
   494
            return CLOSE;
63
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 53
diff changeset
   495
    }
47be318f4cbc Added "-s" for querying the job state.
viric@llimona
parents: 53
diff changeset
   496
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   497
    return NOBREAK; /* normal */
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   498
}
4
viric@llimona
parents: 3
diff changeset
   499
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 178
diff changeset
   500
static void s_runjob(int jobid, int index)
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   501
{
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   502
    int s;
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   503
    
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   504
    if (!client_cs[index].hasjob)
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   505
        error("Run job of the client %i which doesn't have any job", index);
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   506
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   507
    s = client_cs[index].socket;
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   508
218
f084c8de313f First attempt at multiple slot running.
viric@mandarina
parents: 178
diff changeset
   509
    s_send_runjob(s, jobid);
8
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   510
}
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   511
03339adb7014 Some more code for execution.
viric@llimona
parents: 5
diff changeset
   512
static void s_newjob_ok(int index)
4
viric@llimona
parents: 3
diff changeset
   513
{
viric@llimona
parents: 3
diff changeset
   514
    int s;
viric@llimona
parents: 3
diff changeset
   515
    struct msg m;
viric@llimona
parents: 3
diff changeset
   516
    
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   517
    if (!client_cs[index].hasjob)
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   518
        error("Run job of the client %i which doesn't have any job", index);
4
viric@llimona
parents: 3
diff changeset
   519
viric@llimona
parents: 3
diff changeset
   520
    s = client_cs[index].socket;
viric@llimona
parents: 3
diff changeset
   521
viric@llimona
parents: 3
diff changeset
   522
    m.type = NEWJOB_OK;
viric@llimona
parents: 3
diff changeset
   523
    m.u.jobid = client_cs[index].jobid;
viric@llimona
parents: 3
diff changeset
   524
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   525
    send_msg(s, &m);
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   526
}
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   527
295
a63f43a17fd7 Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents: 290
diff changeset
   528
static void s_newjob_nok(int index)
a63f43a17fd7 Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents: 290
diff changeset
   529
{
a63f43a17fd7 Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents: 290
diff changeset
   530
    int s;
a63f43a17fd7 Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents: 290
diff changeset
   531
    struct msg m;
a63f43a17fd7 Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents: 290
diff changeset
   532
    
a63f43a17fd7 Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents: 290
diff changeset
   533
    if (!client_cs[index].hasjob)
a63f43a17fd7 Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents: 290
diff changeset
   534
        error("Run job of the client %i which doesn't have any job", index);
a63f43a17fd7 Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents: 290
diff changeset
   535
a63f43a17fd7 Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents: 290
diff changeset
   536
    s = client_cs[index].socket;
a63f43a17fd7 Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents: 290
diff changeset
   537
a63f43a17fd7 Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents: 290
diff changeset
   538
    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: 290
diff changeset
   539
a63f43a17fd7 Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents: 290
diff changeset
   540
    send_msg(s, &m);
a63f43a17fd7 Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents: 290
diff changeset
   541
}
a63f43a17fd7 Adding the option '-B' for Mark, that will make ts quit if it cannot enqueue a
viric <viriketo@gmail.com>
parents: 290
diff changeset
   542
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   543
static void dump_conn_struct(FILE *out, const struct Client_conn *p)
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   544
{
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   545
    fprintf(out, "  new_conn\n");
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   546
    fprintf(out, "    socket %i\n", p->socket);
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   547
    fprintf(out, "    hasjob \"%i\"\n", p->hasjob);
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   548
    fprintf(out, "    jobid %i\n", p->jobid);
4
viric@llimona
parents: 3
diff changeset
   549
}
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   550
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   551
void dump_conns_struct(FILE *out)
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   552
{
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   553
    int i;
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   554
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   555
    fprintf(out, "New_conns");
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   556
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   557
    for(i=0; i < nconnections; ++i)
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   558
    {
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   559
        dump_conn_struct(out, &client_cs[i]);
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   560
    }
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   561
}