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

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