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

segfault on Gentoo #902

Closed
dm9pZCAq opened this issue Sep 10, 2021 · 9 comments
Closed

segfault on Gentoo #902

dm9pZCAq opened this issue Sep 10, 2021 · 9 comments
Labels
help wanted Extra attention is needed

Comments

@dm9pZCAq
Copy link
Contributor

Describe the bug
segfault when running gitui

To Reproduce
Steps to reproduce the behavior:
run gitui on eny directory

Context (please complete the following information):

Additional context
with gitui-0.16.2 everything works fine, but with same ebuild but for 0.17.1 after successful build, it's segfaults at runtime

firstly i was think this is because of git_branch name is_valid but my tests compiles and runs fine

C
#include <stdio.h>
#include <git2/branch.h>

#define LEN(X) (sizeof(X) / sizeof *(X))

int
main(void)
{

	size_t	    i;
	int	    status  = -1;
	const char *tests[] = {
		"refs/heads/name",
		"master",
		"-master",
	};

	for (i = 0; i < LEN(tests); i -= (~0L), status = -1) {
		printf("git_branch_name_is_valid(%s) -> %d, ",
		       tests[i],
		       git_branch_name_is_valid(&status, tests[i]));
		printf("status %d\n", status);
	}

	return 0;
}

out:

git_branch_name_is_valid(refs/heads/name) -> -1, status 0
git_branch_name_is_valid(master) -> -1, status 0
git_branch_name_is_valid(-master) -> 0, status 0

lddtree:

a.out => ./a.out (interpreter => /lib/ld-musl-x86_64.so.1)
    libgit2.so.1.2 => /usr/lib/libgit2.so.1.2
        libssl.so.1.1 => /usr/lib/libssl.so.1.1
        libcrypto.so.1.1 => /usr/lib/libcrypto.so.1.1
        libpcre.so.1 => /lib/libpcre.so.1
        libhttp_parser.so.2.9 => /usr/lib/libhttp_parser.so.2.9
        libz.so.1 => /lib/libz.so.1
        libssh2.so.1 => /usr/lib/libssh2.so.1
    libc.so => /usr/lib/libc.so

rust
use git2::Branch;

type BoxedErr = Box<dyn(::std::error::Error)>;
type Result<T> = ::std::result::Result<T, BoxedErr>;

fn main() -> Result<()> {
    for name in ["refs/heads/name", "master", "-master"] {
        let valid = Branch::name_is_valid(name)?;
        println!("{:#?}", valid);
    }

    Ok(())
}

out:

true
true
false

lddtree:

Test => ./target/debug/Test (interpreter => /lib/ld-musl-x86_64.so.1)
    libgit2.so.1.2 => /usr/lib/libgit2.so.1.2
        libpcre.so.1 => /lib/libpcre.so.1
        libhttp_parser.so.2.9 => /usr/lib/libhttp_parser.so.2.9
        libz.so.1 => /lib/libz.so.1
        libssh2.so.1 => /usr/lib/libssh2.so.1
    libssl.so.1.1 => /usr/lib/libssl.so.1.1
    libcrypto.so.1.1 => /usr/lib/libcrypto.so.1.1
    libgcc_s.so.1 => /usr/lib/gcc/x86_64-gentoo-linux-musl/11.2.0/libgcc_s.so.1
    libc.so => /usr/lib/libc.so

strace gitui

maybe you know what it could be?

@extrawurst extrawurst changed the title yet another segfault on Gentoo segfault on Gentoo Sep 10, 2021
@extrawurst extrawurst added the help wanted Extra attention is needed label Sep 10, 2021
@extrawurst
Copy link
Owner

extrawurst commented Sep 10, 2021

I am clearly not enough of a linux pro for this. on my ubuntu box for dummies everything seems to works. did you try with the stock libgit2 1.2.0?

also can you run it in a debugger so we get a useful callstack where it crashes?

@dm9pZCAq also I am curious: what added value the issue description "yet another" had?

@dm9pZCAq
Copy link
Contributor Author

also can you run it in a debugger so we get a useful callstack where it crashes?

can you recommend some useful tools for rust debugging?

what added value the issue description "yet another" had?

because that's "yet another" weird segfault on Gentoo (first is here #459)

@dm9pZCAq
Copy link
Contributor Author

ok, with best debug tool (putting dbg! after each line in fn main) i find out that segfault caused by this line

asyncgit::register_tracing_logging();

after i commented it out, everything works fine

@dm9pZCAq
Copy link
Contributor Author

for me, this causes segfault too

#include <stdio.h>
#include <git2/trace.h>

void
callback(git_trace_level_t level, const char *msg)
{
	puts(msg);
}

int
main(void)
{
	printf("%d\n", git_trace_set(GIT_TRACE_TRACE, callback));
	return 0;
}

i'll go figure it out...

@dm9pZCAq
Copy link
Contributor Author

ok, i figured out...

the problem was that i compiled libgit2 without tracing support (-DENABLE_TRACE=OFF)

gitui is only package on my system, that requires tracing from libgit

maybe it would be better to add --feature for libgit tracing, and users that don't need it, will be able to disable it?

@extrawurst
Copy link
Owner

ok, i figured out...

the problem was that i compiled libgit2 without tracing support (-DENABLE_TRACE=OFF)

gitui is only package on my system, that requires tracing from libgit

maybe it would be better to add --feature for libgit tracing, and users that don't need it, will be able to disable it?

afaik tracing is on by default. so yeah maybe a note in the readme to mention that we require this to be enabled would make sense

@dm9pZCAq
Copy link
Contributor Author

tracing is on by default

on most distros yes, but on Gentoo you have choice what to use and this is not enabled by default

@dm9pZCAq
Copy link
Contributor Author

this is how i did it:


it can be enabled by default, but have this choice will be cool

?

asyncgit/src/lib.rs:

///
#[cfg(feature = "trace-libgit")]
pub fn register_tracing_logging() -> bool {
    fn git_trace(level: git2::TraceLevel, msg: &str) {
        log::info!("[{:?}]: {}", level, msg);
    }
    git2::trace_set(git2::TraceLevel::Trace, git_trace)
}

///
#[cfg(not(feature = "trace-libgit"))]
pub fn register_tracing_logging() -> bool {
    true
}

and add feature to Cargo.toml

@extrawurst
Copy link
Owner

@dm9pZCAq I gladly accept a PR for this 👍

@dm9pZCAq dm9pZCAq mentioned this issue Sep 10, 2021
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants