gpt4 book ai didi

c++ - 如果程序在没有sudo的情况下运行,则gtk_init会导致在Ubuntu 16.04上崩溃

转载 作者:行者123 更新时间:2023-12-02 10:37:54 33 4
gpt4 key购买 nike

如果运行不带sudo的程序,则gtk_init会导致ubuntu 16.04崩溃。如果使用sudo运行,则没有问题。在其他ubuntu版本上,使用sudo和不使用sudo也没有问题。

最小可重现的示例:

#include <gtk/gtk.h>

int main(int argc, char* argv[])
{
gtk_init (&argc, &argv);

for (int i = 0; i < 10; ++i)
{
printf("%d\n", i);
usleep(1000 * 1000);
}
return 0;
}

堆栈跟踪:
Thread 2 "dconf worker" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb6567b40 (LWP 6735)]
0xb71bbfd0 in g_source_set_ready_time () from /lib/i386-linux-gnu/libglib-2.0.so.0
(gdb) bt
#0 0xb71bbfd0 in g_source_set_ready_time () from /lib/i386-linux-gnu/libglib-2.0.so.0
#1 0xb73e8bf4 in g_task_get_type () from /usr/lib/i386-linux-gnu/libgio-2.0.so.0
#2 0xb744b6a0 in ?? () from /usr/lib/i386-linux-gnu/libgio-2.0.so.0
#3 0xb743eb00 in ?? () from /usr/lib/i386-linux-gnu/libgio-2.0.so.0
#4 0xb73bd0e9 in g_initable_init () from /usr/lib/i386-linux-gnu/libgio-2.0.so.0
#5 0xb743f230 in g_bus_get_sync () from /usr/lib/i386-linux-gnu/libgio-2.0.so.0
#6 0xb668c314 in ?? () from /usr/lib/i386-linux-gnu/gio/modules/libdconfsettings.so
#7 0xb668c423 in ?? () from /usr/lib/i386-linux-gnu/gio/modules/libdconfsettings.so
#8 0x0807e22a in g_main_context_dispatch ()
#9 0x0807e638 in g_main_context_iterate.isra ()
#10 0x0807e700 in g_main_context_iteration ()
#11 0xb668c58b in ?? () from /usr/lib/i386-linux-gnu/gio/modules/libdconfsettings.so
#12 0x0809eabd in g_thread_proxy ()
#13 0xb7aaf295 in start_thread (arg=0xb6567b40) at pthread_create.c:333
#14 0xb79d10ae in clone () at ../sysdeps/unix/sysv/linux/i386/clone.S:114

我试图将strace输出与sudo和不使用sudo进行比较-没有创建sudo时出现问题线程 dconf worker,但是如果使用sudo运行,则不会创建该线程,并且Programm可以正常工作

如何解决此问题?

UPD:带有`libglib2.0-0-dbg的Stacktrace
Thread 2 "dconf worker" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb6567b40 (LWP 3574)]
0xb71bbfd0 in g_source_set_ready_time (source=0xb5c09938, ready_time=-1)
at /build/glib2.0-2aRhhS/glib2.0-2.48.2/./glib/gmain.c:1786
1786 /build/glib2.0-2aRhhS/glib2.0-2.48.2/./glib/gmain.c: No such file or directory.
(gdb) bt
#0 0xb71bbfd0 in g_source_set_ready_time (source=0xb5c09938, ready_time=-1)
at /build/glib2.0-2aRhhS/glib2.0-2.48.2/./glib/gmain.c:1786
#1 0xb73e8bf4 in g_task_get_type () at /build/glib2.0-2aRhhS/glib2.0-2.48.2/./gio/gtask.c:1907
#2 0xb73e8bf4 in g_task_get_type () at /build/glib2.0-2aRhhS/glib2.0-2.48.2/./gio/gtask.c:590
#3 0xb744b6a0 in _g_dbus_worker_new () at /build/glib2.0-2aRhhS/glib2.0-2.48.2/./gio/gdbusprivate.c:227
#4 0xb744b6a0 in _g_dbus_worker_new () at /build/glib2.0-2aRhhS/glib2.0-2.48.2/./gio/gdbusprivate.c:267
#5 0xb744b6a0 in _g_dbus_worker_new (stream=0xb5c016c8, capabilities=G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING, initially_frozen=0, message_received_callback=0xb7438400 <on_worker_message_received>, message_about_to_be_sent_callback=0xb7435eb0 <on_worker_message_about_to_be_sent>, disconnected_callback=0xb74359c0 <on_worker_closed>, user_data=0xb5c04818)
at /build/glib2.0-2aRhhS/glib2.0-2.48.2/./gio/gdbusprivate.c:1649
#6 0xb743eb00 in initable_init (initable=0xb5c04818, cancellable=0x0, error=0xb6567068)
at /build/glib2.0-2aRhhS/glib2.0-2.48.2/./gio/gdbusconnection.c:2573
#7 0xb73bd0e9 in g_initable_init (initable=0xb5c04818, cancellable=0x0, error=0xb6567068)
at /build/glib2.0-2aRhhS/glib2.0-2.48.2/./gio/ginitable.c:112
#8 0xb743f230 in g_bus_get_sync (bus_type=G_BUS_TYPE_SESSION, cancellable=0x0, error=0xb6567068)
at /build/glib2.0-2aRhhS/glib2.0-2.48.2/./gio/gdbusconnection.c:7254
#9 0xb668c314 in () at /usr/lib/i386-linux-gnu/gio/modules/libdconfsettings.so
#10 0xb668c423 in () at /usr/lib/i386-linux-gnu/gio/modules/libdconfsettings.so
#11 0x0807e22a in g_main_context_dispatch ()
#12 0x0807e638 in g_main_context_iterate.isra ()
#13 0x0807e700 in g_main_context_iteration ()
#14 0xb668c58b in () at /usr/lib/i386-linux-gnu/gio/modules/libdconfsettings.so
#15 0x0809eabd in g_thread_proxy ()
#16 0xb7aaf295 in start_thread (arg=0xb6567b40) at pthread_create.c:333
#17 0xb79d10ae in clone () at ../sysdeps/unix/sysv/linux/i386/clone.S:114

最佳答案

取消设置GTK2_MODULESGTK_MODULESGTK_IM_MODULE可解决此问题,但我不明白

#include <gtk/gtk.h>

int main(int argc, char* argv[])
{
unsetenv("GTK2_MODULES");
unsetenv("GTK_MODULES");
unsetenv("GTK_IM_MODULE");

gtk_init (&argc, &argv);

for (int i = 0; i < 10; ++i)
{
printf("%d\n", i);
usleep(1000 * 1000);
}
return 0;
}
为什么起作用

关于c++ - 如果程序在没有sudo的情况下运行,则gtk_init会导致在Ubuntu 16.04上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59424607/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com