| 1 |
diff -ru a/src/Makefile.am b/src/Makefile.am |
| 2 |
--- a/src/Makefile.am 2012-04-10 01:20:40.000000000 -0700 |
| 3 |
+++ b/src/Makefile.am 2015-05-04 14:22:45.000000000 -0700 |
| 4 |
@@ -1,4 +1,4 @@ |
| 5 |
-AM_CFLAGS = $(GCC_CFLAG) $(NOVA_CFLAGS) $(CONSTELLATION_CFLAGS) @CFLAGS@ |
| 6 |
+AM_CFLAGS = $(GCC_CFLAG) -DPKGLIBDIR=\"$(pkglibdir)\" $(NOVA_CFLAGS) $(CONSTELLATION_CFLAGS) @CFLAGS@ |
| 7 |
AM_YFLAGS = -d |
| 8 |
LDADD = libpromises.la |
| 9 |
|
| 10 |
diff -ru a/src/Makefile.in b/src/Makefile.in |
| 11 |
--- a/src/Makefile.in 2012-04-10 01:20:49.000000000 -0700 |
| 12 |
+++ b/src/Makefile.in 2015-05-04 14:44:28.000000000 -0700 |
| 13 |
@@ -483,7 +483,7 @@ |
| 14 |
top_builddir = @top_builddir@ |
| 15 |
top_srcdir = @top_srcdir@ |
| 16 |
workdir = @workdir@ |
| 17 |
-AM_CFLAGS = $(GCC_CFLAG) $(NOVA_CFLAGS) $(CONSTELLATION_CFLAGS) @CFLAGS@ |
| 18 |
+AM_CFLAGS = $(GCC_CFLAG) -DPKGLIBDIR=\"$(pkglibdir)\" $(NOVA_CFLAGS) $(CONSTELLATION_CFLAGS) @CFLAGS@ |
| 19 |
AM_YFLAGS = -d |
| 20 |
LDADD = libpromises.la |
| 21 |
|
| 22 |
diff -ru a/src/generic_agent.c b/src/generic_agent.c |
| 23 |
--- a/src/generic_agent.c 2012-04-10 01:20:40.000000000 -0700 |
| 24 |
+++ b/src/generic_agent.c 2015-05-05 13:29:27.000000000 -0700 |
| 25 |
@@ -1832,6 +1832,8 @@ |
| 26 |
printf("\n"); |
| 27 |
printf("Copyright (C) CFEngine AS 2008-%d\n", BUILD_YEAR); |
| 28 |
printf("See Licensing at http://cfengine.com/3rdpartylicenses\n"); |
| 29 |
+ printf("\n"); |
| 30 |
+ printf(".so module directory: %s\n", PKGLIBDIR); |
| 31 |
} |
| 32 |
|
| 33 |
/*******************************************************************/ |
| 34 |
diff -ru a/src/sysinfo.c b/src/sysinfo.c |
| 35 |
--- a/src/sysinfo.c 2012-04-10 01:20:40.000000000 -0700 |
| 36 |
+++ b/src/sysinfo.c 2015-05-05 13:20:47.000000000 -0700 |
| 37 |
@@ -33,6 +33,7 @@ |
| 38 |
|
| 39 |
#include "cf3.defs.h" |
| 40 |
#include "cf3.extern.h" |
| 41 |
+#include <ltdl.h> |
| 42 |
|
| 43 |
#ifdef IRIX |
| 44 |
# include <sys/syssgi.h> |
| 45 |
@@ -63,6 +64,10 @@ |
| 46 |
static void CreateClassesFromCanonification(char *canonified); |
| 47 |
static void GetCPUInfo(void); |
| 48 |
|
| 49 |
+void CfRegisterHardClass(const char *class); |
| 50 |
+static int LoadModule(const char *path); |
| 51 |
+static void LoadModules(const char *dir); |
| 52 |
+ |
| 53 |
/*******************************************************************/ |
| 54 |
|
| 55 |
void CalculateDomainName(const char *nodename, const char *dnsname, char *fqname, char *uqname, char *domain) |
| 56 |
@@ -248,6 +253,10 @@ |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
+CfDebug("Cfengine: load modules\n"); |
| 61 |
+LoadModules(PKGLIBDIR); |
| 62 |
+CfDebug("Cfengine: modules loaded\n"); |
| 63 |
+ |
| 64 |
/* |
| 65 |
* solarisx86 is a historically defined class for Solaris on x86. We have to |
| 66 |
* define it manually now. |
| 67 |
@@ -2120,3 +2129,71 @@ |
| 68 |
} |
| 69 |
|
| 70 |
} |
| 71 |
+ |
| 72 |
+/*******************************************************************/ |
| 73 |
+ |
| 74 |
+typedef int (*cf_mod_getclasses) (void); |
| 75 |
+ |
| 76 |
+void CfRegisterHardClass(const char *class) |
| 77 |
+{ |
| 78 |
+ CreateClassesFromCanonification (CanonifyName (class)); |
| 79 |
+} |
| 80 |
+ |
| 81 |
+static int LoadModule(const char *path) |
| 82 |
+{ |
| 83 |
+ lt_dlhandle dl; |
| 84 |
+ const lt_dlinfo *info; |
| 85 |
+ cf_mod_getclasses mod_getclasses; |
| 86 |
+ int i; |
| 87 |
+ int rc = -1; |
| 88 |
+ |
| 89 |
+ if (!(dl = lt_dlopen (path))) { |
| 90 |
+ fprintf (stderr, "dlopen(%s) failed.\n", path); |
| 91 |
+ return (rc); |
| 92 |
+ } |
| 93 |
+ |
| 94 |
+ if ((mod_getclasses = lt_dlsym (dl, "cfagent_module_getclasses"))) |
| 95 |
+ mod_getclasses (); |
| 96 |
+ |
| 97 |
+ lt_dlclose (dl); |
| 98 |
+ |
| 99 |
+ return (0); |
| 100 |
+} |
| 101 |
+ |
| 102 |
+static void LoadModules(const char *dir) |
| 103 |
+{ |
| 104 |
+ DIR *dirp = NULL; |
| 105 |
+ struct dirent *entry = NULL; |
| 106 |
+ char path[4096]; |
| 107 |
+ char *p; |
| 108 |
+ |
| 109 |
+ memset (path, 0, sizeof (path)); |
| 110 |
+ |
| 111 |
+ lt_dlinit(); |
| 112 |
+ |
| 113 |
+ if (!(dirp = opendir (dir))) |
| 114 |
+ return; |
| 115 |
+ |
| 116 |
+ strncpy(path, dir, 4095); |
| 117 |
+ p = path + strlen (dir); |
| 118 |
+ *(p++) = '/'; |
| 119 |
+ |
| 120 |
+ CfDebug("Cfengine: module search path: %s\n", p); |
| 121 |
+ |
| 122 |
+ while ((entry = readdir(dirp))) { |
| 123 |
+ CfDebug("Cfengine: searching %s\n", entry->d_name); |
| 124 |
+ int len = strlen(entry->d_name); |
| 125 |
+ |
| 126 |
+ if (strcmp (entry->d_name + len - 3, ".so") != 0) |
| 127 |
+ continue; |
| 128 |
+ |
| 129 |
+ strcpy (p, entry->d_name); |
| 130 |
+ LoadModule (path); |
| 131 |
+ } |
| 132 |
+ |
| 133 |
+ closedir (dirp); |
| 134 |
+ |
| 135 |
+ lt_dlexit(); |
| 136 |
+} |
| 137 |
+ |
| 138 |
+/*******************************************************************/ |