void setup_pseudo_filesystems() { // This only works in the real environment. #ifndef UNITTEST OK_OR_WARN(mount("", "/proc", "proc", 0, NULL), "Cannot mount /proc"); OK_OR_WARN(mount("", "/sys", "sysfs", 0, NULL), "Cannot mount /sys"); // /dev should be automatically created/mounted by Linux OK_OR_WARN(mkdir("/dev/pts", 0755), "Cannot create /dev/pts"); OK_OR_WARN(mkdir("/dev/shm", 0755), "Cannot create /dev/shm"); OK_OR_WARN(mount("", "/dev/pts", "devpts", 0, "gid=5,mode=620"), "Cannot mount /dev/pts"); #endif }
static void configure_hostname() { debug("configure_hostname"); char hostname[128] = "\0"; if (options.hostname_pattern) { // Set the hostname based on a pattern char unique_id[64] = "xxxxxxxx"; if (options.uniqueid_exec) system_cmd(options.uniqueid_exec, unique_id, sizeof(unique_id)); sprintf(hostname, options.hostname_pattern, unique_id); } else { // Set the hostname from /etc/hostname FILE *fp = fopen("/etc/hostname", "r"); if (!fp) { warn("/etc/hostname not found"); return; } // The hostname should be the first line of the file if (fgets(hostname, sizeof(hostname), fp)) trim_whitespace(hostname); fclose(fp); } if (*hostname == '\0') { warn("Not setting empty hostname"); return; } debug("Hostname: %s", hostname); #ifndef UNITTEST OK_OR_WARN(sethostname(hostname, strlen(hostname)), "Error setting hostname: %s", strerror(errno)); #endif }