@@ -242,6 +242,40 @@ int seccomp(unsigned int op, unsigned int flags, void *args)
242
242
#define SIBLING_EXIT_FAILURE 0xbadface
243
243
#define SIBLING_EXIT_NEWPRIVS 0xbadfeed
244
244
245
+ static int __filecmp (pid_t pid1 , pid_t pid2 , int fd1 , int fd2 )
246
+ {
247
+ #ifdef __NR_kcmp
248
+ errno = 0 ;
249
+ return syscall (__NR_kcmp , pid1 , pid2 , KCMP_FILE , fd1 , fd2 );
250
+ #else
251
+ errno = ENOSYS ;
252
+ return -1 ;
253
+ #endif
254
+ }
255
+
256
+ /* Have TH_LOG report actual location filecmp() is used. */
257
+ #define filecmp (pid1 , pid2 , fd1 , fd2 ) ({ \
258
+ int _ret; \
259
+ \
260
+ _ret = __filecmp(pid1, pid2, fd1, fd2); \
261
+ if (_ret != 0) { \
262
+ if (_ret < 0 && errno == ENOSYS) { \
263
+ TH_LOG("kcmp() syscall missing (test is less accurate)");\
264
+ _ret = 0; \
265
+ } \
266
+ } \
267
+ _ret; })
268
+
269
+ TEST (kcmp )
270
+ {
271
+ int ret ;
272
+
273
+ ret = __filecmp (getpid (), getpid (), 1 , 1 );
274
+ EXPECT_EQ (ret , 0 );
275
+ if (ret != 0 && errno == ENOSYS )
276
+ SKIP (return , "Kernel does not support kcmp() (missing CONFIG_CHECKPOINT_RESTORE?)" );
277
+ }
278
+
245
279
TEST (mode_strict_support )
246
280
{
247
281
long ret ;
@@ -3601,16 +3635,6 @@ TEST(seccomp_get_notif_sizes)
3601
3635
EXPECT_EQ (sizes .seccomp_notif_resp , sizeof (struct seccomp_notif_resp ));
3602
3636
}
3603
3637
3604
- static int filecmp (pid_t pid1 , pid_t pid2 , int fd1 , int fd2 )
3605
- {
3606
- #ifdef __NR_kcmp
3607
- return syscall (__NR_kcmp , pid1 , pid2 , KCMP_FILE , fd1 , fd2 );
3608
- #else
3609
- errno = ENOSYS ;
3610
- return -1 ;
3611
- #endif
3612
- }
3613
-
3614
3638
TEST (user_notification_continue )
3615
3639
{
3616
3640
pid_t pid ;
@@ -3635,20 +3659,14 @@ TEST(user_notification_continue)
3635
3659
int dup_fd , pipe_fds [2 ];
3636
3660
pid_t self ;
3637
3661
3638
- ret = pipe (pipe_fds );
3639
- if (ret < 0 )
3640
- exit (1 );
3662
+ ASSERT_GE (pipe (pipe_fds ), 0 );
3641
3663
3642
3664
dup_fd = dup (pipe_fds [0 ]);
3643
- if (dup_fd < 0 )
3644
- exit ( 1 );
3665
+ ASSERT_GE (dup_fd , 0 );
3666
+ EXPECT_NE ( pipe_fds [ 0 ], dup_fd );
3645
3667
3646
3668
self = getpid ();
3647
-
3648
- ret = filecmp (self , self , pipe_fds [0 ], dup_fd );
3649
- if (ret )
3650
- exit (2 );
3651
-
3669
+ ASSERT_EQ (filecmp (self , self , pipe_fds [0 ], dup_fd ), 0 );
3652
3670
exit (0 );
3653
3671
}
3654
3672
0 commit comments