Don't calling exit() from libmdb.so

Nirgal <[email protected]> Tue, 3 Jan 2012 22:00:29 +0000
Newsgroups gmane.comp.db.mdb-tools.devel
Message-ID <[email protected]>
--Boundary-00=_Eq3APfAAQhs+oVL
Content-Type: Text/Plain;
  charset="utf-8"
Content-Transfer-Encoding: 7bit

Hi everyone

Debian packaging analysis is complaining about the fact that libmdb might call exit().

> N:    In the case of an error, the library should instead return an
> N:    appropriate error code to the calling program which can then determine
> N:    how to handle the error, including performing any required clean-up.

Does the attached patch looks ok for you?

--Boundary-00=_Eq3APfAAQhs+oVL
Content-Type: text/x-patch;
  charset="UTF-8";
  name="05_nolibexit"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="05_nolibexit"

Index: mdbtools/src/libmdb/write.c
===================================================================
--- mdbtools.orig/src/libmdb/write.c
+++ mdbtools/src/libmdb/write.c
@@ -554,8 +554,8 @@
 	}
 	mdb_debug(MDB_DEBUG_WRITE, "writing page %d", pgnum);
 	if (!mdb_write_pg(mdb, pgnum)) {
-		fprintf(stderr, "write failed! exiting...\n");
-		exit(1);
+		fprintf(stderr, "write failed!\n");
+		return 0;
 	}
 
 	mdb_update_indexes(table, num_fields, fields, pgnum, rownum);
@@ -685,8 +685,14 @@
 	}
 	/* do it! */
 	mdb_replace_row(table, table->cur_row-1, row_buffer, new_row_size);
-	return 0;
+	return 0; /* FIXME */
 }
+
+/* WARNING the return code is opposite to convention used elsewhere:
+ * returns 0 on success
+ * returns 1 on failure
+ * This might change on next ABI break.
+ */
 int 
 mdb_replace_row(MdbTableDef *table, int row, void *new_row, int new_row_size)
 {
@@ -745,8 +751,8 @@
 	}
 	/* drum roll, please */
 	if (!mdb_write_pg(mdb, table->cur_phys_pg)) {
-		fprintf(stderr, "write failed! exiting...\n");
-		exit(1);
+		fprintf(stderr, "write failed!\n");
+		return 1;
 	}
 	return 0;
 }

--Boundary-00=_Eq3APfAAQhs+oVL
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
--Boundary-00=_Eq3APfAAQhs+oVL
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
mdbtools-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mdbtools-dev

--Boundary-00=_Eq3APfAAQhs+oVL--