<commit_before>#include "../include/memory.h"
#include "../include/process.h"

#include <dirent.h>

using std::array;
using std::string;
using std::unique_ptr;
using std::vector;

int Spawner::NormalTimer::cpid;
std::mutex Spawner::NormalTimer::lock;

string Spawner::receiveErrorMessage(int status, int fd) {
	string message;
	array<char, 4096> buff;
	// Read errors from fd
	ssize_t rc;
	while ((rc = read(fd, buff.data(), buff.size())) > 0)
		message.append(buff.data(), rc);

	if (message.size()) // Error in tracee
		THROW(message);

	if (WIFEXITED(status))
		message = concat("returned ",
			toString(WEXITSTATUS(status)));

	else if (WIFSIGNALED(status))
		message = concat("killed by signal ", toString(WTERMSIG(status)), " - ",
			strsignal(WTERMSIG(status)));

	return message;
};

string getCWD() {
	array<char, PATH_MAX> buff;
	if (getcwd(buff.data(), buff.size()))
		THROW("Failed to get CWD", error(errno));

	if (buff[0] != '/') {
		errno = ENOENT; // Improper path, but getcwd() succeed
		THROW("Failed to get CWD", error(errno));
	}

	string res(buff.data());
	if (res.back() != '/')
		res += '/';

	return res;
}

string getExec(pid_t pid) {
	array<char, 4096> buff;
	string path = concat("/proc/", toString(pid), "/exe");

	ssize_t rc = readlink(path.c_str(), buff.data(), buff.size());
	if ((rc == -1 && errno == ENAMETOOLONG)<commit_msg>Fix regression<commit_after>#include "../include/memory.h"
#include "../include/process.h"

#include <dirent.h>

using std::array;
using std::string;
using std::unique_ptr;
using std::vector;

int Spawner::NormalTimer::cpid;
std::mutex Spawner::NormalTimer::lock;

string Spawner::receiveErrorMessage(int status, int fd) {
	string message;
	array<char, 4096> buff;
	// Read errors from fd
	ssize_t rc;
	while ((rc = read(fd, buff.data(), buff.size())) > 0)
		message.append(buff.data(), rc);

	if (message.size()) // Error in tracee
		THROW(message);

	if (WIFEXITED(status))
		message = concat("returned ",
			toString(WEXITSTATUS(status)));

	else if (WIFSIGNALED(status))
		message = concat("killed by signal ", toString(WTERMSIG(status)), " - ",
			strsignal(WTERMSIG(status)));

	return message;
};

string getCWD() {
	array<char, PATH_MAX> buff;
	if (!getcwd(buff.data(), buff.size()))
		THROW("Failed to get CWD", error(errno));

	if (buff[0] != '/') {
		errno = ENOENT; // Improper path, but getcwd() succeed
		THROW("Failed to get CWD", error(errno));
	}

	string res(buff.data());
	if (res.back() != '/')
		res += '/';

	return res;
}

string getExec(pid_t pid) {
	array<char, 4096> buff;
	string path = concat("/proc/", toString(pid), "/exe");

	ssize_t rc = readlink(path.c_str(), buff.data(), buff.size());
	if ((rc == -1 && errno == ENAMETOOLONG)
{'fraction_non_alphanumeric': 0.1916850625459897, 'fraction_numerical': 0.008094186902133923, 'mean_word_length': 4.594650205761317, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '7079850', 'n_tokens_mistral': 1055, 'n_tokens_neox': 998, 'n_words': 238}