<commit_before>/*
 * Copyright (c) 2018 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 "podman.h"
#include <varlink.h>
#include <sys/epoll.h>
#include <sys/signalfd.h>

typedef struct varlink {
    int			epoll_fd;
    int			signal_fd;
    VarlinkConnection	*connection;
} varlink_t;

typedef struct varlink_reply {
    char		*error;
    VarlinkObject	*parameters;
} varlink_reply_t;

static inline int
epoll_control(int epfd, int op, int fd, uint32_t events, void *ptr)
{
    struct epoll_event	event = {.events = events, .data = {.ptr = ptr}};

    return epoll_ctl(epfd, op, fd, &event);
}

static varlink_t *
varlink_connect(void)
{
    static varlink_t	varlink;
    static int		setup;
    sigset_t		mask;
    int			sts;

    if (setup == 0) {
	if ((varlink.epoll_fd = epoll_create1(EPOLL_CLOEXEC)) < 0)
	    return NULL;
	sigemptyset(&mask);
	sigaddset(&mask, SIGTERM);
	sigaddset(&mask, SIGINT);
	sigaddset(&mask, SIGPIPE);
	sigprocmask(SIG_BLOCK, &mask, NULL);
	varlink.signal_fd = signalfd(-1, &mask, SFD_NONBLOCK | SFD_CLOEXEC);
	if (varlink.signal_fd < 0)
	    return NULL;
	epoll_control(varlink.epoll_fd, EPOLL_CTL_ADD, varlink.signal_fd, EPOLLIN, NULL);
	setup = 1;
    }

    sts = varlink_connection_new(&varlink.connection, "unix:/run/podman/io.podman");
    if (sts != 0)
	return NULL;

    return &varlink;
}<commit_msg>pmdapodman: log varlink connection error message<commit_after>/*
 * Copyright (c) 2018 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 "podman.h"
#include <varlink.h>
#include <sys/epoll.h>
#include <sys/signalfd.h>

typedef struct varlink {
    int			epoll_fd;
    int			signal_fd;
    VarlinkConnection	*connection;
} varlink_t;

typedef struct varlink_reply {
    char		*error;
    VarlinkObject	*parameters;
} varlink_reply_t;

static inline int
epoll_control(int epfd, int op, int fd, uint32_t events, void *ptr)
{
    struct epoll_event	event = {.events = events, .data = {.ptr = ptr}};

    return epoll_ctl(epfd, op, fd, &event);
}

static varlink_t *
varlink_connect(void)
{
    static varlink_t	varlink;
    static int		setup;
    sigset_t		mask;
    int			sts;

    if (setup == 0) {
	if ((varlink.epoll_fd = epoll_create1(EPOLL_CLOEXEC)) < 0)
	    return NULL;
	sigemptyset(&mask);
	sigaddset(&mask, SIGTERM);
	sigaddset(&mask, SIGINT);
	sigaddset(&mask, SIGPIPE);
	sigprocmask(SIG_BLOCK, &mask, NULL);
	varlink.signal_fd = signalfd(-1, &mask, SFD_NONBLOCK | SFD_CLOEXEC);
	if (varlink.signal_fd < 0)
	    return NULL;
	epoll_control(varlink.epoll_fd, EPOLL_CTL_ADD, varlink.signal_fd, EPOLLIN, NULL);
	setup = 1;
    }

    sts = varlink_connection_new(&varlink.connection, "unix:/run/podman/io.podman");
    if (sts != 0) {
	fprintf(stderr, "Error connecting to varlink %s: %s\n",
		"unix:/run/podman/io.podman",
		varlink_error_string(-sts));
	return NULL;
    }

    return &varlink;
}
{'fraction_non_alphanumeric': 0.10655090765588003, 'fraction_numerical': 0.007366482504604052, 'mean_word_length': 3.8494897959183674, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, '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': '4595783', 'n_tokens_mistral': 1388, 'n_tokens_neox': 1328, 'n_words': 406}