Makefile.in: Fix typo in definition of all_objs.
[paraslash.git] / client.c
1 /*
2 * Copyright (C) 1997-2009 Andre Noll <maan@systemlinux.org>
3 *
4 * Licensed under the GPL v2. For licencing details see COPYING.
5 */
6
7 /** \file client.c the client program used to connect to para_server */
8
9 #include <regex.h>
10 #include <openssl/rc4.h>
11
12 #include "para.h"
13 #include "list.h"
14 #include "sched.h"
15 #include "crypt.h"
16 #include "client.cmdline.h"
17 #include "string.h"
18 #include "stdin.h"
19 #include "stdout.h"
20 #include "client.h"
21 #include "error.h"
22
23 INIT_CLIENT_ERRLISTS;
24
25 static struct client_task *ct;
26 static struct stdin_task sit;
27 static struct stdout_task sot;
28
29 static void supervisor_post_select(__a_unused struct sched *s, struct task *t)
30 {
31 if (ct->task.error < 0) {
32 t->error = ct->task.error;
33 return;
34 }
35 if (ct->status == CL_SENDING) {
36 stdin_set_defaults(&sit);
37 sit.buf = para_malloc(sit.bufsize),
38 register_task(&sit.task);
39 ct->inbuf = sit.buf;
40 ct->in_loaded = &sit.loaded;
41 ct->in_error = &sit.task.error;
42 t->error = -E_TASK_STARTED;
43 return;
44 }
45 if (ct->status == CL_RECEIVING) {
46 stdout_set_defaults(&sot);
47 sot.bufp = &ct->buf;
48 sot.loaded = &ct->loaded;
49 sot.input_error = &ct->task.error;
50 register_task(&sot.task);
51 t->error = -E_TASK_STARTED;
52 return;
53 }
54 }
55
56 static struct task svt = {
57 .post_select = supervisor_post_select,
58 .status = "supervisor task"
59 };
60
61 static int client_loglevel; /* loglevel */
62 INIT_STDERR_LOGGING(client_loglevel);
63
64
65 /**
66 * The client program to connect to para_server.
67 *
68 * \param argc Usual argument count.
69 * \param argv Usual argument vector.
70 *
71 * It registers two tasks: The client task that communicates with para_server
72 * and the standard out task that writes any output produced by the client task
73 * to standard out.
74 *
75 * \return EXIT_SUCCESS or EXIT_FAILURE
76 *
77 * \sa client_open(), stdout.c, stdout.h, para_client(1), para_server(1)
78 */
79 int main(int argc, char *argv[])
80 {
81
82 int ret;
83 static struct sched s;
84
85 init_random_seed_or_die();
86 s.default_timeout.tv_sec = 1;
87 s.default_timeout.tv_usec = 0;
88 ret = client_open(argc, argv, &ct, &client_loglevel);
89 if (ret < 0) /* can not use PARA_LOG here because ct is NULL */
90 exit(EXIT_FAILURE);
91 register_task(&svt);
92 ret = schedule(&s);
93 if (ret < 0)
94 PARA_ERROR_LOG("%s\n", para_strerror(-ret));
95 client_close(ct);
96 return ret >= 0? EXIT_SUCCESS: EXIT_FAILURE;
97 }