You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

219 lines
5.4 KiB

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