Permalink
Browse files

better stdout/stderr/stdin handling

should fix arch 100% cpu bug in daemon mode. See
https://aur.archlinux.org/packages.php?ID=45551
  • Loading branch information...
poelzi committed Dec 16, 2011
1 parent df1997c commit ffd81a24e589a621a279c57a0e07a738ceb295eb
Showing with 6 additions and 4 deletions.
  1. +6 −4 src/ulatencyd.c
View
@@ -463,6 +463,7 @@ int main (int argc, char *argv[])
{
GError *error = NULL;
GOptionContext *context;
+ int i = 0;
// required for dbus
g_type_init ();
@@ -501,10 +502,11 @@ int main (int argc, char *argv[])
if (sid < 0) {
exit (1);
}
-
- close(STDIN_FILENO);
- close(STDOUT_FILENO);
- close(STDERR_FILENO);
+ // ensure std* exist but do nothing
+ i=open("/dev/null",O_RDWR);
+ dup2(i, STDIN_FILENO);
+ dup2(i, STDOUT_FILENO);
+ dup2(i, STDERR_FILENO);
}
load_config();

0 comments on commit ffd81a2

Please sign in to comment.