Use FIFO pipes for input

This commit is contained in:
Alex 2020-08-05 22:16:38 +02:00
parent c73dbe983a
commit e1fdae99e4
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
3 changed files with 33 additions and 2 deletions

View File

@ -120,7 +120,27 @@ int main(int argc, char* argv[])
/* Create server.port/global for FIFO */
path[1] = category[CAT_GLOB];
path[2] = NULL;
if (mkdir_bottomup(path)) {}
if (mkdir_bottomup(path)) {
path[2] = "in";
path[3] = NULL;
char pbuf[PATH_MAX];
int tmp;
if (assemble_path(path, pbuf, sizeof(pbuf))) {
if ((mkfifo(pbuf, S_IRUSR | S_IWUSR | S_IWGRP)) != 0 && errno != EEXIST)
LOG_ERRNO(LOG_ERROR, "Couldn't create FIFO for input.", pbuf);
else {
LOG_CONN(LOG_INFO, "Created a FIFO pipe for input.", pbuf, &cons[t]);
ssize_t fd;
if ((fd = open(pbuf, O_RDONLY | O_NONBLOCK)) != -1)
cons[t].fds[1] = fd;
else {
LOG_ERRNO(LOG_WARN, "Couldn't open FIFO pipe for reading.", pbuf);
cons[t].fds[1] = -1;
}
}
} else
LOG(LOG_WARN, "Couldn't assemble path for FIFO!", NULL);
}
if ((sendbuflen = Assm_mesg(sendbuf, Assm_cmd_NICK(cons[t].names.nick), sizeof(sendbuf))) > 0)
flush_buffer(sendbuf, sendbuflen, &cons[t]);
@ -214,6 +234,13 @@ int main(int argc, char* argv[])
break;
}
}
if (cons[t].fds[1] != -1) {
LOG(LOG_DEBUG, "About to attempt to read input on FIFO.", NULL);
if ((sendbuflen = read(cons[t].fds[1], sendbuf, sizeof(sendbuf))) > 0)
flush_buffer(sendbuf, sendbuflen, &cons[t]);
else if (sendbuflen == -1 && errno != EAGAIN)
LOG_ERRNO(LOG_WARN, "Couldn't read from input FIFO.", NULL);
}
}
} while (actcon > 0);
return EXIT_SUCCESS;

View File

@ -31,6 +31,9 @@
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#define UIRC_HELPERS
#include "../lib/uIRC/include/uirc.h"

View File

@ -106,7 +106,8 @@ int readline_mem(Buffer_Info* bs)
return READLINE_EOF;
else
return READLINE_UNKNOWN_ERR;
}
} else if (b_read == 0)
return READLINE_EOF;
bs->append_pos += b_read;
*bs->append_pos = '\0';
if (b_read == 0)