bridge.c revision 5430f7f2bc7330f3088b894166bf3524a067e3d8
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2010 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <stddef.h>
#include "log.h"
#include "util.h"
#include "socket-util.h"
#define EXTRA_SIZE 16
static bool initial_nul = false;
static bool auth_over = false;
unsigned j;
assert(l > 0);
}
buf[j*2] = 0;
}
size_t r;
if (line[0] == 0 && !initial_nul) {
initial_nul = true;
line += 1;
l -= 1;
r = 1;
} else
r = 0;
r += l;
auth_over = true;
r += 13;
r += 14 + len;
} else
r += l;
return r;
}
if (*in_buffer_full <= 0)
return *in_buffer_full;
/* If authentication is done, we don't touch anything anymore */
if (auth_over)
return *in_buffer_full;
if (*in_buffer_full < 2)
return 0;
for (i = 0; i <= *in_buffer_full - 2; i ++) {
/* Fully lines can be send on */
if (i > good) {
old_length = i - good;
} else
good = i+2;
}
if (auth_over)
break;
}
return good;
}
union sockaddr_union sa;
if (argc > 1) {
log_error("This program takes no argument.");
return EXIT_FAILURE;
}
log_open();
goto finish;
}
log_error("Failed to connect: %m");
goto finish;
}
log_error("Failed to create epoll: %m");
goto finish;
}
log_error("Failed to regiser fds in epoll: %m");
goto finish;
}
do {
ssize_t k;
int i, nfds;
continue;
log_error("epoll_wait(): %m");
goto finish;
}
for (i = 0; i < nfds; i++) {
stdin_readable = true;
stdout_writable = false;
stdout_whup = true;
}
stdout_writable = true;
fd_writable = false;
fd_whup = true;
}
fd_readable = true;
fd_writable = true;
}
}
while ((stdin_readable && in_buffer_full <= 0) ||
(fd_readable && out_buffer_full <= 0) ||
(stdout_writable && out_buffer_full > 0)) {
size_t in_buffer_good = 0;
stdin_readable = false;
k = 0;
else {
log_error("read(): %m");
goto finish;
}
} else
in_buffer_full += (size_t) k;
if (k == 0) {
stdin_rhup = true;
stdin_readable = false;
}
}
if (fd_writable && in_buffer_good > 0) {
fd_writable = false;
fd_whup = true;
fd_writable = false;
} else {
log_error("write(): %m");
goto finish;
}
} else {
in_buffer_full -= k;
}
}
fd_readable = false;
k = 0;
else {
log_error("read(): %m");
goto finish;
}
} else
out_buffer_full += (size_t) k;
if (k == 0) {
fd_rhup = true;
fd_readable = false;
}
}
if (stdout_writable && out_buffer_full > 0) {
stdout_writable = false;
stdout_whup = true;
stdout_writable = false;
} else {
log_error("write(): %m");
goto finish;
}
} else {
out_buffer_full -= k;
}
}
}
fd_whup = true;
fd_writable = false;
}
stdout_whup = true;
stdout_writable = false;
}
} while (!stdout_whup || !fd_whup);
r = EXIT_SUCCESS;
if (fd >= 0)
if (ep >= 0)
return r;
}