[systemd-devel] [PATCH 2/3] journal: use audit event names instead of numbers

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Mon Apr 20 07:58:16 PDT 2015


On Mon, Apr 20, 2015 at 04:43:20PM +0200, Lennart Poettering wrote:
> On Tue, 14.04.15 21:58, Zbigniew Jędrzejewski-Szmek (zbyszek at in.waw.pl) wrote:
> 
> > +const char *audit_type_name(int type,
> > +                            char buf[AUDIT_NAME_BUF_SIZE]) {
> > +        const char *s;
> > +
> > +        s = audit_type_to_string(type);
> > +        if (s)
> > +                return s;
> > +
> > +        /* This is inspired by DNS TYPEnnn formatting */
> > +        snprintf(buf, AUDIT_NAME_BUF_SIZE, "AUDIT%04i", type);
> > +        return buf;
> 
> Shouldn't we stick to <audit-xyz> at least, to stay congruent to what
> we so far did, at least for the unknown ones?
I thought the visual difference between the capitalized names and what we
used so far is too big: e.g. ADD_USER and <audit-1114>, and it is better
to have something visually similar at least.
 
> Also, may turn this into a macro expression using ({}) that returns
> this as alloca() allocated string? 
You mean the whole function? I'll try that. The only downside is it
cannot be called directly in the args to another function.

> > +}
> > diff --git src/journal/audit-type.h src/journal/audit-type.h
> > index 9f37716cd6..a2c98cee80 100644
> > --- src/journal/audit-type.h
> > +++ src/journal/audit-type.h
> > @@ -21,6 +21,11 @@
> >    along with systemd; If not, see <http://www.gnu.org/licenses/>.
> >  ***/
> >  
> > +#include "macro.h"
> >  
> >  const char *audit_type_to_string(int type);
> >  int audit_type_from_string(const char *s);
> > +
> > +#define AUDIT_NAME_BUF_SIZE sizeof("AUDIT")-1 +
> >  DECIMAL_STR_MAX(int)
> 
> Will break if people use expressions like 3*AUDIT_NAME_BUF_SIZE, since
> it is missing the surrounding ().
OK.

> > +const char *audit_type_name(int type,
> > +                            char buf[AUDIT_NAME_BUF_SIZE]);
OK.

Thanks for the review, I'll submit another version.

Zbyszek


More information about the systemd-devel mailing list