Deleted Added
full compact
hooks.c (204076) hooks.c (211884)
1/*-
2 * Copyright (c) 2010 The FreeBSD Foundation
3 * All rights reserved.
4 *
5 * This software was developed by Pawel Jakub Dawidek under sponsorship from
6 * the FreeBSD Foundation.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 14 unchanged lines hidden (view full) ---

23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2010 The FreeBSD Foundation
3 * All rights reserved.
4 *
5 * This software was developed by Pawel Jakub Dawidek under sponsorship from
6 * the FreeBSD Foundation.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 14 unchanged lines hidden (view full) ---

23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: head/sbin/hastd/hooks.c 204076 2010-02-18 23:16:19Z pjd $");
31__FBSDID("$FreeBSD: head/sbin/hastd/hooks.c 211884 2010-08-27 14:35:39Z pjd $");
32
33#include <sys/types.h>
34#include <sys/wait.h>
35
36#include <assert.h>
37#include <fcntl.h>
38#include <stdio.h>
39#include <stdlib.h>

--- 16 unchanged lines hidden (view full) ---

56 /*
57 * Close all descriptors.
58 */
59 maxfd = sysconf(_SC_OPEN_MAX);
60 if (maxfd < 0) {
61 pjdlog_errno(LOG_WARNING, "sysconf(_SC_OPEN_MAX) failed");
62 maxfd = 1024;
63 }
32
33#include <sys/types.h>
34#include <sys/wait.h>
35
36#include <assert.h>
37#include <fcntl.h>
38#include <stdio.h>
39#include <stdlib.h>

--- 16 unchanged lines hidden (view full) ---

56 /*
57 * Close all descriptors.
58 */
59 maxfd = sysconf(_SC_OPEN_MAX);
60 if (maxfd < 0) {
61 pjdlog_errno(LOG_WARNING, "sysconf(_SC_OPEN_MAX) failed");
62 maxfd = 1024;
63 }
64 for (fd = 0; fd <= maxfd; fd++)
65 close(fd);
64 for (fd = 0; fd <= maxfd; fd++) {
65 switch (fd) {
66 case STDIN_FILENO:
67 case STDOUT_FILENO:
68 case STDERR_FILENO:
69 if (pjdlog_mode_get() == PJDLOG_MODE_STD)
70 break;
71 /* FALLTHROUGH */
72 default:
73 close(fd);
74 break;
75 }
76 }
77 if (pjdlog_mode_get() == PJDLOG_MODE_STD)
78 return;
66 /*
67 * Redirect stdin, stdout and stderr to /dev/null.
68 */
69 fd = open(_PATH_DEVNULL, O_RDONLY);
70 if (fd < 0) {
71 pjdlog_errno(LOG_WARNING, "Unable to open %s for reading",
72 _PATH_DEVNULL);
73 } else if (fd != STDIN_FILENO) {

--- 75 unchanged lines hidden ---
79 /*
80 * Redirect stdin, stdout and stderr to /dev/null.
81 */
82 fd = open(_PATH_DEVNULL, O_RDONLY);
83 if (fd < 0) {
84 pjdlog_errno(LOG_WARNING, "Unable to open %s for reading",
85 _PATH_DEVNULL);
86 } else if (fd != STDIN_FILENO) {

--- 75 unchanged lines hidden ---