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

Use udev for getting serial number #63

Merged
merged 1 commit into from
Sep 28, 2018
Merged

Use udev for getting serial number #63

merged 1 commit into from
Sep 28, 2018

Conversation

jpo-joyent
Copy link
Contributor

We already depend on udev anyway.

See also / fixes: #59

We already depend on udev anyway.

See also / fixes: #59
Copy link
Owner

@jaypipes jaypipes left a 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") {
Copy link
Owner

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.

Copy link
Contributor Author

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) {
Copy link
Owner

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 {
Copy link
Owner

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")
}
Copy link
Owner

Choose a reason for hiding this comment

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

++

@jaypipes jaypipes merged commit dc69682 into jaypipes:master Sep 28, 2018
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.

More reliable vendor/serial/path extraction via udev
2 participants