-/*
- * NAME
- * pids_list_free_all
- *
- * DESCRIPTION
- * Frees memory allocated in the given list
- *
- * PARAMETERS
- * `list' Pids list
- */
-void pids_list_free_all(pids_list_t *list) {
- while (list) {
- pids_list_t *previous = list;
- list = list->next;
- free(previous);
- }
-}
-
-typedef struct stub_proc_pid {
- proc_comm_t comm;
- pid_t pid;
-} stub_proc_pid_t;
-
-static const char *proc_fs = "/tmp/procfs_stub";
-
-/*
- * NAME
- * stub_procfs_setup
- *
- * DESCRIPTION
- * Prepares testing environment by creating temporary
- * PID/comm file structure.
- *
- * PARAMETERS
- * `proc_pids_array' Array of stub_proc_pid_t structs. Represents
- * which PIDs should hold given process name.
- * `proc_pids_array_length' Element count of input array.
- *
- * RETURN VALUE
- * 0 on success.
- * -1 on base dir creation error.
- * -2 on comm file creation error.
- */
-int stub_procfs_setup(const stub_proc_pid_t *proc_pids_array,
- const size_t proc_pids_array_length) {
- if (mkdir(proc_fs, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) {
- return -1;
- }
- char path[256];
-
- for (size_t i = 0; i < proc_pids_array_length; ++i) {
- memset(path, 0, sizeof(path));
- snprintf(path, STATIC_ARRAY_SIZE(path), "%s/%d", proc_fs,
- proc_pids_array[i].pid);
- mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
- strncat(path, "/comm", STATIC_ARRAY_SIZE(path) - strlen(path) - 1);
-
- FILE *fp = fopen(path, "w");
- if (!fp) {
- return -2;
- }
- fwrite(proc_pids_array[i].comm, sizeof(char),
- strlen(proc_pids_array[i].comm), fp);
- fclose(fp);
- }
- return 0;
-}
-
-/*
- * NAME
- * stub_procfs_teardown
- *
- * DESCRIPTION
- * Clears testing environment: removes stub proc files.
- * NOTE - This function could be implemented by usage of nftw, but this
- * would require #define _XOPEN_SOURCE 500, which
- * messes up intel_rdt includes.
- *
- * RETURN VALUE
- * system command result
- */
-int stub_procfs_teardown() {
- char cmd[256];
- sstrncpy(cmd, "rm -rf ", STATIC_ARRAY_SIZE(cmd));
- strncat(cmd, proc_fs, STATIC_ARRAY_SIZE(cmd) - strlen(cmd) - 1);
- return system(cmd);