*/
extern struct kafs_profile kafs_config_profile;
extern struct kafs_cell_db *kafs_cellserv_db;
+extern const char *kafs_this_cell;
extern int kafs_read_config(const char *const *files,
struct kafs_report *report);
extern struct kafs_cell *kafs_lookup_cell(const char *cell_name,
struct kafs_profile kafs_config_profile = { .name = "<kafsconfig>" };
struct kafs_cell_db *kafs_cellserv_db;
+const char *kafs_this_cell;
#define verbose(r, fmt, ...) \
do { \
return NULL;
}
+/*
+ * Read the [defaults] section.
+ */
+static void kafs_read_defaults(struct kafs_profile *prof, struct kafs_report *report)
+{
+ const struct kafs_profile *def;
+ const char *p;
+
+ def = kafs_profile_find_first_child(prof, kafs_profile_value_is_list, "defaults", report);
+ if (!def) {
+ verbose(report, "Cannot find [defaults] section");
+ return;
+ }
+
+ /* Find the current cell name (thiscell = <cellname>) */
+ p = kafs_profile_get_string(def, "thiscell", report);
+ if (p)
+ kafs_this_cell = p;
+}
+
/*
* Read the configuration and initialise the cell database.
*/
if (!kafs_cellserv_db)
return -1;
+ kafs_read_defaults(&kafs_config_profile, report);
return 0;
}
{
unsigned int i;
char buf[4096];
- int fd;
+ int fd, n;
if (!redirect_to_stdout) {
fd = open("/proc/fs/afs/cells", O_WRONLY);
for (i = 0; i < db->nr_cells; i++) {
const struct kafs_cell *cell = db->cells[i];
- int n;
n = snprintf(buf, sizeof(buf) - 1, "add %s", cell->name);
if (write(fd, buf, n) != n) {
}
}
+ if (kafs_this_cell) {
+ if (!redirect_to_stdout) {
+ fd = open("/proc/net/afs/rootcell", O_WRONLY);
+ if (fd == -1) {
+ _error("Can't open /proc/fs/afs/rootcell: %m");
+ exit(1);
+ }
+ }
+
+ n = strlen(kafs_this_cell);
+ if (write(fd, kafs_this_cell, n) != n) {
+ _error("Can't set root cell '%s': %m", kafs_this_cell);
+ exit(1);
+ }
+
+ if (!redirect_to_stdout) {
+ if (close(fd) == -1) {
+ _error("Can't close /proc/fs/afs/rootcell: %m");
+ exit(1);
+ }
+ } else {
+ if (write(1, "\n", 1) == -1)
+ perror("stdout");
+ }
+
+ }
+
exit(0);
}