<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <error.h>

#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>


enum { PORT = 1337 };


int sockfd;

typedef struct {
	int id;
	int threads;
	int input_len;
} WorkArgs;


void* work_thread(WorkArgs* args) {
	char line[1024];
	snprintf(line, sizeof(line),
		"../index/index mr %d ../index/wiki/dump_%04d.txt",
		args->threads, args->input_len);

	FILE* f = popen(line, "r");
	size_t len = fread(line, 1, sizeof(line), f);
	if (len <= 0) printf("work %d error\n", args->id);
	else printf("work %d output: %.*s", args->id, len, line);
	pclose(f);

	snprintf(line, sizeof(line), "work %d done", args->id);
	printf("%s\n", line);
	send(sockfd, line, strlen(line) + 1, 0);

	free(args);
	return NULL;
}


void handle_command(char* cmd) {
	char* p = strchr(cmd, ' ');
	if (!p) goto ERROR;
	*p++ = '\0';
	printf("command: %s %s\n", cmd, p);

	if (strcmp(cmd, "work") == 0) {
		WorkArgs* args = malloc(sizeof(WorkArgs));
		if (sscanf(p, "%d %d %d",
			&args->id, &args->threads, &args->input_len) != 3) goto ERROR;
		pthread_t work;
		pthread_create(&work, NULL, work_thread, args);
	}
	else if (strcmp(cmd, "cpu") == 0) {
		int cpus, freq;
		if (sscanf(p, "%d %d", &cpus, &freq) != 2) goto ERROR;

		// enable/disable 2nd cpu
		if (cpus == 1 || cpus == 2) {
			FILE* f = fopen("/sys/devices/system/cpu/cpu1/online", "w");
			if (!f) {
				printf("cpu error\n");
				return;
			}
			fprintf(f, cpus == 2 ? "1\n" : "0\n");
			fclose(f);
		}
		else goto ERROR;

		// change cpu freq
		printf("%d\n", system("cpufreq-set --governor userspace"));
		printf("%d\n", system("cpufreq-set --min 30000"));
		printf("%d\n", system("cpufreq-set --max 1008000"));
		char line[256];
		sprintf(line, "cpufreq-set --freq %d000", freq);
		printf("%d\n", system(line));

	}
	else goto ERROR;
	return;
ERROR:
	printf("error parsing command: %s\n", cmd);
}
<commit_msg>send error code<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <error.h>

#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>


enum { PORT = 1337 };


int sockfd;

typedef struct {
	int id;
	int threads;
	int input_len;
} WorkArgs;


void* work_thread(WorkArgs* args) {
	char line[1024];
	snprintf(line, sizeof(line),
		"../index/index mr %d ../index/wiki/dump_%04d.txt",
		args->threads, args->input_len);

	FILE* f = popen(line, "r");
	size_t len = fread(line, 1, sizeof(line), f);
	if (len <= 0) printf("work %d error\n", args->id);
	else printf("work %d output: %.*s", args->id, len, line);
	int ret = pclose(f);

	snprintf(line, sizeof(line), "work %d done %d", args->id, ret);
	printf("%s\n", line);
	send(sockfd, line, strlen(line) + 1, 0);

	free(args);
	return NULL;
}


void handle_command(char* cmd) {
	char* p = strchr(cmd, ' ');
	if (!p) goto ERROR;
	*p++ = '\0';
	printf("command: %s %s\n", cmd, p);

	if (strcmp(cmd, "work") == 0) {
		WorkArgs* args = malloc(sizeof(WorkArgs));
		if (sscanf(p, "%d %d %d",
			&args->id, &args->threads, &args->input_len) != 3) goto ERROR;
		pthread_t work;
		pthread_create(&work, NULL, work_thread, args);
	}
	else if (strcmp(cmd, "cpu") == 0) {
		int cpus, freq;
		if (sscanf(p, "%d %d", &cpus, &freq) != 2) goto ERROR;

		// enable/disable 2nd cpu
		if (cpus == 1 || cpus == 2) {
			FILE* f = fopen("/sys/devices/system/cpu/cpu1/online", "w");
			if (!f) {
				printf("cpu error\n");
				return;
			}
			fprintf(f, cpus == 2 ? "1\n" : "0\n");
			fclose(f);
		}
		else goto ERROR;

		// change cpu freq
		char line[1024];
		sprintf(line,
			"cpufreq-set --governor userspace && "
			"cpufreq-set --min 30000 && "
			"cpufreq-set --max 1008000 && "
			"cpufreq-set --freq %d000", freq);
		if (system(line) != 0) {
			printf("cpu error\n");
			return;
		}

	}
	else goto ERROR;
	return;
ERROR:
	printf("error parsing command: %s\n", cmd);
}

{'fraction_non_alphanumeric': 0.2131565527791943, 'fraction_numerical': 0.022947475777664456, 'mean_word_length': 3.5775962660443406, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 35, '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': '7027372', 'n_tokens_mistral': 1800, 'n_tokens_neox': 1619, 'n_words': 413}