Debian Codegraph @

contrib/cfengine/cfengine-2.2.10/0005-Add-support-for-dynamic-modules-for-hard-classes.patch

raw
1 From 6410674f99cd1e1b5b669fdc6ab7cee1e74f9dfc Mon Sep 17 00:00:00 2001
2 From: Mark A. Grondona <[email protected]>
3 Date: Tue, 8 Jun 2010 16:12:38 -0700
4 Subject: [PATCH 5/5] Add support for dynamic modules for hard classes
5
6 Load any DSO modules from PKGLIBDIR, and allow them to instantiate
7 new hard classes via the CfRegisterHardClass() callback.
8 ---
9 src/nameinfo.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10 1 files changed, 67 insertions(+), 0 deletions(-)
11
12 diff --git a/src/nameinfo.c b/src/nameinfo.c
13 index 8d15d10..fb79c8b 100644
14 --- a/src/nameinfo.c
15 +++ b/src/nameinfo.c
16 @@ -33,6 +33,7 @@
17 #include "cf.defs.h"
18 #include "cf.extern.h"
19 #include "../pub/global.h"
20 +#include "../libltdl/ltdl.h"
21 #ifdef IRIX
22 #include <sys/syssgi.h>
23 #endif
24 @@ -55,6 +56,69 @@
25
26 /*******************************************************************/
27
28 +typedef int (*cf_mod_getclasses) (void);
29 +
30 +void CfRegisterHardClass(const char *class)
31 +{
32 + AddClassToHeap (CanonifyName (class));
33 +}
34 +
35 +static int LoadModule(const char *path)
36 +{
37 + lt_dlhandle dl;
38 + const lt_dlinfo *info;
39 + cf_mod_getclasses mod_getclasses;
40 + int i;
41 + int rc = -1;
42 +
43 + if (!(dl = lt_dlopen (path))) {
44 + fprintf (stderr, "dlopen(%s) failed.\n", path);
45 + return (rc);
46 + }
47 +
48 + if ((mod_getclasses = lt_dlsym (dl, "cfagent_module_getclasses")))
49 + mod_getclasses ();
50 +
51 + lt_dlclose (dl);
52 +
53 + return (0);
54 +}
55 +
56 +static void LoadModules(const char *dir)
57 +{
58 + DIR *dirp = NULL;
59 + struct dirent *entry = NULL;
60 + char path[4096];
61 + char *p;
62 +
63 + memset (path, 0, sizeof (path));
64 +
65 + lt_dlinit();
66 +
67 + if (!(dirp = opendir (dir)))
68 + return;
69 +
70 + strncpy(path, dir, 4095);
71 + p = path + strlen (dir);
72 + *(p++) = '/';
73 +
74 + while ((entry = readdir(dirp))) {
75 + int len = strlen(entry->d_name);
76 +
77 + if (strcmp (entry->d_name + len - 3, ".so") != 0)
78 + continue;
79 +
80 + strcpy (p, entry->d_name);
81 + LoadModule (path);
82 + }
83 +
84 + closedir (dirp);
85 +
86 + lt_dlexit();
87 +}
88 +
89 +/*******************************************************************/
90 +
91 void GetNameInfo()
92
93 { int i,found = false;
94 @@ -145,6 +209,8 @@ for (i = 0; CLASSATTRIBUTES[i][0] != '\0'; i++)
95 }
96 }
97
98 +LoadModules(PKGLIBDIR);
99 +
100 if ((sp = malloc(strlen(VSYSNAME.nodename)+1)) == NULL)
101 {
102 FatalError("malloc failure in initialize()");
103 @@ -171,6 +237,7 @@ AddClassToHeap(CanonifyName(sp));
104
105 free(sp); /* Release the ressource */
106
107 +
108
109 if ((tloc = time((time_t *)NULL)) == -1)
110 {
111 --
112 1.6.5.2
113