Message ID | 1645519272-2733-3-git-send-email-xuyang2018.jy@fujitsu.com |
---|---|
State | Accepted |
Headers | show |
Series | [v3,1/7] Merge multiple pidfd*.h into one header | expand |
Hi! > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Copyright (c) 2022 FUJITSU LIMITED. All rights reserved. > + * Author: Yang Xu <xuyang2018.jy@fujitsu.com> > + */ > + > +#ifndef TST_SAFE_PIDFD_H__ > +#define TST_SAFE_PIDFD_H__ > + > +#include <unistd.h> > +#include "lapi/pidfd.h" > + > +int safe_pidfd_open(const char *file, const int lineno, pid_t pid, > + unsigned int flags); > + > +#define SAFE_PIDFD_OPEN(pid, flags) \ > + safe_pidfd_open(__FILE__, __LINE__, (pid), (flags)) Is there a reason why we start a new header instead of adding this into the tst_safe_macros.h?
Hi Cyril > Hi! >> +// SPDX-License-Identifier: GPL-2.0-or-later >> +/* >> + * Copyright (c) 2022 FUJITSU LIMITED. All rights reserved. >> + * Author: Yang Xu<xuyang2018.jy@fujitsu.com> >> + */ >> + >> +#ifndef TST_SAFE_PIDFD_H__ >> +#define TST_SAFE_PIDFD_H__ >> + >> +#include<unistd.h> >> +#include "lapi/pidfd.h" >> + >> +int safe_pidfd_open(const char *file, const int lineno, pid_t pid, >> + unsigned int flags); >> + >> +#define SAFE_PIDFD_OPEN(pid, flags) \ >> + safe_pidfd_open(__FILE__, __LINE__, (pid), (flags)) > > Is there a reason why we start a new header instead of adding this into > the tst_safe_macros.h? Just avoid a big tst_safe_macros.h like tst_safe_sysv_ipc.h does. Also the pidfd related syscalls seems no libc wrapper. Based on the above two points, I started a new header. Also if you want to merge it into tst_safe_macros.h, I will do(I don't have objection to add this into tst_safe_macros.h ). Best Regards Yang Xu > >
Hi! > Just avoid a big tst_safe_macros.h like tst_safe_sysv_ipc.h does. > Also the pidfd related syscalls seems no libc wrapper. > > Based on the above two points, I started a new header. Also if you want > to merge it into tst_safe_macros.h, I will do(I don't have objection to > add this into tst_safe_macros.h ). I would have just added the definitions to the tst_safe_macros.h, but it's not a big deal. Otherwise the actuall code looks good, with the header merged to tst_safe_macros.h: Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Hi Cyril,Petr I merged this patchset, thanks for your review. Best Regards Yang Xu > Hi! >> Just avoid a big tst_safe_macros.h like tst_safe_sysv_ipc.h does. >> Also the pidfd related syscalls seems no libc wrapper. >> >> Based on the above two points, I started a new header. Also if you want >> to merge it into tst_safe_macros.h, I will do(I don't have objection to >> add this into tst_safe_macros.h ). > > I would have just added the definitions to the tst_safe_macros.h, but > it's not a big deal. > > Otherwise the actuall code looks good, with the header merged to tst_safe_macros.h: > > Reviewed-by: Cyril Hrubis<chrubis@suse.cz> >
diff --git a/include/tst_safe_pidfd.h b/include/tst_safe_pidfd.h new file mode 100644 index 000000000..5c37099bd --- /dev/null +++ b/include/tst_safe_pidfd.h @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2022 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu <xuyang2018.jy@fujitsu.com> + */ + +#ifndef TST_SAFE_PIDFD_H__ +#define TST_SAFE_PIDFD_H__ + +#include <unistd.h> +#include "lapi/pidfd.h" + +int safe_pidfd_open(const char *file, const int lineno, pid_t pid, + unsigned int flags); + +#define SAFE_PIDFD_OPEN(pid, flags) \ + safe_pidfd_open(__FILE__, __LINE__, (pid), (flags)) + +#endif /* TST_SAFE_PIDFD_H__ */ diff --git a/lib/tst_safe_pidfd.c b/lib/tst_safe_pidfd.c new file mode 100644 index 000000000..c9fe5e1d0 --- /dev/null +++ b/lib/tst_safe_pidfd.c @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2022 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu <xuyang2018.jy@fujitsu.com> + */ + +#define TST_NO_DEFAULT_MAIN +#include "tst_test.h" +#include "tst_safe_pidfd.h" + +int safe_pidfd_open(const char *file, const int lineno, pid_t pid, + unsigned int flags) +{ + int rval; + + rval = pidfd_open(pid, flags); + + if (rval == -1) { + tst_brk_(file, lineno, TBROK | TERRNO, + "pidfd_open(%i, %i) failed", pid, flags); + } else if (rval < 0) { + tst_brk_(file, lineno, TBROK | TERRNO, + "Invalid pidfd_open(%i, %i) return value %d", + pid, flags, rval); + } + + return rval; +}
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com> --- include/tst_safe_pidfd.h | 19 +++++++++++++++++++ lib/tst_safe_pidfd.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 include/tst_safe_pidfd.h create mode 100644 lib/tst_safe_pidfd.c