-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Replace popen('uname -ap') with uname() syscall in bvar kernel_version #3517
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
Open
weim0000
wants to merge
5
commits into
apache:master
Choose a base branch
from
weim0000:fix_uname
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+62
−3
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7b6d678
Replace popen('uname -ap') with uname() syscall in bvar kernel_version
3c83555
Update processor variable assignment for Apple platforms
weim0000 4877659
update unittest add <string.h>
4f67f87
update unittest for bvar_variable kernel_version
432abde
Fix kernel_version to match uname -ap output format across platforms
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| #include <unistd.h> // getpagesize | ||
| #include <sys/types.h> | ||
| #include <sys/resource.h> // getrusage | ||
| #include <sys/utsname.h> // uname | ||
| #include <dirent.h> // dirent | ||
| #include <iomanip> // setw | ||
| #include <stdio.h> | ||
|
|
@@ -617,11 +618,26 @@ static void get_cmdline(std::ostream& os, void*) { | |
| struct ReadVersion { | ||
| std::string content; | ||
| ReadVersion() { | ||
| std::ostringstream oss; | ||
| if (butil::read_command_output(oss, "uname -ap") != 0) { | ||
| struct utsname buf; | ||
| if (uname(&buf) != 0) { | ||
| LOG(ERROR) << "Fail to read kernel version"; | ||
| return; | ||
| } | ||
| #if defined(__APPLE__) && (defined(__aarch64__) || defined(__arm64__)) | ||
| const char* processor = "arm"; | ||
| #elif defined(__APPLE__) && defined(__x86_64__) | ||
| const char* processor = "i386"; | ||
| #else | ||
| const char* processor = buf.machine; | ||
| #endif | ||
| std::ostringstream oss; | ||
| oss << buf.sysname << ' ' << buf.nodename << ' ' | ||
| << buf.release << ' ' << buf.version << ' ' | ||
| << buf.machine << ' ' << processor; | ||
| #if !defined(__APPLE__) | ||
| oss << " GNU/Linux"; | ||
| #endif | ||
| oss << '\n'; | ||
|
Author
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. @wwbmmm here |
||
| content.append(oss.str()); | ||
| } | ||
| }; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The reconstructed output is not byte-equivalent to
uname -apas stated in the PR. On Linux,uname -apappends the operating-system identifier as the final field, e.g.... aarch64 GNU/Linux; this new code stops atmachine processorand drops that OS field entirely. Additionally,uname(1)omits a field whose value is the literal string "unknown" (common foruname -p), whereas this code always appendsprocessor(here equal tobuf.machine, producing a duplicatedmachinevalue).If exact parity with the previous output is required (e.g. for scrapers/keying off the string), either append the proper OS name field (
GNU/Linuxon Linux; none on macOS) and mirror uname's handling of "unknown", or update the PR description to not claim the output format is preserved. Since these fields are informational this may be acceptable, but the claim and the format should match.🤖 This reply was automatically generated by brpc-oncall
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.
'GNU/Linux' has been added here. Please take a look at the following four lines of code
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.
@wwbmmm Please check the latest code,thanks