[Rpm-maint] [PATCH 19/19] Add callback notification for policy and relabeling
Steve Lawrence
slawrence at tresys.com
Tue Feb 2 20:25:22 UTC 2010
Because policy installation and file system relabeling can take a while to
complete, it can look like rpm is hanging. This patch adds callback types
for policy installation and filesystem relabel start/stop. This also updates
rpm to display a notification for the new callbacks.
---
lib/rpmcallback.h | 6 +++++-
lib/rpminstall.c | 40 ++++++++++++++++++++++++++++++++++++++++
lib/transaction.c | 8 ++++++++
python/rpmmodule.c | 4 ++++
4 files changed, 57 insertions(+), 1 deletions(-)
diff --git a/lib/rpmcallback.h b/lib/rpmcallback.h
index 3544567..82db666 100644
--- a/lib/rpmcallback.h
+++ b/lib/rpmcallback.h
@@ -27,7 +27,11 @@ typedef enum rpmCallbackType_e {
RPMCALLBACK_REPACKAGE_STOP = (1 << 12), /* obsolete, unused */
RPMCALLBACK_UNPACK_ERROR = (1 << 13),
RPMCALLBACK_CPIO_ERROR = (1 << 14),
- RPMCALLBACK_SCRIPT_ERROR = (1 << 15)
+ RPMCALLBACK_SCRIPT_ERROR = (1 << 15),
+ RPMCALLBACK_POLICY_START = (1 << 16),
+ RPMCALLBACK_POLICY_STOP = (1 << 17),
+ RPMCALLBACK_RELABEL_START = (1 << 18),
+ RPMCALLBACK_RELABEL_STOP = (1 << 19)
} rpmCallbackType;
/**
diff --git a/lib/rpminstall.c b/lib/rpminstall.c
index 568e13f..367688c 100644
--- a/lib/rpminstall.c
+++ b/lib/rpminstall.c
@@ -184,6 +184,46 @@ void * rpmShowProgress(const void * arg,
rpmcliProgressCurrent = 0;
break;
+ case RPMCALLBACK_POLICY_START:
+ rpmcliHashesCurrent = 0;
+ rpmcliProgressTotal = 1;
+ rpmcliProgressCurrent = 0;
+ if (!(flags & INSTALL_LABEL))
+ break;
+ if (flags & INSTALL_HASH)
+ fprintf(stdout, "%-28s", _("Installing Policy..."));
+ else
+ fprintf(stdout, "%s\n", _("Installing Policy..."));
+ (void) fflush(stdout);
+ break;
+
+ case RPMCALLBACK_POLICY_STOP:
+ if (flags & INSTALL_HASH)
+ printHash(1, 1);
+ rpmcliProgressTotal = 1;
+ rpmcliProgressCurrent = 0;
+ break;
+
+ case RPMCALLBACK_RELABEL_START:
+ rpmcliHashesCurrent = 0;
+ rpmcliProgressTotal = 1;
+ rpmcliProgressCurrent = 0;
+ if (!(flags & INSTALL_LABEL))
+ break;
+ if (flags & INSTALL_HASH)
+ fprintf(stdout, "%-28s", _("Relabeling Filesystem..."));
+ else
+ fprintf(stdout, "%s\n", _("Relabeling Filesystem..."));
+ (void) fflush(stdout);
+ break;
+
+ case RPMCALLBACK_RELABEL_STOP:
+ if (flags & INSTALL_HASH)
+ printHash(1, 1);
+ rpmcliProgressTotal = 1;
+ rpmcliProgressCurrent = 0;
+ break;
+
case RPMCALLBACK_UNINST_PROGRESS:
break;
case RPMCALLBACK_UNINST_START:
diff --git a/lib/transaction.c b/lib/transaction.c
index 0788393..cfb38db 100644
--- a/lib/transaction.c
+++ b/lib/transaction.c
@@ -1174,6 +1174,8 @@ static rpmRC rpmtsRelabelFiles(rpmts ts)
goto exit;
}
+ rpmtsNotify(ts, NULL, RPMCALLBACK_RELABEL_START, 0, 1);
+
/* execute restorecon -R / */
pid = fork();
switch (pid) {
@@ -1195,6 +1197,8 @@ static rpmRC rpmtsRelabelFiles(rpmts ts)
goto exit;
}
}
+
+ rpmtsNotify(ts, NULL, RPMCALLBACK_RELABEL_STOP, 1, 1);
#endif /* WITH_SELINUX */
rc = RPMRC_OK;
@@ -1286,11 +1290,15 @@ static rpmRC rpmtsLoadPolicy(rpmts ts)
goto err;
}
+ rpmtsNotify(ts, NULL, RPMCALLBACK_POLICY_START, 0, 1);
+
rc = rpmpolsInstall(ps, ts);
if (rc != RPMRC_OK) {
goto err;
}
+ rpmtsNotify(ts, NULL, RPMCALLBACK_POLICY_STOP, 1, 1);
+
rc = rpmpolsSaveState(ps, rpmtsGetRdb(ts), rpmtsGetTid(ts));
if (rc != RPMRC_OK) {
goto err;
diff --git a/python/rpmmodule.c b/python/rpmmodule.c
index 2bb087a..7c4eb47 100644
--- a/python/rpmmodule.c
+++ b/python/rpmmodule.c
@@ -427,6 +427,10 @@ static int initModule(PyObject *m)
REGISTER_ENUM(RPMCALLBACK_UNPACK_ERROR);
REGISTER_ENUM(RPMCALLBACK_CPIO_ERROR);
REGISTER_ENUM(RPMCALLBACK_SCRIPT_ERROR);
+ REGISTER_ENUM(RPMCALLBACK_POLICY_START);
+ REGISTER_ENUM(RPMCALLBACK_POLICY_STOP);
+ REGISTER_ENUM(RPMCALLBACK_RELABEL_START);
+ REGISTER_ENUM(RPMCALLBACK_RELABEL_STOP);
REGISTER_ENUM(RPMPROB_BADARCH);
REGISTER_ENUM(RPMPROB_BADOS);
--
1.6.2.5
More information about the Rpm-maint
mailing list