7f6313
--- open-iscsi-2.0-870.1/usr/idbm.c~	2009-01-28 13:23:47.000000000 +0100
7f6313
+++ open-iscsi-2.0-870.1/usr/idbm.c	2009-01-28 13:25:06.000000000 +0100
7f6313
@@ -843,7 +843,7 @@ int idbm_lock(void)
7f6313
 	if (access(LOCK_DIR, F_OK) != 0) {
7f6313
 		if (mkdir(LOCK_DIR, 0660) != 0) {
7f6313
 			log_error("Could not open %s. Exiting\n", LOCK_DIR);
7f6313
-			exit(-1);
7f6313
+			return errno;
7f6313
 		}
7f6313
 	}
7f6313
 
7f6313
@@ -857,10 +857,10 @@ int idbm_lock(void)
7f6313
 			break;
7f6313
 
7f6313
 		if (errno != EEXIST) {
7f6313
+			log_error("Maybe you are not root?");
7f6313
 			log_error("Could not lock discovery DB: %s: %s",
7f6313
 					LOCK_WRITE_FILE, strerror(errno));
7f6313
-			log_error("Maybe you are not root?");
7f6313
-			exit(-1);
7f6313
+			return errno;
7f6313
 		} else if (i == 0)
7f6313
 			log_debug(2, "Waiting for discovery DB lock");
7f6313
 
7f6313
@@ -915,7 +915,10 @@ static int __idbm_rec_read(node_rec_t *o
7f6313
 	if (!info)
7f6313
 		return ENOMEM;
7f6313
 
7f6313
-	idbm_lock();
7f6313
+	rc = idbm_lock();
7f6313
+	if (rc)
7f6313
+		goto free_info;
7f6313
+
7f6313
 	f = fopen(conf, "r");
7f6313
 	if (!f) {
7f6313
 		log_debug(5, "Could not open %s err %d\n", conf, errno);
7f6313
@@ -931,6 +934,7 @@ static int __idbm_rec_read(node_rec_t *o
7f6313
 
7f6313
 unlock:
7f6313
 	idbm_unlock();
7f6313
+free_info:
7f6313
 	free(info);
7f6313
 	return rc;
7f6313
 }
7f6313
@@ -1386,14 +1390,18 @@ idbm_discovery_read(discovery_rec_t *out
7f6313
 		return ENOMEM;
7f6313
 
7f6313
 	portal = malloc(PATH_MAX);
7f6313
-	if (!portal)
7f6313
+	if (!portal) {
7f6313
+		rc = ENOMEM;
7f6313
 		goto free_info;
7f6313
+	}
7f6313
 
7f6313
 	snprintf(portal, PATH_MAX, "%s/%s,%d", ST_CONFIG_DIR,
7f6313
 		 addr, port);
7f6313
 	log_debug(5, "Looking for config file %s\n", portal);
7f6313
 
7f6313
-	idbm_lock();
7f6313
+	rc = idbm_lock();
7f6313
+	if (rc)
7f6313
+		goto free_info;
7f6313
 
7f6313
 	f = idbm_open_rec_r(portal, ST_CONFIG_NAME);
7f6313
 	if (!f) {
7f6313
@@ -1494,7 +1502,9 @@ static int idbm_rec_write(node_rec_t *re
7f6313
 		 rec->name, rec->conn[0].address, rec->conn[0].port);
7f6313
 	log_debug(5, "Looking for config file %s", portal);
7f6313
 
7f6313
-	idbm_lock();
7f6313
+	rc = idbm_lock();
7f6313
+	if (rc)
7f6313
+		goto free_portal;
7f6313
 
7f6313
 	rc = stat(portal, &statb);
7f6313
 	if (rc) {
7f6313
@@ -1579,13 +1589,16 @@ idbm_discovery_write(discovery_rec_t *re
7f6313
 		return ENOMEM;
7f6313
 	}
7f6313
 
7f6313
-	idbm_lock();
7f6313
+	rc = idbm_lock();
7f6313
+	if (rc)
7f6313
+		goto free_portal;
7f6313
+
7f6313
 	snprintf(portal, PATH_MAX, "%s", ST_CONFIG_DIR);
7f6313
 	if (access(portal, F_OK) != 0) {
7f6313
 		if (mkdir(portal, 0660) != 0) {
7f6313
 			log_error("Could not make %s\n", portal);
7f6313
 			rc = errno;
7f6313
-			goto free_portal;
7f6313
+			goto unlock;
7f6313
 		}
7f6313
 	}
7f6313
 
7f6313
@@ -1596,13 +1609,14 @@ idbm_discovery_write(discovery_rec_t *re
7f6313
 	if (!f) {
7f6313
 		log_error("Could not open %s err %d\n", portal, errno);
7f6313
 		rc = errno;
7f6313
-		goto free_portal;
7f6313
+		goto unlock;
7f6313
 	}
7f6313
 
7f6313
 	idbm_print(IDBM_PRINT_TYPE_DISCOVERY, rec, 1, f);
7f6313
 	fclose(f);
7f6313
-free_portal:
7f6313
+unlock:
7f6313
 	idbm_unlock();
7f6313
+free_portal:
7f6313
 	free(portal);
7f6313
 	return rc;
7f6313
 }
7f6313
@@ -1722,7 +1736,10 @@ int idbm_add_node(node_rec_t *newrec, di
7f6313
 	log_debug(7, "node addition making link from %s to %s", node_portal,
7f6313
 		 disc_portal);
7f6313
 
7f6313
-	idbm_lock();
7f6313
+	rc = idbm_lock();
7f6313
+	if (rc)
7f6313
+		goto free_portal;
7f6313
+
7f6313
 	if (symlink(node_portal, disc_portal)) {
7f6313
 		if (errno == EEXIST)
7f6313
 			log_debug(7, "link from %s to %s exists", node_portal,
7f6313
@@ -2009,7 +2026,10 @@ static int idbm_remove_disc_to_node_link
7f6313
 	if (rc)
7f6313
 		goto done;
7f6313
 
7f6313
-	idbm_lock();
7f6313
+	rc = idbm_lock();
7f6313
+	if (rc)
7f6313
+		goto done;
7f6313
+
7f6313
 	if (!stat(portal, &statb)) {
7f6313
 		if (unlink(portal)) {
7f6313
 			log_error("Could not remove link %s err %d\n",
7f6313
@@ -2046,7 +2066,10 @@ int idbm_delete_node(node_rec_t *rec)
7f6313
 	log_debug(5, "Removing config file %s iface id %s\n",
7f6313
 		  portal, rec->iface.name);
7f6313
 
7f6313
-	idbm_lock();
7f6313
+	rc = idbm_lock();
7f6313
+	if (rc)
7f6313
+		goto free_portal;
7f6313
+
7f6313
 	if (!stat(portal, &statb))
7f6313
 		goto rm_conf;
7f6313
 
7f6313
diff -up open-iscsi-2.0-870.1/usr/iface.c~ open-iscsi-2.0-870.1/usr/iface.c
7f6313
--- open-iscsi-2.0-870.1/usr/iface.c~	2009-01-28 13:29:31.000000000 +0100
7f6313
+++ open-iscsi-2.0-870.1/usr/iface.c	2009-01-28 13:29:31.000000000 +0100
7f6313
@@ -208,7 +208,10 @@ int iface_conf_read(struct iface_rec *if
7f6313
 		return 0;
7f6313
 	}
7f6313
 
7f6313
-	idbm_lock();
7f6313
+	rc = idbm_lock();
7f6313
+	if (rc)
7f6313
+		return rc;
7f6313
+
7f6313
 	rc = __iface_conf_read(iface);
7f6313
 	idbm_unlock();
7f6313
 	return rc;
7f6313
@@ -232,11 +235,15 @@ int iface_conf_delete(struct iface_rec *
7f6313
 		return ENOMEM;
7f6313
 
7f6313
 	sprintf(iface_conf, "%s/%s", IFACE_CONFIG_DIR, iface->name);
7f6313
-	idbm_lock();
7f6313
+	rc = idbm_lock();
7f6313
+	if (rc)
7f6313
+		goto free_conf;
7f6313
+
7f6313
 	if (unlink(iface_conf))
7f6313
 		rc = errno;
7f6313
 	idbm_unlock();
7f6313
 
7f6313
+free_conf:
7f6313
 	free(iface_conf);
7f6313
 	return rc;
7f6313
 }
7f6313
@@ -267,10 +274,14 @@ int iface_conf_write(struct iface_rec *i
7f6313
 		goto free_conf;
7f6313
 	}
7f6313
 
7f6313
-	idbm_lock();
7f6313
+	rc = idbm_lock();
7f6313
+	if (rc)
7f6313
+		goto close_f;
7f6313
+
7f6313
 	idbm_print(IDBM_PRINT_TYPE_IFACE, iface, 1, f);
7f6313
 	idbm_unlock();
7f6313
 
7f6313
+close_f:
7f6313
 	fclose(f);
7f6313
 free_conf:
7f6313
 	free(iface_conf);
7f6313
@@ -471,7 +482,9 @@ void iface_setup_host_bindings(void)
7f6313
 {
7f6313
 	int nr_found = 0;
7f6313
 
7f6313
-	idbm_lock();
7f6313
+	if (idbm_lock())
7f6313
+		return;
7f6313
+
7f6313
 	if (access(IFACE_CONFIG_DIR, F_OK) != 0) {
7f6313
 		if (mkdir(IFACE_CONFIG_DIR, 0660) != 0) {
7f6313
 			log_error("Could not make %s. HW/OFFLOAD iscsi "
7f6313
@@ -658,7 +671,12 @@ int iface_for_each_iface(void *data, int
7f6313
 			continue;
7f6313
 		}
7f6313
 
7f6313
-		idbm_lock();
7f6313
+		err = idbm_lock();
7f6313
+		if (err) {
7f6313
+			free(iface);
7f6313
+			continue;
7f6313
+		}
7f6313
+
7f6313
 		err = __iface_conf_read(iface);
7f6313
 		idbm_unlock();
7f6313
 		if (err) {