woodruffw / screenfetch-c

A rewrite of screenFetch in C.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

segmentation fault

m-wells opened this issue · comments

I'm using Arch Linux (3.18.5-1 kernel). With a fresh clone I get the following issue.

:> make
Testing for X11...
gcc -O3 -std=c99 -Wall -Wformat -Wunused-variable -pedantic -Wno-unused-result ./tests/x11test.c -o ./x11test -lX11
Looks good.
Testing for OpenGL...
gcc -O3 -std=c99 -Wall -Wformat -Wunused-variable -pedantic -Wno-unused-result ./tests/gltest.c -o ./gltest -lGL
Looks good.
gcc -O3 -std=c99 -Wall -Wformat -Wunused-variable -pedantic -Wno-unused-result -D_POSIX_C_SOURCE=200112L -c src/logos.c -o src/logos.o
gcc -O3 -std=c99 -Wall -Wformat -Wunused-variable -pedantic -Wno-unused-result -D_POSIX_C_SOURCE=200112L -c src/util.c -o src/util.o
gcc -O3 -std=c99 -Wall -Wformat -Wunused-variable -pedantic -Wno-unused-result -D_POSIX_C_SOURCE=200112L -c src/main.c -o src/main.o
gcc -O3 -std=c99 -Wall -Wformat -Wunused-variable -pedantic -Wno-unused-result -D_POSIX_C_SOURCE=200112L -c src/arrays.c -o src/arrays.o
gcc -O3 -std=c99 -Wall -Wformat -Wunused-variable -pedantic -Wno-unused-result -D_POSIX_C_SOURCE=200112L -c src/disp.c -o src/disp.o
gcc -O3 -std=c99 -Wall -Wformat -Wunused-variable -pedantic -Wno-unused-result -D_POSIX_C_SOURCE=200112L -c src/error_flag.c -o src/error_flag.o
gcc -O3 -std=c99 -Wall -Wformat -Wunused-variable -pedantic -Wno-unused-result -D_POSIX_C_SOURCE=200112L -c src/plat/linux/detect.c -o src/plat/linux/detect.o
gcc -O3 -std=c99 -Wall -Wformat -Wunused-variable -pedantic -Wno-unused-result -D_POSIX_C_SOURCE=200112L ./src/logos.o ./src/util.o ./src/main.o ./src/arrays.o ./src/disp.o ./src/error_flag.o ./src/plat/linux/detect.o -o ./screenfetch-c  -lX11 -lGL

:> ./screenfetch-c 
[[ ! ]] Error: No desktop environment found.
Segmentation fault (core dumped)

Any idea what is going on here?

I have libgl and libX11 installed.

Well, the segfault's occurring after detect_de, which means that it's either in detect_wm, detect_wm_theme, or detect_gtk. Of those, detect_wm is the most likely because of its EWMH pointer voodoo.

Could you run a backtrace of the binary in gdb or a similar tool? Also, what window manager are you using? If it isn't EWMH compliant, it could be that I'm missing a failsafe somewhere.

Thanks for reporting this.

Best,
William

:> gdb screenfetch-c 
GNU gdb (GDB) 7.8.2
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from screenfetch-c...done.
(gdb) run
Starting program: /home/mark/builds/screenfetch-c/screenfetch-c 
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[New Thread 0x7fffef88d700 (LWP 1741)]
[Thread 0x7fffef88d700 (LWP 1741) exited]
[[ ! ]] Error: No desktop environment found.

Program received signal SIGSEGV, Segmentation fault.
0x000000000040428c in detect_wm () at src/plat/linux/detect.c:655
655             if (!(XGetWindowProperty(disp, *wm_check_window,
(gdb) bt
#0  0x000000000040428c in detect_wm () at src/plat/linux/detect.c:655
#1  0x00000000004012ca in main (argc=1, argv=0x7fffffffe2d8) at src/main.c:102

I'm using XMonad.

I was able to resolve this issue by adding setWMName "LG3D" to my LogHook (in my xmonad.hs file). Now I get

:> ./screenfetch-c 
[[ ! ]] Error: No desktop environment found.
                   -`                  mark@##########
                  .o+`                 OS: Arch Linux
                 `ooo/                 Kernel: Linux 3.18.6-1-ARCH x86_64
                `+oooo:                CPU: Intel(R) Core(TM)2 CPU         T7200  @ 2.00GHz
               `+oooooo:               GPU: Gallium 0.4 on ATI RV515
               -+oooooo+:              Shell: bash version 4.3.33(1)
             `/:-:++oooo+:             Packages: 556
            `/++++/+++++++:            Disk: 32G / 458G (6%)
           `/++++++++++++++:           Memory: 1711MB / 3264MB
          `/+++ooooooooooooo/`         Uptime: 0h 37m 37s
         ./ooosssso++osssssso+`        Resolution: 1600x1700
        .oossssso-````/ossssss+`       DE: Unknown
       -osssssso.      :ssssssso.      WM: LG3D
      :osssssss/        osssso+++.     WM Theme: Unknown
     /ossssssss/        +ssssooo/-     GTK: Unknown (GTK2), Unknown (Icons)
   `/ossssso+/:-        -:/+osssso+-   Icon Theme: Unknown
  `+sso+:-`                 `.-/+oso:  Font: Unknown
 `++:.                           `-/+/
 .`                                 `/

I can suppress the error message by redirecting the error stream

~/builds/screenfetch-c/screenfetch-c 2> /dev/null

but this feels sloppy.

Cheers

Alright, that clears it up.
It seems that XMonad supports EWMH and actually responds to _NET_SUPPORTING_WM_CHECK with a Window * as expected, but that Window doesn't actually contain the _NET_WM_NAME atom expected unless explicitly configured with setWMName.

I'm going to install XMonad and do some testing. Hopefully I'll be able to fix it today or tomorrow.

Also, to suppress that error message about the desktop environment, use the -E flag.

Best,
William

Try building from f0915aa.

That condition change prevents the segfault on my XMonad.

This might actually be an upstream issue - AFAIK, window managers are not supposed to set _NET_SUPPORTING_WM_CHECK and succeed without also providing a valid _NET_WM_NAME, which XMonad doesn't unless manually specified.

Best,
William

This does indeed resolve the segmentation fault. I can now build it with or without explicitly setting the WM name. I do still receive the following error message

:> ./screenfetch-c
[[ ! ]] Error: No desktop environment found. (src/plat/linux/detect.c:628)
                   -`                  mark@foobar
                  .o+`                 OS: Arch Linux
                 `ooo/                 Kernel: Linux 3.18.6-1-ARCH x86_64
                `+oooo:                CPU: Intel(R) Core(TM)2 CPU         T7200  @ 2.00GHz
               `+oooooo:               GPU: Gallium 0.4 on ATI RV515
               -+oooooo+:              Shell: bash version 4.3.33(1)
             `/:-:++oooo+:             Packages: 556
            `/++++/+++++++:            Disk: 32G / 458G (6%)
           `/++++++++++++++:           Memory: 1714MB / 3264MB
          `/+++ooooooooooooo/`         Uptime: 2h 7m 52s
         ./ooosssso++osssssso+`        Resolution: 1600x1700
        .oossssso-````/ossssss+`       DE: Unknown
       -osssssso.      :ssssssso.      WM: LG3D
      :osssssss/        osssso+++.     WM Theme: Unknown
     /ossssssss/        +ssssooo/-     GTK: Unknown (GTK2), Unknown (Icons)
   `/ossssso+/:-        -:/+osssso+-   Icon Theme: Unknown
  `+sso+:-`                 `.-/+oso:  Font: Unknown
 `++:.                           `-/+/
 .`                                 `/

which can be redirected and suppressed.

Cheers,
Mark

Great!

If you don't have a DE installed, that error message will always occur (but can be suppressed with -E).

I eventually intend to refactor screenfetch-c so that the 'DE: ' field doesn't show up at all on systems without one.

Thanks again for reporting the bug,
William