Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Build fixes for ubuntu 8.10/64.

gcc seems to have been wise to all of the syscalls being cast to void
to avoid doing real result checking in unlikely errors.
  • Loading branch information...
commit 2c196ed6cacfd3eea845a3b9a5758a698096d97b 1 parent ad00048
Dustin Sallings dustin authored

Showing 1 changed file with 26 additions and 7 deletions. Show diff stats Hide diff stats

  1. +26 7 daemon.c
33 daemon.c
@@ -35,6 +35,7 @@
35 35 #endif
36 36
37 37 #include <fcntl.h>
  38 +#include <stdio.h>
38 39 #include <stdlib.h>
39 40 #include <unistd.h>
40 41
@@ -56,15 +57,33 @@ int daemonize(int nochdir, int noclose)
56 57 if (setsid() == -1)
57 58 return (-1);
58 59
59   - if (nochdir == 0)
60   - (void)chdir("/");
  60 + if (nochdir == 0) {
  61 + if(chdir("/") != 0) {
  62 + perror("chdir");
  63 + return (-1);
  64 + }
  65 + }
61 66
62 67 if (noclose == 0 && (fd = open("/dev/null", O_RDWR, 0)) != -1) {
63   - (void)dup2(fd, STDIN_FILENO);
64   - (void)dup2(fd, STDOUT_FILENO);
65   - (void)dup2(fd, STDERR_FILENO);
66   - if (fd > STDERR_FILENO)
67   - (void)close(fd);
  68 + if(dup2(fd, STDIN_FILENO) < 0) {
  69 + perror("dup2 stdin");
  70 + return (-1);
  71 + }
  72 + if(dup2(fd, STDOUT_FILENO) < 0) {
  73 + perror("dup2 stdout");
  74 + return (-1);
  75 + }
  76 + if(dup2(fd, STDERR_FILENO) < 0) {
  77 + perror("dup2 stderr");
  78 + return (-1);
  79 + }
  80 +
  81 + if (fd > STDERR_FILENO) {
  82 + if(close(fd) < 0) {
  83 + perror("close");
  84 + return (-1);
  85 + }
  86 + }
68 87 }
69 88 return (0);
70 89 }

0 comments on commit 2c196ed

Please sign in to comment.
Something went wrong with that request. Please try again.