Skip to content

Commit

Permalink
Add a frontend-backend version check
Browse files Browse the repository at this point in the history
Fixes #24
  • Loading branch information
rprichard committed Apr 22, 2018
1 parent 34ec0e4 commit 94e8b8c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions backend/wslbridge-backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,16 @@ void optionNotAllowed(const char *opt, const char *why, const T &val, const T &u
}
}

static void frontendVersionCheck(const char *frontendVersion) {
if (strcmp(frontendVersion, STRINGIFY(WSLBRIDGE_VERSION)) != 0) {
fprintf(stderr,
"error: wslbridge frontend-backend version mismatch"
" (frontend is version '%s', backend is version '%s')\n",
frontendVersion, STRINGIFY(WSLBRIDGE_VERSION));
exit(1);
}
}

} // namespace

int main(int argc, char *argv[]) {
Expand Down Expand Up @@ -519,10 +529,12 @@ int main(int argc, char *argv[]) {
// just to discard it.
{ "debug-fork", false, nullptr, 0 },
{ "version", false, nullptr, 'v' },
{ "check-version", true, nullptr, 'V' },
{ nullptr, false, nullptr, 0 },
};

int ch = 0;
bool versionChecked = false;
while ((ch = getopt_long(argc, argv, "+3:0:1:2:k:c:r:w:t:e:C:l", kOptionTable, nullptr)) != -1) {
switch (ch) {
case 0:
Expand All @@ -544,10 +556,19 @@ int main(int argc, char *argv[]) {
case 'v':
printf("wslbridge-backend " STRINGIFY(WSLBRIDGE_VERSION) "\n");
exit(0);
case 'V':
// Do the version check early before we choke on an unexpected
// argument from a mismatched frontend.
frontendVersionCheck(optarg);
versionChecked = true;
break;
default:
exit(1);
}
}
if (!versionChecked) {
frontendVersionCheck("<old>"); // The frontend predates the version-checking.
}
for (int i = optind; i < argc; ++i) {
childParams.argv.push_back(argv[i]);
}
Expand Down
2 changes: 2 additions & 0 deletions frontend/wslbridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,8 @@ int main(int argc, char *argv[]) {
appendBashArg(bashCmdLine, L"--debug-fork");
}

appendBashArg(bashCmdLine, L"--check-version=" STRINGIFY(WSLBRIDGE_VERSION));

std::array<wchar_t, 1024> buffer;
int iRet = swprintf(buffer.data(), buffer.size(),
L" -3%d -0%d -1%d -k%s -w%d -t%d",
Expand Down

0 comments on commit 94e8b8c

Please sign in to comment.