<commit_before>/*
 * author: <NAME> <<EMAIL>>
 */

#ifndef PREPARED_CHILD_PROCESS_HXX
#define PREPARED_CHILD_PROCESS_HXX

#include "util/StaticArray.hxx"
#include "ResourceLimits.hxx"
#include "RefenceOptions.hxx"
#include "NamespaceOptions.hxx"

#include <string>
#include <forward_list>

#include <assert.h>

template<typename T> struct ConstBuffer;

struct PreparedChildProcess {
    StaticArray<const char *, 32> args;
    StaticArray<const char *, 32> env;
    int stdin_fd = -1, stdout_fd = -1, stderr_fd = -1, control_fd = -1;

    RefenceOptions refence;

    NamespaceOptions ns;

    ResourceLimits rlimits;

    /**
     * String allocations for SetEnv().
     */
    std::forward_list<std::string> strings;

    PreparedChildProcess();
    ~PreparedChildProcess();

    PreparedChildProcess(const PreparedChildProcess &) = delete;
    PreparedChildProcess &operator=(const PreparedChildProcess &) = delete;

    bool InsertWrapper(ConstBuffer<const char *> w);

    void Append(const char *arg) {
        assert(arg != nullptr);

        args.push_back(arg);
    }

    bool PutEnv(const char *p) {
        if (env.size() + 1 >= env.capacity())
            return false;

        env.push_back(p);
        return true;
    }

    bool SetEnv(const char *name, const char *value);

    /**<commit_msg>spawn/Prepared: Append() returns bool<commit_after>/*
 * author: <NAME> <<EMAIL>>
 */

#ifndef PREPARED_CHILD_PROCESS_HXX
#define PREPARED_CHILD_PROCESS_HXX

#include "util/StaticArray.hxx"
#include "ResourceLimits.hxx"
#include "RefenceOptions.hxx"
#include "NamespaceOptions.hxx"

#include <string>
#include <forward_list>

#include <assert.h>

template<typename T> struct ConstBuffer;

struct PreparedChildProcess {
    StaticArray<const char *, 32> args;
    StaticArray<const char *, 32> env;
    int stdin_fd = -1, stdout_fd = -1, stderr_fd = -1, control_fd = -1;

    RefenceOptions refence;

    NamespaceOptions ns;

    ResourceLimits rlimits;

    /**
     * String allocations for SetEnv().
     */
    std::forward_list<std::string> strings;

    PreparedChildProcess();
    ~PreparedChildProcess();

    PreparedChildProcess(const PreparedChildProcess &) = delete;
    PreparedChildProcess &operator=(const PreparedChildProcess &) = delete;

    bool InsertWrapper(ConstBuffer<const char *> w);

    bool Append(const char *arg) {
        assert(arg != nullptr);

        if (args.size() + 1 >= env.capacity())
            return false;

        args.push_back(arg);
        return true;
    }

    bool PutEnv(const char *p) {
        if (env.size() + 1 >= env.capacity())
            return false;

        env.push_back(p);
        return true;
    }

    bool SetEnv(const char *name, const char *value);

    /**
{'fraction_non_alphanumeric': 0.12212905577834487, 'fraction_numerical': 0.006926722566532993, 'mean_word_length': 3.2476780185758516, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 28, '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': '1321740', 'n_tokens_mistral': 923, 'n_tokens_neox': 873, 'n_words': 205}