#include <sys/ioctl.h>
#include <sys/termios.h>
-#include <sys/types.h>
#include <errno.h>
#include <poll.h>
#include <unistd.h>
+#include <cctype>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
+#include "base/atomicio.hh"
#include "base/misc.hh"
#include "base/output.hh"
#include "base/socket.hh"
void
Terminal::listen(int port)
{
+ if (ListenSocket::allDisabled()) {
+ warn_once("Sockets disabled, not accepting terminal connections");
+ return;
+ }
+
while (!listener.listen(port, true)) {
DPRINTF(Terminal,
": can't bind address terminal port %d inuse PID %d\n",
int fd = listener.accept(true);
if (data_fd != -1) {
char message[] = "terminal already attached!\n";
- ::write(fd, message, sizeof(message));
+ atomic_write(fd, message, sizeof(message));
::close(fd);
return;
}
if (data_fd < 0)
panic("Terminal not properly attached.\n");
- size_t ret;
- for (;;) {
- ret = ::write(data_fd, buf, len);
-
- if (ret >= 0)
- break;
-
- if (errno != EINTR)
- detach();
- }
+ ssize_t ret = atomic_write(data_fd, buf, len);
+ if (ret < len)
+ detach();
return ret;
}
if (DTRACE(Terminal)) {
static char last = '\0';
- if (c != '\n' && c != '\r' ||
- last != '\n' && last != '\r') {
+ if ((c != '\n' && c != '\r') || (last != '\n' && last != '\r')) {
if (c == '\n' || c == '\r') {
int size = linebuf.size();
char *buffer = new char[size + 1];