void populate_tab(void) { struct autoentry *ent; char *path, *cmd; int error; autoh_t ah; path = cmd = NULL; for (ent = entries; ent != NULL; ent = ent->ae_next) { free(path); free(cmd); error = asprintf(&path, "%s/%s", ent->ae_mnt, ent->ae_path); if (error == -1) err(1, "asprintf"); error = asprintf(&cmd, "mkdir -p %s", path); if (error == -1) err(1, "asprintf"); error = system(cmd); if (error) { warn("system: %s", cmd); continue; } if (autoh_get(ent->ae_mnt, &ah)) { warn("autoh_get %s", path); continue; } error = autoh_togglepath(ah, AUTO_MOUNTER, getpid(), path); if (error) { err(1, "AUTO_MOUNTER %s", path); continue; } if (ent->ae_browse) { error = autoh_togglepath(ah, AUTO_BROWSE, getpid(), path); if (error) err(1, "AUTO_BROWSE %s", path); } if (ent->ae_direct) { error = autoh_togglepath(ah, AUTO_DIRECT, getpid(), path); if (error) err(1, "AUTO_DIRECT %s", path); } if (ent->ae_indirect) { error = autoh_togglepath(ah, AUTO_INDIRECT, getpid(), path); if (error) err(1, "AUTO_INDIRECT %s", path); } autoh_free(ah); } free(path); free(cmd); }
/* * Get an array of pointers to all the currently mounted autofs * instances. */ int autoh_getall(autoh_t **arrayp, int *cntp) { struct statfs *sfsp; int cnt, i, pos; autoh_t *array; array = NULL; /* * We use getfsstat to prevent avoid the lookups on the mountpoints * that statfs(2) would do. */ if (getmntlst(&sfsp, &cnt)) goto err; array = *arrayp = calloc(cnt + 1, sizeof(**arrayp)); if (array == NULL) goto err; for (i = 0, pos = 0; i < cnt; i++) { if (autoh_get(sfsp[i].f_mntonname, &array[pos]) == -1) { /* not an autofs entry, that's ok, otherwise bail */ if (errno == ENOTTY) continue; goto err; } pos++; } if (pos == 0) { errno = ENOENT; goto err; } *arrayp = array; *cntp = pos; safe_free(sfsp); return (0); err: safe_free(sfsp); if (array) autoh_freeall(array); return (-1); }