<commit_before>/*
 * Copyright 2013-2016 <NAME>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may 
 * not use this file except in compliance with the License. You may obtain 
 * a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License. 
 */

#include "watchdogd.hpp"
#include <sys/wait.h>
#include "sub.hpp"
#include "init.hpp"
#include "pidfile.hpp"
#include "daemon.hpp"

static int CloseStandardFileDescriptors(void)
{
	int ret = 0;
	struct stat statBuf;

	int fd = open("/dev/null", O_RDWR);

	if (fd < 0) {
		Logmsg(LOG_CRIT, "Unable to open: /dev/null: %s:",
		       MyStrerror(errno));
		return -1;
	}

	if (fstat(fd, &statBuf) != 0) {
		Logmsg(LOG_CRIT, "Stat failed %s", MyStrerror(errno));
		goto error;
	} else if (S_ISCHR(statBuf.st_mode) == 0
		   && S_ISBLK(statBuf.st_mode) == 0) {
		Logmsg(LOG_CRIT, "/dev/null is not a unix device file");
		goto error;
	}

	ret = dup2(fd, STDIN_FILENO);
	if (ret < 0) {
		Logmsg(LOG_CRIT, "dup2 failed: STDIN_FILENO: %s",
		       MyStrerror(errno));
		goto error;
	}

	ret = dup2(fd, STDOUT_FILENO);
	if (ret < 0) {
		Logmsg(LOG_CRIT, "dup2 failed: STDOUT_FILENO: %s",
		       MyStrerror(errno));
		goto error;
	}

	ret = dup2(fd, STDERR_FILENO);
	if (ret < 0) {
		Logmsg(LOG_CRIT, "dup2 failed: STDERR_FILENO: %s",
		       MyStrerror(errno));
		goto error;
	}

	close(fd);
	return 0;
 error:
	close(fd);
	return -1;
}

static void CloseFileDescriptors(long maxfd)
{
	long fd = 0;

	while (fd < maxfd || fd == maxfd) {<commit_msg>remove unused function<commit_after>/*
 * Copyright 2013-2016 <NAME>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may 
 * not use this file except in compliance with the License. You may obtain 
 * a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License. 
 */

#include "watchdogd.hpp"
#include <sys/wait.h>
#include "sub.hpp"
#include "init.hpp"
#include "pidfile.hpp"
#include "daemon.hpp"

static void CloseFileDescriptors(long maxfd)
{
	long fd = 0;

	while (fd < maxfd || fd == maxfd) {
{'fraction_non_alphanumeric': 0.12242647058823529, 'fraction_numerical': 0.015808823529411764, 'mean_word_length': 3.6913793103448276, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3774863', 'n_tokens_mistral': 991, 'n_tokens_neox': 928, 'n_words': 315}