Re: [Rpm-maint] [PATCH v2 3/4] rpmplugins: Introduce new fsm_pre and fsm_post hooks

2016-09-23 Thread Panu Matilainen

On 09/23/2016 02:12 PM, Stefan Berger wrote:

Panu Matilainen  wrote on 09/23/2016 03:03:48
AM:


From: Panu Matilainen 
To: Stefan Berger , rpm-maint@lists.rpm.org
Cc: Stefan Berger/Watson/IBM@IBMUS, fionnuala.gun...@gmail.com
Date: 09/23/2016 03:03 AM
Subject: Re: [Rpm-maint] [PATCH v2 3/4] rpmplugins: Introduce new
fsm_pre and fsm_post hooks

On 09/22/2016 08:30 PM, Stefan Berger wrote:

Introduce fsm_pre and fsm_post hooks, which are invoked
before and after the package files are installed.

Signed-off-by: Stefan Berger 

[...]

diff --git a/lib/rpmplugins.h b/lib/rpmplugins.h
index 39762c3..3702526 100644
--- a/lib/rpmplugins.h
+++ b/lib/rpmplugins.h
@@ -167,6 +167,25 @@ rpmRC rpmpluginsCallFsmFilePrepare(rpmPlugins

plugins, rpmfi fi,

const char *path, const char

*dest,

mode_t mode, rpmFsmOp op);

+/** \ingroup rpmplugins
+ * Call the fsm pre plugin hook.
+ * @param plugins   plugins structure
+ * @param te  processed transaction element
+ * @return  RPMRC_OK on success, RPMRC_FAIL otherwise
+ */
+RPM_GNUC_INTERNAL
+rpmRC rpmpluginsCallFsmPre(rpmPlugins plugins, rpmte te);
+
+/** \ingroup rpmplugins
+ * Call the fsm post plugin hook.
+ * @param plugins   plugins structure
+ * @param te  processed transaction element
+ * @param res  fsm result code
+ * @return  RPMRC_OK on success, RPMRC_FAIL otherwise
+ */
+RPM_GNUC_INTERNAL
+rpmRC rpmpluginsCallFsmPost(rpmPlugins plugins, rpmte te, int rc);
+


Any particular reason not to pass the associated rpmfiles to these hooks



too? That would be the main object of these hooks, regardless of what
your particular needs in this case are.


I only passed the parameters that I actually need. I can add the files to
that as well, if other plugins may require them.


The point here isn't really what *you* need, its more about what makes 
sense. It's an interface that will some day be public... but before that 
we might need to come up with better names for things :)




Or actually to really follow the generic style of the plugin interface,
you'd *only* pass the files "object" and not the transaction element,
you can get and store that from PsmPre already.


PsmPre also passes the rpmte.


Yes, PsmPre and Post pass the rpmte, because Psm is all about packages 
(because, well, that's what transaction elements are). Fsm is about 
files, so logic suggests it should get files as its argument.



PsmPre run after the post install scriptlet runs, so therefore we
cannot use it.


Um, PsmPre runs before any script, so you could store the rpmte from 
there, to be used in the other hooks that run "under" it. PsmPost (which 
also gets the te) runs after scripts so its too late for your purposes.


The hooks are sort of nested:

tsm_pre
psm_pre
[scriptlet_*]
[fsm_file_*]
[scriptlet_*]
psm_post
tsm_post

...so if you need the transaction element in a hook where its not 
available in hook arguments, you can store it locally in psm_pre and 
it'll be valid until psm_post finishes.


The hooks are paired in a way that if _pre is executed then _post is 
always executed as well. scriptlet_* and fsm_* hooks are only called if 
the package has any scriptlets or files though.


Hope that clarifies things a bit, and feel free to ask for details if 
unclear. http://rpm.org/wiki/DevelDocs/Plugins could also use 
improvement of course.


- Panu -

___
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint


Re: [Rpm-maint] [PATCH v2 3/4] rpmplugins: Introduce new fsm_pre and fsm_post hooks

2016-09-23 Thread Stefan Berger
Panu Matilainen  wrote on 09/23/2016 03:03:48 
AM:

> From: Panu Matilainen 
> To: Stefan Berger , rpm-maint@lists.rpm.org
> Cc: Stefan Berger/Watson/IBM@IBMUS, fionnuala.gun...@gmail.com
> Date: 09/23/2016 03:03 AM
> Subject: Re: [Rpm-maint] [PATCH v2 3/4] rpmplugins: Introduce new 
> fsm_pre and fsm_post hooks
> 
> On 09/22/2016 08:30 PM, Stefan Berger wrote:
> > Introduce fsm_pre and fsm_post hooks, which are invoked
> > before and after the package files are installed.
> >
> > Signed-off-by: Stefan Berger 
> [...]
> > diff --git a/lib/rpmplugins.h b/lib/rpmplugins.h
> > index 39762c3..3702526 100644
> > --- a/lib/rpmplugins.h
> > +++ b/lib/rpmplugins.h
> > @@ -167,6 +167,25 @@ rpmRC rpmpluginsCallFsmFilePrepare(rpmPlugins
> plugins, rpmfi fi,
> > const char *path, const char 
*dest,
> > mode_t mode, rpmFsmOp op);
> >
> > +/** \ingroup rpmplugins
> > + * Call the fsm pre plugin hook.
> > + * @param plugins   plugins structure
> > + * @param te  processed transaction element
> > + * @return  RPMRC_OK on success, RPMRC_FAIL otherwise
> > + */
> > +RPM_GNUC_INTERNAL
> > +rpmRC rpmpluginsCallFsmPre(rpmPlugins plugins, rpmte te);
> > +
> > +/** \ingroup rpmplugins
> > + * Call the fsm post plugin hook.
> > + * @param plugins   plugins structure
> > + * @param te  processed transaction element
> > + * @param res  fsm result code
> > + * @return  RPMRC_OK on success, RPMRC_FAIL otherwise
> > + */
> > +RPM_GNUC_INTERNAL
> > +rpmRC rpmpluginsCallFsmPost(rpmPlugins plugins, rpmte te, int rc);
> > +
> 
> Any particular reason not to pass the associated rpmfiles to these hooks 

> too? That would be the main object of these hooks, regardless of what 
> your particular needs in this case are.

I only passed the parameters that I actually need. I can add the files to 
that as well, if other plugins may require them.

> 
> Or actually to really follow the generic style of the plugin interface, 
> you'd *only* pass the files "object" and not the transaction element, 
> you can get and store that from PsmPre already.

PsmPre also passes the rpmte. PsmPre run after the post install scriptlet 
runs, so therefore we cannot use it.

> 
> ...or alternatively you could install the signatures from one of the 
> FsmFile hooks where the file-level action is available, then you dont 
> need access to the transaction element. And actually it'd probably be 
> more correct too because files can get skipped for various reasons, in 
> which case you should not add the signature either.

Good, I'll try to move it there...

   Stefan

> 
> So technically none of this is actually needed. Unless I'm missing 
> something, I'm not at all familiar with IMA really.
> 
>- Panu -
> 
> 
> 
>- Panu -
> 
> >  #ifdef __cplusplus
> >  }
> >  #endif
> >
> 


___
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint


Re: [Rpm-maint] [PATCH v2 3/4] rpmplugins: Introduce new fsm_pre and fsm_post hooks

2016-09-23 Thread Panu Matilainen

On 09/22/2016 08:30 PM, Stefan Berger wrote:

Introduce fsm_pre and fsm_post hooks, which are invoked
before and after the package files are installed.

Signed-off-by: Stefan Berger 

[...]

diff --git a/lib/rpmplugins.h b/lib/rpmplugins.h
index 39762c3..3702526 100644
--- a/lib/rpmplugins.h
+++ b/lib/rpmplugins.h
@@ -167,6 +167,25 @@ rpmRC rpmpluginsCallFsmFilePrepare(rpmPlugins plugins, 
rpmfi fi,
const char *path, const char *dest,
mode_t mode, rpmFsmOp op);

+/** \ingroup rpmplugins
+ * Call the fsm pre plugin hook.
+ * @param plugins  plugins structure
+ * @param te   processed transaction element
+ * @return RPMRC_OK on success, RPMRC_FAIL otherwise
+ */
+RPM_GNUC_INTERNAL
+rpmRC rpmpluginsCallFsmPre(rpmPlugins plugins, rpmte te);
+
+/** \ingroup rpmplugins
+ * Call the fsm post plugin hook.
+ * @param plugins  plugins structure
+ * @param te   processed transaction element
+ * @param res  fsm result code
+ * @return RPMRC_OK on success, RPMRC_FAIL otherwise
+ */
+RPM_GNUC_INTERNAL
+rpmRC rpmpluginsCallFsmPost(rpmPlugins plugins, rpmte te, int rc);
+


Any particular reason not to pass the associated rpmfiles to these hooks 
too? That would be the main object of these hooks, regardless of what 
your particular needs in this case are.


Or actually to really follow the generic style of the plugin interface, 
you'd *only* pass the files "object" and not the transaction element, 
you can get and store that from PsmPre already.


...or alternatively you could install the signatures from one of the 
FsmFile hooks where the file-level action is available, then you dont 
need access to the transaction element. And actually it'd probably be 
more correct too because files can get skipped for various reasons, in 
which case you should not add the signature either.


So technically none of this is actually needed. Unless I'm missing 
something, I'm not at all familiar with IMA really.


- Panu -



- Panu -


 #ifdef __cplusplus
 }
 #endif



___
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint


[Rpm-maint] [PATCH v2 3/4] rpmplugins: Introduce new fsm_pre and fsm_post hooks

2016-09-22 Thread Stefan Berger
Introduce fsm_pre and fsm_post hooks, which are invoked
before and after the package files are installed.

Signed-off-by: Stefan Berger 
---
 lib/psm.c|  6 +-
 lib/rpmplugin.h  |  6 ++
 lib/rpmplugins.c | 35 +++
 lib/rpmplugins.h | 19 +++
 4 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/lib/psm.c b/lib/psm.c
index 341441b..ddd38d1 100644
--- a/lib/psm.c
+++ b/lib/psm.c
@@ -586,11 +586,13 @@ static rpmRC rpmpsmUnpack(rpmpsm psm)
 rpmpsmNotify(psm, RPMCALLBACK_INST_PROGRESS, 0);
 
 if (!(rpmtsFlags(psm->ts) & RPMTRANS_FLAG_JUSTDB)) {
-   if (rpmfilesFC(psm->files) > 0) {
+   fsmrc = rpmpluginsCallFsmPre(rpmtsPlugins(psm->ts), psm->te);
+   if (!fsmrc && rpmfilesFC(psm->files) > 0) {
fsmrc = rpmPackageFilesInstall(psm->ts, psm->te, psm->files,
   psm, &failedFile);
saved_errno = errno;
}
+   rpmpluginsCallFsmPost(rpmtsPlugins(psm->ts), psm->te, fsmrc);
 }
 
 /* XXX make sure progress reaches 100% */
@@ -627,10 +629,12 @@ static rpmRC rpmpsmRemove(rpmpsm psm)
 
 /* XXX should't we log errors from here? */
 if (!(rpmtsFlags(psm->ts) & RPMTRANS_FLAG_JUSTDB)) {
+   fsmrc = rpmpluginsCallFsmPre(rpmtsPlugins(psm->ts), psm->te);
if (rpmfilesFC(psm->files) > 0) {
fsmrc = rpmPackageFilesRemove(psm->ts, psm->te, psm->files,
  psm, &failedFile);
}
+   rpmpluginsCallFsmPost(rpmtsPlugins(psm->ts), psm->te, fsmrc);
 }
 /* XXX make sure progress reaches 100% */
 rpmpsmNotify(psm, RPMCALLBACK_UNINST_PROGRESS, psm->total);
diff --git a/lib/rpmplugin.h b/lib/rpmplugin.h
index fd81aec..b6f230c 100644
--- a/lib/rpmplugin.h
+++ b/lib/rpmplugin.h
@@ -41,6 +41,8 @@ typedef rpmRC (*plugin_init_func)(rpmPlugin plugin, rpmts ts);
 typedef void (*plugin_cleanup_func)(rpmPlugin plugin);
 typedef rpmRC (*plugin_tsm_pre_func)(rpmPlugin plugin, rpmts ts);
 typedef rpmRC (*plugin_tsm_post_func)(rpmPlugin plugin, rpmts ts, int res);
+typedef rpmRC (*plugin_fsm_pre_func)(rpmPlugin plugin, rpmte te);
+typedef rpmRC (*plugin_fsm_post_func)(rpmPlugin plugin, rpmte te, int res);
 typedef rpmRC (*plugin_psm_pre_func)(rpmPlugin plugin, rpmte te);
 typedef rpmRC (*plugin_psm_post_func)(rpmPlugin plugin, rpmte te, int res);
 typedef rpmRC (*plugin_scriptlet_pre_func)(rpmPlugin plugin,
@@ -60,6 +62,8 @@ typedef rpmRC (*plugin_fsm_file_prepare_func)(rpmPlugin 
plugin, rpmfi fi,
  const char* path,
  const char *dest,
  mode_t file_mode, rpmFsmOp op);
+typedef rpmRC (*plugin_fsm_pre_func)(rpmPlugin plugin, rpmte te);
+typedef rpmRC (*plugin_fsm_post_func)(rpmPlugin plugin, rpmte te, int res);
 
 typedef struct rpmPluginHooks_s * rpmPluginHooks;
 struct rpmPluginHooks_s {
@@ -80,6 +84,8 @@ struct rpmPluginHooks_s {
 plugin_fsm_file_pre_func   fsm_file_pre;
 plugin_fsm_file_post_func  fsm_file_post;
 plugin_fsm_file_prepare_func   fsm_file_prepare;
+plugin_fsm_pre_funcfsm_pre;
+plugin_fsm_post_func   fsm_post;
 };
 
 #ifdef __cplusplus
diff --git a/lib/rpmplugins.c b/lib/rpmplugins.c
index 97e5d30..98cd5ca 100644
--- a/lib/rpmplugins.c
+++ b/lib/rpmplugins.c
@@ -401,3 +401,38 @@ rpmRC rpmpluginsCallFsmFilePrepare(rpmPlugins plugins, 
rpmfi fi,
 
 return rc;
 }
+
+rpmRC rpmpluginsCallFsmPre(rpmPlugins plugins, rpmte te)
+{
+plugin_fsm_pre_func hookFunc;
+int i;
+rpmRC rc = RPMRC_OK;
+
+for (i = 0; i < plugins->count; i++) {
+   rpmPlugin plugin = plugins->plugins[i];
+   RPMPLUGINS_SET_HOOK_FUNC(fsm_pre);
+   if (hookFunc && hookFunc(plugin, te) == RPMRC_FAIL) {
+   rpmlog(RPMLOG_ERR, "Plugin %s: hook fsm_pre failed\n", 
plugin->name);
+   rc = RPMRC_FAIL;
+   }
+}
+
+return rc;
+}
+
+rpmRC rpmpluginsCallFsmPost(rpmPlugins plugins, rpmte te, int res)
+{
+plugin_fsm_post_func hookFunc;
+int i;
+rpmRC rc = RPMRC_OK;
+
+for (i = 0; i < plugins->count; i++) {
+   rpmPlugin plugin = plugins->plugins[i];
+   RPMPLUGINS_SET_HOOK_FUNC(fsm_post);
+   if (hookFunc && hookFunc(plugin, te, res) == RPMRC_FAIL) {
+   rpmlog(RPMLOG_WARNING, "Plugin %s: hook fsm_post failed\n", 
plugin->name);
+   }
+}
+
+return rc;
+}
diff --git a/lib/rpmplugins.h b/lib/rpmplugins.h
index 39762c3..3702526 100644
--- a/lib/rpmplugins.h
+++ b/lib/rpmplugins.h
@@ -167,6 +167,25 @@ rpmRC rpmpluginsCallFsmFilePrepare(rpmPlugins plugins, 
rpmfi fi,
const char *path, const char *dest,
mode_t mode, rpmFsmOp op);
 
+/** \ingroup rpmplugins
+ * Call the fsm pre plugin hook.
+ * @param plugins  plugins structure
+ * @param te   processed tr