[Initng-svn] r4048 - initng/trunk/plugins/iparser

svn at initng.thinktux.net svn at initng.thinktux.net
Mon May 8 07:25:11 CEST 2006


Author: jimmy
Date: Mon May  8 07:25:10 2006
New Revision: 4048

Modified:
   initng/trunk/plugins/iparser/initng_i_parser.c

Log:
Fix a really nasty bug in i parser, doing ngc -u test/abc/def will hang initng.


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	Mon May  8 07:25:10 2006
@@ -147,6 +147,9 @@
 	char filetoparse[200];
 	service_cache_h *got_serv = NULL;
 	const char *service_strip, *path_strip = NULL;
+	/* if path points to service_to_find this is the first run */
+	int first = (path==service_to_find);
+	/*D_("test_parse(%s, %s)\n", path, service_to_find);*/
 
 	/* get string from last '/' char */
 	if ((service_strip = strrchr(service_to_find, '/')))
@@ -162,8 +165,6 @@
 	strcat(filetoparse, INITNG_EXT);
 	if ((got_serv = parse_file(filetoparse, service_to_find)))
 	{
-		if(path != service_to_find)
-			free(path);
 		return (got_serv);
 	}
 
@@ -174,8 +175,6 @@
 	strcat(filetoparse, INITNG_EXT);
 	if ((got_serv = parse_file(filetoparse, service_to_find)))
 	{
-		if(path != service_to_find)
-			free(path);
 		return (got_serv);
 	}
 	/* 3, try /etc/initng/daemon/bluetooth/serial/daemon.i */
@@ -184,8 +183,6 @@
 	strcat(filetoparse, INITNG_EXT);
 	if ((got_serv = parse_file(filetoparse, service_to_find)))
 	{
-		if(path != service_to_find)
-			free(path);
 		return (got_serv);
 	}
 	
@@ -204,17 +201,18 @@
 		strcat(filetoparse, INITNG_EXT);
 		if ((got_serv = parse_file(filetoparse, service_to_find)))
 		{
-			if(path != service_to_find)
-				free(path);
 			return (got_serv);
 		}
 	}
 
-	/* Now we make a copy of path that we can modify */
-	path=i_strdup(service_to_find);
-	if(!path)
-		return(NULL);
-
+	/* If this function is not run inside this function.. */
+	if(first)
+	{
+		path=i_strdup(service_to_find);
+		if(!path)
+			return(NULL);
+	}
+	
 	/* Cut path on last '/' */
 	char *p = NULL;
 
@@ -226,15 +224,18 @@
 
 		/* call own function again with a shorter path */
 		got_serv = test_parse(path, service_to_find);
-		if (got_serv)
-		{
-			/* if found, the path is freed upstream */
-			return (got_serv);
-		}
+
+		/* if this is the first in stack, we need to free */
+		if(first)
+			free(path);
+			
+		/* if found, the path is freed upstream */
+		return (got_serv);
 	}
 
 	/* path is only freed on succes, do it else here */
-	free(path);
+	if(first)
+		free(path);
 
 	return (NULL);
 }
@@ -352,20 +353,15 @@
 		 */
 
 		/* parse line, with options from that service type */
-		if (parse_service_line(&file, watch_for, NULL, stype,
-							   filename, &match, &exact_match) == TRUE)
-		{
-			D_("parse_service_line(%s, %s)\n", match ? match->name : NULL,
-			   exact_match ? exact_match->name : NULL);
-
-			/* ok, jump the ending '}' stack */
-			/* NOTE: file == file_conenct, we cant check file[-1] */
-			if (file[0] == '}' && (file != file_content && file[-1] != '\\'))
-				file++;
-		}
-
-	}										/* end while */
+		parse_service_line(&file, watch_for, NULL, stype,
+							   filename, &match, &exact_match);
+		
+		D_("parse_service_line(%s, %s)\n", match ? match->name : NULL,
+		   exact_match ? exact_match->name : NULL);
+		
+	} /* end while */
 
+	/* free file_content */
 	if (file_content)
 	{
 		free(file_content);
@@ -375,6 +371,8 @@
 	/* Return what we got, and hope for the best */
 	if (exact_match)
 		return (exact_match);
+		
+	/* else, return any match */
 	return (match);
 }
 
@@ -550,7 +548,7 @@
 
 		/* skip spaces and empty lines with them */
 		JUMP_NSPACES(*to_parse);
-
+		
 		/* end of row */
 		/* TODO, make sure (*to_parse)[-1] is not before the string */
 		if (CH_(to_parse, ';'))
@@ -558,9 +556,9 @@
 			(*to_parse)++;
 			continue;
 		}
-
+		
 		/* end of file or stack */
-		if (!(*to_parse) || CH_(to_parse, '}'))
+		if (!(*to_parse)[0] || CH_(to_parse, '}'))
 		{
 			DL_(*to_parse,
 				"When escaping from parse_service_line while loop");
@@ -583,7 +581,7 @@
 			if (!CH_(to_parse, ';'))
 			{
 				FL_(*to_parse, "Must be a ';' char here");
-				break;
+				return(FALSE);
 			}
 
 			/* jump the ';' char */
@@ -596,12 +594,27 @@
 		initng_service_cache_free(new_service);
 		new_service = NULL;
 		return (FALSE);
+	} /* while */
+	
+	/* make sure the while loop only stoped on a break */
+	if(!(*to_parse)[0])
+	{
+		FL_(*to_parse, "Service file did end unexpected.\n");
+		return(FALSE);
 	}
+	
+	/* skip the '}' char we must stand on */
+	(*to_parse)++;
 
 	set_string(&FROM_FILE, new_service, i_strdup(filename));
 
 	/* Add this entry to the initng service cache, it might be the next service we are looking for */
-	initng_service_cache_register(new_service);
+	if(!initng_service_cache_register(new_service))
+	{
+		initng_service_cache_free(new_service);
+		return(FALSE);
+	}
+		
 
 	/* if not watching for anything special */
 	if (!watch_for)


More information about the Initng-svn mailing list