Skip to content

Commit

Permalink
Merge branch 'mer1870_do_not_close_wd_device' into 'master'
Browse files Browse the repository at this point in the history
[dsme-wdd] Do not close watchdog file descriptors when daemonizing. Fixes MER#1870

See merge request !22
  • Loading branch information
spiiroin committed Feb 5, 2018
2 parents 57f7e8a + 7f2f993 commit e12053b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
16 changes: 16 additions & 0 deletions dsme/dsme-wdd-wd.c
Expand Up @@ -7,6 +7,11 @@
@author Igor Stoppa <igor.stopaa@nokia.com>
@author Semi Malinen <semi.malinen@nokia.com>
@author Matias Muhonen <ext-matias.muhonen@nokia.com>
@author Kalle Lampila <kalle.lampila@cybercom.com>
@author Jarkko Nikula <jarkko.nikula@jollamobile.com>
@author Simo Piiroinen <simo.piiroinen@jollamobile.com>
@author Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
This file is part of Dsme.
Expand Down Expand Up @@ -63,6 +68,17 @@ static const wd_t wd[] = {
/* watchdog file descriptors */
static int wd_fd[WD_COUNT];

bool dsme_wd_is_wd_fd(int fd)
{
int i;

for (i = 0; i < WD_COUNT; ++i) {
if (wd_fd[i] != -1 && fd == wd_fd[i])
return true;
}

return false;
}

void dsme_wd_kick(void)
{
Expand Down
5 changes: 5 additions & 0 deletions dsme/dsme-wdd-wd.h
Expand Up @@ -6,6 +6,10 @@
Copyright (C) 2004-2010 Nokia Corporation.
@author Semi Malinen <semi.malinen@nokia.com>
@author Matias Muhonen <ext-matias.muhonen@nokia.com>
@author Pekka Lundstrom <pekka.lundstrom@jollamobile.com>
@author Simo Piiroinen <simo.piiroinen@jollamobile.com>
@author Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
This file is part of Dsme.
Expand Down Expand Up @@ -39,6 +43,7 @@
extern "C" {
#endif

bool dsme_wd_is_wd_fd(int fd);
void dsme_wd_kick(void);
void dsme_wd_kick_from_sighnd(void);
bool dsme_wd_init(void);
Expand Down
6 changes: 5 additions & 1 deletion dsme/dsme-wdd.c
Expand Up @@ -16,6 +16,7 @@
@author Simo Piiroinen <simo.piiroinen@jollamobile.com>
@author Jarkko Nikula <jarkko.nikula@jollamobile.com>
@author Carsten Munk <carsten.munk@jollamobile.com>
@author Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
This file is part of Dsme.
Expand Down Expand Up @@ -162,11 +163,14 @@ static int daemonize(void)

/* Close all file descriptors and redirect stdio to /dev/null */
i = getdtablesize();

if (i == -1) {
i = 256;
}

while (--i >= 0) {
close(i);
if (!dsme_wd_is_wd_fd(i))
close(i);
}

i = open("/dev/null", O_RDWR);
Expand Down

0 comments on commit e12053b

Please sign in to comment.