more bugs/fixes \o/

This commit is contained in:
kuntz 2021-02-16 12:59:59 -06:00
parent c66b92a294
commit 73594fe569

27
main.c
View File

@ -16,6 +16,7 @@ typedef float r32 ; typedef double r64 ;
//----------------------------------------------------------------------------------------------------------------------
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <inttypes.h>
#include <semaphore.h>
#include <stdarg.h>
@ -100,7 +101,7 @@ void pump(struct sockaddr_in * const restrict addr, const si sock)
else
{
errno = 0;
pid_t pid = fork();
const pid_t pid = fork();
if (pid == -1) // error
{
@ -130,7 +131,7 @@ void pump(struct sockaddr_in * const restrict addr, const si sock)
if (res == -1)
{
o("%s > close(sock) error: %d\n", datetime(dtbuf), errno);
o("%s > close(sock) error: %d (%s)\n", datetime(dtbuf), errno, ip);
exit(EXIT_FAILURE);
}
@ -216,7 +217,7 @@ void pump(struct sockaddr_in * const restrict addr, const si sock)
if (res == -1)
{
o("%s > close(client_sock) error: %d\n", datetime(dtbuf), errno);
o("%s > close(client_sock) error: %d (%s)\n", datetime(dtbuf), errno, ip);
exit(EXIT_FAILURE);
}
@ -239,18 +240,22 @@ void pump(struct sockaddr_in * const restrict addr, const si sock)
//----------------------------------------------------------------------------------------------------------------------
si main(si argc, s8 ** argv)
{
signal(SIGCHLD, SIG_IGN); // ignore children when they die
if ((csoutput = mmap(0, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0)) == MAP_FAILED)
errno = 0;
if (signal(SIGCHLD, SIG_IGN) == SIG_ERR)
{
o("mmap error\n");
perror("signal error");
return EXIT_FAILURE;
}
errno = 0;
si res = sem_init(csoutput, 1, 1);
if ((csoutput = mmap(0, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0)) == MAP_FAILED)
{
perror("mmap error");
return EXIT_FAILURE;
}
if (res == -1)
errno = 0;
if (sem_init(csoutput, 1, 1) == -1)
{
perror("sem_init error");
return EXIT_FAILURE;
@ -307,7 +312,7 @@ si main(si argc, s8 ** argv)
for (si i=0;i<options;i++)
{
errno = 0;
res = setsockopt(sock, p[i][0], p[i][1], v[i], p[i][2]);
const si res = setsockopt(sock, p[i][0], p[i][1], v[i], p[i][2]);
if (res == -1)
{
@ -319,7 +324,7 @@ si main(si argc, s8 ** argv)
#undef options
errno = 0;
res = bind(sock, (void *)&addr, sizeof(struct sockaddr_in));
si res = bind(sock, (void *)&addr, sizeof(struct sockaddr_in));
if (res == -1)
{