Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Command line flags for query input and output#8786

Merged
directionless merged 13 commits into
osquery:masterfrom
directionless:seph/issue-8525-commandline-options
Apr 7, 2026
Merged

Command line flags for query input and output#8786
directionless merged 13 commits into
osquery:masterfrom
directionless:seph/issue-8525-commandline-options

Conversation

@directionless
Copy link
Copy Markdown
Member

@directionless directionless commented Mar 8, 2026

Fixes: #8525
Fixes: #8148
Fixes: #7972
Fixes: #7961

Reading #8525 I think there's merit to it. While in my go code, working with stdin and stdout is pretty simple, it does end up feeling uglier in other places. Especially in some exec wrappers where needing to use stdin means invoking a bash shell.

While I was here, I took at pass at fixing some of the other stdin related things. Or closing them, because I think we have more options.

So I have Claude Code take a shot at implementing these.

@directionless directionless marked this pull request as ready for review March 8, 2026 16:48
@directionless directionless requested review from a team as code owners March 8, 2026 16:48
Copy link
Copy Markdown
Member

@zwass zwass left a comment

Choose a reason for hiding this comment

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

Generally seems good to me. I think the section I commented on could be simplified. I'd feel better about the whole thing if it used more of the C++ style memory handling like scope_guard but I think much of this was adapted from the original SQLite C and I don't think we need to do that refactor here.

Comment thread osquery/devtools/shell.cpp Outdated
Comment on lines +1922 to +1955
// Run a single query from --query flag
rc = runQuery(&data, FLAGS_query.c_str());
if (rc != 0) {
if (output_file != nullptr) {
fclose(output_file);
}
if (data.prettyPrint != nullptr) {
delete data.prettyPrint;
}
return rc;
}
} else if (!FLAGS_query_file.empty()) {
// Read query from file and execute
std::string query_content;
auto status = readFile(FLAGS_query_file, query_content);
if (!status.ok()) {
fprintf(stderr,
"Error reading query file '%s': %s\n",
FLAGS_query_file.c_str(),
status.getMessage().c_str());
if (output_file != nullptr) {
fclose(output_file);
}
return 1;
}
rc = runQuery(&data, query_content.c_str());
if (rc != 0) {
if (output_file != nullptr) {
fclose(output_file);
}
if (data.prettyPrint != nullptr) {
delete data.prettyPrint;
}
return rc;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do these cases return rc when the cases above just set the rc and handle it below? It seems like it spreads out all the places where error handling needs to happen.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Probably because I told my robot to prefer early returns.

Anyhow, I moved this close (and the pretty print) one to scope guards and I cleaned this up. How's it look?

Copy link
Copy Markdown
Member

@zwass zwass left a comment

Choose a reason for hiding this comment

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

LGTM, always happy to see scope guard.

@directionless directionless merged commit 825b983 into osquery:master Apr 7, 2026
24 checks passed
@directionless directionless deleted the seph/issue-8525-commandline-options branch April 7, 2026 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

2 participants