<commit_before>/*
 * Utility functions for the pipe PMDA.
 *
 * Copyright (c) 2015 Red Hat.
 * 
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */

#include "pmapi.h"
#include "impl.h"
#include "util.h"
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif

#define PARENT_END 0			/* parent end of the pipe */
#define CHILD_END 1			/* child end of the pipe */
#define STDOUT_FD 1			/* stdout fd */

int
start_cmd(const char *cmd, pid_t *ppid)
{
    pid_t	child_pid;
    int		i, pipe_fds[2];

    if (pmDebug & DBG_TRACE_APPL0)
	__pmNotifyErr(LOG_INFO, "%s: Trying to run command: %s", __FUNCTION__,
		  cmd);

    /* Create the pipes. */
#if defined(HAVE_PIPE2)
    if ((pipe2(pipe_fds, O_CLOEXEC|O_NONBLOCK)) < 0) {
	__pmNotifyErr(LOG_ERR, "%s: pipe2() returned %s", __FUNCTION__,
		      strerror(errno));
	return -1;
    }
#else
    if ((sts = pipe(pipe_fds)) < 0) {
	__pmNotifyErr(LOG_ERR, "%s: pipe() returned %s", __FUNCTION__,
		      strerror(errno));
	return -1;
    }

    /* Set the right flags on the pipes. */
    if (fcntl(pipe_fds[PARENT_END], F_SETFL, O_NDELAY) < 0 ||
	fcntl(pipe_fds[CHILD_END], F_SETFL, O_NDELAY) < 0) {
	__pmNotifyErr(LOG_ERR, "%s: fcntl() returned %s", __FUNCTION__,
		      strerror(errno));
	return -1;<commit_msg>pipe PMDA: fix compilation error when pipe2() not available<commit_after>/*
 * Utility functions for the pipe PMDA.
 *
 * Copyright (c) 2015 Red Hat.
 * 
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */

#include "pmapi.h"
#include "impl.h"
#include "util.h"
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif

#define PARENT_END 0			/* parent end of the pipe */
#define CHILD_END 1			/* child end of the pipe */
#define STDOUT_FD 1			/* stdout fd */

int
start_cmd(const char *cmd, pid_t *ppid)
{
    pid_t	child_pid;
    int		i, pipe_fds[2];
#if !defined(HAVE_PIPE2)
    int		sts;
#endif

    if (pmDebug & DBG_TRACE_APPL0)
	__pmNotifyErr(LOG_INFO, "%s: Trying to run command: %s", __FUNCTION__,
		  cmd);

    /* Create the pipes. */
#if defined(HAVE_PIPE2)
    if ((pipe2(pipe_fds, O_CLOEXEC|O_NONBLOCK)) < 0) {
	__pmNotifyErr(LOG_ERR, "%s: pipe2() returned %s", __FUNCTION__,
		      strerror(errno));
	return -1;
    }
#else
    if ((sts = pipe(pipe_fds)) < 0) {
	__pmNotifyErr(LOG_ERR, "%s: pipe() returned %s", __FUNCTION__,
		      strerror(errno));
	return -1;
    }

    /* Set the right flags on the pipes. */
    if (fcntl(pipe_fds[PARENT_END], F_SETFL, O_NDELAY) < 0 ||
	fcntl(pipe_fds[CHILD_END], F_SETFL, O_NDELAY) < 0) {
	__pmNotifyErr(LOG_ERR, "%s: fcntl() returned %s", __FUNCTION__,
		      strerror(errno));
	return -1;
{'fraction_non_alphanumeric': 0.11672374429223745, 'fraction_numerical': 0.011986301369863013, 'mean_word_length': 3.581699346405229, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, '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': '5248222', 'n_tokens_mistral': 1297, 'n_tokens_neox': 1221, 'n_words': 418}