All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ivan Gyurdiev <ivg2@cornell.edu>
To: selinux@tycho.nsa.gov
Cc: dwalsh@redhat.com
Subject: Re: [ 5/9 ] [ SEMANAGE ] Change database to singly-linked list
Date: Thu, 29 Sep 2005 23:04:38 -0400	[thread overview]
Message-ID: <433CAB46.7090709@cornell.edu> (raw)
In-Reply-To: <433CA7CA.6000207@cornell.edu>

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

This patch changes the previously doubly-linked list in database.c to a 
singly-linked list, which is sufficient.

[-- Attachment #2: libsemanage.04.dbase_single_link.diff --]
[-- Type: text/x-patch, Size: 1580 bytes --]

diff -Naur libsemanage/src/database.c libsemanage.new2/src/database.c
--- libsemanage/src/database.c	2005-09-29 17:54:40.000000000 -0400
+++ libsemanage.new2/src/database.c	2005-09-29 18:03:08.000000000 -0400
@@ -12,7 +12,6 @@
 /* Representation of the database once loaded in memory */
 typedef struct cache_entry {
 	record_t data;
-	struct cache_entry* prev;
 	struct cache_entry* next;
 } cache_entry_t;
 
@@ -98,10 +97,7 @@
 	if (entry == NULL)
 		goto omem;
 	entry->data = data;
-	entry->prev = NULL;
 	entry->next = dbase->cache;
-	if (dbase->cache != NULL)
-		dbase->cache->prev = entry;
 	dbase->cache = entry;
 	dbase->cache_sz++;
 
@@ -267,29 +263,26 @@
 	dbase_t* dbase,
 	record_key_t key) {
 
-	cache_entry_t* entry;
-	int status;
+	cache_entry_t *ptr, *prev = NULL;
 
 	if (dbase_cache_fill(dbase) < 0)
 		goto err;
 
-	status = dbase_cache_locate(dbase, key, &entry);
-	if (status < 0)
-		goto err;
-	
-	else if (status != STATUS_NODATA) {
-		if (entry->next != NULL)
-			entry->next->prev = entry->prev;
-
-		if (entry->prev != NULL)
-			entry->prev->next = entry->next;
+	for (ptr = dbase->cache; ptr != NULL; ptr = ptr->next) {
+		if (! dbase->rtable->compare(ptr->data, key)) {
+			if (prev != NULL)
+				prev->next = ptr->next;
+			else
+				dbase->cache = ptr->next;
+
+			dbase->rtable->free(ptr->data);
+			dbase->cache_sz--;
+			free(ptr);
+			return STATUS_SUCCESS;
+		}
 		else
-			dbase->cache = entry->next;
-
-		dbase->rtable->free(entry->data);
-		dbase->cache_sz--;
-		free(entry);
-	}
+			prev = ptr;
+        }
 
 	return STATUS_SUCCESS;
 	err:

  parent reply	other threads:[~2005-09-30  3:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-30  2:49 [ 1/9 ] [ SEPOL ] Eliminate struct pointer typedefs Ivan Gyurdiev
2005-09-30  2:52 ` [ 2/9 ] [ SEMANAGE ] Restore sepol compatibility Ivan Gyurdiev
2005-09-30  2:55 ` [ 3/9 ] [ SEMANAGE ] Rename files Ivan Gyurdiev
2005-09-30  3:02 ` [ 4/9 ] [ SEMANAGE ] Database initialization Stage 1 Ivan Gyurdiev
2005-09-30 18:42   ` Ivan Gyurdiev
2005-09-30  3:04 ` Ivan Gyurdiev [this message]
2005-09-30  3:07 ` [ 6/9 ] [ SEMANAGE ] Database Initialization Stage 2 Ivan Gyurdiev
2005-09-30  3:14 ` [ 7/9 ] [ SEMANAGE ] Backend separation (Init 3) Ivan Gyurdiev
2005-09-30 13:45   ` Ivan Gyurdiev
2005-09-30  3:16 ` [ 8/9 ] [ SEMANAGE ] Eliminate struct pointer typedefs Ivan Gyurdiev
2005-09-30  3:26 ` [ 9/9 ] [ SEPOL ] User list function, Bugfixes Ivan Gyurdiev
2005-09-30  3:29 ` Memory leaks Ivan Gyurdiev
2005-09-30  6:01   ` Ivan Gyurdiev
2005-09-30  3:34 ` Linking to semanage Ivan Gyurdiev
2005-09-30  5:56   ` Ivan Gyurdiev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=433CAB46.7090709@cornell.edu \
    --to=ivg2@cornell.edu \
    --cc=dwalsh@redhat.com \
    --cc=selinux@tycho.nsa.gov \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.