[Initng-svn] r3995 - in initng/trunk: src
svn at initng.thinktux.net
svn at initng.thinktux.net
Wed May 3 13:16:48 CEST 2006
Author: jimmy
Date: Wed May 3 13:16:47 2006
New Revision: 3995
Modified:
initng/trunk/plugins/iparser/initng_i_parser.c
initng/trunk/src/initng_string_tools.c
Log:
Improved the way initng_i_parser searches for .i files with content.
Modified: initng/trunk/plugins/iparser/initng_i_parser.c
==============================================================================
--- initng/trunk/plugins/iparser/initng_i_parser.c (original)
+++ initng/trunk/plugins/iparser/initng_i_parser.c Wed May 3 13:16:47 2006
@@ -139,14 +139,82 @@
}
+/* if path is daemon/bluetooth/serial/daemon */
+static service_cache_h *test_parse(char * path, const char *service_to_find)
+{
+ char filetoparse[200];
+ service_cache_h *got_serv = NULL;
+ const char * service_strip, * path_strip = NULL;
+
+ /* get string from last '/' char */
+ if((service_strip = strrchr(service_to_find, '/')))
+ service_strip++;
+ else
+ service_strip = service_to_find;
+
+ /* 1, try /etc/initng/daemon/bluetooth/serial/daemon/daemon.i */
+ strcpy(filetoparse, INITNG_ROOT "/");
+ strcat(filetoparse, path);
+ strcat(filetoparse, "/");
+ strcat(filetoparse, service_strip);
+ strcat(filetoparse, INITNG_EXT);
+ if ((got_serv = parse_file(filetoparse, service_to_find)))
+ return (got_serv);
+
+ /* 2. try /etc/initng/daemon/bluetooth/serial/daemon/default.i */
+ strcpy(filetoparse, INITNG_ROOT "/");
+ strcat(filetoparse, path);
+ strcat(filetoparse, "/default");
+ strcat(filetoparse, INITNG_EXT);
+ if ((got_serv = parse_file(filetoparse, service_to_find)))
+ return (got_serv);
+
+ /* 3, try /etc/initng/daemon/bluetooth/serial/daemon.i */
+ strcpy(filetoparse, INITNG_ROOT "/");
+ strcat(filetoparse, path);
+ strcat(filetoparse, INITNG_EXT);
+ if ((got_serv = parse_file(filetoparse, service_to_find)))
+ return (got_serv);
+
+ if((path_strip = strrchr(path, '/')))
+ path_strip++;
+ else
+ path_strip = path;
+
+ /* 4, A last try with path_strip if differ. */
+ if(strcmp(path_strip, service_strip)!=0)
+ {
+ strcpy(filetoparse, INITNG_ROOT "/");
+ strcat(filetoparse, path);
+ strcat(filetoparse, "/");
+ strcat(filetoparse, path_strip);
+ strcat(filetoparse, INITNG_EXT);
+ if ((got_serv = parse_file(filetoparse, service_to_find)))
+ return (got_serv);
+ }
+
+ /* Cut path on last '/' */
+ char *p = NULL;
+ if((p=strrchr(path, '/')))
+ {
+ p[0]='\0';
+
+ /* call own function again with a shorter path */
+ got_serv=test_parse(path, service_to_find);
+ if(got_serv)
+ {
+ return(got_serv);
+ }
+ }
+
+ return(NULL);
+}
/* Load a service from a service_to_find or process_path */
static service_cache_h *initng_i_parser(const char *service_to_find)
{
- char filetoparse[200];
service_cache_h *got_serv = NULL;
- char *path = NULL;
- const char *service = NULL;
+ char * path = NULL;
assert(service_to_find);
D_("Parsing for %s\n", service_to_find);
@@ -176,105 +244,17 @@
* and service "udevd"
*/
- /* set up a patch copy, has to be free() */
- path = st_get_path(service_to_find);
-
- /* this is a pointer to a entry in service_to_find */
- service = st_strip_path(service_to_find);
-
- D_("initng_i_parser(%s);\n", service_to_find);
- /* example INITNG_ROOT=/etc/initng service_to_find="daemon/sshd INITNG_EXT=".i" */
- /* TRY NO 1, try load "/etc/initng/daemon/sshd.i" */
- /* TRY NO 2, try load "/etc/initng/daemon/sshd/sshd.i" */
- /* TRY NO 3, try load "/etc/initng/daemon/sshd/default.i" */
- /* TRY NO 4, try load "/etc/initng/daemon/default.i" */
- /* TRY NO 5, try load "/etc/initng/daemon/daemon.i */
- /* TRY NO 6, try load "/etc/initng/sshd.i" */
- /* TRY NO 7, try load "/etc/initng/daemon.i */
-
- /* TRY NO 1, try load "/etc/initng/daemon/sshd/sshd.i" */
- strcpy(filetoparse, INITNG_ROOT "/");
- strcat(filetoparse, service_to_find);
- strcat(filetoparse, "/");
- strcat(filetoparse, service);
- strcat(filetoparse, INITNG_EXT);
- if ((got_serv = parse_file(filetoparse, service_to_find)))
+ path=i_strdup(service_to_find);
+ if(!path)
+ return(NULL);
+
+ got_serv=test_parse(path, service_to_find);
+ if(got_serv)
{
- free(path);
- return (got_serv);
- }
- filetoparse[0] = '\0';
-
- /* TRY NO 2, try load "/etc/initng/daemon/sshd.i" */
- strcpy(filetoparse, INITNG_ROOT "/");
- strcat(filetoparse, service_to_find);
- strcat(filetoparse, INITNG_EXT);
- if ((got_serv = parse_file(filetoparse, service_to_find)))
- {
- free(path);
- return (got_serv);
- }
- filetoparse[0] = '\0';
-
- /* TRY NO 3, try load "/etc/initng/daemon/sshd/default.i" */
- strcpy(filetoparse, INITNG_ROOT "/");
- strcat(filetoparse, service_to_find);
- strcat(filetoparse, "/default" INITNG_EXT);
- if ((got_serv = parse_file(filetoparse, service_to_find)))
- {
- free(path);
- return (got_serv);
- }
- filetoparse[0] = '\0';
-
- /* TRY NO 4, try "/etc/initng/daemon/default.i" */
- strcpy(filetoparse, INITNG_ROOT "/");
- strcat(filetoparse, path);
- strcat(filetoparse, "/default" INITNG_EXT);
-
- if ((got_serv = parse_file(filetoparse, service_to_find)))
- {
- free(path);
- return (got_serv);
- }
- filetoparse[0] = '\0';
-
- strcpy(filetoparse, INITNG_ROOT "/");
- strcat(filetoparse, path);
- strcat(filetoparse, "/");
- strcat(filetoparse, path);
- strcat(filetoparse, INITNG_EXT);
- if ((got_serv = parse_file(filetoparse, service_to_find)))
- {
- free(path);
- return (got_serv);
- }
- filetoparse[0] = '\0';
-
- /* TRY NO 6, try "/etc/initng/sshd.i" */
- strcpy(filetoparse, INITNG_ROOT "/");
- strcat(filetoparse, service);
- strcat(filetoparse, INITNG_EXT);
- if ((got_serv = parse_file(filetoparse, service_to_find)))
- {
- free(path);
- return (got_serv);
- }
- filetoparse[0] = '\0';
-
- /* TRY NO 7, try "/etc/initng/daemon.i" */
- strcpy(filetoparse, INITNG_ROOT "/");
- strcat(filetoparse, path);
- strcat(filetoparse, INITNG_EXT);
- if ((got_serv = parse_file(filetoparse, service_to_find)))
- {
- free(path);
- return (got_serv);
+ return(got_serv);
}
- filetoparse[0] = '\0';
D_("Was not able to parse: %s\n", service_to_find);
- free(path);
return (NULL);
}
Modified: initng/trunk/src/initng_string_tools.c
==============================================================================
--- initng/trunk/src/initng_string_tools.c (original)
+++ initng/trunk/src/initng_string_tools.c Wed May 3 13:16:47 2006
@@ -317,6 +317,16 @@
assert(string);
+#ifdef EXP
+ /* go to last '/' */
+ char * end = strrchr(*string, '/');
+ if(end)
+ {
+ end[0]='\0';
+ return(TRUE);
+ }
+ return(FALSE);
+#endif
/* stand on last char */
while ((*string)[i] != '\0')
i++;
More information about the Initng-svn
mailing list