brndnmtthws / conky

Light-weight system monitor for X, Wayland (sort of), and other things, too
https://conky.cc
GNU General Public License v3.0
7.16k stars 615 forks source link

[Bug]: Segfault when reloading config when using cairo in lua #1375

Open Myvillithdar opened 1 year ago

Myvillithdar commented 1 year ago

What happened?

I have a conky config that loads a lua file that does some cairo stuff. When I write to the conky config (not the other lua file) and conky attempts to reload it, it segfaults.

I've attached a minimal config that reproduces the issue.

Version

1.17.0_pre

Which OS/distro are you seeing the problem on?

Arch Linux

Conky config

-- Conky config:
conky.config = {
    alignment = 'top_left',
    background = false,
    border_width = 1,
    cpu_avg_samples = 2,
    default_color = 'white',
    default_outline_color = 'white',
    default_shade_color = 'white',
    double_buffer = true,
    draw_borders = false,
    draw_graph_borders = true,
    draw_outline = false,
    draw_shades = false,
    extra_newline = false,
    font = 'DejaVu Sans Mono:size=12',
    gap_x = 60,
    gap_y = 60,
    minimum_height = 5,
    minimum_width = 5,
    net_avg_samples = 2,
    no_buffers = true,
    out_to_console = false,
    out_to_ncurses = false,
    out_to_stderr = false,
    out_to_x = true,
    own_window = true,
    own_window_class = 'Conky',
    own_window_type = 'desktop',
    show_graph_range = false,
    show_graph_scale = false,
    stippled_borders = 0,
    update_interval = 1.0,
    uppercase = false,
    use_spacer = 'none',
    use_xft = true,
    lua_load = './script.lua',
    lua_draw_hook_pre = 'main',
}

conky.text = [[ ]]

---------------------------------------------------------
--Contents of script.lua:
require 'cairo'

function conky_main()
    if conky_window == nil then
        return
    end
    local cs = cairo_xlib_surface_create (
        conky_window.display,
        conky_window.drawable,
        conky_window.visual,
        conky_window.width,
        conky_window.height
    )
    cairo_surface_destroy(cs)
end

Stack trace

#0  0x00007ffff3b76610 in ?? ()
No symbol table info available.
#1  0x00007ffff7deee02 in XCloseDisplay (dpy=0x5555557c2340) at /usr/src/debug/libx11/libX11-1.8.3/src/ClDisplay.c:65
        ext = 0x5555557a80a0
        i = <optimized out>
#2  0x00005555555f08ca in deinit_x11 () at /usr/src/debug/conky-lua-nv/conky-1.17.0/src/x11.cc:274
No locals.
#3  priv::out_to_x_setting::cleanup (this=<optimized out>, l=...) at /usr/src/debug/conky-lua-nv/conky-1.17.0/src/x11.cc:93
        s = {L = 0x5555557b7ac0, n = 1}
#4  0x00005555555c5b63 in conky::cleanup_config_settings (l=...) at /usr/src/debug/conky-lua-nv/conky-1.17.0/src/setting.cc:311
        i = 2
        s = {L = <optimized out>, n = 0}
        v = std::vector of length 130, capacity 130 = {0x5555557829a0 <display_name[abi:cxx11]>, 0x555555782920 <out_to_x>, 0x5555557828e0 <use_xft>, 
          0x555555782fa0 <font>, 0x555555782c20 <font_template[abi:cxx11]>, 0x555555782c78 <font_template[abi:cxx11]+88>, 
          0x555555782cd0 <font_template[abi:cxx11]+176>, 0x555555782d28 <font_template[abi:cxx11]+264>, 0x555555782d80 <font_template[abi:cxx11]+352>, 
          0x555555782dd8 <font_template[abi:cxx11]+440>, 0x555555782e30 <font_template[abi:cxx11]+528>, 0x555555782e88 <font_template[abi:cxx11]+616>, 
          0x555555782ee0 <font_template[abi:cxx11]+704>, 0x555555782f38 <font_template[abi:cxx11]+792>, 0x5555557833a0 <color>, 0x5555557833e0 <color+64>, 
          0x555555783420 <color+128>, 0x555555783460 <color+192>, 0x5555557834a0 <color+256>, 0x5555557834e0 <color+320>, 0x555555783520 <color+384>, 
          0x555555783560 <color+448>, 0x5555557835a0 <color+512>, 0x5555557835e0 <color+576>, 0x555555783360 <default_color>, 
          0x555555783320 <default_shade_color>, 0x5555557832e0 <default_outline_color>, 0x5555557832a0 <border_inner_margin>, 
          0x555555783260 <border_outer_margin>, 0x555555783220 <border_width>, 0x555555783620 <text_alignment>, 0x5555557831e0 <set_transparent>, 
          0x555555783180 <own_window_class[abi:cxx11]>, 0x555555783120 <own_window_title[abi:cxx11]>, 0x5555557830e0 <own_window_type>, 
          0x5555557830a0 <own_window_hints>, 0x555555783060 <own_window_argb_value>, 0x555555782860 <use_argb_visual>, 0x555555783b40 <background_colour>, 
          0x555555783020 <own_window>, 0x555555782820 <use_xdbe>, 0x5555557827c0 <imlib_cache_size>, 0x555555783da0 <(anonymous namespace)::draw_blended>, 
          0x555555643260 <no_buffers>, 0x555555643200 <bar_fill[abi:cxx11]>, 0x5555556431a0 <bar_unfill[abi:cxx11]>, 0x555555643140 <github_token[abi:cxx11]>, 
          0x5555556447a0 <disable_auto_reload>, 0x555555644740 <use_spacer>, 0x555555644700 <short_units>, 0x5555556446c0 <format_human_readable>, 
          0x555555643fe0 <units_spacer[abi:cxx11]>, 0x555555643fa0 <out_to_stdout>, 0x555555643f60 <out_to_stderr>, 0x555555643ee0 <update_interval>, 
          0x555555643e80 <update_interval_on_battery>, 0x555555643e20 <detect_battery[abi:cxx11]>, 0x555555643de0 <music_player_interval>, 
          0x555555644660 <max_text_width>, 0x555555644620 <stuff_in_uppercase>, 0x5555556445e0 <stuff_in_lowercase>, 0x555555644580 <total_run_times>, 
          0x555555644540 <fork_to_background>, 0x555555643900 <cpu_avg_samples>, 0x5555556438c0 <net_avg_samples>, 0x555555643880 <diskio_avg_samples>, 
          0x555555643840 <show_graph_scale>, 0x555555643800 <show_graph_range>, 0x555555644500 <graph_gradient_mode>, 0x555555643740 <gap_x>, 
          0x555555643700 <gap_y>, 0x5555556436c0 <draw_borders>, 0x555555643680 <draw_graph_borders>, 0x555555643640 <stippled_borders>, 
          0x555555643600 <draw_shades>, 0x5555556435c0 <draw_outline>, 0x555555643560 <minimum_height>, 0x555555643520 <minimum_width>, 
          0x5555556434e0 <maximum_width>, 0x5555556434a0 <utf8_mode>, 0x555555643460 <max_user_text>, 0x555555643420 <text_buffer_size>, 
          0x5555556444c0 <pad_percents>, 0x55555564e300 <current_mail_spool>, 0x55555564e3c0 <(anonymous namespace)::imap>, 
          0x55555564e360 <(anonymous namespace)::pop3>, 0x55555577bfc0 <if_up_strictness>, 0x55555577c000 <(anonymous namespace)::_template>, 
          0x55555577c058 <(anonymous namespace)::_template+88>, 0x55555577c0b0 <(anonymous namespace)::_template+176>, 
          0x55555577c108 <(anonymous namespace)::_template+264>, 0x55555577c160 <(anonymous namespace)::_template+352>, 
          0x55555577c1b8 <(anonymous namespace)::_template+440>, 0x55555577c210 <(anonymous namespace)::_template+528>, 
          0x55555577c268 <(anonymous namespace)::_template+616>, 0x55555577c2c0 <(anonymous namespace)::_template+704>, 
          0x55555577c318 <(anonymous namespace)::_template+792>, 0x55555577c6e0 <(anonymous namespace)::default_bar_width>, 
          0x55555577c6a0 <(anonymous namespace)::default_bar_height>, 0x55555577c660 <(anonymous namespace)::default_graph_width>, 
          0x55555577c620 <(anonymous namespace)::default_graph_height>, 0x55555577c5e0 <(anonymous namespace)::default_gauge_width>, 
          0x55555577c5a0 <(anonymous namespace)::default_gauge_height>, 0x55555577c560 <(anonymous namespace)::store_graph_data_explicitly>, 
          0x55555577c500 <(anonymous namespace)::console_graph_ticks>, 0x55555577c7a0 <output_unit>, 0x55555577c7e0 <times_in_seconds>, 
          0x55555577c880 <top_name_width>, 0x55555577c840 <top_name_verbose>, 0x55555577d9e0 <extra_newline>, 0x55555577dac0 <overwrite_file>, 
          0x55555577da60 <append_file>, 0x55555577dc40 <(anonymous namespace)::xftalpha>, 0x55555577df20 <(anonymous namespace)::lua_load>, 
          0x55555577dec0 <(anonymous namespace)::lua_startup_hook>, 0x55555577de60 <(anonymous namespace)::lua_shutdown_hook>, 
          0x55555577de00 <(anonymous namespace)::lua_draw_hook_pre>, 0x55555577dda0 <(anonymous namespace)::lua_draw_hook_post>, 
          0x5555557825a0 <top_cpu_separate>, 0x555555782720 <(anonymous namespace)::mpd_port>, 0x5555557826c0 <(anonymous namespace)::mpd_host>, 
          0x555555782660 <(anonymous namespace)::mpd_password>, 0x555555782760 <max_port_monitor_connections>, 0x555555782960 <head_index>, 
          0x5555557828a0 <forced_redraw>, 0x555555783c60 <hddtemp_host>, 0x555555783c00 <hddtemp_port>, 0x555555783ce0 <(anonymous namespace)::nvidia_display>, 
          0x555555783de0 <(anonymous namespace)::imlib_cache_flush_interval>, 0x555555784000 <out_to_ncurses>}
#5  0x000055555557f766 in clean_up_without_threads (memtofree1=<optimized out>, memtofree1@entry=0x0, memtofree2=<optimized out>, memtofree2@entry=0x0)
    at /usr/include/c++/12.2.1/bits/unique_ptr.h:191
No locals.
#6  0x00005555555810e2 in clean_up (memtofree2=0x0, memtofree1=0x0) at /usr/src/debug/conky-lua-nv/conky-1.17.0/src/conky.cc:1911
No locals.
#7  reload_config () at /usr/src/debug/conky-lua-nv/conky-1.17.0/src/conky.cc:1848
        sb = <optimized out>
        sb = <optimized out>
#8  reload_config () at /usr/src/debug/conky-lua-nv/conky-1.17.0/src/conky.cc:1838
        sb = {st_dev = 2051, st_ino = 45633428, st_nlink = 1, st_mode = 33188, st_uid = 1000, st_gid = 1000, __pad0 = 0, st_rdev = 0, st_size = 895, 
          st_blksize = 4096, st_blocks = 8, st_atim = {tv_sec = 1674000549, tv_nsec = 305377066}, st_mtim = {tv_sec = 1674000549, tv_nsec = 305377066}, 
          st_ctim = {tv_sec = 1674000549, tv_nsec = 305377066}, __glibc_reserved = {0, 0, 0}}
#9  0x0000555555585c80 in main_loop () at /usr/src/debug/conky-lua-nv/conky-1.17.0/src/conky.cc:1803
        ev = 0x7fffffffdf10
        len = 16
        idx = 0
        descriptors = {fds_bits = {8, 0 <repeats 15 times>}}
        time_to_wait = {tv_sec = 0, tv_usec = 0}
        terminate = 0
        t = <optimized out>
        inotify_config_wd = 2
        inotify_buff = "\002\000\000\000\000\200", '\000' <repeats 11 times>, "z{UUU\000\000\000+%\022na$u\000\367yUUU\000\000\300z{UUU\000\000\360\337\377\377\377--Type <RET> for more, q to quit, c to continue without paging--
\177\000\000\300\336wUUU\000\000\000\000\000\000\000\000\000\000\300z{UUU\000\000\360\337\377\377\377\177\000\000\vk\\UUU", '\000' <repeats 18 times>, "\220\337\377\377\377\177", '\000' <repeats 26 times>, "\001\000\000\000\000\000\000\000\000+%\022na$u\260#}UUU\000\000\360\337\377\377\377\177\000\000\300\336wUUU\000\000\003\000\000\000\000\000\000\000\240\337cUUU\000\000"...
#10 0x0000555555570cc2 in main (argc=3, argv=0x7fffffffe318) at /usr/src/debug/conky-lua-nv/conky-1.17.0/src/main.cc:355
        curl_global = <optimized out>

Relevant log output

conky: desktop window (227) is root window
conky: window type - desktop
conky: drawing to created window (0xe00001)
conky: drawing to double buffer
conky: 'conky.config' modified, reloading...
Segmentation fault (core dumped)
IfGremlinThen commented 11 months ago

I've run into this same issue on Linux Mint 21.2 & Debian Edition 6.

After a bunch of testing I've determined that the issue is caused by this line:

local cs=cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, w, h)

@Myvillithdar It's my understanding that Cairo must be able to match the width and height of your Conky window, so I'm using:

local w=conky_window.width
local h=conky_window.height

But that obviously hasn't solved the problem. This is the function I'm using that's giving me the segfault:

function conky_draw_bg()
    if conky_window==nil then return end
    local w=conky_window.width
    local h=conky_window.height
    local cs=cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, w, h)
    cr=cairo_create(cs)

    cairo_move_to(cr,corner_r,0)
    cairo_line_to(cr,w-corner_r,0)
    cairo_curve_to(cr,w,0,w,0,w,corner_r)
    cairo_line_to(cr,w,h-corner_r)
    cairo_curve_to(cr,w,h,w,h,w-corner_r,h)
    cairo_line_to(cr,corner_r,h)
    cairo_curve_to(cr,0,h,0,h,0,h-corner_r)
    cairo_line_to(cr,0,corner_r)
    cairo_curve_to(cr,0,0,0,0,corner_r,0)
    cairo_close_path(cr)

    cairo_set_source_rgba(cr,rgb_to_r_g_b(bg_colour,bg_alpha))
    cairo_fill(cr)
end

EDIT: This only appears to occur in the repo version of conky-all which has conky 1.12.2. The appimage of 1.12.2 does not segfault under the same conditions.

SunPodder commented 9 months ago

Someone found a solution to this?