1

我目前正在使用 UNIX 套接字在我的 C++ 程序和 Webots(机器人模拟器)之间进行通信。但是,我注意到过了一段时间(1~2 小时)后,Webots 意外关闭,没有任何明显的原因(或者我还没有发现),这是我在做什么的螺丝C++程序,因为我需要不断地发送和接收数据包。

因此,为了安全起见,我在我的代码上实现了一些Webots-checker,使用system()and pidof()

(...)
if (system("pidof -s webots-bin")!=0) system("webots &");
(...)

它只是检查是否有任何名为 的进程,webots-bin如果找不到则重新启动该程序。但是,当这应该起作用时(几个小时后,当 Webots 关闭时),我得到一个缓冲区溢出错误:

 *** buffer overflow detected ***: /usr/local/webots/webots-bin terminated
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x5c)[0x7fea104cd5cc]
/lib/x86_64-linux-gnu/libc.so.6(+0x110560)[0x7fea104cc560]
/lib/x86_64-linux-gnu/libc.so.6(+0x10f9e9)[0x7fea104cb9e9]
/lib/x86_64-linux-gnu/libc.so.6(_IO_default_xsputn+0xdb)[0x7fea10438aeb]
/lib/x86_64-linux-gnu/libc.so.6(_IO_vfprintf+0xafb)[0x7fea1040632b]
/lib/x86_64-linux-gnu/libc.so.6(__vsprintf_chk+0x94)[0x7fea104cba84]
/lib/x86_64-linux-gnu/libc.so.6(__sprintf_chk+0x7d)[0x7fea104cb9cd]
/usr/local/webots/webots-    bin(_ZN11WbViewpoint17createOgreObjectsEP22WbOgreRenderingContext+0x58)[0x67c9f8]
/usr/local/webots/webots-bin(_ZN7WbGroup17createOgreObjectsEP22WbOgreRenderingContext+0x61)[0x539c71]
/usr/local/webots/webots-bin(_ZN8WbView3D8setWorldEP17WbSimulationWorld+0x149)[0x672789]
/usr/local/webots/webots-bin(_ZN16WbSimulationView8setWorldEP17WbSimulationWorld+0x26)[0x61d796]
/usr/local/webots/webots-bin(_ZN12WbMainWindow23updateAfterWorldLoadingEb+0x2f)[0x592eaf]
/usr/local/webots/webots-bin[0x589454]
/usr/local/webots/lib/libQtCore.so.4(_ZN11QMetaObject8activateEP7QObjectPKS_iPPv+0x326)[0x7fea129751b6]
/usr/local/webots/webots-bin(_ZN13WbApplication15postWorldLoadedEb+0x30)[0x4c0260]
/usr/local/webots/webots-bin(_ZN13WbApplication9loadWorldE7QStringb+0x398)[0x4c3928]
/usr/local/webots/webots-bin(_ZN12WbMainWindow11revertWorldEv+0x74)[0x592974]
/usr/local/webots/webots-bin[0x5893fd]
/usr/local/webots/lib/libQtCore.so.4(_ZN7QObject5eventEP6QEvent+0x38e)[0x7fea1297108e]
/usr/local/webots/lib/libQtGui.so.4(_ZN7QWidget5eventEP6QEvent+0x4f)[0x7fea12f3037f]
/usr/local/webots/lib/libQtGui.so.4(_ZN11QMainWindow5eventEP6QEvent+0x7b)[0x7fea1333135b]
/usr/local/webots/lib/libQtGui.so.4(_ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent+0xac)[0x7fea12ed741c]
/usr/local/webots/lib/libQtGui.so.4(_ZN12QApplication6notifyEP7QObjectP6QEvent+0x13d)[0x7fea12edf28d]
/usr/local/webots/lib/libQtCore.so.4(_ZN16QCoreApplication14notifyInternalEP7QObjectP6QEvent+0x8c)[0x7fea1295e6fc]
/usr/local/webots/lib/libQtCore.so.4(_ZN23QCoreApplicationPrivate16sendPostedEventsEP7QObjectiP11QThreadData+0x3d3)[0x7fea12962f53]
/usr/local/webots/lib/libQtCore.so.4(+0x1d2183)[0x7fea12990183]
/lib/x86_64-linux-gnu/libglib-2.0.so.0(g_main_context_dispatch+0x135)[0x7fea0f8ddf05]
/lib/x86_64-linux-gnu/libglib-2.0.so.0(+0x49248)[0x7fea0f8de248]
/lib/x86_64-linux-gnu/libglib-2.0.so.0(g_main_context_iteration+0x34)[0x7fea0f8de304]
/usr/local/webots/lib/libQtCore.so.4(_ZN20QEventDispatcherGlib13processEventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE+0x73)[0x7fea1298fcc3]
/usr/local/webots/lib/libQtGui.so.4(+0x2c809e)[0x7fea12f8b09e]
/usr/local/webots/lib/libQtCore.so.4(_ZN10QEventLoop13processEventsE6QFlagsINS_17ProcessEventsFlagEE+0x32)[0x7fea1295d2b2]
/usr/local/webots/lib/libQtCore.so.4(_ZN10QEventLoop4execE6QFlagsINS_17ProcessEventsFlagEE+0x164)[0x7fea1295d724]
/usr/local/webots/lib/libQtCore.so.4(_ZN16QCoreApplication4execEv+0xb9)[0x7fea12963319]
/usr/local/webots/webots-bin(main+0x52)[0x681302]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5)[0x7fea103ddea5]
/usr/local/webots/webots-bin[0x4b3fc9]
======= Memory map: ========
00400000-0072e000 r-xp 00000000 08:12 7870974                                /usr/local/webots/webots-bin
0092e000-0092f000 r--p 0032e000 08:12 7870974                                /usr/local/webots/webots-bin
0092f000-00933000 rw-p 0032f000 08:12 7870974                            /usr/local/webots/webots-bin
00933000-00937000 rw-p 00000000 00:00 0 
025c2000-07c2e000 rw-p 00000000 00:00 0                                  [heap]
7fe9ea900000-7fe9f0000000 rw-p 00000000 00:00 0 
7fe9f0000000-7fe9f0021000 rw-p 00000000 00:00 0 
7fe9f0021000-7fe9f4000000 ---p 00000000 00:00 0 
7fe9f4034000-7fe9f6034000 rw-p 00000000 00:00 0 
7fe9f6034000-7fe9f60b4000 rw-s 00000000 00:04 100827158                  /SYSV00000000 (deleted)
7fe9f60b4000-7fe9f6114000 rw-s 00000000 00:04 100761621                  /SYSV00000000     (deleted)
7fe9f6114000-7fe9f65ce000 rw-s 00000000 00:04 100728852                  /SYSV00000000 (deleted)
7fe9f65ce000-7fe9f65cf000 ---p 00000000 00:00 0 
7fe9f65cf000-7fe9f6ecf000 rw-p 00000000 00:00 0                          [stack:24593]
7fe9f6ecf000-7fe9f6fcf000 rw-s 05352000 00:05 1862                       /dev/ati/card0
7fe9f6fcf000-7fe9f78cf000 rw-p 00000000 00:00 0 
7fe9f78cf000-7fe9f7acf000 rw-s 050c0000 00:05 1862                       /dev/ati/card0
7fe9f7acf000-7fe9f7bcf000 rw-p 00000000 00:00 0 
7fe9f7bcf000-7fe9f7dcf000 rw-s 050bd000 00:05 1862                       /dev/ati/card0
7fe9f7dcf000-7fe9f80d0000 rw-p 00000000 00:00 0 
7fe9f80d0000-7fe9f8122000 r--p 00000000 08:12 8782802                        /usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-B.ttf
7fe9f8122000-7fe9f8134000 r-xp 00000000 08:12 8128035                        /usr/lib/x86_64-linux-gnu/pkcs11/gnome-keyring-pkcs11.so
7fe9f8134000-7fe9f8333000 ---p 00012000 08:12 8128035                        /usr/lib/x86_64-linux-gnu/pkcs11/gnome-keyring-pkcs11.so
7fe9f8333000-7fe9f8335000 r--p 00011000 08:12 8128035                        /usr/lib/x86_64-linux-gnu/pkcs11/gnome-keyring-pkcs11.so
7fe9f8335000-7fe9f8336000 rw-p 00013000 08:12 8128035                        /usr/lib/x86_64-linux-gnu/pkcs11/gnome-keyring-pkcs11.so
7fe9f8336000-7fe9f8338000 r-xp 00000000 08:12 265883                     /lib/x86_64-    linux-gnu/libkeyutils.so.1.4
7fe9f8338000-7fe9f8538000 ---p 00002000 08:12 265883                     /lib/x86_64-    linux-gnu/libkeyutils.so.1.4
7fe9f8538000-7fe9f8539000 r--p 00002000 08:12 265883                     /lib/x86_64-    linux-gnu/libkeyutils.so.1.4
7fe9f8539000-7fe9f853a000 rw-p 00003000 08:12 265883                     /lib/x86_64-        linux-gnu/libkeyutils.so.1.4
7fe9f853a000-7fe9f8541000 r-xp 00000000 08:12 7740965                        /usr/lib/x86_64-linux-gnu/libkrb5support.so.0.1
7fe9f8541000-7fe9f8740000 ---p 00007000 08:12 7740965                    /usr/lib/x86_64-linux-gnu/libkrb5support.so.0.1
7fe9f8740000-7fe9f8741000 r--p 00006000 08:12 7740965                    /usr/lib/x86_64-linux-gnu/libkrb5support.so.0.1
7fe9f8741000-7fe9f8742000 rw-p 00007000 08:12 7740965                    /usr/lib/x86_64-linux-gnu/libkrb5support.so.0.1
7fe9f8742000-7fe9f8745000 r-xp 00000000 08:12 265848                     /lib/x86_64-linux-gnu/libcom_err.so.2.1
7fe9f8745000-7fe9f8944000 ---p 00003000 08:12 265848                     /lib/x86_64-linux-gnu/libcom_err.so.2.1
7fe9f8944000-7fe9f8945000 r--p 00002000 08:12 265848                     /lib/x86_64-linux-gnu/libcom_err.so.2.1
7fe9f8945000-7fe9f8946000 rw-p 00003000 08:12 265848                     /lib/x86_64-linux-gnu/libcom_err.so.2.1Aborted (core dumped)

使用system()从程序中启动和关闭 Webots 是可行的,但目前似乎失败了,可能是因为关闭了 Webots 的方式?

编辑:分叉程序并用于启动Webots时会发生同样的事情execlp,但如果我定期关闭并重新打开则不会。从回溯(我已经添加)中,我认为问题出在 Webots 二进制文件中,但据我所知。有没有办法防止这种缓冲区溢出?

4

0 回答 0