#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>

int main(void) {
    FILE *file = fopen("info.md", "w");

    if (file == NULL) {
        perror("fopen");
        return EXIT_FAILURE;
    }

    char hostname[256];

    if (gethostname(hostname, sizeof(hostname)) != 0) {
        perror("gethostname");
        fclose(file);
        return EXIT_FAILURE;
    }

    fprintf(file, "# Process information\n\n");

    fprintf(file, "Hostname: %s\n", hostname);
    fprintf(file, "PID: %d\n", getpid());
    fprintf(file, "UID: %d\n", getuid());

    fprintf(file, "\n## Contents of /tmp\n\n");

    fflush(file);

    char command[512];
    snprintf(
        command,
        sizeof(command),
        "ls /tmp/ >> info.md"
    );

    int result = system(command);

    fclose(file);

    if (result != 0) {
        fprintf(stderr, "Could not list /tmp\n");
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}
