Re: [LTP] [PATCH v2 1/2] Add SAFE_KEYCTL macro
Cyril Hrubis <[email protected]> Wed, 21 Aug 2024 14:12:20 +0200
| Newsgroups | dev.linux.lists.landlock,it.linux.lists.ltp |
|---|---|
| Message-ID | <[email protected]> |
Hi! > // SPDX-License-Identifier: GPL-2.0-or-later > /* > - * Copyright (c) 2017 Cyril Hrubis <[email protected]> > + * Ccmdyright (c) 2017 Cyril Hrubis <[email protected]> I suppose that you did replace op with cmd and corrupted this line. > */ > > #ifndef LAPI_KEYCTL_H__ > @@ -179,4 +179,28 @@ static inline key_serial_t keyctl_join_session_keyring(const char *name) { > # define KEY_OTH_ALL 0x0000003f > #endif /* !KEY_POS_VIEW */ > > +static inline long safe_keyctl(const char *file, const int lineno, > + int cmd, unsigned long arg2, unsigned long arg3, > + unsigned long arg4, unsigned long arg5) ^ trailing whitespaces > +{ > + long rval; > + > + rval = keyctl(cmd, arg2, arg3, arg4, arg5); > + if (rval == -1) { > + tst_brk_(file, lineno, TBROK | TERRNO, > + "keyctl(%d, %lu, %lu, %lu, %lu)", > + cmd, arg2, arg3, arg4, arg5); > + } else if (rval < 0) { > + tst_brk_(file, lineno, TBROK | TERRNO, > + "Invalid keyctl(%d, %lu, %lu, %lu, %lu) " > + "return value %ld", > + cmd, arg2, arg3, arg4, arg5, rval); > + } Looking at man 2 keyctl() we should fail for non-zero return value for most of the operations but the ones listed in RETURN VALUE paragraph. > + return rval; > +} > +#define SAFE_KEYCTL(cmd, arg2, arg3, arg4, arg5) \ > + safe_keyctl(__FILE__, __LINE__, \ > + (cmd), (arg2), (arg3), (arg4), (arg5)) > + > #endif /* LAPI_KEYCTL_H__ */ > > -- > 2.43.0 > > > -- > Mailing list info: https://lists.linux.it/listinfo/ltp -- Cyril Hrubis [email protected]