Mailinglist Archive: zypp-commit (171 mails)

< Previous Next >
[zypp-commit] <sat-solver> master : - close fds before calling rpm
  • From: Michael Schroeder <mls@xxxxxxx>
  • Date: Tue, 23 Jun 2009 16:48:39 +0200
  • Message-id: <E1MJ7J1-0000us-Py@xxxxxxxxxxxxxxxx>
ref: refs/heads/master
commit 5aecff6bbe9c576c8e177bf34193a69b68bdf3c5
Author: Michael Schroeder <mls@xxxxxxx>
Date: Tue Jun 23 16:48:39 2009 +0200

- close fds before calling rpm
---
CMakeLists.txt | 1 +
examples/solv.c | 53 ++++++++++++++++++++++++++++++++-------------
ext/pool_fileconflicts.c | 1 +
src/transaction.c | 27 +++++++++++++++++++++++
src/transaction.h | 5 ++++
5 files changed, 71 insertions(+), 16 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8298c93..81f915e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -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)
diff --git a/examples/solv.c b/examples/solv.c
index 46b95b9..9e70c7f 100644
--- a/examples/solv.c
+++ b/examples/solv.c
@@ -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);
diff --git a/ext/pool_fileconflicts.c b/ext/pool_fileconflicts.c
index 1858df4..ed0a41c 100644
--- a/ext/pool_fileconflicts.c
+++ b/ext/pool_fileconflicts.c
@@ -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++;
}
diff --git a/src/transaction.c b/src/transaction.c
index 6047dad..8e8cebf 100644
--- a/src/transaction.c
+++ b/src/transaction.c
@@ -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 */
diff --git a/src/transaction.h b/src/transaction.h
index 2738e5c..8bd1ebd 100644
--- a/src/transaction.h
+++ b/src/transaction.h
@@ -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);

--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages