From 052c7632321ce29932694ec325ca9537ae5aab8f Mon Sep 17 00:00:00 2001 From: Biswapriyo Nath Date: Sun, 8 Apr 2018 01:09:53 +0530 Subject: [PATCH 1/2] add backend path from command --- frontend/wslbridge.cc | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/frontend/wslbridge.cc b/frontend/wslbridge.cc index d483b82..82c8d73 100644 --- a/frontend/wslbridge.cc +++ b/frontend/wslbridge.cc @@ -484,6 +484,18 @@ static std::wstring findBackendProgram() { return ret; } +static std::wstring getBackendPath(char* cPath) { + wchar_t path[MAX_PATH]; + mbstowcs(path, cPath, MAX_PATH); + std::wstring progDir = std::wstring(path); + std::wstring ret = progDir + (L"\\" BACKEND_PROGRAM); + if (!pathExists(ret)) { + fatal("error: '%s' backend program is missing\n", + wcsToMbs(ret).c_str()); + } + return ret; +} + static wchar_t lowerDrive(wchar_t ch) { if (ch >= L'a' && ch <= L'z') { return ch; @@ -620,6 +632,7 @@ static void usage(const char *prog) { printf(" An initial '~' indicates the WSL home directory.\n"); printf(" -e VAR Copies VAR into the WSL environment.\n"); printf(" -e VAR=VAL Sets VAR to VAL in the WSL environment.\n"); + printf(" -p path Path for wslbridge-backend.\n"); printf(" -T Do not use a pty.\n"); printf(" -t Use a pty (as long as stdin is a tty).\n"); printf(" -t -t Force a pty (even if stdin is not a tty).\n"); @@ -981,6 +994,7 @@ int main(int argc, char *argv[]) { Environment env; std::string spawnCwd; + auto backendPathInfo = normalizePath(findBackendProgram());; std::string distroGuid; enum class TtyRequest { Auto, Yes, No, Force } ttyRequest = TtyRequest::Auto; @@ -993,7 +1007,7 @@ int main(int argc, char *argv[]) { { "distro-guid", true, nullptr, 'd' }, { nullptr, false, nullptr, 0 }, }; - while ((c = getopt_long(argc, argv, "+e:C:tT", kOptionTable, nullptr)) != -1) { + while ((c = getopt_long(argc, argv, "+e:C:p:tT", kOptionTable, nullptr)) != -1) { switch (c) { case 0: // Ignore long option. @@ -1020,6 +1034,11 @@ int main(int argc, char *argv[]) { case 'h': usage(argv[0]); break; + case 'p': + if(optarg) { + backendPathInfo = normalizePath(getBackendPath(optarg)); + } + break; case 't': if (ttyRequest == TtyRequest::Yes) { ttyRequest = TtyRequest::Force; @@ -1083,7 +1102,7 @@ int main(int argc, char *argv[]) { } const auto bashPath = findSystemProgram(L"bash.exe"); - const auto backendPathInfo = normalizePath(findBackendProgram()); + //const auto backendPathInfo = normalizePath(findBackendProgram()); const auto backendPathWin = backendPathInfo.first; const auto fsname = backendPathInfo.second; const auto backendPathWsl = convertPathToWsl(backendPathWin); From 48fa325f88c0f17b47d9600f008afd29fca64379 Mon Sep 17 00:00:00 2001 From: Biswapriyo Nath Date: Fri, 13 Apr 2018 00:43:02 +0530 Subject: [PATCH 2/2] Fix to obtain backend path replace `-p` option with `-b` or `--backend` option in `getopt_long()`. And add the path in findBackendProgram() function. --- frontend/wslbridge.cc | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/frontend/wslbridge.cc b/frontend/wslbridge.cc index 82c8d73..8b13278 100644 --- a/frontend/wslbridge.cc +++ b/frontend/wslbridge.cc @@ -474,21 +474,13 @@ static std::wstring getModuleFileName(HMODULE module) { return std::wstring(path); } -static std::wstring findBackendProgram() { - std::wstring progDir = dirname(getModuleFileName(getCurrentModule())); +static std::wstring findBackendProgram(std::string backendPath) { + std::wstring progDir = mbsToWcs(backendPath); std::wstring ret = progDir + (L"\\" BACKEND_PROGRAM); if (!pathExists(ret)) { - fatal("error: '%s' backend program is missing\n", - wcsToMbs(ret).c_str()); + progDir = dirname(getModuleFileName(getCurrentModule())); + ret = progDir + (L"\\" BACKEND_PROGRAM); } - return ret; -} - -static std::wstring getBackendPath(char* cPath) { - wchar_t path[MAX_PATH]; - mbstowcs(path, cPath, MAX_PATH); - std::wstring progDir = std::wstring(path); - std::wstring ret = progDir + (L"\\" BACKEND_PROGRAM); if (!pathExists(ret)) { fatal("error: '%s' backend program is missing\n", wcsToMbs(ret).c_str()); @@ -628,11 +620,11 @@ static void usage(const char *prog) { printf("Runs a program within a Windows Subsystem for Linux (WSL) pty\n"); printf("\n"); printf("Options:\n"); + printf(" -b path Path of only folder where wslbridge-backend present.\n"); printf(" -C WSLDIR Changes the working directory to WSLDIR first.\n"); printf(" An initial '~' indicates the WSL home directory.\n"); printf(" -e VAR Copies VAR into the WSL environment.\n"); printf(" -e VAR=VAL Sets VAR to VAL in the WSL environment.\n"); - printf(" -p path Path for wslbridge-backend.\n"); printf(" -T Do not use a pty.\n"); printf(" -t Use a pty (as long as stdin is a tty).\n"); printf(" -t -t Force a pty (even if stdin is not a tty).\n"); @@ -993,25 +985,32 @@ int main(int argc, char *argv[]) { } Environment env; + std::string backendPath; std::string spawnCwd; - auto backendPathInfo = normalizePath(findBackendProgram());; std::string distroGuid; enum class TtyRequest { Auto, Yes, No, Force } ttyRequest = TtyRequest::Auto; int debugFork = 0; int c = 0; const struct option kOptionTable[] = { + { "backend", true, nullptr, 'b' }, { "help", false, nullptr, 'h' }, { "debug-fork", false, &debugFork, 1 }, { "version", false, nullptr, 'v' }, { "distro-guid", true, nullptr, 'd' }, { nullptr, false, nullptr, 0 }, }; - while ((c = getopt_long(argc, argv, "+e:C:p:tT", kOptionTable, nullptr)) != -1) { + while ((c = getopt_long(argc, argv, "+b:e:C:tT", kOptionTable, nullptr)) != -1) { switch (c) { case 0: // Ignore long option. break; + case 'b': + backendPath = optarg; + if (backendPath.empty()) { + fatal("error: the -b option requires a non-empty string argument"); + } + break; case 'e': { const char *eq = strchr(optarg, '='); const auto varname = eq ? std::string(optarg, eq - optarg) : std::string(optarg); @@ -1034,11 +1033,6 @@ int main(int argc, char *argv[]) { case 'h': usage(argv[0]); break; - case 'p': - if(optarg) { - backendPathInfo = normalizePath(getBackendPath(optarg)); - } - break; case 't': if (ttyRequest == TtyRequest::Yes) { ttyRequest = TtyRequest::Force; @@ -1102,7 +1096,7 @@ int main(int argc, char *argv[]) { } const auto bashPath = findSystemProgram(L"bash.exe"); - //const auto backendPathInfo = normalizePath(findBackendProgram()); + const auto backendPathInfo = normalizePath(findBackendProgram(backendPath)); const auto backendPathWin = backendPathInfo.first; const auto fsname = backendPathInfo.second; const auto backendPathWsl = convertPathToWsl(backendPathWin);