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

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