[x] Request for enhancement (RFE)
231
NixOS
machinectl shell should forward the exit code of the process that it spawned inside the container. This makes it easier to use machinectl inside of scripts.
# machinectl shell <name> /bin/sh -c 'exit 1'
Connected to machine <name> Press ^] three times within 1s to exit session.
Connection to machine <name> terminated.
$ echo $?
0
# machinectl shell <name> /bin/sh -c 'exit 1'
Connected to machine <name> Press ^] three times within 1s to exit session.
Connection to machine <name> terminated.
$ echo $?
1
systemd-run --wait supports this now, and given the similarity of the concepts, adding this to machinectl shell would be a good idea and not hard to do.
I looked into this now, and I think implementing this would not be the best idea, as this would mean "machinectl shell" would have to acquire higher PK privileges than it currently does, and this functionality is pretty much redundant anyway, as "systemd-run --wait" implements this in a much more powerful and better way.
hence, for your usecase, please use "systemd-run --wait". The "machinectl shell" is more focussed on proper interactive user sessions in the container, like a full login sessions.
Background: "machinectl shell" currently invokes a machined bus funciton callen OpenMachineShell() which is pretty simple: after a PK authorization it returns a PTY file descriptor that has a shell on the other end. And that's really it, no further information is exchanged after that, except what is delivered directly via the kernel's pty device.
If we'd change this, and propagate exit status info like systemd-run, then we'd have to use a more complex API, that permits continously watching the unit state. This API is protected by a higher PK set, and I am not sure that's desriable to require for all cases...
Hope that makes sense.
I filed PR #4975 now, that adds a bit of documentation about this, and points users to use "systemd-run -M" when they look for things like exit status information.
Most helpful comment
I looked into this now, and I think implementing this would not be the best idea, as this would mean "machinectl shell" would have to acquire higher PK privileges than it currently does, and this functionality is pretty much redundant anyway, as "systemd-run --wait" implements this in a much more powerful and better way.
hence, for your usecase, please use "systemd-run --wait". The "machinectl shell" is more focussed on proper interactive user sessions in the container, like a full login sessions.
Background: "machinectl shell" currently invokes a machined bus funciton callen OpenMachineShell() which is pretty simple: after a PK authorization it returns a PTY file descriptor that has a shell on the other end. And that's really it, no further information is exchanged after that, except what is delivered directly via the kernel's pty device.
If we'd change this, and propagate exit status info like systemd-run, then we'd have to use a more complex API, that permits continously watching the unit state. This API is protected by a higher PK set, and I am not sure that's desriable to require for all cases...
Hope that makes sense.
I filed PR #4975 now, that adds a bit of documentation about this, and points users to use "systemd-run -M" when they look for things like exit status information.