1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com> 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 18static 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 27static 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 41static struct tst_test test = { 42 .test_all = run, 43}; 44