]> www.infradead.org Git - users/dhowells/kafs-client.git/commitdiff
Honour 'sysname' setting in preload
authorDavid Howells <dhowells@redhat.com>
Tue, 22 Jan 2019 17:47:31 +0000 (17:47 +0000)
committerDavid Howells <dhowells@redhat.com>
Tue, 22 Jan 2019 17:47:31 +0000 (17:47 +0000)
If a defaults section exists in the configuration and this contains a
setting for the workstation's @sys substitution list, e.g.:

        [defaults]
        sysname = fedora28_x86 amd64_linux

then load this into kernel after the cell list has been preloaded.

Signed-off-by: David Howells <dhowells@redhat.com>
src/include/kafs/cellserv.h
src/lib_cell_lookup.c
src/preload-cells.c

index 00e081e3928c3f3c518d463a988f3a6116550584..a232b0bc8443834c82bbd131ade5fb4590519168 100644 (file)
@@ -147,6 +147,7 @@ extern int kafs_dns_lookup_vlservers(struct kafs_server_list *vsl,
 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,
index 2029707188938589ae40e7e6d8284fcf82cecb02..f0481513f89555974913a223c027a3305d7f167a 100644 (file)
@@ -24,6 +24,7 @@ static const char *const kafs_std_config[] = {
 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 {                                                            \
@@ -72,6 +73,11 @@ static void kafs_read_defaults(struct kafs_profile *prof, struct kafs_report *re
        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;
 }
 
 /*
index c51bba335e8394688aa06eb757d125355dcc660b..d0db1c60793e29c6c057d03c54b3974bc4ab41b6 100644 (file)
@@ -61,6 +61,39 @@ static void _error(const char *fmt, ...)
        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
  */
@@ -104,33 +137,8 @@ int do_preload(const struct kafs_cell_db *db, bool redirect_to_stdout)
                }
        }
 
-       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);
 }