Increased resilience and added some more logging

This commit is contained in:
2022-07-02 08:17:15 -05:00
parent ad88090956
commit 6db24d8ab6
5 changed files with 27 additions and 7 deletions

View File

@@ -6,8 +6,8 @@ key domain.key 8001
cert domain.crt 8001
# Port 8001 can have TLS, but it's self signed and very bad.
timeout 2000 8000
timeout 2000 8001
timeout 200000 8000
timeout 200000 8001
# Set these values for the ports
set port 8000

View File

@@ -107,6 +107,7 @@ static void createProcess(int id) {
for (i = 0; i < sizeof(signals) / sizeof(signals[0]); i++)
unsetsignal(signals[i]);
unsetsignal(SIGCHLD);
setsignal(SIGPIPE, SIG_IGN);
connfd = socket(AF_UNIX, SOCK_STREAM, 0);
if (connfd < 0) {
@@ -125,9 +126,10 @@ static void createProcess(int id) {
static void remakeChild(int signal) {
pid_t pid;
int i;
pid = wait(NULL);
createLog("A child has died, recreating");
int i, status;
pid = wait(&status);
createFormatLog("A child has died, recreating: %s",
strsignal(WTERMSIG(status)));
for (i = 0; i < processes - 1; i++) {
if (runners[i].pid == pid) {
close(runners[i].fd);

View File

@@ -117,8 +117,8 @@ remove:
int portind;
newfd = recvFd(connfd);
if (newfd < 0) {
createLog("Message received that included an invalid fd");
continue;
createLog("Message received that included an invalid fd, quitting");
exit(EXIT_FAILURE);
}
while (conninfo->valid == 0) ;
portind = conninfo->portind;

View File

@@ -36,6 +36,7 @@ char *xstrdup(char *str);
int createLog(char *msg);
int createErrorLog(char *msg, int err);
int createFormatLog(char *fmt, ...);
int istrcmp(char *s1, char *s2);
/* case insensitive strcmp */
RequestType getType(char *str);

View File

@@ -20,6 +20,7 @@
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
#include <unistd.h>
@@ -125,6 +126,22 @@ int createErrorLog(char *msg, int err) {
return 0;
}
int createFormatLog(char *fmt, ...) {
va_list ap;
char *log;
int code;
va_start(ap, fmt);
log = malloc(vsnprintf(NULL, 0, fmt, ap) + 1);
va_end(ap);
if (log == NULL)
return 1;
va_start(ap, fmt);
vsprintf(log, fmt, ap);
va_end(ap);
code = createLog(log);
return code;
}
int istrcmp(char *s1, char *s2) {
int i;
for (i = 0;; i++) {