-
-
Notifications
You must be signed in to change notification settings - Fork 4
feat(session): surface exec exit-status / exit-signal via SshSession.exitInfo #232
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -779,6 +779,38 @@ class FakeSshServer( | |
| } | ||
| } | ||
|
|
||
| /** SSH_MSG_CHANNEL_REQUEST `exit-status` (RFC 4254 section 6.10). */ | ||
| suspend fun sendChannelExitStatus(recipientChannel: Int, exitStatus: Int) { | ||
| val payload = ByteArrayOutputStream() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should be able to use the |
||
| payload.write(ByteBuffer.allocate(4).putInt(recipientChannel).array()) | ||
| payload.writeString("exit-status".toByteArray(Charsets.US_ASCII)) | ||
| payload.write(0) // want_reply = false | ||
| payload.write(ByteBuffer.allocate(4).putInt(exitStatus).array()) | ||
| writeMutex.withLock { | ||
| serverIo.writePacket(SshEnums.MessageType.SSH_MSG_CHANNEL_REQUEST.id().toInt(), payload.toByteArray()) | ||
| } | ||
| } | ||
|
|
||
| /** SSH_MSG_CHANNEL_REQUEST `exit-signal` (RFC 4254 section 6.10). */ | ||
| suspend fun sendChannelExitSignal( | ||
| recipientChannel: Int, | ||
| signalName: String, | ||
| coreDumped: Boolean = false, | ||
| errorMessage: String = "", | ||
| ) { | ||
| val payload = ByteArrayOutputStream() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should be able to use the |
||
| payload.write(ByteBuffer.allocate(4).putInt(recipientChannel).array()) | ||
| payload.writeString("exit-signal".toByteArray(Charsets.US_ASCII)) | ||
| payload.write(0) // want_reply = false | ||
| payload.writeString(signalName.toByteArray(Charsets.US_ASCII)) | ||
| payload.write(if (coreDumped) 1 else 0) | ||
| payload.writeString(errorMessage.toByteArray(Charsets.UTF_8)) | ||
| payload.writeString(ByteArray(0)) // language tag | ||
| writeMutex.withLock { | ||
| serverIo.writePacket(SshEnums.MessageType.SSH_MSG_CHANNEL_REQUEST.id().toInt(), payload.toByteArray()) | ||
| } | ||
| } | ||
|
|
||
| suspend fun sendChannelEof(recipientChannel: Int) { | ||
| val payload = ByteBuffer.allocate(4).putInt(recipientChannel).array() | ||
| writeMutex.withLock { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the RFC says this should be
uint32, but this is converting to integer here. PreferLongto preserve the full range. It might be prudent to add a test for the 0xffff_ffffL boundary condition as well.