- close fds before calling rpm
authorMichael Schroeder <mls@suse.de>
Tue, 23 Jun 2009 14:48:39 +0000 (16:48 +0200)
committerMichael Schroeder <mls@suse.de>
Tue, 23 Jun 2009 14:48:39 +0000 (16:48 +0200)
CMakeLists.txt
examples/solv.c
ext/pool_fileconflicts.c
src/transaction.c
src/transaction.h

index 8298c93..81f915e 100644 (file)
@@ -133,6 +133,7 @@ ADD_SUBDIRECTORY(ext)
 ADD_SUBDIRECTORY(tools)
 ADD_SUBDIRECTORY(applayer)
 ADD_SUBDIRECTORY(tests)
+ADD_SUBDIRECTORY(examples)
 ADD_SUBDIRECTORY(doc)
 
 FIND_PACKAGE(SWIG)
index 46b95b9..9e70c7f 100644 (file)
@@ -441,7 +441,7 @@ fc_cb(Pool *pool, Id p, void *cbdata)
 }
 
 void
-runrpm(const char *arg, const char *name)
+runrpm(const char *arg, const char *name, int dupfd3, FILE **newpkgsfps, int newpkgs)
 {
   pid_t pid;
   int status;
@@ -453,6 +453,20 @@ runrpm(const char *arg, const char *name)
     }
   if (pid == 0)
     {
+      int i;
+      for (i = 0; i < newpkgs; i++)
+       {
+         if (!newpkgsfps[i])
+           continue;
+         if (dupfd3 != -1 && fileno(newpkgsfps[i]) == dupfd3)
+           continue;
+         close(fileno(newpkgsfps[i]));
+       }
+      if (dupfd3 != -1 && dupfd3 != 3)
+       {
+         dup2(dupfd3, 3);
+         close(dupfd3);
+       }
       if (strcmp(arg, "-e") == 0)
         execlp("rpm", "rpm", arg, "--nodeps", "--nodigest", "--nosignature", name, (char *)0);
       else
@@ -486,15 +500,6 @@ main(int argc, char **argv)
   Id *newpkgsps = 0;
   struct fcstate fcstate;
 
-  pool = pool_create();
-  // pool_setdebuglevel(pool, 2);
-  setarch(pool);
-  repoinfos = read_repoinfos(pool, "/etc/zypp/repos.d", &nrepoinfos);
-  read_repos(pool, repoinfos, nrepoinfos);
-  // FOR_REPOS(i, repo)
-  //   printf("%s: %d solvables\n", repo->name, repo->nsolvables);
-  pool_addfileprovides(pool);
-  pool_createwhatprovides(pool);
   if (!strcmp(argv[1], "install") || !strcmp(argv[1], "in"))
     mode = SOLVER_INSTALL;
   else if (!strcmp(argv[1], "erase") || !strcmp(argv[1], "rm"))
@@ -508,6 +513,17 @@ main(int argc, char **argv)
       fprintf(stderr, "Usage: solv install|erase|update|show <select>\n");
       exit(1);
     }
+
+  pool = pool_create();
+  // pool_setdebuglevel(pool, 2);
+  setarch(pool);
+  repoinfos = read_repoinfos(pool, "/etc/zypp/repos.d", &nrepoinfos);
+  read_repos(pool, repoinfos, nrepoinfos);
+  // FOR_REPOS(i, repo)
+  //   printf("%s: %d solvables\n", repo->name, repo->nsolvables);
+  pool_addfileprovides(pool);
+  pool_createwhatprovides(pool);
+
   queue_init(&job);
   for (i = 2; i < argc; i++)
     mkselect(pool, argv[i], 0, &job);
@@ -523,7 +539,10 @@ main(int argc, char **argv)
       for (i = 0; i < job.count; i += 2)
        {
          FOR_JOB_SELECT(p, pp, job.elements[i], job.elements[i + 1])
-           printf("  - %s\n", solvid2str(pool, p));
+           {
+             Solvable *s = pool_id2solvable(pool, p);
+             printf("  - %s [%s]\n", solvable2str(pool, s), s->repo->name);
+           }
        }
       exit(0);
     }
@@ -673,7 +692,7 @@ rerunsolver:
     }
   transaction_order(trans, 0);
 
-  printf("Committing transaction:\n");
+  printf("Committing transaction:\n\n");
   for (i = 0; i < trans->steps.count; i++)
     {
       char rpmname[256];
@@ -697,7 +716,7 @@ rerunsolver:
          if (evrp > evr && evrp[0] == ':' && evrp[1])
            evr = evrp + 1;
          sprintf(rpmname, "%s-%s.%s", id2str(pool, s->name), evr, id2str(pool, s->arch));
-         runrpm("-e", rpmname);
+         runrpm("-e", rpmname, -1, newpkgsfps, newpkgs);
          break;
        case SOLVER_TRANSACTION_INSTALL:
        case SOLVER_TRANSACTION_MULTIINSTALL:
@@ -708,15 +727,17 @@ rerunsolver:
          fp = j < newpkgs ? newpkgsfps[j] : 0;
          rewind(fp);
          lseek(fileno(fp), 0, SEEK_SET);
-         sprintf(rpmname, "/dev/fd/%d", fileno(fp));
-         runrpm(type == SOLVER_TRANSACTION_MULTIINSTALL ? "-i" : "-U", rpmname);
+         runrpm(type == SOLVER_TRANSACTION_MULTIINSTALL ? "-i" : "-U", "/dev/fd/3", fileno(fp), newpkgsfps, newpkgs);
+         fclose(fp);
+         newpkgsfps[j] = 0;
          break;
        default:
          break;
        }
     }
   for (i = 0; i < newpkgs; i++)
-    fclose(newpkgsfps[i]);
+    if (newpkgsfps[i])
+      fclose(newpkgsfps[i]);
   sat_free(newpkgsfps);
   sat_free(newpkgsps);
   solver_free(solv);
index 1858df4..ed0a41c 100644 (file)
@@ -104,6 +104,7 @@ finddirs_cb(void *cbdatav, const char *fn, int fmode, const char *md5)
   /* found a conflict, this dir is used in multiple packages */
   if (cbdata->dirmap[2 * h + 1] != -1)
     {
+      MAPSET(&cbdata->idxmap, cbdata->dirmap[2 * h + 1]);
       cbdata->dirmap[2 * h + 1] = -1;
       cbdata->dirconflicts++;
     }
index 6047dad..8e8cebf 100644 (file)
@@ -666,7 +666,34 @@ transaction_calculate(Transaction *trans, Queue *decisionq, Map *noobsmap)
     }
 }
 
+int
+transaction_installedresult(Transaction *trans, Queue *installedq)
+{
+  Pool *pool = trans->pool;
+  Repo *installed = pool->installed;
+  Solvable *s;
+  int i, cutoff;
+  Id p;
 
+  queue_empty(installedq);
+  /* first the new installs, than the kept packages */
+  for (i = 0; i < trans->steps.count; i++)
+    {
+      p = trans->steps.elements[i];
+      s = pool->solvables + p;
+      if (installed && s->repo == installed)
+       continue;
+      queue_push(installedq, p);
+    }
+  cutoff = installedq->count;
+  if (installed)
+    {
+      FOR_REPO_SOLVABLES(installed, p, s)
+       if (!MAPTST(&trans->transactsmap, p))
+          queue_push(installedq, p);
+    }
+  return cutoff;
+}
 
 struct _TransactionElement {
   Id p;                /* solvable id */
index 2738e5c..8bd1ebd 100644 (file)
@@ -98,6 +98,11 @@ extern Id   transaction_type(Transaction *trans, Id p, int mode);
 extern void transaction_classify(Transaction *trans, int mode, Queue *classes);
 extern void transaction_classify_pkgs(Transaction *trans, int mode, Id type, Id from, Id to, Queue *pkgs);
 
+/* return all packages that will be installed after the transaction is run*/
+/* The new packages are put at the head of the queue, the number of new
+   packages is returned */
+extern int transaction_installedresult(Transaction *trans, Queue *installedq);
+
 /* order a transaction */
 extern void transaction_order(Transaction *trans, int flags);