Skip to content
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

Fixes for ShellExecutioner #16

Merged
merged 2 commits into from
Oct 4, 2024
Merged

Fixes for ShellExecutioner #16

merged 2 commits into from
Oct 4, 2024

Conversation

cjonesy
Copy link
Contributor

@cjonesy cjonesy commented Oct 4, 2024

Some fixes for ShellExecutioner based on my experience using it more extensively.

  • Resolving an issue where output pipe is still reading when the command completes, logging an error. This was caused by calling .Close() on the pipe instead of letting it close itself (as indicated in the documentation of os/exec).
  • Enabling the ability to pass options for the shell
  • Removing the need to write the command to disk before running it, this was unnecessary and just added more stuff to cleanup.
  • Fixing log output of ShellExecutioner - prior to this a failed command's output would be logged as INFO. It now logs correctly as ERROR.
  • Fixing bug where using the TimeWatcher to send data to ShellExecutioner causes a panic:
    panic: interface conversion: interface {} is time.Time, not string. The change channel is interface{}, but I had always intended for this time value to be passed as a string.

@cjonesy cjonesy requested a review from a team as a code owner October 4, 2024 14:53
@cjonesy cjonesy requested review from ruffin and rthrelkeld8 October 4, 2024 14:53
@@ -18,7 +19,7 @@ const (
DataEnvVarName = "GOVERSEER_DATA"

// DefaultShell is the default shell to use when executing a command
DefaultShell = "/bin/sh"
DefaultShell = "/bin/sh -ec"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting a sane default here, -e makes it exit on error. -c tells sh to run the string of commands in a shell session.

@@ -146,8 +147,26 @@ func New(cfg config.Config) (*ShellExecutioner, error) {
}, nil
}

func (e *ShellExecutioner) enableOutputStreaming(cmd *exec.Cmd) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Execute function was getting crowded, moved this out to make it a bit easier to read.

@cjonesy cjonesy merged commit f38c347 into main Oct 4, 2024
4 checks passed
@cjonesy cjonesy deleted the shell-executioner-fixes branch October 4, 2024 15:33
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