Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HPC: Ensure load balancer finds hq when located in same directory #59

Open
linusseelinger opened this issue Feb 26, 2024 · 3 comments · May be fixed by #67
Open

HPC: Ensure load balancer finds hq when located in same directory #59

linusseelinger opened this issue Feb 26, 2024 · 3 comments · May be fixed by #67

Comments

@linusseelinger
Copy link
Member

Currently needs PATH variable to be extended by location of hq

@Crambor
Copy link
Collaborator

Crambor commented Feb 28, 2024

Would it be fine to implement a function that checks for the existence of this binary in PATH and expands for execution?

proof of concept below (excluding any checks for whether this binary is executable):

#include <cstdlib>
#include <iostream>
#include <string>
#include <filesystem>
#include <vector>

std::string findBinary() {
    std::vector<std::string> pathsToCheck;

    // Check in PATH
    if (const char* env_p = std::getenv("PATH")) {
        std::string pathEnv = env_p;
        std::string delimiter = ":";
        size_t pos = 0;
        while ((pos = pathEnv.find(delimiter)) != std::string::npos) {
            pathsToCheck.push_back(pathEnv.substr(0, pos));
            pathEnv.erase(0, pos + delimiter.length());
        }
        pathsToCheck.push_back(pathEnv);
    }

    // Also check current directory
    pathsToCheck.push_back(".");

    for (const auto& path : pathsToCheck) {
        std::filesystem::path fullPath = path + "/hq";
        if (std::filesystem::exists(fullPath) && std::filesystem::is_regular_file(fullPath)) {
            return fullPath;
        }
    }

    throw std::runtime_error("Error: 'hq' binary not found in PATH or current directory.");
}

int main() {
    std::string hqBinaryPath;
    try {
        hqBinaryPath = findBinary();
        std::cout << "Found hq binary at: " << hqBinaryPath << std::endl;
    } catch (const std::runtime_error& e) {
        std::cerr << e.what() << std::endl;
        return EXIT_FAILURE;
    }
    return EXIT_SUCCESS;
}

@linusseelinger
Copy link
Member Author

I wonder if a hq installation outside the load balancer directory is realistic, so maybe we should just directly call ./hq ?
Playing devil's advocate, I just tried creating a directory with a colon in its name, turns out that is valid and would break the parser

@linusseelinger
Copy link
Member Author

Quickly fixed by recent commit. Additionally checking for hq binary as in #67 would be nicer though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants