Skip to content

Commit

Permalink
cleanup socket support for doors and update whatsnew.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
wwiv committed Jun 4, 2021
1 parent c528709 commit 22d37e1
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 39 deletions.
39 changes: 20 additions & 19 deletions bbs/chnedit.cpp
Expand Up @@ -62,25 +62,26 @@ static void showchains() {
}

void ShowChainCommandLineHelp() {
bout << "|#2 Macro Value\r\n";
bout << "|#7 ======== =======================================\r\n";
bout << "|#1 % |#9 A single \'%\' Character\r\n";
bout << "|#1 %1 |#9 CHAIN.TXT full pathname (legacy parameter)\r\n";
bout << "|#1 %A |#9 CALLINFO.BBS full pathname \r\n";
bout << "|#1 %C |#9 CHAIN.TXT full pathname \r\n";
bout << "|#1 %D |#9 DORIFOx.DEF full pathname \r\n";
bout << "|#1 %E |#9 DOOR32.SYS full pathname \r\n";
bout << "|#1 %H |#9 Socket Handle \r\n";
bout << "|#1 %I |#9 TEMP directory for the instance \r\n";
bout << "|#1 %K |#9 GFiles Comment File For Archives\r\n";
bout << "|#1 %M |#9 Modem Baud Rate\r\n";
bout << "|#1 %N |#9 Node (Instance) number\r\n";
bout << "|#1 %O |#9 PCBOARD.SYS full pathname\r\n";
bout << "|#1 %P |#9 ComPort Number\r\n";
bout << "|#1 %R |#9 DOOR.SYS Full Pathname\r\n";
bout << "|#1 %S |#9 Com Port Baud Rate\r\n";
bout << "|#1 %T |#9 Minutes Remaining\r\n";
bout << "|#1 %U |#9 Users Handle (primary name)\r\n";
bout << "|#2Macro Value\r\n";
bout << "|#7===== ===============================================================\r\n";
bout << "|#1 %% |#9 A single '%' Character\r\n";
bout << "|#1 %1 |#9 CHAIN.TXT full pathname (legacy parameter)\r\n";
bout << "|#1 %A |#9 CALLINFO.BBS full pathname \r\n";
bout << "|#1 %C |#9 CHAIN.TXT full pathname \r\n";
bout << "|#1 %D |#9 DORIFOx.DEF full pathname \r\n";
bout << "|#1 %E |#9 DOOR32.SYS full pathname \r\n";
bout << "|#1 %H |#9 Socket Handle \r\n";
bout << "|#1 %I |#9 TEMP directory for the instance \r\n";
bout << "|#1 %K |#9 GFiles Comment File For Archives\r\n";
bout << "|#1 %M |#9 Modem Baud Rate\r\n";
bout << "|#1 %N |#9 Node (Instance) number\r\n";
bout << "|#1 %O |#9 PCBOARD.SYS full pathname\r\n";
bout << "|#1 %P |#9 ComPort Number\r\n";
bout << "|#1 %R |#9 DOOR.SYS Full Pathname\r\n";
bout << "|#1 %S |#9 Com Port Baud Rate\r\n";
bout << "|#1 %T |#9 Minutes Remaining\r\n";
bout << "|#1 %U |#9 Users Handle (primary name)\r\n";
bout << "|#1 %Z |#9Socket port/path '12345' or '/wwiv/bbs/e/1/scratch/wwiv.sock'\r\n";
bout.nl();
}

Expand Down
3 changes: 0 additions & 3 deletions bbs/exec.h
Expand Up @@ -22,9 +22,6 @@
#include "bbs/stuffin.h"
#include <string>

// Used to execute a command, called by ExecuteCommandline and the WFC
//int exec_cmdline(const std::string& user_command_line, int flags);

// Used to execute a command, called by ExecuteCommandline and the WFC
int exec_cmdline(wwiv::bbs::CommandLine& sc, int flags);

Expand Down
9 changes: 5 additions & 4 deletions bbs/exec_socket.cpp
Expand Up @@ -60,7 +60,7 @@ static bool SetBlockingMode(SOCKET sock, bool blocking_mode) {
#endif // _WIN32
}

ExecSocket::ExecSocket(const std::filesystem::path& dir, exec_socket_type_t type)
ExecSocket::ExecSocket(const std::filesystem::path& dir, uint16_t port, exec_socket_type_t type)
: dir_(dir), type_(type) {
stop_.store(false);

Expand Down Expand Up @@ -108,7 +108,7 @@ ExecSocket::ExecSocket(const std::filesystem::path& dir, exec_socket_type_t type
sizeof(optval));

my_addr.sin_family = AF_INET;
my_addr.sin_port = htons(12345);
my_addr.sin_port = htons(port);
memset(&(my_addr.sin_zero), 0, 8);
my_addr.sin_addr.s_addr = INADDR_ANY;

Expand All @@ -129,7 +129,7 @@ ExecSocket::ExecSocket(const std::filesystem::path& dir, exec_socket_type_t type
VLOG(1) << "Bound to port: " << port_;
}

if (listen(server_socket_, 5) == -1) {
if (listen(server_socket_, 1) == -1) {
LOG(ERROR) << "listen error";
server_socket_ = -1;
return;
Expand Down Expand Up @@ -170,7 +170,7 @@ std::optional<int> ExecSocket::accept() {

std::string ExecSocket::z() const {
if (type_ == exec_socket_type_t::port) {
return fmt::format("localhost:{}", port_);
return fmt::format("{}", port_);
}
return path().string();
}
Expand Down Expand Up @@ -240,6 +240,7 @@ pump_socket_result_t ExecSocket::pump_socket(EXEC_SOCKET_HANDLE hProcess, int so
}
wwiv::os::sleep_for(std::chrono::milliseconds(100));
}
return pump_socket_result_t::process_exit;
}

bool ExecSocket::stop_pump() {
Expand Down
5 changes: 4 additions & 1 deletion bbs/exec_socket.h
Expand Up @@ -44,7 +44,9 @@ typedef pid_t EXEC_SOCKET_HANDLE;

class ExecSocket final {
public:
ExecSocket(const std::filesystem::path& dir, exec_socket_type_t type);
ExecSocket(const std::filesystem::path& dir)
: ExecSocket(dir, 0, exec_socket_type_t::unix_domain) {}
ExecSocket(uint16_t port) : ExecSocket("", port, exec_socket_type_t::port) {}
~ExecSocket();
std::optional<int> accept();

Expand All @@ -62,6 +64,7 @@ class ExecSocket final {
static bool process_still_active(EXEC_SOCKET_HANDLE h);

private:
ExecSocket(const std::filesystem::path& dir, uint16_t port, exec_socket_type_t type);
const std::filesystem::path dir_;
exec_socket_type_t type_;
std::filesystem::path unix_path_;
Expand Down
10 changes: 6 additions & 4 deletions bbs/exec_unix.cpp
Expand Up @@ -258,17 +258,15 @@ int exec_cmdline(wwiv::bbs::CommandLine& cmdline, int flags) {
need_reopen_io = true;
bout.remoteIO()->close(true);
} else if (flags & EFLAG_LISTEN_SOCK) {
exec_socket = std::make_unique<wwiv::bbs::ExecSocket>(a()->sess().dirs().scratch_directory(),
wwiv::bbs::exec_socket_type_t::port);
exec_socket = std::make_unique<wwiv::bbs::ExecSocket>(0);
// Add %Z into the commandline.
if (exec_socket->listening()) {
cmdline.add('Z', exec_socket->z());
VLOG(1) << "listening to socket: " << exec_socket->z();
}

} else if (flags & EFLAG_UNIX_SOCK) {
exec_socket = std::make_unique<wwiv::bbs::ExecSocket>(a()->sess().dirs().scratch_directory(),
wwiv::bbs::exec_socket_type_t::unix_domain);
exec_socket = std::make_unique<wwiv::bbs::ExecSocket>(a()->sess().dirs().scratch_directory());
// Add %Z into the commandline.
if (exec_socket->listening()) {
cmdline.add('Z', exec_socket->z());
Expand Down Expand Up @@ -299,6 +297,10 @@ int exec_cmdline(wwiv::bbs::CommandLine& cmdline, int flags) {
VLOG(1) << "Forcefully terminating pid: " << pid;
kill(pid, SIGKILL);
}
} else {
// sockets closed but process still running.
VLOG(1) << "Accept never happend; Forcefully terminating pid: " << pid;
kill(pid, SIGKILL);
}
}

Expand Down
17 changes: 11 additions & 6 deletions bbs/exec_win32.cpp
Expand Up @@ -570,17 +570,16 @@ int exec_cmdline(wwiv::bbs::CommandLine& cmdline, int flags) {
return false;
}
} else if (flags & EFLAG_LISTEN_SOCK) {
exec_socket = std::make_unique<wwiv::bbs::ExecSocket>(a()->sess().dirs().scratch_directory(),
wwiv::bbs::exec_socket_type_t::port);
uint16_t port = 0;
exec_socket = std::make_unique<wwiv::bbs::ExecSocket>(port);
// Add %Z into the commandline.
if (exec_socket->listening()) {
cmdline.add('Z', exec_socket->z());
working_cmdline = cmdline.cmdline();
}

} else if (flags & EFLAG_UNIX_SOCK) {
exec_socket = std::make_unique<wwiv::bbs::ExecSocket>(a()->sess().dirs().scratch_directory(),
wwiv::bbs::exec_socket_type_t::unix_domain);
exec_socket = std::make_unique<wwiv::bbs::ExecSocket>(a()->sess().dirs().scratch_directory());
// Add %Z into the commandline.
if (exec_socket->listening()) {
cmdline.add('Z', exec_socket->z());
Expand Down Expand Up @@ -636,11 +635,17 @@ int exec_cmdline(wwiv::bbs::CommandLine& cmdline, int flags) {
const auto res = exec_socket->pump_socket(pi.hProcess, sock.value(), *bout.remoteIO());
if (res != pump_socket_result_t::process_exit) {
// sockets closed but process still running.
DWORD exit_code;
if (TerminateProcess(pi.hProcess, &exit_code)) {
VLOG(1) << "Sockets closed, process still running; Forcefully terminating pid: "
<< pi.hProcess;
if (TerminateProcess(pi.hProcess, 127)) {
terminated = true;
}
}
} else {
VLOG(1) << "Accept never happend; Forcefully terminating pid: " << pi.hProcess;
if (TerminateProcess(pi.hProcess, 127)) {
terminated = true;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion bbs/stuffin.h
Expand Up @@ -55,7 +55,7 @@ namespace wwiv::bbs {
* %S Com port BPS rate "38400"
* %T Time remaining (min) "30"
* %U Username "Rushfan #1"
*
* %Z Socket port or path "12345" or "/wwiv/bbs/e/1/scratch/wwiv.sock"
* \endverbatim
*/
class CommandLine {
Expand Down
8 changes: 7 additions & 1 deletion install/docs/whatsnew.txt
Expand Up @@ -46,7 +46,13 @@ What's New in WWIV 5.7.1 (2021)
when using PIPE since the pipe name is hard coded to be
\\.\PIPE\WWIV# and \\.\PIPE\WWIV#C where # is the node number.
+ WWIVFOSS is now bundled with the OS/2 cpack target.
+
+ WWIV supports listening on either a TCP local socket port or an UNIX
socket for the door to connect back to instead of using socket passing
ala DOOR32 style. This works on both Windows and UNIX. Please note that
Windows 10 17063 or later is needed for AF_UNIX support on Windows.
This is handy for using QEMU from within BBS to run DOS based doors.
The port number or socket path will be available as a new (%Z) replacable
parameter from chainedit when using the selected chain execution mode.



Expand Down

0 comments on commit 22d37e1

Please sign in to comment.