aboutsummaryrefslogtreecommitdiff
path: root/xbmc/platform/posix/main.cpp
blob: 9abacb7502daf08eea518594c6b63c0d9f1e948d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 *  Copyright (C) 2005-2018 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#include <sys/resource.h>
#include <signal.h>

#include <cstring>

#if defined(TARGET_DARWIN_OSX) || defined(TARGET_FREEBSD)
  #include "Util.h"
  // SDL redefines main as SDL_main
  #ifdef HAS_SDL
    #include <SDL/SDL.h>
  #endif
#endif

#include "AppParamParser.h"
#include "FileItem.h"
#include "messaging/ApplicationMessenger.h"
#include "PlayListPlayer.h"
#include "platform/MessagePrinter.h"
#include "platform/xbmc.h"
#include "utils/log.h"

#ifdef HAS_LIRC
#include "platform/linux/input/LIRC.h"
#endif

#include <locale.h>

namespace
{

class CPOSIXSignalHandleThread : public CThread
{
public:
  CPOSIXSignalHandleThread()
  : CThread("POSIX signal handler")
  {}
protected:
  void Process() override
  {
    CMessagePrinter::DisplayMessage("Exiting application");
    KODI::MESSAGING::CApplicationMessenger::GetInstance().PostMsg(TMSG_QUIT);
  }
};

extern "C"
{

void XBMC_POSIX_HandleSignal(int sig)
{
  // Spawn handling thread: the current thread that this signal was catched on
  // might have been interrupted in a call to PostMsg() while holding a lock
  // there, which would lead to a deadlock if PostMsg() was called directly here
  // as PostMsg() is not supposed to be reentrant
  auto thread = new CPOSIXSignalHandleThread;
  thread->Create(true);
}

}

}


int main(int argc, char* argv[])
{
#if defined(_DEBUG)
  struct rlimit rlim;
  rlim.rlim_cur = rlim.rlim_max = RLIM_INFINITY;
  if (setrlimit(RLIMIT_CORE, &rlim) == -1)
    CLog::Log(LOGDEBUG, "Failed to set core size limit (%s)", strerror(errno));
#endif

  // Set up global SIGINT/SIGTERM handler
  struct sigaction signalHandler;
  std::memset(&signalHandler, 0, sizeof(signalHandler));
  signalHandler.sa_handler = &XBMC_POSIX_HandleSignal;
  signalHandler.sa_flags = SA_RESTART;
  sigaction(SIGINT, &signalHandler, nullptr);
  sigaction(SIGTERM, &signalHandler, nullptr);

  setlocale(LC_NUMERIC, "C");

  CAppParamParser appParamParser;
  appParamParser.Parse(argv, argc);

  return XBMC_Run(true, appParamParser);
}