- /* Drop duplicates and non-existing directories from the search path. We figure out whether two directories are
- * the same by comparing their device and inode numbers. */
-
- if (!p->search_path)
- return 0;
-
- while (p->search_path[c]) {
- struct stat st;
- size_t k;
-
- /* Never strip the transient and control directories from the path */
- if (path_equal_ptr(p->search_path[c], p->transient) ||
- path_equal_ptr(p->search_path[c], p->persistent_control) ||
- path_equal_ptr(p->search_path[c], p->runtime_control)) {
- c++;
- continue;
- }
-
- r = chase_symlinks_and_stat(p->search_path[c], p->root_dir, 0, NULL, &st);
- if (r == -ENOENT)
- goto remove_item;
- if (r < 0) {
- /* If something we don't grok happened, let's better leave it in. */
- log_debug_errno(r, "Failed to chase and stat %s: %m", p->search_path[c]);
- c++;
- continue;
- }
-
- for (k = 0; k < n_stats; k++)
- if (stats[k].st_dev == st.st_dev &&
- stats[k].st_ino == st.st_ino)
- break;
-
- if (k < n_stats) /* Is there already an entry with the same device/inode? */
- goto remove_item;
-
- if (!GREEDY_REALLOC(stats, allocated, n_stats+1))
- return -ENOMEM;
-
- stats[n_stats++] = st;
- c++;
- continue;
-
- remove_item:
- free(p->search_path[c]);
- memmove(p->search_path + c,
- p->search_path + c + 1,
- (strv_length(p->search_path + c + 1) + 1) * sizeof(char*));
- }
-