Skip to content

Commit

Permalink
Merge pull request #1124 from elfmz/ttyx-experiment
Browse files Browse the repository at this point in the history
TTY clipboard improvements (touch #810)
  • Loading branch information
elfmz authored Dec 1, 2021
2 parents b17a56e + 9b4f961 commit 126a52b
Show file tree
Hide file tree
Showing 32 changed files with 1,210 additions and 330 deletions.
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,22 @@ else()
add_subdirectory(WinPort/src/Backend/WX)
endif()

if (NOT DEFINED TTYX)
find_package(X11)
if(X11_FOUND)
message(STATUS "Building with TTY X11 extensions due to X11 found")
add_subdirectory(WinPort/src/Backend/TTY/TTYX)
else()
message(STATUS "Building without TTY X11 extensions due to X11 not found")
endif()
elseif (TTYX)
message(STATUS "Building with TTY X11 extensions due to TTYX=${TTYX}")
add_subdirectory(WinPort/src/Backend/TTY/TTYX)
else()
message(STATUS "Building without TTY X11 extensions due to TTYX=${TTYX}")
endif()


##############################
# plugins directives

Expand Down Expand Up @@ -440,6 +456,7 @@ install(PROGRAMS "${INSTALL_DIR}/${EXECUTABLE_NAME}" DESTINATION "bin" RENAME fa
install(DIRECTORY "${INSTALL_DIR}/" DESTINATION "lib/far2l" USE_SOURCE_PERMISSIONS COMPONENT base FILES_MATCHING
PATTERN "colorer/base" EXCLUDE
PATTERN "far2l_gui.so"
PATTERN "far2l_ttyx.broker"
PATTERN "plug/*.far-plug-*"
PATTERN "plug/*.broker")

Expand Down
2 changes: 0 additions & 2 deletions NetRocks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ src/BackgroundTasks.cpp
src/Location.cpp
src/ConnectionsPool.cpp
src/ImportFarFtpSites.cpp
src/Host/IPC.cpp
src/Host/HostLocal.cpp
src/Host/HostRemote.cpp
src/UI/DialogUtils.cpp
Expand Down Expand Up @@ -56,7 +55,6 @@ src/Protocol/Protocol.cpp
set(PROTOCOL_SOURCES
src/Erroring.cpp
src/Host/HostRemoteBroker.cpp
src/Host/IPC.cpp
)


Expand Down
14 changes: 0 additions & 14 deletions NetRocks/src/Erroring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,3 @@ ServerIdentityMismatchError::ServerIdentityMismatchError(const std::string &iden
}

////////////

static std::string FormatIPCError(const char *msg, unsigned int code)
{
std::string s = msg;
char sz[32];
snprintf(sz, sizeof(sz) - 1, " (0x%x)", code);
s+= sz;
return s;
}

IPCError::IPCError(const char *msg, unsigned int code)
: std::runtime_error(TeeStr(FormatIPCError(msg, code)))
{
}
5 changes: 0 additions & 5 deletions NetRocks/src/Erroring.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ struct ServerIdentityMismatchError : std::runtime_error
ServerIdentityMismatchError(const std::string &identity);
};

struct IPCError : std::runtime_error
{
IPCError(const char *msg, unsigned int code);
};

struct AbortError : std::runtime_error
{
AbortError() : std::runtime_error("Operation aborted") {}
Expand Down
44 changes: 14 additions & 30 deletions NetRocks/src/Host/HostRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ void HostRemote::CheckReady()

void HostRemote::OnBroken()
{
IPCRecver::SetFD(-1);
IPCSender::SetFD(-1);
IPCEndpoint::SetFD(-1, -1);
_peer = 0;
}

Expand All @@ -171,31 +170,16 @@ void HostRemote::ReInitialize()
throw std::runtime_error("No server specified");
}

int master2broker[2] = {-1, -1};
int broker2master[2] = {-1, -1};
int r = pipe(master2broker);
if (r == 0) {
r = pipe(broker2master);
if (r != 0)
CheckedCloseFDPair(master2broker);
}
if (r != 0)
throw IPCError("pipe() error", errno);

fcntl(master2broker[1], F_SETFD, FD_CLOEXEC);
fcntl(broker2master[0], F_SETFD, FD_CLOEXEC);


std::string broker_path = StrWide2MB(G.plugin_path);
CutToSlash(broker_path, true);
std::string broker_pathname = broker_path;
broker_pathname+= pi->broker;
broker_pathname+= ".broker";
char arg1[32], arg2[32];
itoa(master2broker[0], arg1, 10);
itoa(broker2master[1], arg2, 10);

fprintf(stderr, "NetRocks: starting broker '%s' '%s' '%s'\n", broker_pathname.c_str(), arg1, arg2);
PipeIPCFD ipc_fd;

fprintf(stderr, "NetRocks: starting broker '%s' '%s' '%s'\n",
broker_pathname.c_str(), ipc_fd.broker_arg_r, ipc_fd.broker_arg_w);
const bool use_tsocks = G.GetGlobalConfigBool("UseProxy", false);
pid_t pid = fork();
if (pid == 0) {
Expand All @@ -211,7 +195,8 @@ void HostRemote::ReInitialize()
setenv("TSOCKS_CONFFILE", G.tsocks_config.c_str(), 1);
}
if (fork() == 0) {
execl(broker_pathname.c_str(), broker_pathname.c_str(), arg1, arg2, NULL);
execl(broker_pathname.c_str(),
broker_pathname.c_str(), ipc_fd.broker_arg_r, ipc_fd.broker_arg_w, NULL);
_exit(-1);
exit(-2);
}
Expand All @@ -225,11 +210,10 @@ void HostRemote::ReInitialize()
}
// G.info.FSF->Execute(cmdstr.c_str(), EF_HIDEOUT | EF_NOWAIT); //_interactive

CheckedCloseFD(master2broker[0]);
CheckedCloseFD(broker2master[1]);
IPCEndpoint::SetFD(ipc_fd.broker2master[0], ipc_fd.master2broker[1]);

IPCRecver::SetFD(broker2master[0]);
IPCSender::SetFD(master2broker[1]);
// so far so good - avoid automatic closing of pipes FDs in ipc_fd's d-tor
ipc_fd.Detach();

uint32_t ipc_ver_magic = 0;

Expand All @@ -241,12 +225,12 @@ void HostRemote::ReInitialize()

} catch (std::exception &) {
OnBroken();
throw std::runtime_error(StrPrintf("Failed to start '%s' '%s' '%s'", broker_path.c_str(), arg1, arg2));
throw std::runtime_error(StrPrintf("Failed to start '%s' '%s' '%s'", broker_path.c_str(), ipc_fd.broker_arg_r, ipc_fd.broker_arg_w));
}

if (ipc_ver_magic != IPC_VERSION_MAGIC) {
OnBroken();
throw std::runtime_error(StrPrintf("Wrong version of '%s' '%s' '%s'", broker_path.c_str(), arg1, arg2));
throw std::runtime_error(StrPrintf("Wrong version of '%s' '%s' '%s'", broker_path.c_str(), ipc_fd.broker_arg_r, ipc_fd.broker_arg_w));
}

std::unique_lock<std::mutex> locker(_mutex);
Expand Down Expand Up @@ -325,7 +309,7 @@ void HostRemote::ReInitialize()

default:
OnBroken();
throw IPCError("Unexpected protocol init status", status);
throw PipeIPCError("Unexpected protocol init status", status);
}
}
}
Expand Down Expand Up @@ -384,7 +368,7 @@ void HostRemote::RecvReply(IPCCommand cmd)
throw ProtocolUnsupportedError(str);
}

throw IPCError("Wrong command reply", (unsigned int)cmd);
throw PipeIPCError("Wrong command reply", (unsigned int)cmd);
}
}

Expand Down
2 changes: 1 addition & 1 deletion NetRocks/src/Host/HostRemote.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "../SitesConfig.h"

class HostRemote : protected IPCRecver, protected IPCSender, public std::enable_shared_from_this<HostRemote>, public IHost
class HostRemote : protected IPCEndpoint, public std::enable_shared_from_this<HostRemote>, public IHost
{
friend class HostRemoteDirectoryEnumer;
friend class HostRemoteFileIO;
Expand Down
4 changes: 2 additions & 2 deletions NetRocks/src/Host/HostRemoteBroker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class HostRemoteBroker : protected IPCEndpoint
case IPC_EXECUTE_COMMAND: OnExecuteCommand(); break;

default:
throw IPCError("HostRemoteBroker: bad command", (unsigned int)c);
throw PipeIPCError("HostRemoteBroker: bad command", (unsigned int)c);
}
}

Expand All @@ -309,7 +309,7 @@ class HostRemoteBroker : protected IPCEndpoint
SendPOD(IPC_PI_OK);
break;

} catch (IPCError &) {
} catch (PipeIPCError &) {
throw;

} catch (AbortError &) {
Expand Down
153 changes: 0 additions & 153 deletions NetRocks/src/Host/IPC.cpp

This file was deleted.

Loading

0 comments on commit 126a52b

Please sign in to comment.