libstore: add log-fd to ssh-ng as well

this way we can get ssh error message if connection setup fails.

Change-Id: Ifc001f77ec0477fb9786f7767a47f3745d6475ff
This commit is contained in:
eldritch horrors
2025-07-14 17:02:30 +00:00
parent d20c3d3643
commit 334b8e2b20
3 changed files with 42 additions and 14 deletions
+2 -2
View File
@@ -71,12 +71,12 @@ try {
StoreConfig::Params storeParams;
if (storeUri.starts_with("ssh://")) {
pipe.create();
storeParams["log-fd"] = std::to_string(pipe.writeSide.get());
storeParams["max-connections"] = "1";
}
if (storeUri.starts_with("ssh://") || storeUri.starts_with("ssh-ng://")) {
pipe.create();
storeParams["log-fd"] = std::to_string(pipe.writeSide.get());
if (sshKey != "")
storeParams["ssh-key"] = sshKey;
if (sshPublicHostKey != "")
+34 -10
View File
@@ -28,27 +28,51 @@ struct SSHStoreConfig : virtual RemoteStoreConfig, virtual CommonSSHStoreConfig
}
};
struct SSHStoreConfigWithLog : SSHStoreConfig
{
SSHStoreConfigWithLog(const Params & params)
: StoreConfig(params)
, RemoteStoreConfig(params)
, CommonSSHStoreConfig(params)
, SSHStoreConfig(params)
{
}
// Hack for getting ssh errors into build-remote.
// Intentionally not in `SSHStoreConfig` so that it doesn't appear in
// the documentation
const Setting<int> logFD{
this, -1, "log-fd", "file descriptor to which SSH's stderr is connected"
};
};
class SSHStore final : public RemoteStore
{
SSHStoreConfig config_;
SSHStoreConfigWithLog config_;
public:
SSHStore(const std::string & scheme, const std::string & host, SSHStoreConfig config)
SSHStore(const std::string & scheme, const std::string & host, SSHStoreConfigWithLog config)
: Store(config)
, RemoteStore(config)
, config_(std::move(config))
, host(host)
, ssh(
host,
config_.port,
config_.sshKey,
config_.sshPublicHostKey,
config_.compress)
, ssh(host,
config_.port,
config_.sshKey,
config_.sshPublicHostKey,
config_.compress,
config_.logFD)
{
}
SSHStoreConfig & config() override { return config_; }
const SSHStoreConfig & config() const override { return config_; }
SSHStoreConfigWithLog & config() override
{
return config_;
}
const SSHStoreConfigWithLog & config() const override
{
return config_;
}
static std::set<std::string> uriSchemes() { return {"ssh-ng"}; }
+6 -2
View File
@@ -30,8 +30,12 @@ private:
void addCommonSSHOpts(Strings & args);
public:
SSH(const std::string & host, const std::optional<uint16_t> port, const std::string & keyFile, const std::string & sshPublicHostKey, bool compress, int logFD = -1);
SSH(const std::string & host,
const std::optional<uint16_t> port,
const std::string & keyFile,
const std::string & sshPublicHostKey,
bool compress,
int logFD);
struct Connection
{