PERFORCE change 124937 for review

Zhouyi ZHOU zhouzhouyi at FreeBSD.org
Wed Aug 8 23:01:24 PDT 2007


http://perforce.freebsd.org/chv.cgi?CH=124937

Change 124937 by zhouzhouyi at zhouzhouyi_mactest on 2007/08/09 06:01:19

	Merging the handling of mac hooks match into macconf.c

Affected files ...

.. //depot/projects/soc2007/zhouzhouyi_mactest_soc/regression/mactest/fifo_io.c#2 edit
.. //depot/projects/soc2007/zhouzhouyi_mactest_soc/regression/mactest/macconf.c#2 edit
.. //depot/projects/soc2007/zhouzhouyi_mactest_soc/regression/mactest/mactest.c#11 edit
.. //depot/projects/soc2007/zhouzhouyi_mactest_soc/regression/mactest/mactest.h#3 edit

Differences ...

==== //depot/projects/soc2007/zhouzhouyi_mactest_soc/regression/mactest/fifo_io.c#2 (text+ko) ====

@@ -71,7 +71,7 @@
 	u_char buffer[10];
 	int error;
 	int i, len;
-	int notgood = 0;
+
 
 	while ((ch = getopt(argc, argv, "r:w:f:p:")) != -1) {
 		switch(ch) {
@@ -190,102 +190,8 @@
 
 	close(logfd);
 
-	/* compare the configuration file and parse result */
-	{
-
-		struct mactestlog_record *record_from_log, *record_from_conf;
-		if ((inputfile = fopen("/var/log/mactest", "r")) < 0){
-			fprintf(stderr,"/var/log/mactest do not exists!\n");
-			exit(1);
-		}
-
-		yyparse();
-		fclose(inputfile);
-		record_from_log = mactestlog_record_chain;
-		if ((inputfile = fopen(macconf_file, "r")) == NULL){
-			fprintf(stderr, "mactest.conf do not exists!\n");
-			exit(1);
-		}
-
-		mactestlog_record_chain = 0;
-		yyparse();
-		fclose(inputfile);
-		record_from_conf = mactestlog_record_chain;
-
-		/* See if record_from_conf is contained in record_from_log */
-		/* pid == -1 means matching the running pid */
-		pid = getpid();
-
-		while (record_from_conf) {
-			struct mactestlog_record * iterator = record_from_log;
-			while (iterator) {
-				if (!((record_from_conf->pid == -1&& iterator->pid == pid)||
-					record_from_conf->pid == iterator->pid||
-					record_from_conf->pid == -2/*matching any pid*/)){
-					iterator = iterator->next;
-					continue;
-				}
-		
-				if (strcmp(record_from_conf->machookname, iterator->machookname))
-				{
-					iterator = iterator->next;
-					continue;
-				}
-				if (modes_or_flags_compare(record_from_conf->modes_or_flags,
-					iterator->modes_or_flags)){
-					iterator = iterator->next;
-					continue;
-				}
-				if (labelstrings_compare(record_from_conf->labelstrings,
-					iterator->labelstrings)){
-					iterator = iterator->next;
-					continue;
-				}
-				break;
-			}
-			if (iterator)			
-				record_from_conf = record_from_conf->next;
-			else{
-				notgood = 1;
-				fprintf(stderr, "missing ...\n");
-				struct modes_or_flags *iterator1, *tmp1;
-				struct labelstrings *iterator2, *tmp2;
-				fprintf(stderr, "pid = %d ", record_from_conf->pid);
-				fprintf(stderr, "hookname: %s\n", record_from_conf->machookname);
-
-				iterator1 = record_from_conf->modes_or_flags;
-				if (iterator1) {
-					while (iterator1) {
-						tmp1 = iterator1;
-						iterator1 = iterator1->next;
-					}
-					fprintf(stderr, "	with modes or flags#");
-					while (tmp1) {
-						fprintf(stderr, " %s", tmp1->modflagname);
-						tmp1 = tmp1->prev;
-					}
-					fprintf(stderr, "\n");
-				}
+ 	machookmatch(macconf_file, pid1);
 
-				iterator2 = record_from_conf->labelstrings;
-				if (iterator2) {
-					while (iterator2) {
-						tmp2 = iterator2;
-						iterator2 = iterator2->next;
-					}
-					fprintf(stderr, "	with labels:");
-					while (tmp2) {
-						if (!strcmp("*",tmp2->labelstring))
-							fprintf(stderr, " any");
-						else
-							fprintf(stderr, " %s", tmp2->labelstring);
-						tmp2 = tmp2->prev;
-					}
-					fprintf(stderr, "\n");
-				}
-				record_from_conf = record_from_conf->next;
-			}	
-		}
-	}		
 	return (0);
 }
+

==== //depot/projects/soc2007/zhouzhouyi_mactest_soc/regression/mactest/macconf.c#2 (text+ko) ====

@@ -18,19 +18,22 @@
 #include <signal.h>
 #include "mactest.h"
 
-/* compare modes_or_flags from mactest.conf and from /var/log/mactest, should be exact match
- * and order appears in the sequence is irrelevance */
-int modes_or_flags_compare(struct modes_or_flags * mf_conf, struct modes_or_flags *mf_log)
+/*
+ * compare modes_or_flags from mactest.conf and from /var/log/mactest, should
+ * be exact match and order appears in the sequence is irrelevance
+ */
+int
+modes_or_flags_compare(struct modes_or_flags *mf_conf, struct modes_or_flags *mf_log)
 {
 
-	struct modes_or_flags * tmp, *tmp1;
+	struct modes_or_flags *tmp, *tmp1;
 
 	tmp = mf_conf;
 	while (tmp) {
-		tmp1 = mf_log; 
+		tmp1 = mf_log;
 		if (!tmp1)
 			return 1;
-		while(tmp1) {
+		while (tmp1) {
 			if (!strcmp(tmp->modflagname, tmp1->modflagname))
 				break;
 			tmp1 = tmp1->next;
@@ -42,10 +45,10 @@
 
 	tmp = mf_log;
 	while (tmp) {
-		tmp1 = mf_conf; 
+		tmp1 = mf_conf;
 		if (!tmp1)
 			return 1;
-		while(tmp1) {
+		while (tmp1) {
 			if (!strcmp(tmp->modflagname, tmp1->modflagname))
 				break;
 			tmp1 = tmp1->next;
@@ -58,33 +61,38 @@
 	return 0;
 }
 
-/* compare labelstrings from mactest.conf and from /var/log/mactest, should be exact match
- * and order of the modules appears in a label is irrelevance */
-int label_compare(char *conf, char *log)
+/*
+ * compare labelstrings from mactest.conf and from /var/log/mactest, should
+ * be exact match and order of the modules appears in a label is irrelevance
+ */
+int
+label_compare(char *conf, char *log)
 {
 
-	char *element_data, *element_data1, *element_data2, *tmp, *conf1, *tmp2;
+	char           *element_data, *element_data1, *element_data2, *tmp,
+	               *conf1, *tmp2;
 	if (!strcmp(conf, "*"))
 		return 0;
 	tmp2 = conf1 = strdup(conf);
 	while ((element_data = strsep(&conf1, ",")) != NULL) {
 		tmp = element_data1 = strdup(log);
-		while ((element_data2 = strsep(&element_data1, ",")) != NULL){
+		while ((element_data2 = strsep(&element_data1, ",")) != NULL) {
 			if (!strcmp(element_data2, element_data))
 				break;
 		}
-		if (element_data2 == NULL){
+		if (element_data2 == NULL) {
 			free(tmp);
 			free(tmp2);
 			return 1;
-		}else
+		} else
 			free(tmp);
 	}
 	free(tmp2);
 	return 0;
 }
 
-int labelstrings_compare(struct labelstrings *ls_conf, struct labelstrings *ls_log)
+int
+labelstrings_compare(struct labelstrings *ls_conf, struct labelstrings *ls_log)
 {
 
 	while (ls_conf) {
@@ -98,4 +106,101 @@
 	if (ls_log)
 		return 1;
 	return 0;
-} 
+}
+
+/* compare the configuration file and parse result */
+void
+machookmatch(const char *macconf_file, pid_t pid)
+{
+
+
+
+	struct mactestlog_record *record_from_log, *record_from_conf;
+	if ((inputfile = fopen("/var/log/mactest", "r")) < 0) {
+		fprintf(stderr, "/var/log/mactest do not exists!\n");
+		exit(1);
+	}
+	yyparse();
+	fclose(inputfile);
+	record_from_log = mactestlog_record_chain;
+	if ((inputfile = fopen(macconf_file, "r")) == NULL) {
+		fprintf(stderr, "mactest.conf do not exists!\n");
+		exit(1);
+	}
+	mactestlog_record_chain = 0;
+	yyparse();
+	fclose(inputfile);
+	record_from_conf = mactestlog_record_chain;
+
+	/* See if record_from_conf is contained in record_from_log */
+	/* pid == -1 means matching the running pid */
+	pid = getpid();
+
+	while (record_from_conf) {
+		struct mactestlog_record *iterator = record_from_log;
+		while (iterator) {
+			if (!((record_from_conf->pid == -1 && iterator->pid == pid) ||
+			      record_from_conf->pid == iterator->pid ||
+			      record_from_conf->pid == -2 /* matching any pid */ )) {
+				iterator = iterator->next;
+				continue;
+			}
+			if (strcmp(record_from_conf->machookname, iterator->machookname)) {
+				iterator = iterator->next;
+				continue;
+			}
+			if (modes_or_flags_compare(record_from_conf->modes_or_flags,
+						iterator->modes_or_flags)) {
+				iterator = iterator->next;
+				continue;
+			}
+			if (labelstrings_compare(record_from_conf->labelstrings,
+						 iterator->labelstrings)) {
+				iterator = iterator->next;
+				continue;
+			}
+			break;
+		}
+		if (iterator)
+			record_from_conf = record_from_conf->next;
+		else {
+
+			fprintf(stderr, "missing ...\n");
+			struct modes_or_flags *iterator1, *tmp1;
+			struct labelstrings *iterator2, *tmp2;
+			fprintf(stderr, "pid = %d ", record_from_conf->pid);
+			fprintf(stderr, "hookname: %s\n", record_from_conf->machookname);
+
+			iterator1 = record_from_conf->modes_or_flags;
+			if (iterator1) {
+				while (iterator1) {
+					tmp1 = iterator1;
+					iterator1 = iterator1->next;
+				}
+				fprintf(stderr, "	with modes or flags#");
+				while (tmp1) {
+					fprintf(stderr, " %s", tmp1->modflagname);
+					tmp1 = tmp1->prev;
+				}
+				fprintf(stderr, "\n");
+			}
+			iterator2 = record_from_conf->labelstrings;
+			if (iterator2) {
+				while (iterator2) {
+					tmp2 = iterator2;
+					iterator2 = iterator2->next;
+				}
+				fprintf(stderr, "	with labels:");
+				while (tmp2) {
+					if (!strcmp("*", tmp2->labelstring))
+						fprintf(stderr, " any");
+					else
+						fprintf(stderr, " %s", tmp2->labelstring);
+					tmp2 = tmp2->prev;
+				}
+				fprintf(stderr, "\n");
+			}
+			record_from_conf = record_from_conf->next;
+		}
+	}
+}

==== //depot/projects/soc2007/zhouzhouyi_mactest_soc/regression/mactest/mactest.c#11 (text+ko) ====

@@ -46,6 +46,7 @@
 #include <signal.h>
 #include "mactest.h"
 
+
 #ifndef HAS_TRUNCATE64
 #define	truncate64	truncate
 #endif
@@ -541,90 +542,6 @@
 	return (i);
 }
 
-
-
-
-/* compare modes_or_flags from mactest.conf and from /var/log/mactest, should be exact match
- * and order appears in the sequence is irrelevance */
-static int modes_or_flags_compare(struct modes_or_flags * mf_conf, struct modes_or_flags *mf_log)
-{
-
-	struct modes_or_flags * tmp, *tmp1;
-
-	tmp = mf_conf;
-	while (tmp) {
-		tmp1 = mf_log; 
-		if (!tmp1)
-			return 1;
-		while(tmp1) {
-			if (!strcmp(tmp->modflagname, tmp1->modflagname))
-				break;
-			tmp1 = tmp1->next;
-		}
-		if (!tmp1)
-			return 1;
-		tmp = tmp->next;
-	}
-
-	tmp = mf_log;
-	while (tmp) {
-		tmp1 = mf_conf; 
-		if (!tmp1)
-			return 1;
-		while(tmp1) {
-			if (!strcmp(tmp->modflagname, tmp1->modflagname))
-				break;
-			tmp1 = tmp1->next;
-		}
-		if (!tmp1)
-			return 1;
-		tmp = tmp->next;
-	}
-
-	return 0;
-}
-
-/* compare labelstrings from mactest.conf and from /var/log/mactest, should be exact match
- * and order of the modules appears in a label is irrelevance */
-static label_compare(char *conf, char *log)
-{
-
-	char *element_data, *element_data1, *element_data2, *tmp, *conf1, *tmp2;
-	if (!strcmp(conf, "*"))
-		return 0;
-	tmp2 = conf1 = strdup(conf);
-	while ((element_data = strsep(&conf1, ",")) != NULL) {
-		tmp = element_data1 = strdup(log);
-		while ((element_data2 = strsep(&element_data1, ",")) != NULL){
-			if (!strcmp(element_data2, element_data))
-				break;
-		}
-		if (element_data2 == NULL){
-			free(tmp);
-			free(tmp2);
-			return 1;
-		}else
-			free(tmp);
-	}
-	free(tmp2);
-	return 0;
-}
-static int labelstrings_compare(struct labelstrings *ls_conf, struct labelstrings *ls_log)
-{
-
-	while (ls_conf) {
-		if (!ls_log)
-			return 1;
-		if (label_compare(ls_conf->labelstring, ls_log->labelstring))
-			return 1;
-		ls_conf = ls_conf->next;
-		ls_log = ls_log->next;
-	}
-	if (ls_log)
-		return 1;
-	return 0;
-} 
-
 int
 main(int argc, char *argv[])
 {
@@ -637,7 +554,6 @@
 	int mactestpipefd, logfd;
 	char buf[2048];
 	int ch;
-	int notgood = 0;
 
 
 	while ((ch = getopt(argc, argv, "m:f:")) != -1) {
@@ -707,108 +623,10 @@
 	}
 	
 	close(logfd);
-	
-	/* compare the configuration file and parse result */
-	{
 
-		struct mactestlog_record *record_from_log, *record_from_conf;
-		if ((inputfile = fopen("/var/log/mactest", "r")) < 0){
-			fprintf(stderr,"/var/log/mactest do not exists!\n");
-			exit(1);
-		}
+ 	machookmatch(macconf_file, pid);	
 
-		yyparse();
-		fclose(inputfile);
-		record_from_log = mactestlog_record_chain;
-		if ((inputfile = fopen(macconf_file, "r")) == NULL){
-			fprintf(stderr, "mactest.conf do not exists!\n");
-			exit(1);
-		}
-
-		mactestlog_record_chain = 0;
-		yyparse();
-		fclose(inputfile);
-		record_from_conf = mactestlog_record_chain;
-
-		/* See if record_from_conf is contained in record_from_log */
-		/* pid == -1 means matching the running pid */
-		pid = getpid();
-
-		while (record_from_conf) {
-			struct mactestlog_record * iterator = record_from_log;
-			while (iterator) {
-				if (!((record_from_conf->pid == -1&& iterator->pid == pid)||
-					record_from_conf->pid == iterator->pid||
-					record_from_conf->pid == -2/*matching any pid*/)){
-					iterator = iterator->next;
-					continue;
-				}
-		
-				if (strcmp(record_from_conf->machookname, iterator->machookname))
-				{
-					iterator = iterator->next;
-					continue;
-				}
-				if (modes_or_flags_compare(record_from_conf->modes_or_flags,
-					iterator->modes_or_flags)){
-					iterator = iterator->next;
-					continue;
-				}
-				if (labelstrings_compare(record_from_conf->labelstrings,
-					iterator->labelstrings)){
-					iterator = iterator->next;
-					continue;
-				}
-				break;
-			}
-			if (iterator)			
-				record_from_conf = record_from_conf->next;
-			else{
-				notgood = 1;
-				fprintf(stderr, "missing ...\n");
-				struct modes_or_flags *iterator1, *tmp1;
-				struct labelstrings *iterator2, *tmp2;
-				fprintf(stderr, "pid = %d ", record_from_conf->pid);
-				fprintf(stderr, "hookname: %s\n", record_from_conf->machookname);
-
-				iterator1 = record_from_conf->modes_or_flags;
-				if (iterator1) {
-					while (iterator1) {
-						tmp1 = iterator1;
-						iterator1 = iterator1->next;
-					}
-					fprintf(stderr, "	with modes or flags#");
-					while (tmp1) {
-						fprintf(stderr, " %s", tmp1->modflagname);
-						tmp1 = tmp1->prev;
-					}
-					fprintf(stderr, "\n");
-				}
-
-				iterator2 = record_from_conf->labelstrings;
-				if (iterator2) {
-					while (iterator2) {
-						tmp2 = iterator2;
-						iterator2 = iterator2->next;
-					}
-					fprintf(stderr, "	with labels:");
-					while (tmp2) {
-						if (!strcmp("*",tmp2->labelstring))
-							fprintf(stderr, " any");
-						else
-							fprintf(stderr, " %s", tmp2->labelstring);
-						tmp2 = tmp2->prev;
-					}
-					fprintf(stderr, "\n");
-				}
-				record_from_conf = record_from_conf->next;
-			}	
-		}
-	}		
-	if (notgood)
-		exit(1);
-	else
-		exit(0);
+	exit(0);
 }
 
 static const char *

==== //depot/projects/soc2007/zhouzhouyi_mactest_soc/regression/mactest/mactest.h#3 (text+ko) ====

@@ -57,5 +57,6 @@
 int modes_or_flags_compare(struct modes_or_flags * mf_conf, struct modes_or_flags *mf_log);
 int label_compare(char *conf, char *log);
 int labelstrings_compare(struct labelstrings *ls_conf, struct labelstrings *ls_log);
+void machookmatch(const char *macconf_file, pid_t pid);
 #endif /* !_REGRESSION_MAC_TEST__H */
 


More information about the p4-projects mailing list