<commit_before>/* Copyright 2014-2015 <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 "connector.h"
#include "command.h"
#include "event.h"
#include "log.h"
#include "nyx.h"
#include "poll.h"
#include "state.h"
#include "utils.h"

#include <stdio.h>

static int
daemon_mode(nyx_t *nyx)
{
    if (!nyx_watches_init(nyx))
    {
        log_error("No valid watched configured - terminating now");

        return 0;
    }

    /* start the event handler loop */
    if (!event_loop(nyx, dispatch_event))
    {
        log_warn("Failed to initialize event manager "
                  "- trying polling mechanism next");

        if (!poll_loop(nyx, dispatch_poll_result))
        {
            log_error("Failed to start loop manager as well - terminating");
            return 0;
        }
    }

    return 1;
}

static int
command_mode(nyx_t *nyx)
{
    int success = 0;

    if (!nyx->options.commands)
    {
        log_error("no command specified at all");
        return 0;
    }

    if (parse_command(nyx->options.commands) != NULL)<commit_msg>extend warning on event initialization failure<commit_after>/* Copyright 2014-2015 <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 "connector.h"
#include "command.h"
#include "event.h"
#include "log.h"
#include "nyx.h"
#include "poll.h"
#include "state.h"
#include "utils.h"

#include <stdio.h>

static int
daemon_mode(nyx_t *nyx)
{
    if (!nyx_watches_init(nyx))
    {
        log_error("No valid watched configured - terminating now");

        return 0;
    }

    /* start the event handler loop */
    if (!event_loop(nyx, dispatch_event))
    {
        log_warn("Failed to initialize event manager "
                  "- trying polling mechanism next");

        log_warn("Try enabling CONFIG_CONNECTOR in your kernel config "
                 "and run nyx with root privileges");

        if (!poll_loop(nyx, dispatch_poll_result))
        {
            log_error("Failed to start loop manager as well - terminating");
            return 0;
        }
    }

    return 1;
}

static int
command_mode(nyx_t *nyx)
{
    int success = 0;

    if (!nyx->options.commands)
    {
        log_error("no command specified at all");
        return 0;
    }

    if (parse_command(nyx->options.commands) != NULL)
{'fraction_non_alphanumeric': 0.10235507246376811, 'fraction_numerical': 0.010265700483091788, 'mean_word_length': 2.825635103926097, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '6130882', 'n_tokens_mistral': 1010, 'n_tokens_neox': 956, 'n_words': 347}