6 #include "lib/rpmplugin.h"
10 unsigned int scriptfail;
14 static rpmRC syslog_init(rpmPlugin plugin, rpmts ts)
16 /* XXX make this configurable? */
17 const char * log_ident = "[RPM]";
18 struct logstat * state = rcalloc(1, sizeof(*state));
20 rpmPluginSetData(plugin, state);
21 openlog(log_ident, (LOG_PID), LOG_USER);
25 static void syslog_cleanup(rpmPlugin plugin)
27 struct logstat * state = rpmPluginGetData(plugin);
32 static rpmRC syslog_tsm_pre(rpmPlugin plugin, rpmts ts)
34 struct logstat * state = rpmPluginGetData(plugin);
37 state->scriptfail = 0;
40 /* Assume we are logging but... */
43 /* ...don't log test transactions */
44 if (rpmtsFlags(ts) & (RPMTRANS_FLAG_TEST|RPMTRANS_FLAG_BUILD_PROBS))
47 /* ...don't log chroot transactions */
48 if (!rstreq(rpmtsRootDir(ts), "/"))
52 syslog(LOG_NOTICE, "Transaction ID %x started", rpmtsGetTid(ts));
58 static rpmRC syslog_tsm_post(rpmPlugin plugin, rpmts ts, int res)
60 struct logstat * state = rpmPluginGetData(plugin);
63 if (state->pkgfail || state->scriptfail) {
64 syslog(LOG_WARNING, "%u elements failed, %u scripts failed",
65 state->pkgfail, state->scriptfail);
67 syslog(LOG_NOTICE, "Transaction ID %x finished: %d",
68 rpmtsGetTid(ts), res);
75 static rpmRC syslog_psm_post(rpmPlugin plugin, rpmte te, int res)
77 struct logstat * state = rpmPluginGetData(plugin);
81 const char *op = (rpmteType(te) == TR_ADDED) ? "install" : "erase";
82 const char *outcome = "success";
83 /* XXX: Permit configurable header queryformat? */
84 const char *pkg = rpmteNEVRA(te);
86 if (res != RPMRC_OK) {
92 syslog(lvl, "%s %s: %s", op, pkg, outcome);
97 static rpmRC syslog_scriptlet_post(rpmPlugin plugin,
98 const char *s_name, int type, int res)
100 struct logstat * state = rpmPluginGetData(plugin);
102 if (state->logging && res) {
103 syslog(LOG_WARNING, "scriptlet %s failure: %d\n", s_name, res);
109 struct rpmPluginHooks_s syslog_hooks = {
111 .cleanup = syslog_cleanup,
112 .tsm_pre = syslog_tsm_pre,
113 .tsm_post = syslog_tsm_post,
114 .psm_post = syslog_psm_post,
115 .scriptlet_post = syslog_scriptlet_post,