xref: /aosp_15_r20/external/ltp/testcases/kernel/watchqueue/wqueue04.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]>
4  */
5 
6 /*\
7  * [Description]
8  *
9  * Test if keyctl link is correctly recognized by watch queue.
10  */
11 
12 #define _GNU_SOURCE
13 
14 #include "tst_test.h"
15 #include "lapi/keyctl.h"
16 #include "common.h"
17 
saw_key_linked(struct watch_notification * n,size_t len,unsigned int wtype)18 static void saw_key_linked(struct watch_notification *n, size_t len,
19 			   unsigned int wtype)
20 {
21 	if (wqueue_key_event(n, len, wtype, NOTIFY_KEY_LINKED))
22 		tst_res(TPASS, "keyctl link has been recognized");
23 	else
24 		tst_res(TFAIL, "keyctl link has not been recognized");
25 }
26 
run(void)27 static void run(void)
28 {
29 	int fd;
30 	key_serial_t key;
31 
32 	fd = wqueue_watch(256, &wqueue_filter);
33 	key = wqueue_add_key(fd);
34 
35 	keyctl(KEYCTL_LINK, key, KEY_SPEC_SESSION_KEYRING);
36 	wqueue_consumer(fd, saw_key_linked);
37 
38 	SAFE_CLOSE(fd);
39 }
40 
41 static struct tst_test test = {
42 	.test_all = run,
43 };
44