<commit_before>package utils

//#include <stdio.h>
//#include <stdlib.h>
//#include <unistd.h>
//#include <sys/types.h>
//#include <sys/stat.h>
//#include <sys/wait.h>
//#include <sys/time.h>
//#include <sys/resource.h>
//#include <fcntl.h>
/*
int daemonize(char *cmd, char *argv[], int pipe, int fds[], int num) {
	int status = 0, fd, pid, i;
	struct sigaction sa;

	pid = fork();
	if (pid < 0) {
		return -1;
	} else if (pid > 0) {
		if (waitpid(pid, &status, 0) < 0)
			return -1;
		return WEXITSTATUS(status);
	}
	//Become a session leader to lose controlling TTY
	setsid();

	//Ensure future opens won't allocate controlling TTYs
	sa.sa_handler = SIG_IGN;
	sigemptyset(&sa.sa_mask);
	sa.sa_flags = 0;
	if (sigaction(SIGHUP, &sa, NULL) < 0) {
		_exit(-1);
	}

	pid = fork();
	if (pid < 0) {
		_exit(-1);
	} else if (pid > 0) {
		_exit(0);
	}

	if (pipe > 0) {
		char buf[4];
		int ret;

		pid = getpid();

		buf[0] = pid >> 24;
		buf[1] = pid >> 16;
		buf[2] = pid >> 8;
		buf[3] = pid;

		ret = write(pipe, buf, 4);
		if (ret != 4)
			_exit(-1);
	}

	//Clear file creation mask
	umask(0);
	//Change the current working directory to the root so we won't prevent file system from being unmounted
	if (chdir("/") < 0)
		_exit(-1);

	//Close all open file descriptors
	for (i = 0; i < num; i++) {
		if (fds[i] == 0 || fds[i] == 1 || fds[i] == 2)
			continue;

		close(fds[i]);
	}
	//Attach file descriptors 0, 1, and 2 to /dev/null
	fd = open("/dev/null", O_RDWR);
	dup2(fd, 0);
	dup2(fd, 1);
	dup2(fd, 2);
	close(fd);

	if (execvp(cmd, argv) < 0)
		_exit(-1);
	return -1;
}
*/
import "C"

import (
	"encoding/binary"
	"fmt"
	"io/ioutil"
	"strconv"
	"syscall"
	"unsafe"
)

func ExecInDaemon(cmd string, argv []string) (pid uint32, err error) {
	// convert the args to the C style args
	cargs := make([]*C.char, len(argv))
<commit_msg>fix ExecInDaemon bug<commit_after>package utils

//#include <stdio.h>
//#include <stdlib.h>
//#include <unistd.h>
//#include <sys/types.h>
//#include <sys/stat.h>
//#include <sys/wait.h>
//#include <sys/time.h>
//#include <sys/resource.h>
//#include <fcntl.h>
/*
int daemonize(char *cmd, char *argv[], int pipe, int fds[], int num) {
	int status = 0, fd, pid, i;
	struct sigaction sa;

	pid = fork();
	if (pid < 0) {
		return -1;
	} else if (pid > 0) {
		if (waitpid(pid, &status, 0) < 0)
			return -1;
		return WEXITSTATUS(status);
	}
	//Become a session leader to lose controlling TTY
	setsid();

	//Ensure future opens won't allocate controlling TTYs
	sa.sa_handler = SIG_IGN;
	sigemptyset(&sa.sa_mask);
	sa.sa_flags = 0;
	if (sigaction(SIGHUP, &sa, NULL) < 0) {
		_exit(-1);
	}

	pid = fork();
	if (pid < 0) {
		_exit(-1);
	} else if (pid > 0) {
		_exit(0);
	}

	if (pipe > 0) {
		char buf[4];
		int ret;

		pid = getpid();

		buf[0] = pid >> 24;
		buf[1] = pid >> 16;
		buf[2] = pid >> 8;
		buf[3] = pid;

		ret = write(pipe, buf, 4);
		if (ret != 4)
			_exit(-1);
	}

	//Clear file creation mask
	umask(0);
	//Change the current working directory to the root so we won't prevent file system from being unmounted
	if (chdir("/") < 0)
		_exit(-1);

	//Close all open file descriptors
	for (i = 0; i < num; i++) {
		if (fds[i] == 0 || fds[i] == 1 || fds[i] == 2)
			continue;

		close(fds[i]);
	}
	//Attach file descriptors 0, 1, and 2 to /dev/null
	fd = open("/dev/null", O_RDWR);
	dup2(fd, 0);
	dup2(fd, 1);
	dup2(fd, 2);
	close(fd);

	if (execvp(cmd, argv) < 0)
		_exit(-1);
	return -1;
}
*/
import "C"

import (
	"encoding/binary"
	"fmt"
	"io/ioutil"
	"strconv"
	"syscall"
	"unsafe"
)

func ExecInDaemon(cmd string, argv []string) (pid uint32, err error) {
	// convert the args to the C style args
	// +1 for the list of arguments must be terminated by a null pointer
	cargs := make([]*C.char, len(argv)+1)

{'fraction_non_alphanumeric': 0.190984262469992, 'fraction_numerical': 0.026673779674579887, 'mean_word_length': 3.0496760259179267, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2054028', 'n_tokens_mistral': 1737, 'n_tokens_neox': 1588, 'n_words': 469}