Index: trunk/ippTools/src/stacktool.c
===================================================================
--- trunk/ippTools/src/stacktool.c	(revision 11985)
+++ trunk/ippTools/src/stacktool.c	(revision 11986)
@@ -124,4 +124,12 @@
     }
 
+    // we have to support multipe exp_tags
+    psMetadataItem *p4_ids = psMetadataLookup(config->args, "-p4_id");
+    if (!p4_ids) {
+        // this shouldn't actually happen when using psArgs
+        psError(PS_ERR_UNKNOWN, true, "-p4_id is required");
+        return false;
+    }
+
     psTime *registered = NULL;
     {
@@ -141,5 +149,5 @@
     p6RunRow *run = p6RunRowAlloc(
             0,          // ID
-            "reg",      // state
+            "run",      // state
             workdir,
             NULL,       // dvodb
@@ -153,5 +161,14 @@
         return true;
     }
+
+    if (!psDBTransaction(config->dbh)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+
     if (!p6RunInsertObject(config->dbh, run)) {
+        if (!psDBRollback(config->dbh)) {
+            psError(PS_ERR_UNKNOWN, false, "database error");
+        }
         psError(PS_ERR_UNKNOWN, false, "database error");
         psFree(run);
@@ -161,4 +178,24 @@
     // get the assigned p4_id
     run->p6_id = psDBLastInsertID(config->dbh);
+
+    // insert the p6InputSkyfile rows
+    psListIterator *iter = psListIteratorAlloc(p4_ids->data.list, 0, false);
+    psMetadataItem *item = NULL;
+    while ((item = psListGetAndIncrement(iter))) {
+        if (!p6InputSkyfileInsert(config->dbh, run->p6_id, atoi((char *)item->data.V))) {
+            if (!psDBRollback(config->dbh)) {
+                psError(PS_ERR_UNKNOWN, false, "database error");
+            }
+            psError(PS_ERR_UNKNOWN, false, "failed to insert p6InputSkyfile rows");
+            return false;
+        }
+    }
+    psFree(iter);
+
+    // point of no return
+    if (!psDBCommit(config->dbh)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
 
     bool simple = false;
