Attempt to fix doors using stdio redirection.. seems to work, use at own risk

This commit is contained in:
Andrew Pamment 2016-04-06 16:54:38 +10:00
parent d4c12ad755
commit b9e7e995b9

28
doors.c
View File

@ -10,6 +10,8 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#if defined(linux) #if defined(linux)
# include <pty.h> # include <pty.h>
#elif defined(__OpenBSD__) || defined(__NetBSD__)
# include <util.h>
#else #else
# include <libutil.h> # include <libutil.h>
#endif #endif
@ -18,6 +20,17 @@
extern struct bbs_config conf; extern struct bbs_config conf;
extern int mynode; extern int mynode;
int running_door_pid = 0;
int running_door = 0;
void doorchld_handler(int s)
{
// waitpid() might overwrite errno, so we save and restore it:
while(waitpid(-1, NULL, WNOHANG) > 0);
running_door = 0;
}
int write_door32sys(int socket, struct user_record *user) { int write_door32sys(int socket, struct user_record *user) {
struct stat s; struct stat s;
char buffer[256]; char buffer[256];
@ -121,6 +134,7 @@ void rundoor(int socket, struct user_record *user, char *cmd, int stdio) {
fd_set fdset; fd_set fdset;
int t; int t;
struct winsize ws; struct winsize ws;
struct sigaction sa;
if (write_door32sys(socket, user) != 0) { if (write_door32sys(socket, user) != 0) {
return; return;
@ -138,7 +152,17 @@ void rundoor(int socket, struct user_record *user, char *cmd, int stdio) {
ws.ws_row = 24; ws.ws_row = 24;
ws.ws_col = 80; ws.ws_col = 80;
running_door = 1;
if (openpty(&master, &slave, NULL, NULL, &ws) == 0) { if (openpty(&master, &slave, NULL, NULL, &ws) == 0) {
sa.sa_handler = doorchld_handler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
if (sigaction(SIGCHLD, &sa, NULL) == -1) {
perror("sigaction");
exit(1);
}
pid = fork(); pid = fork();
if (pid < 0) { if (pid < 0) {
return; return;
@ -156,7 +180,9 @@ void rundoor(int socket, struct user_record *user, char *cmd, int stdio) {
execvp(cmd, arguments); execvp(cmd, arguments);
} else { } else {
while(1) { running_door_pid = pid;
while(running_door != 0) {
FD_ZERO(&fdset); FD_ZERO(&fdset);
FD_SET(master, &fdset); FD_SET(master, &fdset);
FD_SET(socket, &fdset); FD_SET(socket, &fdset);