-
Notifications
You must be signed in to change notification settings - Fork 174
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
Use udev for getting serial number #63
Conversation
We already depend on udev anyway. See also / fixes: #59
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.
Nice work, @jpo-joyent :) Thanks so much for your contribution!
} | ||
|
||
udevInfo := make(map[string]string) | ||
for _, udevLine := range strings.Split(string(udevBytes), "\n") { |
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.
Might be nice to include a code comment that demonstrates what the output of cat /run/udev/data/b{devNo}
looks like. That way, future readers of the code in the block below understand what's going on with the strings.SplitN() and HasPrefix() stuff.
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.
Alternatively, #66
@@ -74,53 +74,41 @@ func DiskVendor(disk string) string { | |||
return strings.TrimSpace(string(contents)) | |||
} | |||
|
|||
func udevInfo(disk string) (map[string]string, error) { |
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.
A short docstring describing what is in the returned map would be cool (future patch, though, not needed in this one)
|
||
// There are two serial number keys, ID_SERIAL and ID_SERIAL_SHORT | ||
// The non-_SHORT version often duplicates vendor information collected elsewhere, so use _SHORT. | ||
if path, ok := info["ID_SERIAL_SHORT"]; ok { |
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.
Might be worth putting "ID_SERIAL_SHORT" into a string const at the top of the file.
|
||
func pathRunUdevData() string { | ||
return filepath.Join(pathRoot(), "run", "udev", "data") | ||
} |
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.
++
We already depend on udev anyway.
See also / fixes: #59