All of lore.kernel.org
 help / color / mirror / Atom feed
* libsemanage performance patch
@ 2006-01-03 18:57 Russell Coker
  2006-01-03 17:28 ` Ivan Gyurdiev
  2006-01-05 13:34 ` Stephen Smalley
  0 siblings, 2 replies; 5+ messages in thread
From: Russell Coker @ 2006-01-03 18:57 UTC (permalink / raw)
  To: SE-Linux

[-- Attachment #1: Type: text/plain, Size: 309 bytes --]

Optimised string and FILE * operations in libsemanage.

-- 
http://www.coker.com.au/selinux/   My NSA Security Enhanced Linux packages
http://www.coker.com.au/bonnie++/  Bonnie++ hard drive benchmark
http://www.coker.com.au/postal/    Postal SMTP/POP benchmark
http://www.coker.com.au/~russell/  My home page

[-- Attachment #2: libsemanage.diff --]
[-- Type: text/x-diff, Size: 6901 bytes --]

diff -rup libsemanage-1.5.3/src.orig/database_file.c libsemanage-1.5.3/src/database_file.c
--- libsemanage-1.5.3/src.orig/database_file.c	2005-12-15 06:16:51.000000000 +1100
+++ libsemanage-1.5.3/src/database_file.c	2006-01-01 18:50:36.000000000 +1100
@@ -7,6 +7,8 @@ typedef struct dbase_file dbase_t;
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <stdio.h>
+#include <stdio_ext.h>
 #include "debug.h"
 #include "handle.h"
 #include "parse_utils.h"
@@ -202,6 +204,7 @@ static int dbase_file_flush(
 			fname, strerror(errno));
 		goto err;
 	}
+	__fsetlocking(str, FSETLOCKING_BYCALLER);
 
 	for (ptr = dbase->cache_tail; ptr != NULL; ptr = ptr->prev) {
 		if (dbase->rftable->print(handle, ptr->data, str) < 0)
diff -rup libsemanage-1.5.3/src.orig/database_policydb.c libsemanage-1.5.3/src/database_policydb.c
--- libsemanage-1.5.3/src.orig/database_policydb.c	2005-12-15 06:16:51.000000000 +1100
+++ libsemanage-1.5.3/src/database_policydb.c	2006-01-01 19:25:18.000000000 +1100
@@ -7,6 +7,7 @@ typedef struct dbase_policydb dbase_t;
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
+#include <stdio_ext.h>
 #include <errno.h>
 
 #include <sepol/policydb.h>
@@ -87,6 +88,7 @@ static int dbase_policydb_cache(
 	
 	/* If the file was opened successfully, read a policydb */
 	if (fp != NULL) {
+		__fsetlocking(fp, FSETLOCKING_BYCALLER);
 		if (sepol_policy_file_create(&pf) < 0) {
 			ERR(handle, "could not create policy file object");
 			goto err;
diff -rup libsemanage-1.5.3/src.orig/direct_api.c libsemanage-1.5.3/src/direct_api.c
--- libsemanage-1.5.3/src.orig/direct_api.c	2005-12-15 06:16:51.000000000 +1100
+++ libsemanage-1.5.3/src/direct_api.c	2006-01-01 18:06:17.000000000 +1100
@@ -24,6 +24,7 @@
 #include <assert.h>
 #include <fcntl.h>
 #include <stdio.h>
+#include <stdio_ext.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -305,6 +306,7 @@ static int semanage_write_module(semanag
 		ERR(sh, "Could not open %s for writing.", filename);
 		return -1;
 	}
+	__fsetlocking(outfile, FSETLOCKING_BYCALLER);
 	sepol_policy_file_set_fp(pf, outfile);
 	sepol_policy_file_set_handle(pf, sh->sepolh);
 	retval = sepol_module_package_write(package, pf);
@@ -575,6 +577,7 @@ static int semanage_direct_list(semanage
 			 * report it */
 			continue;
 		}
+		__fsetlocking(fp, FSETLOCKING_BYCALLER);
 		sepol_policy_file_set_fp(pf, fp);
 		if (sepol_module_package_info(pf, &type, &name, &version)) {
 			fclose(fp);
diff -rup libsemanage-1.5.3/src.orig/parse_utils.c libsemanage-1.5.3/src/parse_utils.c
--- libsemanage-1.5.3/src.orig/parse_utils.c	2005-12-15 06:16:51.000000000 +1100
+++ libsemanage-1.5.3/src/parse_utils.c	2006-01-02 19:24:13.000000000 +1100
@@ -86,7 +86,8 @@ int parse_skip_space(
 	semanage_handle_t* handle, 
 	parse_info_t* info) {
 
-	size_t len = 0;
+	size_t buf_len = 0;
+	ssize_t len;
 	int lineno = info->lineno;
 	char* buffer = NULL;
 	char* ptr;
@@ -102,12 +103,11 @@ int parse_skip_space(
 	parse_dispose_line(info);
 
 	while (info->file_stream &&
-		(getline(&buffer, &len, info->file_stream) > 0)) {
+		((len = getline(&buffer, &buf_len, info->file_stream)) > 0)) {
 
 		lineno++;
 
 		/* Eat newline, preceding whitespace */
-		len = strlen(buffer);
 		if (buffer[len - 1] == '\n')
 			buffer[len - 1] = '\0';
 
@@ -116,10 +116,7 @@ int parse_skip_space(
 			ptr++;
 
 		/* Skip comments and blank lines */
-		if (!(*ptr) || *ptr == '#')
-			goto next;
-
-		else {
+		if ((*ptr) && *ptr != '#') {
 			char* tmp = strdup(buffer);
 			if (!tmp)
 				goto omem;
@@ -131,10 +128,6 @@ int parse_skip_space(
 
 			return STATUS_SUCCESS;
 		}
-
-		next:
-		free(buffer);
-		buffer = NULL;
 	}
 
 	free(buffer);
@@ -206,10 +199,12 @@ int parse_assert_str(
 	parse_info_t* info, 
 	const char* assert_str) {
 
+	size_t len = strlen(assert_str);
+
 	if (parse_assert_noeof(handle, info) < 0)
 		return STATUS_ERR;
 
-	if (strncmp(info->ptr, assert_str, strlen(assert_str))) {
+	if (strncmp(info->ptr, assert_str, len)) {
 		ERR(handle, "experted string \"%s\", but found \"%s\" "
 			"(%s: %u):\n%s", assert_str, info->ptr, 
 			info->filename, info->lineno, info->orig_line);
@@ -217,7 +212,7 @@ int parse_assert_str(
 		return STATUS_ERR;
 	}
 
-	info->ptr += strlen(assert_str);
+	info->ptr += len;
 	return STATUS_SUCCESS;
 }
 
@@ -231,10 +226,12 @@ int parse_optional_ch(parse_info_t* info
 }
 
 int parse_optional_str(parse_info_t* info, const char* str) {
-	if (info->ptr && strncmp(info->ptr, str, strlen(str)))
+	size_t len = strlen(str);
+
+	if (info->ptr && strncmp(info->ptr, str, len))
 		return STATUS_NODATA;
 	else {
-		info->ptr += strlen(str);
+		info->ptr += len;
 		return STATUS_SUCCESS;
 	}
 }
diff -rup libsemanage-1.5.3/src.orig/semanage_store.c libsemanage-1.5.3/src/semanage_store.c
--- libsemanage-1.5.3/src.orig/semanage_store.c	2005-12-15 06:16:51.000000000 +1100
+++ libsemanage-1.5.3/src/semanage_store.c	2006-01-02 19:18:57.000000000 +1100
@@ -44,6 +44,7 @@ typedef struct dbase_policydb dbase_t;
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
+#include <stdio_ext.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -287,16 +288,9 @@ int semanage_create_store(semanage_handl
 
 /* Callback used by scandir() to select files. */
 static int semanage_filename_select(const struct dirent *d) {
-	int len;
-
-	/* For some reason XFS doesn't set d_type so we actually have
-	 * to use stat() to decide if it's a directory or not :(
-	 */
-	len = strlen(d->d_name);
-	if (len == 1 && d->d_name[0] == '.')
-		return 0;
-	if (len == 2 && d->d_name[0] == '.' &&
-	    d->d_name[1] == '.')
+	if (d->d_name[0] == '.'
+		  && (d->d_name[1] == '\0'
+		   || (d->d_name[1] == '.' && d->d_name[2] == '\0')))
 		return 0;
 	return 1;
 }
@@ -831,9 +825,9 @@ int semanage_split_fc(semanage_handle_t 
 		return -1;
 	}
 
-	while (fgets(buf, PATH_MAX, file_con)) {
-		if (strstr(buf, "HOME_DIR") ||
-		    strstr(buf, "HOME_ROOT") ||
+	while (fgets_unlocked(buf, PATH_MAX, file_con)) {
+		if (strncmp(buf, "HOME_DIR", 8) ||
+		    strncmp(buf, "HOME_ROOT", 9) ||
 		    strstr(buf, "ROLE")) {
 			/* This contains one of the template variables, write it to homedir.template */
 			if (write(hd, buf, strnlen(buf, PATH_MAX)) == 0) {
@@ -1267,6 +1261,7 @@ static int semanage_load_module(semanage
 		ERR(sh, "Could not open module file %s for reading.", filename);
 		goto cleanup;
 	}
+	__fsetlocking(fp, FSETLOCKING_BYCALLER);
 	sepol_policy_file_set_fp(pf, fp);
 	sepol_policy_file_set_handle(pf, sh->sepolh);
 	if (sepol_module_package_read(*package, pf, 0) == -1) {
@@ -1402,6 +1397,7 @@ int semanage_expand_sandbox(semanage_han
  		ERR(sh, "Could not open kernel policy %s for writing.", kernel_filename);
 		goto cleanup;
 	}
+	__fsetlocking(outfile, FSETLOCKING_BYCALLER);
 	if (sepol_policy_file_create(&pf)) {
  		ERR(sh, "Out of memory!");
 		goto cleanup;

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-01-05 17:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-01-03 18:57 libsemanage performance patch Russell Coker
2006-01-03 17:28 ` Ivan Gyurdiev
2006-01-03 17:51   ` Ivan Gyurdiev
2006-01-05 13:34 ` Stephen Smalley
2006-01-05 17:57   ` Stephen Smalley

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.