extern struct kafs_profile kafs_config_profile;
extern struct kafs_cell_db *kafs_cellserv_db;
extern const char *kafs_this_cell;
+extern const char *kafs_sysname;
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;
+const char *kafs_sysname;
#define verbose(r, fmt, ...) \
do { \
p = kafs_profile_get_string(def, "thiscell", report);
if (p)
kafs_this_cell = p;
+
+ /* Find the @sys substitutions (sysname = <sub> <sub> ...) */
+ p = kafs_profile_get_string(def, "sysname", report);
+ if (p)
+ kafs_sysname = p;
}
/*
va_end(va);
}
+/*
+ * Write a string to a proc file.
+ */
+static void write_to_proc(const char *file, const char *str, bool redirect_to_stdout)
+{
+ int fd = 1, n;
+
+ if (!str)
+ return;
+
+ if (redirect_to_stdout) {
+ printf("WRITE '%s' TO %s\n", str, file);
+ return;
+ }
+
+ fd = open(file, O_WRONLY);
+ if (fd == -1) {
+ _error("Can't open %s: %m", file);
+ exit(1);
+ }
+
+ n = strlen(str);
+ if (write(fd, str, n) != n) {
+ _error("Can't write '%s' to %s: %m", str, file);
+ exit(1);
+ }
+
+ if (close(fd) == -1) {
+ _error("Can't close %s: %m", file);
+ exit(1);
+ }
+}
+
/*
* Parse the cell database file
*/
}
}
- 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");
- }
-
- }
-
+ write_to_proc("/proc/net/afs/rootcell", kafs_this_cell, redirect_to_stdout);
+ write_to_proc("/proc/net/afs/sysname", kafs_sysname, redirect_to_stdout);
exit(0);
}