Skip to content

Commit

Permalink
lxc/exec: Use operation to wait directly.
Browse files Browse the repository at this point in the history
When a user calls `lxc exec` the CLI calls ExecInstance, which in turn
attempts to set up an event listener to be used when interacting with
the resulting operation. However, this fails in the case where a user
does not have permission to view events in the project. Instead, we can
use the returned operation ID to wait for it to complete directly via
the API.

Signed-off-by: Mark Laing <mark.laing@canonical.com>
  • Loading branch information
markylaing committed Oct 5, 2023
1 parent a978626 commit 2ca90c9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lxc/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,14 @@ func (c *cmdExec) Run(cmd *cobra.Command, args []string) error {
}

// Wait for the operation to complete
err = op.Wait()
opAPI := op.Get()
if opAPI.Metadata != nil {
exitStatusRaw, ok := opAPI.Metadata["return"].(float64)
currentOp := op.Get()
finishedOp, _, err := d.GetOperationWait(currentOp.ID, -1)
if err != nil {
return err
}

if finishedOp.Metadata != nil {
exitStatusRaw, ok := finishedOp.Metadata["return"].(float64)
if ok {
c.global.ret = int(exitStatusRaw)
}
Expand Down

0 comments on commit 2ca90c9

Please sign in to comment.