10 /*@access rpmlogRec @*/
13 static /*@only@*/ /*@null@*/ rpmlogRec recs = NULL;
15 int rpmlogGetNrecs(void)
20 const char * rpmlogMessage(void)
23 return recs[nrecs-1].message;
24 return _("(no error)");
27 void rpmlogPrint(FILE *f)
34 for (i = 0; i < nrecs; i++) {
35 rpmlogRec rec = recs + i;
36 if (rec->message && *rec->message)
37 fprintf(f, " %s\n", rec->message);
41 void rpmlogClose (void)
45 for (i = 0; i < nrecs; i++) {
46 rpmlogRec rec = recs + i;
48 free((void *)rec->message);
57 void rpmlogOpen (/*@unused@*/ const char *ident, /*@unused@*/ int option,
58 /*@unused@*/ int facility)
62 static int rpmlogMask = RPMLOG_UPTO( RPMLOG_NOTICE );
63 static /*@unused@*/ int rpmlogFacility = RPMLOG_USER;
65 int rpmlogSetMask (int mask)
67 int omask = rpmlogMask;
73 static /*@null@*/ rpmlogCallback _rpmlogCallback = NULL;
75 rpmlogCallback rpmlogSetCallback(rpmlogCallback cb)
77 rpmlogCallback ocb = _rpmlogCallback;
82 static char *rpmlogMsgPrefix[] = {
83 N_("fatal error: "),/*!< RPMLOG_EMERG */
84 N_("fatal error: "),/*!< RPMLOG_ALERT */
85 N_("fatal error: "),/*!< RPMLOG_CRIT */
86 N_("error: "), /*!< RPMLOG_ERR */
87 N_("warning: "), /*!< RPMLOG_WARNING */
88 "", /*!< RPMLOG_NOTICE */
89 "", /*!< RPMLOG_INFO */
90 "D: ", /*!< RPMLOG_DEBUG */
93 static void vrpmlog (unsigned code, const char *fmt, va_list ap)
95 int pri = RPMLOG_PRI(code);
96 int mask = RPMLOG_MASK(pri);
97 /*@unused@*/ int fac = RPMLOG_FAC(code);
98 char msgbuf[BUFSIZ], *msg;
99 FILE * msgout = stderr;
102 if ((mask & rpmlogMask) == 0)
105 /*@-unrecog@*/ vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap); /*@=unrecog@*/
106 msgbuf[sizeof(msgbuf) - 1] = '\0';
109 /* Save copy of all messages at warning (or below == "more important"). */
110 if (pri <= RPMLOG_WARNING) {
113 recs = xmalloc((nrecs+2) * sizeof(*recs));
115 recs = xrealloc(recs, (nrecs+2) * sizeof(*recs));
116 recs[nrecs+1].code = 0;
117 recs[nrecs+1].message = NULL;
122 rec->message = xstrdup(msg);
124 if (_rpmlogCallback) {
126 return; /* XXX Preserve legacy rpmError behavior. */
130 /* rpmMessage behavior */
141 case RPMLOG_ERR: /* XXX Legacy rpmError behavior used stdout w/o prefix. */
147 /* Silly FORTRAN-like carriage control. */
150 else if (rpmlogMsgPrefix[pri] && *rpmlogMsgPrefix[pri])
151 fputs(_(rpmlogMsgPrefix[pri]), msgout);
154 if (pri == RPMLOG_ERR) /* XXX Legacy rpmError behavior appends newline. */
157 if (pri <= RPMLOG_CRIT)
161 void rpmlog (int code, const char *fmt, ...)
166 vrpmlog(code, fmt, ap);
170 const char * rpmErrorString(void)
172 return rpmlogMessage();
175 rpmlogCallback rpmErrorSetCallback(rpmlogCallback cb)
177 return rpmlogSetCallback(cb);