mirror of
https://github.com/skeeto/endlessh.git
synced 2025-12-08 14:13:23 +00:00
Rename all log levels
We're going to include <syslog.h> which #defines some of the same identifiers to a numeric value. This will clash with the current usage in the enum.
This commit is contained in:
58
endlessh.c
58
endlessh.c
@@ -52,10 +52,10 @@ epochms(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static enum loglevel {
|
static enum loglevel {
|
||||||
LOG_NONE,
|
log_none,
|
||||||
LOG_INFO,
|
log_info,
|
||||||
LOG_DEBUG
|
log_debug
|
||||||
} loglevel = LOG_NONE;
|
} loglevel = log_none;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
logmsg(enum loglevel level, const char *format, ...)
|
logmsg(enum loglevel level, const char *format, ...)
|
||||||
@@ -116,9 +116,9 @@ client_new(int fd, long long send_next)
|
|||||||
*/
|
*/
|
||||||
int value = 1;
|
int value = 1;
|
||||||
int r = setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &value, sizeof(value));
|
int r = setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &value, sizeof(value));
|
||||||
logmsg(LOG_DEBUG, "setsockopt(%d, SO_RCVBUF, %d) = %d", fd, value, r);
|
logmsg(log_debug, "setsockopt(%d, SO_RCVBUF, %d) = %d", fd, value, r);
|
||||||
if (r == -1)
|
if (r == -1)
|
||||||
logmsg(LOG_DEBUG, "errno = %d, %s", errno, strerror(errno));
|
logmsg(log_debug, "errno = %d, %s", errno, strerror(errno));
|
||||||
|
|
||||||
/* Get IP address */
|
/* Get IP address */
|
||||||
struct sockaddr_storage addr;
|
struct sockaddr_storage addr;
|
||||||
@@ -143,9 +143,9 @@ client_new(int fd, long long send_next)
|
|||||||
static void
|
static void
|
||||||
client_destroy(struct client *client)
|
client_destroy(struct client *client)
|
||||||
{
|
{
|
||||||
logmsg(LOG_DEBUG, "close(%d)", client->fd);
|
logmsg(log_debug, "close(%d)", client->fd);
|
||||||
long long dt = epochms() - client->connect_time;
|
long long dt = epochms() - client->connect_time;
|
||||||
logmsg(LOG_INFO,
|
logmsg(log_info,
|
||||||
"CLOSE host=%s port=%d fd=%d "
|
"CLOSE host=%s port=%d fd=%d "
|
||||||
"time=%lld.%03lld bytes=%lld",
|
"time=%lld.%03lld bytes=%lld",
|
||||||
client->ipaddr, client->port, client->fd,
|
client->ipaddr, client->port, client->fd,
|
||||||
@@ -162,7 +162,7 @@ statistics_log_totals(struct client *clients)
|
|||||||
long long milliseconds = statistics.milliseconds;
|
long long milliseconds = statistics.milliseconds;
|
||||||
for (long long now = epochms(); clients; clients = clients->next)
|
for (long long now = epochms(); clients; clients = clients->next)
|
||||||
milliseconds += now - clients->connect_time;
|
milliseconds += now - clients->connect_time;
|
||||||
logmsg(LOG_INFO, "TOTALS connects=%lld seconds=%lld.%03lld bytes=%lld",
|
logmsg(log_info, "TOTALS connects=%lld seconds=%lld.%03lld bytes=%lld",
|
||||||
statistics.connects,
|
statistics.connects,
|
||||||
milliseconds / 1000,
|
milliseconds / 1000,
|
||||||
milliseconds % 1000,
|
milliseconds % 1000,
|
||||||
@@ -462,7 +462,7 @@ config_load(struct config *c, const char *file, int hardfail)
|
|||||||
errno = 0;
|
errno = 0;
|
||||||
char *end;
|
char *end;
|
||||||
long v = strtol(tokens[1], &end, 10);
|
long v = strtol(tokens[1], &end, 10);
|
||||||
if (errno || *end || v < LOG_NONE || v > LOG_DEBUG) {
|
if (errno || *end || v < log_none || v > log_debug) {
|
||||||
fprintf(stderr, "%s:%ld: Invalid log level '%s'\n",
|
fprintf(stderr, "%s:%ld: Invalid log level '%s'\n",
|
||||||
file, lineno, tokens[1]);
|
file, lineno, tokens[1]);
|
||||||
if (hardfail) exit(EXIT_FAILURE);
|
if (hardfail) exit(EXIT_FAILURE);
|
||||||
@@ -480,11 +480,11 @@ config_load(struct config *c, const char *file, int hardfail)
|
|||||||
static void
|
static void
|
||||||
config_log(const struct config *c)
|
config_log(const struct config *c)
|
||||||
{
|
{
|
||||||
logmsg(LOG_INFO, "Port %d", c->port);
|
logmsg(log_info, "Port %d", c->port);
|
||||||
logmsg(LOG_INFO, "Delay %ld", c->delay);
|
logmsg(log_info, "Delay %ld", c->delay);
|
||||||
logmsg(LOG_INFO, "MaxLineLength %d", c->max_line_length);
|
logmsg(log_info, "MaxLineLength %d", c->max_line_length);
|
||||||
logmsg(LOG_INFO, "MaxClients %d", c->max_clients);
|
logmsg(log_info, "MaxClients %d", c->max_clients);
|
||||||
logmsg(LOG_INFO, "BindFamily %s",
|
logmsg(log_info, "BindFamily %s",
|
||||||
c->bind_family == AF_INET6 ? "IPv6 Only" :
|
c->bind_family == AF_INET6 ? "IPv6 Only" :
|
||||||
c->bind_family == AF_INET ? "IPv4 Only" :
|
c->bind_family == AF_INET ? "IPv4 Only" :
|
||||||
"IPv4 Mapped IPv6");
|
"IPv4 Mapped IPv6");
|
||||||
@@ -524,15 +524,15 @@ server_create(int port, int family)
|
|||||||
int r, s, value;
|
int r, s, value;
|
||||||
|
|
||||||
s = socket(family == AF_UNSPEC ? AF_INET6 : family, SOCK_STREAM, 0);
|
s = socket(family == AF_UNSPEC ? AF_INET6 : family, SOCK_STREAM, 0);
|
||||||
logmsg(LOG_DEBUG, "socket() = %d", s);
|
logmsg(log_debug, "socket() = %d", s);
|
||||||
if (s == -1) die();
|
if (s == -1) die();
|
||||||
|
|
||||||
/* Socket options are best effort, allowed to fail */
|
/* Socket options are best effort, allowed to fail */
|
||||||
value = 1;
|
value = 1;
|
||||||
r = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &value, sizeof(value));
|
r = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &value, sizeof(value));
|
||||||
logmsg(LOG_DEBUG, "setsockopt(%d, SO_REUSEADDR, true) = %d", s, r);
|
logmsg(log_debug, "setsockopt(%d, SO_REUSEADDR, true) = %d", s, r);
|
||||||
if (r == -1)
|
if (r == -1)
|
||||||
logmsg(LOG_DEBUG, "errno = %d, %s", errno, strerror(errno));
|
logmsg(log_debug, "errno = %d, %s", errno, strerror(errno));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* With OpenBSD IPv6 sockets are always IPv6-only, so the socket option
|
* With OpenBSD IPv6 sockets are always IPv6-only, so the socket option
|
||||||
@@ -544,9 +544,9 @@ server_create(int port, int family)
|
|||||||
errno = 0;
|
errno = 0;
|
||||||
value = (family == AF_INET6);
|
value = (family == AF_INET6);
|
||||||
r = setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &value, sizeof(value));
|
r = setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &value, sizeof(value));
|
||||||
logmsg(LOG_DEBUG, "setsockopt(%d, IPV6_V6ONLY, true) = %d", s, r);
|
logmsg(log_debug, "setsockopt(%d, IPV6_V6ONLY, true) = %d", s, r);
|
||||||
if (r == -1)
|
if (r == -1)
|
||||||
logmsg(LOG_DEBUG, "errno = %d, %s", errno, strerror(errno));
|
logmsg(log_debug, "errno = %d, %s", errno, strerror(errno));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -565,11 +565,11 @@ server_create(int port, int family)
|
|||||||
};
|
};
|
||||||
r = bind(s, (void *)&addr6, sizeof(addr6));
|
r = bind(s, (void *)&addr6, sizeof(addr6));
|
||||||
}
|
}
|
||||||
logmsg(LOG_DEBUG, "bind(%d, port=%d) = %d", s, port, r);
|
logmsg(log_debug, "bind(%d, port=%d) = %d", s, port, r);
|
||||||
if (r == -1) die();
|
if (r == -1) die();
|
||||||
|
|
||||||
r = listen(s, INT_MAX);
|
r = listen(s, INT_MAX);
|
||||||
logmsg(LOG_DEBUG, "listen(%d) = %d", s, r);
|
logmsg(log_debug, "listen(%d) = %d", s, r);
|
||||||
if (r == -1) die();
|
if (r == -1) die();
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
@@ -583,7 +583,7 @@ sendline(struct client *client, int max_line_length, unsigned long *rng)
|
|||||||
int len = randline(line, max_line_length, rng);
|
int len = randline(line, max_line_length, rng);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ssize_t out = write(client->fd, line, len);
|
ssize_t out = write(client->fd, line, len);
|
||||||
logmsg(LOG_DEBUG, "write(%d) = %d", client->fd, (int)out);
|
logmsg(log_debug, "write(%d) = %d", client->fd, (int)out);
|
||||||
if (out == -1) {
|
if (out == -1) {
|
||||||
if (errno == EINTR) {
|
if (errno == EINTR) {
|
||||||
continue; /* try again */
|
continue; /* try again */
|
||||||
@@ -742,13 +742,13 @@ main(int argc, char **argv)
|
|||||||
/* Wait for next event */
|
/* Wait for next event */
|
||||||
struct pollfd fds = {server, POLLIN, 0};
|
struct pollfd fds = {server, POLLIN, 0};
|
||||||
int nfds = fifo->length < config.max_clients;
|
int nfds = fifo->length < config.max_clients;
|
||||||
logmsg(LOG_DEBUG, "poll(%d, %d)", nfds, timeout);
|
logmsg(log_debug, "poll(%d, %d)", nfds, timeout);
|
||||||
int r = poll(&fds, nfds, timeout);
|
int r = poll(&fds, nfds, timeout);
|
||||||
logmsg(LOG_DEBUG, "= %d", r);
|
logmsg(log_debug, "= %d", r);
|
||||||
if (r == -1) {
|
if (r == -1) {
|
||||||
switch (errno) {
|
switch (errno) {
|
||||||
case EINTR:
|
case EINTR:
|
||||||
logmsg(LOG_DEBUG, "EINTR");
|
logmsg(log_debug, "EINTR");
|
||||||
continue;
|
continue;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "endlessh: fatal: %s\n", strerror(errno));
|
fprintf(stderr, "endlessh: fatal: %s\n", strerror(errno));
|
||||||
@@ -759,7 +759,7 @@ main(int argc, char **argv)
|
|||||||
/* Check for new incoming connections */
|
/* Check for new incoming connections */
|
||||||
if (fds.revents & POLLIN) {
|
if (fds.revents & POLLIN) {
|
||||||
int fd = accept(server, 0, 0);
|
int fd = accept(server, 0, 0);
|
||||||
logmsg(LOG_DEBUG, "accept() = %d", fd);
|
logmsg(log_debug, "accept() = %d", fd);
|
||||||
statistics.connects++;
|
statistics.connects++;
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
const char *msg = strerror(errno);
|
const char *msg = strerror(errno);
|
||||||
@@ -767,7 +767,7 @@ main(int argc, char **argv)
|
|||||||
case EMFILE:
|
case EMFILE:
|
||||||
case ENFILE:
|
case ENFILE:
|
||||||
config.max_clients = fifo->length;
|
config.max_clients = fifo->length;
|
||||||
logmsg(LOG_INFO,
|
logmsg(log_info,
|
||||||
"MaxClients %d",
|
"MaxClients %d",
|
||||||
fifo->length);
|
fifo->length);
|
||||||
break;
|
break;
|
||||||
@@ -792,7 +792,7 @@ main(int argc, char **argv)
|
|||||||
close(fd);
|
close(fd);
|
||||||
} else {
|
} else {
|
||||||
fifo_append(fifo, client);
|
fifo_append(fifo, client);
|
||||||
logmsg(LOG_INFO, "ACCEPT host=%s port=%d fd=%d n=%d/%d",
|
logmsg(log_info, "ACCEPT host=%s port=%d fd=%d n=%d/%d",
|
||||||
client->ipaddr, client->port, client->fd,
|
client->ipaddr, client->port, client->fd,
|
||||||
fifo->length, config.max_clients);
|
fifo->length, config.max_clients);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user