diff options
author | Erik Troan <ewt@redhat.com> | 1999-07-23 01:15:23 +0000 |
---|---|---|
committer | Erik Troan <ewt@redhat.com> | 1999-07-23 01:15:23 +0000 |
commit | dd141b96a739d5829293f092237b3bbbcf3d4de6 (patch) | |
tree | 07ca930e80f8dcc108c42f34c2e75b029c944280 | |
parent | a4b8608fe3580b16a13671b11c01055a09a1692a (diff) | |
download | anaconda-dd141b96a739d5829293f092237b3bbbcf3d4de6.tar.gz anaconda-dd141b96a739d5829293f092237b3bbbcf3d4de6.tar.xz anaconda-dd141b96a739d5829293f092237b3bbbcf3d4de6.zip |
changed mod info stuff to not use global variables (though isys.c does
still for no particularly good reason)
-rw-r--r-- | isys/isys.c | 11 | ||||
-rw-r--r-- | isys/isys.h | 12 | ||||
-rw-r--r-- | isys/moduleinfo.c | 72 |
3 files changed, 67 insertions, 28 deletions
diff --git a/isys/isys.c b/isys/isys.c index 1ca2ba45b..65d83e889 100644 --- a/isys/isys.c +++ b/isys/isys.c @@ -12,6 +12,9 @@ #include "pci/pciprobe.h" #include "smp.h" +/* FIXME: this is such a hack -- moduleInfoList ought to be a proper object */ +moduleInfoSet modInfoList; + static PyObject * doFindModInfo(PyObject * s, PyObject * args); static PyObject * doInsmod(PyObject * s, PyObject * args); static PyObject * doMount(PyObject * s, PyObject * args); @@ -100,7 +103,7 @@ static PyObject * getModuleList(PyObject * s, PyObject * args) { return NULL; } - modules = isysGetModuleList(major); + modules = isysGetModuleList(modInfoList, major); if (!modules) { Py_INCREF(Py_None); return Py_None; @@ -187,7 +190,7 @@ static PyObject * doFindModInfo(PyObject * s, PyObject * args) { if (!PyArg_ParseTuple(args, "s", &mod)) return NULL; - mi = isysFindModuleInfo(mod); + mi = isysFindModuleInfo(modInfoList, mod); if (!mi) { Py_INCREF(Py_None); return Py_None; @@ -201,7 +204,7 @@ static PyObject * doReadModInfo(PyObject * s, PyObject * args) { if (!PyArg_ParseTuple(args, "s", &fn)) return NULL; - if (isysReadModuleInfo(fn)) { + if (isysReadModuleInfo(fn, modInfoList)) { PyErr_SetFromErrno(PyExc_IOError); return NULL; } @@ -277,6 +280,8 @@ static PyObject * smpAvailable(PyObject * s, PyObject * args) { } void init_isys(void) { + modInfoList = isysNewModuleInfoSet(); + Py_InitModule("_isys", isysModuleMethods); } diff --git a/isys/isys.h b/isys/isys.h index 01e278601..4b7557fe7 100644 --- a/isys/isys.h +++ b/isys/isys.h @@ -20,11 +20,17 @@ struct moduleInfo { struct moduleArg * args; }; -int isysReadModuleInfo(const char * filename); -struct moduleInfo * isysFindModuleInfo(const char * moduleName); +typedef struct moduleInfoSet_s * moduleInfoSet; + +moduleInfoSet isysNewModuleInfoSet(void); +void isysFreeModuleInfoSet(moduleInfoSet mis); +int isysReadModuleInfo(const char * filename, moduleInfoSet mis); +struct moduleInfo * isysFindModuleInfo(moduleInfoSet mis, + const char * moduleName); /* NULL moduleName indicates the end of the list; the list must be freed() */ -struct moduleInfo * isysGetModuleList(enum driverMajor major); +struct moduleInfo * isysGetModuleList(moduleInfoSet mis, + enum driverMajor major); /* returns -2 for errno, -1 for unknown device */ int devMakeInode(char * devName, char * path); diff --git a/isys/moduleinfo.c b/isys/moduleinfo.c index afc646026..28b30cfc1 100644 --- a/isys/moduleinfo.c +++ b/isys/moduleinfo.c @@ -8,17 +8,20 @@ #include "isys.h" -struct moduleInfo * moduleList = NULL; -int numModules = 0; +struct moduleInfoSet_s { + struct moduleInfo * moduleList; + int numModules; +}; -struct moduleInfo * isysGetModuleList(enum driverMajor major) { +struct moduleInfo * isysGetModuleList(moduleInfoSet mis, + enum driverMajor major) { struct moduleInfo * miList, * next; int i; - next = miList = malloc(sizeof(*miList) * numModules + 1); - for (i = 0; i < numModules; i++) { - if (moduleList[i].major == major || major == DRIVER_NONE) { - *next = moduleList[i]; + next = miList = malloc(sizeof(*miList) * mis->numModules + 1); + for (i = 0; i < mis->numModules; i++) { + if (mis->moduleList[i].major == major || major == DRIVER_NONE) { + *next = mis->moduleList[i]; next++; } } @@ -35,17 +38,22 @@ struct moduleInfo * isysGetModuleList(enum driverMajor major) { return miList; } -struct moduleInfo * isysFindModuleInfo(const char * moduleName) { +struct moduleInfo * isysFindModuleInfo(moduleInfoSet mis, + const char * moduleName) { int i; - for (i = 0; i < numModules; i++) - if (!strcmp(moduleName, moduleList[i].moduleName)) - return moduleList + i; + for (i = 0; i < mis->numModules; i++) + if (!strcmp(moduleName, mis->moduleList[i].moduleName)) + return mis->moduleList + i; return NULL; } -int isysReadModuleInfo(const char * filename) { +moduleInfoSet isysNewModuleInfoSet(void) { + return calloc(sizeof(struct moduleInfoSet_s), 1); +} + +int isysReadModuleInfo(const char * filename, moduleInfoSet mis) { int fd, isIndented; char * buf, * start, * next, * chptr; struct stat sb; @@ -62,8 +70,8 @@ int isysReadModuleInfo(const char * filename) { buf[sb.st_size] = '\0'; close(fd); - nextModule = moduleList; - modulesAlloced = numModules; + nextModule = mis->moduleList; + modulesAlloced = mis->numModules; if (strncmp(buf, "Version 0\n", 10)) return -1; @@ -90,14 +98,14 @@ int isysReadModuleInfo(const char * filename) { if (*start != '\n' && *start && *start != '#') { if (!isIndented) { - if (nextModule && nextModule->moduleName) numModules++; + if (nextModule && nextModule->moduleName) mis->numModules++; - if (numModules == modulesAlloced) { + if (mis->numModules == modulesAlloced) { modulesAlloced += 5; - moduleList = realloc(moduleList, - modulesAlloced * sizeof(*moduleList)); + mis->moduleList = realloc(mis->moduleList, + modulesAlloced * sizeof(*mis->moduleList)); } - nextModule = moduleList + numModules; + nextModule = mis->moduleList + mis->numModules; nextModule->moduleName = strdup(start); nextModule->major = DRIVER_NONE; nextModule->minor = DRIVER_MINOR_NONE; @@ -127,7 +135,6 @@ int isysReadModuleInfo(const char * filename) { chptr = start + strlen(start) - 1; if (*start == '"' && *chptr == '"') { start++; - chptr--; *chptr = '\0'; nextModule->description = strdup(start); } @@ -161,8 +168,29 @@ int isysReadModuleInfo(const char * filename) { start = next; } - if (nextModule && nextModule->moduleName) numModules++; - numModules = nextModule - moduleList; + if (nextModule && nextModule->moduleName) mis->numModules++; + mis->numModules = nextModule - mis->moduleList; return 0; } + +void isysFreeModuleInfoSet(moduleInfoSet mis) { + int i, j; + + for (i = 0; i < mis->numModules; i++) { + if (mis->moduleList[i].moduleName) + free(mis->moduleList[i].moduleName); + + if (mis->moduleList[i].description) + free(mis->moduleList[i].description); + + for (j = 0; i < mis->moduleList[i].numArgs; j++) { + if (mis->moduleList[i].args[j].arg) + free(mis->moduleList[i].args[j].arg) ; + if (mis->moduleList[i].args[j].description) + free(mis->moduleList[i].args[j].description) ; + } + } + + free(mis); +} |