Blame SOURCES/autofs-5.0.9-amd-lookup-add-amd-global-macro-vars.patch

306fa1
autofs-5.0.9 - amd lookup add amd global macro vars
306fa1
306fa1
From: Ian Kent <raven@themaw.net>
306fa1
306fa1
306fa1
---
306fa1
 include/mounts.h |    2 +
306fa1
 lib/macros.c     |   60 +++++++++++++++++++++++++++++++++++++++++-
306fa1
 lib/mounts.c     |   77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
306fa1
 3 files changed, 137 insertions(+), 2 deletions(-)
306fa1
306fa1
diff --git a/include/mounts.h b/include/mounts.h
306fa1
index 3bef086..ca99f8b 100644
306fa1
--- a/include/mounts.h
306fa1
+++ b/include/mounts.h
306fa1
@@ -87,6 +87,8 @@ extern unsigned int nfs_mount_uses_string_options;
306fa1
 
306fa1
 struct substvar *addstdenv(struct substvar *sv);
306fa1
 struct substvar *removestdenv(struct substvar *sv);
306fa1
+void add_std_amd_vars(struct substvar *sv);
306fa1
+void remove_std_amd_vars(void);
306fa1
 
306fa1
 unsigned int query_kproto_ver(void);
306fa1
 unsigned int get_kver_major(void);
306fa1
diff --git a/lib/macros.c b/lib/macros.c
306fa1
index 5109abc..ff9ba89 100644
306fa1
--- a/lib/macros.c
306fa1
+++ b/lib/macros.c
306fa1
@@ -18,11 +18,17 @@
306fa1
 #include <string.h>
306fa1
 #include <limits.h>
306fa1
 #include <sys/utsname.h>
306fa1
+#include <unistd.h>
306fa1
 
306fa1
 #include "automount.h"
306fa1
 
306fa1
 static struct utsname un;
306fa1
 static char processor[65];		/* Not defined on Linux, so we make our own */
306fa1
+static char hostname[HOST_NAME_MAX + 1];
306fa1
+static char host[HOST_NAME_MAX];
306fa1
+static char domain[HOST_NAME_MAX];
306fa1
+static char hostd[HOST_NAME_MAX + 1];
306fa1
+static char endian[] = "unknown";
306fa1
 
306fa1
 /* Predefined variables: tail of link chain */
306fa1
 static struct substvar
306fa1
@@ -31,10 +37,18 @@ static struct substvar
306fa1
 	sv_host   = {"HOST",   un.nodename, 1, &sv_cpu},
306fa1
 	sv_osname = {"OSNAME", un.sysname,  1, &sv_host},
306fa1
 	sv_osrel  = {"OSREL",  un.release,  1, &sv_osname},
306fa1
-	sv_osvers = {"OSVERS", un.version,  1, &sv_osrel
306fa1
+	sv_osvers = {"OSVERS", un.version,  1, &sv_osrel},
306fa1
+	sv_dollar = {"dollar", "$",         1, &sv_osvers},
306fa1
+	sv_true   = {"true",   "1",         1, &sv_dollar},
306fa1
+	sv_false  = {"false",  "0",         1, &sv_true},
306fa1
+	sv_byte	  = {"byte",   endian,	    1, &sv_false},
306fa1
+	sv_host2  = {"host",   host,        1, &sv_byte},
306fa1
+	sv_xhost  = {"xhost",  host,	    1, &sv_host2},
306fa1
+	sv_domain = {"domain", domain,      1, &sv_xhost},
306fa1
+	sv_hostd  = {"hostd",  hostd,       1, &sv_domain
306fa1
 };
306fa1
 
306fa1
-static struct substvar *system_table = &sv_osvers;
306fa1
+static struct substvar *system_table = &sv_hostd;
306fa1
 static unsigned int macro_init_done = 0;
306fa1
 
306fa1
 static pthread_mutex_t table_mutex = PTHREAD_MUTEX_INITIALIZER;
306fa1
@@ -63,6 +77,13 @@ void dump_table(struct substvar *table)
306fa1
 /* Get processor information for predefined macro definitions */
306fa1
 void macro_init(void)
306fa1
 {
306fa1
+	char *local_domain;
306fa1
+
306fa1
+	memset(hostname, 0, HOST_NAME_MAX + 1);
306fa1
+	memset(host, 0, HOST_NAME_MAX);
306fa1
+	memset(domain, 0, HOST_NAME_MAX);
306fa1
+	memset(hostd, 0, HOST_NAME_MAX + 1);
306fa1
+
306fa1
 	macro_lock();
306fa1
 	if (macro_init_done) {
306fa1
 		macro_unlock();
306fa1
@@ -79,6 +100,41 @@ void macro_init(void)
306fa1
 		!strcmp(processor + 2, "86"))
306fa1
 		processor[1] = '3';
306fa1
 
306fa1
+	local_domain = conf_amd_get_sub_domain();
306fa1
+
306fa1
+	if (!gethostname(hostname, HOST_NAME_MAX)) {
306fa1
+		char *dot;
306fa1
+		dot = strchr(hostname, '.');
306fa1
+		if (dot) {
306fa1
+			*dot++ = '\0';
306fa1
+			strcpy(domain, dot);
306fa1
+		}
306fa1
+		strcpy(host, hostname);
306fa1
+		strcpy(hostd, host);
306fa1
+		if (*domain || local_domain) {
306fa1
+			strcat(hostd, ".");
306fa1
+			if (!local_domain)
306fa1
+				strcat(hostd, domain);
306fa1
+			else {
306fa1
+				strcat(hostd, local_domain);
306fa1
+				strcpy(domain, local_domain);
306fa1
+			}
306fa1
+		}
306fa1
+	}
306fa1
+
306fa1
+	if (sizeof(short) == 2) {
306fa1
+		union { short s; char c[sizeof(short)]; } order;
306fa1
+		order.s = 0x0102;
306fa1
+		if (order.c[0] == 1 && order.c[1] == 2)
306fa1
+			strcpy(endian, "big");
306fa1
+		else if (order.c[0] == 2 && order.c[1] == 1)
306fa1
+			strcpy(endian, "little");
306fa1
+		else
306fa1
+			strcpy(endian, "unknown");
306fa1
+	}
306fa1
+
306fa1
+	add_std_amd_vars(system_table);
306fa1
+
306fa1
 	macro_init_done = 1;
306fa1
 	macro_unlock();
306fa1
 	return;
306fa1
diff --git a/lib/mounts.c b/lib/mounts.c
306fa1
index aea6691..4306974 100644
306fa1
--- a/lib/mounts.c
306fa1
+++ b/lib/mounts.c
306fa1
@@ -26,6 +26,7 @@
306fa1
 #include <sys/vfs.h>
306fa1
 #include <pwd.h>
306fa1
 #include <grp.h>
306fa1
+#include <libgen.h>
306fa1
 
306fa1
 #include "automount.h"
306fa1
 
306fa1
@@ -365,6 +366,82 @@ struct substvar *removestdenv(struct substvar *sv)
306fa1
 	return list;
306fa1
 }
306fa1
 
306fa1
+void add_std_amd_vars(struct substvar *sv)
306fa1
+{
306fa1
+	char *tmp;
306fa1
+
306fa1
+	tmp = conf_amd_get_arch();
306fa1
+	if (tmp) {
306fa1
+		macro_global_addvar("arch", 4, tmp);
306fa1
+		free(tmp);
306fa1
+	}
306fa1
+
306fa1
+	tmp = conf_amd_get_karch();
306fa1
+	if (tmp) {
306fa1
+		macro_global_addvar("karch", 5, tmp);
306fa1
+		free(tmp);
306fa1
+	}
306fa1
+
306fa1
+	tmp = conf_amd_get_os();
306fa1
+	if (tmp) {
306fa1
+		macro_global_addvar("os", 2, tmp);
306fa1
+		free(tmp);
306fa1
+	}
306fa1
+
306fa1
+	tmp = conf_amd_get_full_os();
306fa1
+	if (tmp) {
306fa1
+		macro_global_addvar("full_os", 7, tmp);
306fa1
+		free(tmp);
306fa1
+	}
306fa1
+
306fa1
+	tmp = conf_amd_get_os_ver();
306fa1
+	if (tmp) {
306fa1
+		macro_global_addvar("osver", 5, tmp);
306fa1
+		free(tmp);
306fa1
+	}
306fa1
+
306fa1
+	tmp = conf_amd_get_vendor();
306fa1
+	if (tmp) {
306fa1
+		macro_global_addvar("vendor", 6, tmp);
306fa1
+		free(tmp);
306fa1
+	}
306fa1
+
306fa1
+	/* Umm ... HP_UX cluster name, probably not used */
306fa1
+	tmp = conf_amd_get_cluster();
306fa1
+	if (tmp) {
306fa1
+		macro_global_addvar("cluster", 7, tmp);
306fa1
+		free(tmp);
306fa1
+	} else {
306fa1
+		const struct substvar *v = macro_findvar(sv, "domain", 4);
306fa1
+		if (v && *v->val) {
306fa1
+			tmp = strdup(v->val);
306fa1
+			if (tmp)
306fa1
+				macro_global_addvar("cluster", 7, tmp);
306fa1
+		}
306fa1
+	}
306fa1
+
306fa1
+	tmp = conf_amd_get_auto_dir();
306fa1
+	if (tmp) {
306fa1
+		macro_global_addvar("autodir", 7, tmp);
306fa1
+		free(tmp);
306fa1
+	}
306fa1
+
306fa1
+	return;
306fa1
+}
306fa1
+
306fa1
+void remove_std_amd_vars(void)
306fa1
+{
306fa1
+	macro_global_removevar("autodir", 7);
306fa1
+	macro_global_removevar("cluster", 7);
306fa1
+	macro_global_removevar("vendor", 6);
306fa1
+	macro_global_removevar("osver", 5);
306fa1
+	macro_global_removevar("full_os", 7);
306fa1
+	macro_global_removevar("os", 2);
306fa1
+	macro_global_removevar("karch", 5);
306fa1
+	macro_global_removevar("arch", 4);
306fa1
+	return;
306fa1
+ }
306fa1
+
306fa1
 /*
306fa1
  * Make common autofs mount options string
306fa1
  */