Skip to content

migrations: make libc check more resilient #3665

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

Merged
merged 1 commit into from
Feb 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions repo/fsrepo/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func migrationsVersion(bin string) (int, error) {
vs := strings.Trim(string(out), " \n\t")
vn, err := strconv.Atoi(vs)
if err != nil {
return 0, fmt.Errorf("migrations binary version check did not return a number")
return 0, fmt.Errorf("migrations binary version check did not return a number: %s", err)
}

return vn, nil
Expand Down Expand Up @@ -253,17 +253,19 @@ func osWithVariant() (string, error) {
return "", fmt.Errorf("failed to resolve go-ipfs: %s", err)
}

cmd := exec.Command("ldd", bin)
// ldd outputs the system's kind of libc
// - on standard ubuntu: ldd (Ubuntu GLIBC 2.23-0ubuntu5) 2.23
// - on alpine: musl libc (x86_64)
cmd := exec.Command("ldd --version", bin)
buf := new(bytes.Buffer)
cmd.Stdout = buf
err = cmd.Run()
if err != nil {
return "", fmt.Errorf("failed to run ldd: %s", err)
}
// we throw away the error, this code path must not fail because of
// a silly issue such as missing/broken ldd. we'll assume glibc in that case.
_ = cmd.Run()

scan := bufio.NewScanner(buf)
for scan.Scan() {
if strings.Contains(scan.Text(), "libc") && strings.Contains(scan.Text(), "musl") {
if strings.Contains(scan.Text(), "musl") {
return "linux-musl", nil
}
}
Expand Down