Skip to content

Commit

Permalink
Add SIGTERM signalhandler
Browse files Browse the repository at this point in the history
Catch signal and stop e2 in a proper way.
This also writes config and EPG data to the disk.

Signed-off-by: littlesat <littlesat99@yahoo.com>
  • Loading branch information
betacentauri authored and rossi2000 committed Apr 27, 2015
1 parent e9fc7b4 commit 7b9ad81
Showing 1 changed file with 44 additions and 39 deletions.
83 changes: 44 additions & 39 deletions main/enigma.cpp
Expand Up @@ -170,6 +170,48 @@ static const std::string getConfigCurrentSpinner(const std::string &key)

int exit_code;

void quitMainloop(int exitCode)
{
FILE *f = fopen("/proc/stb/fp/was_timer_wakeup", "w");
if (f)
{
fprintf(f, "%d", 0);
fclose(f);
}
else
{
int fd = open("/dev/dbox/fp0", O_WRONLY);
if (fd >= 0)
{
if (ioctl(fd, 10 /*FP_CLEAR_WAKEUP_TIMER*/) < 0)
eDebug("FP_CLEAR_WAKEUP_TIMER failed (%m)");
close(fd);
}
else
eDebug("open /dev/dbox/fp0 for wakeup timer clear failed!(%m)");
}
exit_code = exitCode;
eApp->quit(0);
}

static void sigterm_handler(int num)
{
quitMainloop(128 + num);
}

void catchTermSignal()
{
struct sigaction act;

act.sa_handler = sigterm_handler;
act.sa_flags = SA_RESTART;

if (sigemptyset(&act.sa_mask) == -1)
perror("sigemptyset");
if (sigaction(SIGTERM, &act, 0) == -1)
perror("SIGTERM");
}

int main(int argc, char **argv)
{

Expand Down Expand Up @@ -274,6 +316,7 @@ int main(int argc, char **argv)
printf("executing main\n");

bsodCatchSignals();
catchTermSignal();

setIoPrio(IOPRIO_CLASS_BE, 3);

Expand Down Expand Up @@ -315,47 +358,9 @@ eApplication *getApplication()
return eApp;
}

void quitMainloop(int exitCode)
{
FILE *f = fopen("/proc/stb/fp/was_timer_wakeup", "w");
if (f)
{
fprintf(f, "%d", 0);
fclose(f);
}
else
{
int fd = open("/dev/dbox/fp0", O_WRONLY);
if (fd >= 0)
{
if (ioctl(fd, 10 /*FP_CLEAR_WAKEUP_TIMER*/) < 0)
eDebug("FP_CLEAR_WAKEUP_TIMER failed (%m)");
close(fd);
}
else
eDebug("open /dev/dbox/fp0 for wakeup timer clear failed!(%m)");
}
exit_code = exitCode;
eApp->quit(0);
}

static void sigterm_handler(int num)
{
quitMainloop(128 + num);
}

void runMainloop()
{
struct sigaction act;

act.sa_handler = sigterm_handler;
act.sa_flags = SA_RESTART;

if (sigemptyset(&act.sa_mask) == -1)
perror("sigemptyset");
if (sigaction(SIGTERM, &act, 0) == -1)
perror("SIGTERM");

catchTermSignal();
eApp->runLoop();
}

Expand Down

0 comments on commit 7b9ad81

Please sign in to comment.