我目前正在使用UNIX套接字在我的C ++程序和Webots(机器人模拟器)之间进行通信。然而,我注意到经过一段时间(1~2小时)后,Webots意外地关闭了,没有任何明显的理由(或者我还没有发现它),哪种螺丝我在做什么呢? C ++程序,因为我需要不断发送和接收数据包。
为了安全起见,我使用system()
和pidof()
在我的代码上实现了一些 Webots-checker :
(...)
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关闭的方式已经发生了吗?
execlp
启动Webots时会发生同样的事情,但如果我定期关闭并重新打开则不会。从回溯(我已经添加)我认为问题是在Webots二进制文件中,但据我所知,这是。有没有办法防止这种缓冲区溢出?