-/*
- * Back up all hosts from the sm directory to sm.bak
- */
-static void
-backup_hosts(const char *dirname, const char *bakname)
-{
- struct dirent *de;
- DIR *dir;
-
- if (!(dir = opendir(dirname))) {
- nsm_log(LOG_WARNING,
- "Failed to open %s: %s", dirname, strerror(errno));
- return;
- }
-
- while ((de = readdir(dir)) != NULL) {
- char src[1024], dst[1024];
-
- if (de->d_name[0] == '.')
- continue;
-
- snprintf(src, sizeof(src), "%s/%s", dirname, de->d_name);
- snprintf(dst, sizeof(dst), "%s/%s", bakname, de->d_name);
- if (rename(src, dst) < 0) {
- nsm_log(LOG_WARNING,
- "Failed to rename %s -> %s: %m",
- src, dst);
- }
- }
- closedir(dir);
-}
-
-/*
- * Get all entries from sm.bak and convert them to host entries
- */
-static void
-get_hosts(const char *dirname)
-{
- struct nsm_host *host;
- struct dirent *de;
- DIR *dir;
-
- if (!(dir = opendir(dirname))) {
- nsm_log(LOG_WARNING,
- "Failed to open %s: %s", dirname, strerror(errno));
- return;
- }
-
- host = NULL;
- while ((de = readdir(dir)) != NULL) {
- struct stat stb;
- char path[1024];
-
- if (de->d_name[0] == '.')
- continue;
- if (host == NULL)
- host = calloc(1, sizeof(*host));
- if (host == NULL) {
- nsm_log(LOG_WARNING, "Unable to allocate memory");
- return;
- }
-
- snprintf(path, sizeof(path), "%s/%s", dirname, de->d_name);
- if (stat(path, &stb) < 0)
- continue;
-
- host->last_used = stb.st_mtime;
- host->timeout = NSM_TIMEOUT;
- host->path = strdup(path);
- host->name = strdup(de->d_name);
- host->retries = 100; /* force address retry */
-
- insert_host(host);
- host = NULL;
- }
- closedir(dir);
-
- if (host)
- free(host);
-}
-