server_start.c
author viric <viriketo@gmail.com>
Sun, 20 Mar 2016 11:25:53 +0100
changeset 346 90545736507e
parent 302 c60e0db23bd7
child 359 3cbf0e10ef48
permissions -rw-r--r--
Description: Fix typo Author: Alexander Inyukhin <shurick@sectorb.msk.ru> Last-Update: 2016-03-20
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: 251
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
*/
44
4dcf05746ece Better include files.
viric@llimona
parents: 28
diff changeset
     7
#include <unistd.h>
4dcf05746ece Better include files.
viric@llimona
parents: 28
diff changeset
     8
#include <string.h>
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
     9
#include <sys/types.h>
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
    10
#include <sys/socket.h>
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
    11
#include <sys/un.h>
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
    12
#include <errno.h>
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    13
#include <stdlib.h>
9
9acd8ae3190c First usable version!
lbatlle@npdl268.bpo.hp.com
parents: 3
diff changeset
    14
#include <stdio.h>
146
5e689cb593aa Bones of the "-i" parameter, job info.
viric@llimona
parents: 133
diff changeset
    15
#include <sys/time.h>
302
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
    16
#include <sys/stat.h>
25
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 9
diff changeset
    17
#include <signal.h>
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    18
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
    19
#include "main.h"
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
    20
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
    21
extern int server_socket;
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
    22
251
5e0802df5788 Making a ts.error file for each socket ($TS_SOCKET.error)
viric@mandarina
parents: 231
diff changeset
    23
static char *socket_path;
302
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
    24
static int should_check_owner = 0;
28
107abb4ec98a Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents: 25
diff changeset
    25
25
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 9
diff changeset
    26
static int fork_server();
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 9
diff changeset
    27
251
5e0802df5788 Making a ts.error file for each socket ($TS_SOCKET.error)
viric@mandarina
parents: 231
diff changeset
    28
void create_socket_path(char **path)
28
107abb4ec98a Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents: 25
diff changeset
    29
{
107abb4ec98a Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents: 25
diff changeset
    30
    char *tmpdir;
119
361b08d33762 $USER is no more used for crating the socket path. Now the UID is used.
viric@llimona
parents: 92
diff changeset
    31
    char userid[20];
28
107abb4ec98a Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents: 25
diff changeset
    32
    int size;
107abb4ec98a Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents: 25
diff changeset
    33
64
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 49
diff changeset
    34
    /* As a priority, TS_SOCKET mandates over the path creation */
251
5e0802df5788 Making a ts.error file for each socket ($TS_SOCKET.error)
viric@mandarina
parents: 231
diff changeset
    35
    *path = getenv("TS_SOCKET");
5e0802df5788 Making a ts.error file for each socket ($TS_SOCKET.error)
viric@mandarina
parents: 231
diff changeset
    36
    if (*path != 0)
64
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 49
diff changeset
    37
    {
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 49
diff changeset
    38
        /* We need this in our memory, for forks and future 'free'. */
251
5e0802df5788 Making a ts.error file for each socket ($TS_SOCKET.error)
viric@mandarina
parents: 231
diff changeset
    39
        size = strlen(*path) + 1;
5e0802df5788 Making a ts.error file for each socket ($TS_SOCKET.error)
viric@mandarina
parents: 231
diff changeset
    40
        *path = (char *) malloc(size);
5e0802df5788 Making a ts.error file for each socket ($TS_SOCKET.error)
viric@mandarina
parents: 231
diff changeset
    41
        strcpy(*path, getenv("TS_SOCKET"));
302
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
    42
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
    43
        /* We don't want to check ownership of the socket here,
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
    44
         * as the user may have thought of some shared queue */
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
    45
        should_check_owner = 0;
64
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 49
diff changeset
    46
        return;
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 49
diff changeset
    47
    }
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 49
diff changeset
    48
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 49
diff changeset
    49
    /* ... if the $TS_SOCKET doesn't exist ... */
2a17c9c7b1d5 Added a limit to the number of finished jobs.
viric@llimona
parents: 49
diff changeset
    50
28
107abb4ec98a Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents: 25
diff changeset
    51
    /* Create the path */
107abb4ec98a Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents: 25
diff changeset
    52
    tmpdir = getenv("TMPDIR");
107abb4ec98a Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents: 25
diff changeset
    53
    if (tmpdir == NULL)
107abb4ec98a Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents: 25
diff changeset
    54
        tmpdir = "/tmp";
107abb4ec98a Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents: 25
diff changeset
    55
119
361b08d33762 $USER is no more used for crating the socket path. Now the UID is used.
viric@llimona
parents: 92
diff changeset
    56
    sprintf(userid, "%u", (unsigned int) getuid());
28
107abb4ec98a Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents: 25
diff changeset
    57
107abb4ec98a Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents: 25
diff changeset
    58
    /* Calculate the size */
119
361b08d33762 $USER is no more used for crating the socket path. Now the UID is used.
viric@llimona
parents: 92
diff changeset
    59
    size = strlen(tmpdir) + strlen("/socket-ts.") + strlen(userid) + 1;
28
107abb4ec98a Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents: 25
diff changeset
    60
107abb4ec98a Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents: 25
diff changeset
    61
    /* Freed after preparing the socket address */
251
5e0802df5788 Making a ts.error file for each socket ($TS_SOCKET.error)
viric@mandarina
parents: 231
diff changeset
    62
    *path = (char *) malloc(size);
28
107abb4ec98a Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents: 25
diff changeset
    63
251
5e0802df5788 Making a ts.error file for each socket ($TS_SOCKET.error)
viric@mandarina
parents: 231
diff changeset
    64
    sprintf(*path, "%s/socket-ts.%s", tmpdir, userid);
302
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
    65
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
    66
    should_check_owner = 1;
28
107abb4ec98a Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents: 25
diff changeset
    67
}
107abb4ec98a Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents: 25
diff changeset
    68
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
    69
int try_connect(int s)
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
    70
{
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
    71
    struct sockaddr_un addr;
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
    72
    int res;
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
    73
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
    74
    addr.sun_family = AF_UNIX;
251
5e0802df5788 Making a ts.error file for each socket ($TS_SOCKET.error)
viric@mandarina
parents: 231
diff changeset
    75
    strcpy(addr.sun_path, socket_path);
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
    76
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
    77
    res = connect(s, (struct sockaddr *) &addr, sizeof(addr));
302
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
    78
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
    79
    return res;
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
    80
}
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
    81
302
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
    82
static void
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
    83
try_check_ownership()
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
    84
{
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
    85
    int res;
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
    86
    struct stat socketstat;
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
    87
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
    88
    if (!should_check_owner)
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
    89
        return;
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
    90
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
    91
    res = stat(socket_path, &socketstat);
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
    92
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
    93
    if (res != 0)
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
    94
        error("Cannot state the socket %s.", socket_path);
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
    95
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
    96
    if (socketstat.st_uid != getuid())
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
    97
        error("The uid %i does not own the socket %s.", getuid(), socket_path);
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
    98
}
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
    99
25
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 9
diff changeset
   100
void wait_server_up(int fd)
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   101
{
25
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 9
diff changeset
   102
    char a;
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 9
diff changeset
   103
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 9
diff changeset
   104
    read(fd, &a, 1);
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 9
diff changeset
   105
    close(fd);
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   106
}
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   107
25
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 9
diff changeset
   108
/* Returns the fd where to wait for the parent notification */
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 9
diff changeset
   109
static int fork_server()
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   110
{
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   111
    int pid;
25
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 9
diff changeset
   112
    int p[2];
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   113
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   114
    /* !!! stdin/stdout */
25
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 9
diff changeset
   115
    pipe(p);
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   116
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   117
    pid = fork();
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   118
    switch (pid)
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   119
    {
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   120
        case 0: /* Child */
25
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 9
diff changeset
   121
            close(p[0]);
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   122
            close(server_socket);
66
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
   123
            /* Close all std handles for the server */
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
   124
            close(0);
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
   125
            close(1);
f70a27afd92e Adding "swap jobs" with -U. Fixed a big problem with fds 0, 1, 2.
viric@mandarina
parents: 64
diff changeset
   126
            close(2);
133
4306e96f5906 Added setsid when going background.
viric@llimona
parents: 129
diff changeset
   127
            setsid();
251
5e0802df5788 Making a ts.error file for each socket ($TS_SOCKET.error)
viric@mandarina
parents: 231
diff changeset
   128
            server_main(p[1], socket_path);
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   129
            exit(0);
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   130
            break;
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   131
        case -1: /* Error */
25
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 9
diff changeset
   132
            return -1;
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   133
        default: /* Parent */
25
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 9
diff changeset
   134
            close(p[1]);
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   135
    }
25
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 9
diff changeset
   136
    /* Return the read fd */
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 9
diff changeset
   137
    return p[0];
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 9
diff changeset
   138
}
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 9
diff changeset
   139
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 9
diff changeset
   140
void notify_parent(int fd)
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 9
diff changeset
   141
{
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 9
diff changeset
   142
    char a = 'a';
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 9
diff changeset
   143
    write(fd, &a, 1);
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 9
diff changeset
   144
    close(fd);
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   145
}
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   146
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   147
int ensure_server_up()
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   148
{
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   149
    int res;
25
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 9
diff changeset
   150
    int notify_fd;
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   151
129
312083fb8899 Change PF_UNIX to AF_UNIX. According to socket(2), this is better.
viric@llimona
parents: 119
diff changeset
   152
    server_socket = socket(AF_UNIX, SOCK_STREAM, 0);
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   153
    if (server_socket == -1)
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   154
        error("getting the server socket");
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   155
251
5e0802df5788 Making a ts.error file for each socket ($TS_SOCKET.error)
viric@mandarina
parents: 231
diff changeset
   156
    create_socket_path(&socket_path);
28
107abb4ec98a Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents: 25
diff changeset
   157
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   158
    res = try_connect(server_socket);
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   159
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   160
    /* Good connection */
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   161
    if (res == 0)
302
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
   162
    {
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
   163
        try_check_ownership();
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   164
        return 1;
302
c60e0db23bd7 Adding a check for ownership in the socket.
viric <viriketo@gmail.com>
parents: 267
diff changeset
   165
    }
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   166
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   167
    /* If error other than "No one listens on the other end"... */
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   168
    if (!(errno == ENOENT || errno == ECONNREFUSED))
92
05004c52ecff Better error reports on internal handled errors.
viric@llimona
parents: 66
diff changeset
   169
        error("c: cannot connect to the server");
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   170
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   171
    if (errno == ECONNREFUSED)
251
5e0802df5788 Making a ts.error file for each socket ($TS_SOCKET.error)
viric@mandarina
parents: 231
diff changeset
   172
        unlink(socket_path);
3
2fb8a6bdd024 More code.
viric@llimona
parents: 2
diff changeset
   173
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   174
    /* Try starting the server */
25
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 9
diff changeset
   175
    notify_fd = fork_server();
e9e4babe6262 Now the server is quicly started.
viric@llimona
parents: 9
diff changeset
   176
    wait_server_up(notify_fd);
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   177
    res = try_connect(server_socket);
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   178
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   179
    /* The second time didn't work. Abort. */
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   180
    if (res == -1)
9
9acd8ae3190c First usable version!
lbatlle@npdl268.bpo.hp.com
parents: 3
diff changeset
   181
    {
9acd8ae3190c First usable version!
lbatlle@npdl268.bpo.hp.com
parents: 3
diff changeset
   182
        fprintf(stderr, "The server didn't come up.\n");
9acd8ae3190c First usable version!
lbatlle@npdl268.bpo.hp.com
parents: 3
diff changeset
   183
        exit(-1);
9acd8ae3190c First usable version!
lbatlle@npdl268.bpo.hp.com
parents: 3
diff changeset
   184
    }
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   185
251
5e0802df5788 Making a ts.error file for each socket ($TS_SOCKET.error)
viric@mandarina
parents: 231
diff changeset
   186
    free(socket_path);
28
107abb4ec98a Unified socket path, depending on the username and $TMPDIR.
viric@llimona
parents: 25
diff changeset
   187
2
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   188
    /* Good connection on the second time */
602bd67df3aa Changed tabs to 4 spaces. Rule.
viric@llimona
parents: 1
diff changeset
   189
    return 1;
1
74928e2b27f4 Honta versio de ia strukturo.
viric@llimona
parents:
diff changeset
   190
}