hooks.c (225787) | hooks.c (229945) |
---|---|
1/*- 2 * Copyright (c) 2010 The FreeBSD Foundation 3 * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org> 4 * All rights reserved. 5 * 6 * This software was developed by Pawel Jakub Dawidek under sponsorship from 7 * the FreeBSD Foundation. 8 * --- 15 unchanged lines hidden (view full) --- 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2010 The FreeBSD Foundation 3 * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org> 4 * All rights reserved. 5 * 6 * This software was developed by Pawel Jakub Dawidek under sponsorship from 7 * the FreeBSD Foundation. 8 * --- 15 unchanged lines hidden (view full) --- 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31#include <sys/cdefs.h> |
32__FBSDID("$FreeBSD: head/sbin/hastd/hooks.c 225787 2011-09-27 08:50:37Z pjd $"); | 32__FBSDID("$FreeBSD: head/sbin/hastd/hooks.c 229945 2012-01-10 22:39:07Z pjd $"); |
33 34#include <sys/types.h> 35#include <sys/sysctl.h> 36#include <sys/wait.h> 37 38#include <errno.h> 39#include <fcntl.h> 40#include <libgen.h> --- 59 unchanged lines hidden (view full) --- 100 } 101 102 closefrom(0); 103 104 /* 105 * Redirect stdin, stdout and stderr to /dev/null. 106 */ 107 fd = open(_PATH_DEVNULL, O_RDONLY); | 33 34#include <sys/types.h> 35#include <sys/sysctl.h> 36#include <sys/wait.h> 37 38#include <errno.h> 39#include <fcntl.h> 40#include <libgen.h> --- 59 unchanged lines hidden (view full) --- 100 } 101 102 closefrom(0); 103 104 /* 105 * Redirect stdin, stdout and stderr to /dev/null. 106 */ 107 fd = open(_PATH_DEVNULL, O_RDONLY); |
108 if (fd < 0) { | 108 if (fd == -1) { |
109 pjdlog_errno(LOG_WARNING, "Unable to open %s for reading", 110 _PATH_DEVNULL); 111 } else if (fd != STDIN_FILENO) { | 109 pjdlog_errno(LOG_WARNING, "Unable to open %s for reading", 110 _PATH_DEVNULL); 111 } else if (fd != STDIN_FILENO) { |
112 if (dup2(fd, STDIN_FILENO) < 0) { | 112 if (dup2(fd, STDIN_FILENO) == -1) { |
113 pjdlog_errno(LOG_WARNING, 114 "Unable to duplicate descriptor for stdin"); 115 } 116 close(fd); 117 } 118 fd = open(_PATH_DEVNULL, O_WRONLY); | 113 pjdlog_errno(LOG_WARNING, 114 "Unable to duplicate descriptor for stdin"); 115 } 116 close(fd); 117 } 118 fd = open(_PATH_DEVNULL, O_WRONLY); |
119 if (fd < 0) { | 119 if (fd == -1) { |
120 pjdlog_errno(LOG_WARNING, "Unable to open %s for writing", 121 _PATH_DEVNULL); 122 } else { | 120 pjdlog_errno(LOG_WARNING, "Unable to open %s for writing", 121 _PATH_DEVNULL); 122 } else { |
123 if (fd != STDOUT_FILENO && dup2(fd, STDOUT_FILENO) < 0) { | 123 if (fd != STDOUT_FILENO && dup2(fd, STDOUT_FILENO) == -1) { |
124 pjdlog_errno(LOG_WARNING, 125 "Unable to duplicate descriptor for stdout"); 126 } | 124 pjdlog_errno(LOG_WARNING, 125 "Unable to duplicate descriptor for stdout"); 126 } |
127 if (fd != STDERR_FILENO && dup2(fd, STDERR_FILENO) < 0) { | 127 if (fd != STDERR_FILENO && dup2(fd, STDERR_FILENO) == -1) { |
128 pjdlog_errno(LOG_WARNING, 129 "Unable to duplicate descriptor for stderr"); 130 } 131 if (fd != STDOUT_FILENO && fd != STDERR_FILENO) 132 close(fd); 133 } 134} 135 --- 256 unchanged lines hidden --- | 128 pjdlog_errno(LOG_WARNING, 129 "Unable to duplicate descriptor for stderr"); 130 } 131 if (fd != STDOUT_FILENO && fd != STDERR_FILENO) 132 close(fd); 133 } 134} 135 --- 256 unchanged lines hidden --- |