Skip to content

Bugfix/Ensure libssh is initialized#4812

Merged
tobe2098 merged 4 commits intomainfrom
bugfix/call-ssh-init-finalize
Apr 11, 2026
Merged

Bugfix/Ensure libssh is initialized#4812
tobe2098 merged 4 commits intomainfrom
bugfix/call-ssh-init-finalize

Conversation

@xmkg
Copy link
Copy Markdown
Member

@xmkg xmkg commented Apr 10, 2026

After migrating libssh to vcpkg, it started linking statically against the binary. With dynamic linkage, the DllMain function was already calling ssh_init() so everything was working as intended. This is no longer the case since DllMain is not being invoked in static linkage. Linux and macOS are still fine since there's the libssh_constructor func marked with __attribute__((constructor)), which works with gcc/clang but not with MSVC.

This PR ensures that the library is initialized before first use for both the daemon and the CLI.

  • What does this PR do?
    Ensures libssh is initialized.
  • Why is this change needed?
    Fix broken SSH in Windows.

MULTI-2535

xmkg added 2 commits April 10, 2026 22:23
Signed-off-by: Mustafa Kemal Gilor <mustafa.gilor@canonical.com>
After migrating libssh to vcpkg, it started linking statically against
the binary. With dynamic linkage, DllMain function were already calling
ssh_init() [1] so everything was working as intended. This no longer
the case since DllMain is not being invoked in static linkage. Linux
and macOS is still fine since there's the `libssh_constructor`[2] func
marked with __attribute__((constructor)), which works with gcc/clang
but not with MSVC.

This patch ensures that the library is initialized before first use.

[1]: https://github.com/canonical/libssh/blob/f23d1454e50d0dbb314edd9bf4227ab72303484b/src/init.c#L257
[2]: https://github.com/canonical/libssh/blob/f23d1454e50d0dbb314edd9bf4227ab72303484b/src/init.c#L59
Signed-off-by: Mustafa Kemal Gilor <mustafa.gilor@canonical.com>
@xmkg xmkg requested a review from tobe2098 April 10, 2026 19:33
xmkg added 2 commits April 10, 2026 22:35
Signed-off-by: Mustafa Kemal Gilor <mustafa.gilor@canonical.com>
Signed-off-by: Mustafa Kemal Gilor <mustafa.gilor@canonical.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.54%. Comparing base (13a02c9) to head (54f99ab).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4812   +/-   ##
=======================================
  Coverage   87.54%   87.54%           
=======================================
  Files         258      258           
  Lines       14155    14155           
=======================================
  Hits        12391    12391           
  Misses       1764     1764           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tobe2098 tobe2098 added this pull request to the merge queue Apr 11, 2026
Merged via the queue into main with commit 17fad92 Apr 11, 2026
27 checks passed
@tobe2098 tobe2098 deleted the bugfix/call-ssh-init-finalize branch April 11, 2026 08:23
tobe2098 added a commit that referenced this pull request Apr 11, 2026
After migrating libssh to vcpkg, it started linking statically against
the binary. With dynamic linkage, the DllMain function was [already
calling
ssh_init()](https://github.com/canonical/libssh/blob/f23d1454e50d0dbb314edd9bf4227ab72303484b/src/init.c#L257)
so everything was working as intended. This is no longer the case since
DllMain is not being invoked in static linkage. Linux and macOS are
still fine since there's the
[libssh_constructor](https://github.com/canonical/libssh/blob/f23d1454e50d0dbb314edd9bf4227ab72303484b/src/init.c#L59)
func marked with `__attribute__((constructor))`, which works with
gcc/clang but not with MSVC.

This PR ensures that the library is initialized before first use for
both the daemon and the CLI.

<!-- Please include a summary of the changes and the motivation behind
them. -->
- What does this PR do?
Ensures libssh is initialized.
- Why is this change needed?
Fix broken SSH in Windows.

MULTI-2535
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 this pull request may close these issues.

2 participants