Skip to content

Commit

Permalink
[sensorfwd] Do not call exit() twice when forking a daemon. MER#1749
Browse files Browse the repository at this point in the history
The "one exit() call / entry to main()" rule of thumb is not observed.

Terminate parent with _exit() when child is successfully forked.

Also flush stdio streams before forking.

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Feb 7, 2017
1 parent 28f826f commit 2a66a99
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sensord/main.cpp
Expand Up @@ -137,6 +137,8 @@ int main(int argc, char *argv[])

if (parser.createDaemon())
{
fflush(0);

int pid = fork();

if(pid < 0)
Expand All @@ -145,7 +147,7 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
} else if (pid > 0) {
sensordLogW() << "Created a daemon";
exit(EXIT_SUCCESS);
_exit(EXIT_SUCCESS);
}
}

Expand Down

0 comments on commit 2a66a99

Please sign in to comment.