#include #include #include #include #include #include #include "MultimediaService.h" #include "configUtils.h" #include "MusicPlayer/MusicPlayer.h" #include "VideoPlayer/VideoPlayer.h" #include "DeviceWatcher/DeviceWatcher.h" #include #include #include #include // 用于dladdr static void printStackTrace() { void *callstack[128]; int frames = backtrace(callstack, 128); char **strs = backtrace_symbols(callstack, frames); QString str_hour = QDateTime::currentDateTime().toString("hh"); QString str_min = QDateTime::currentDateTime().toString("mm"); QString str_sec = QDateTime::currentDateTime().toString("ss"); QString str_curTime = str_hour + str_min + str_sec; QString fileName = QString("/data/crash_multimediaService") + str_curTime + QString(".log"); FILE *log = fopen(fileName.toStdString().c_str(), "a"); for (int i = 0; i < frames; ++i) { fprintf(log,"%s\n", strs[i]); } fclose(log); free(strs); } static void handler(int sig, siginfo_t *info, void *ucontext) { (void)ucontext; printf("MultimediaService捕获到信号: %d, 发送进程PID: %d processName:%s\n", sig, info->si_pid, strsignal(sig)) ; switch(sig) { case SIGINT: case SIGILL: case SIGTERM: case SIGSEGV: case SIGFPE: case SIGABRT: printStackTrace(); if(MyClass::m_MusicPlayStatus == 1) { g_DeviceWatcher->onDiskDeviceChangeHandler(g_DeviceWatcher->getUsbDiskPath(), DiskDeviceWatcher::A_Remove); if(g_MusicPlayer->getMusicPthreadValue() != 0) { pthread_join(g_MusicPlayer->getMusicPthreadValue(), NULL); } } if(MyClass::m_VideoPlayStatus == 1) { g_DeviceWatcher->onDiskDeviceChangeHandler(g_DeviceWatcher->getUsbDiskPath(), DiskDeviceWatcher::A_Remove); if(g_VideoPlayer->getVideoPthreadValue() != 0) { pthread_join(g_VideoPlayer->getVideoPthreadValue(), NULL); } } if(MyClass::m_MusicPlayStatus != 1 && MyClass::m_VideoPlayStatus != 1) { g_DeviceWatcher->onDiskDeviceChangeHandler(g_DeviceWatcher->getUsbDiskPath(), DiskDeviceWatcher::A_Remove); } printf("*********pthread exit\n"); CHECK_SYSTEM("echo host > /sys/devices/platform/soc/40000000.usb/usb_role/40000000.usb-role-switch/role"); CHECK_SYSTEM("echo host > /sys/devices/platform/soc/40c00000.usb/usb_role/40c00000.usb-role-switch/role"); break; default: break; } _exit(1); } static void setTextCodec(); int main(int argc, char *argv[]) { freopen("/dev/ttyS0", "w", stdout); freopen("/dev/ttyS0", "w", stderr); printf(">>>>>>>>>>>>pid:%d\n",getpid()); struct sigaction sa; // 清空结构体 memset(&sa, 0, sizeof(sa)); // 指定信号处理函数(使用更强大的 sa_sigaction) sa.sa_sigaction = handler; // 设置 SA_SIGINFO 标志以使用 sa_sigaction sa.sa_flags = SA_SIGINFO; // 可选:在处理此信号时,阻塞其他信号(如SIGTERM) sigemptyset(&sa.sa_mask); if (sigaction(SIGINT, &sa, NULL) == -1) { perror("sigaction 设置失败"); return 1; } else if (sigaction(SIGTERM, &sa, NULL) == -1) { perror("sigaction 设置失败"); return 1; } else if (sigaction(SIGSEGV, &sa, NULL) == -1) { perror("sigaction 设置失败"); return 1; } else if (sigaction(SIGABRT, &sa, NULL) == -1) { perror("sigaction 设置失败"); return 1; } else if (sigaction(SIGILL, &sa, NULL) == -1) { perror("sigaction 设置失败"); return 1; } else if (sigaction(SIGFPE, &sa, NULL) == -1) { perror("sigaction 设置失败"); return 1; } QCoreApplication app(argc, argv); setTextCodec(); MultimediaService multimediaService; (void)multimediaService; return app.exec(); } void setTextCodec() { // 设置默认编码为UTF-8 QTextCodec *codec = QTextCodec::codecForName("UTF-8"); QTextCodec::setCodecForLocale(codec); }