From patchwork Tue Sep 27 16:14:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Palethorpe X-Patchwork-Id: 1683389 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=ibP95rqa; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4McPpP2Fv2z1yq7 for ; Wed, 28 Sep 2022 02:14:37 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id A1D473C8772 for ; Tue, 27 Sep 2022 18:14:34 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 9781F3C0FA6 for ; Tue, 27 Sep 2022 18:14:20 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id D09801A00912 for ; Tue, 27 Sep 2022 18:14:19 +0200 (CEST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 6F1461F8A6; Tue, 27 Sep 2022 16:14:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1664295259; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O82NFjYBB7a4AZJbmjCjcsDHefq1jbZVhOm2bCpTTTE=; b=ibP95rqa2LGhke9tlEDlKbjQ5AE2fO+DtSBo15tWc8p+CkujcozERqKJw8IjihQ/WUSg9O Z9Tu5z0gbgvWIVIt8+p2POsAtjyvV3ztGgUA3ri0pQEdC4vBwbhESFwjnbXNxrsLh9g5GY I8jRJlT3IkeOJ0AlQ1XgIX7xzi/EAAY= Received: from g78.suse.de (unknown [10.163.24.90]) by relay2.suse.de (Postfix) with ESMTP id B8BAC2C172; Tue, 27 Sep 2022 16:14:18 +0000 (UTC) To: ltp@lists.linux.it Date: Tue, 27 Sep 2022 17:14:03 +0100 Message-Id: <20220927161408.23743-2-rpalethorpe@suse.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220927161408.23743-1-rpalethorpe@suse.com> References: <20220927161408.23743-1-rpalethorpe@suse.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH 1/6] api/epoll: Add safe epoll functions X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Palethorpe via ltp From: Richard Palethorpe Reply-To: Richard Palethorpe Cc: Richard Palethorpe Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Probably safe to use it over (p)select/(p)poll now. Signed-off-by: Richard Palethorpe --- include/tst_epoll.h | 36 ++++++++++++++++++++ lib/tst_epoll.c | 81 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 include/tst_epoll.h create mode 100644 lib/tst_epoll.c diff --git a/include/tst_epoll.h b/include/tst_epoll.h new file mode 100644 index 000000000..c5ffc07e3 --- /dev/null +++ b/include/tst_epoll.h @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2022 SUSE LLC + */ + +#include + +#ifndef TST_EPOLL_H +#define TST_EPOLL_H + +typedef int (*tst_on_epoll_fn)(void *, uint32_t); +struct tst_epoll_event_data { + tst_on_epoll_fn on_epoll; + void *self; +}; + +int safe_epoll_create1(const char *const file, const int lineno, + const int flags); + +#define SAFE_EPOLL_CREATE1(flags) \ + safe_epoll_create1(__FILE__, __LINE__, (flags)) + +int safe_epoll_ctl(const char *const file, const int lineno, + int epfd, int op, int fd, struct epoll_event *ev); + +#define SAFE_EPOLL_CTL(epfd, op, fd, ev) \ + safe_epoll_ctl(__FILE__, __LINE__, epfd, op, fd, ev) + +int safe_epoll_wait(const char *const file, const int lineno, + int epfd, struct epoll_event *events, + int maxevents, int timeout); + +#define SAFE_EPOLL_WAIT(epfd, events, maxevents, timeout)\ + safe_epoll_wait(__FILE__, __LINE__, epfd, events, maxevents, timeout) + +#endif diff --git a/lib/tst_epoll.c b/lib/tst_epoll.c new file mode 100644 index 000000000..556b3bdab --- /dev/null +++ b/lib/tst_epoll.c @@ -0,0 +1,81 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2022 SUSE LLC + */ +#define _GNU_SOURCE +#define TST_NO_DEFAULT_MAIN + +#include "tst_test.h" +#include "tst_epoll.h" + +int safe_epoll_create1(const char *const file, const int lineno, + const int flags) +{ + const char *flags_str; + int ret = epoll_create1(flags); + + switch (flags) { + case EPOLL_CLOEXEC: + flags_str = "EPOLL_CLOEXEC"; + break; + case 0: + flags_str = ""; + break; + default: + flags_str = "???"; + } + + if (ret == -1) { + tst_brk_(file, lineno, + TBROK | TERRNO, "epoll_create1(%s)", flags_str); + } + + return ret; +} + +int safe_epoll_ctl(const char *const file, const int lineno, + int epfd, int op, int fd, struct epoll_event *ev) +{ + const char *op_str; + int ret; + + switch (op) { + case EPOLL_CTL_ADD: + op_str = "EPOLL_CTL_ADD"; + break; + case EPOLL_CTL_DEL: + op_str = "EPOLL_CTL_DEL"; + break; + case EPOLL_CTL_MOD: + op_str = "EPOLL_CTL_MOD"; + break; + default: + op_str = "???"; + } + + ret = epoll_ctl(epfd, op, fd, ev); + + if (ret == -1) { + tst_brk_(file, lineno, + TBROK | TERRNO, + "epoll_ctl(%d, %s, %d, ...", epfd, op_str, fd); + } + + return ret; +} + +int safe_epoll_wait(const char *const file, const int lineno, + int epfd, struct epoll_event *events, + int maxevents, int timeout) +{ + int ret = epoll_wait(epfd, events, maxevents, timeout); + + if (ret == -1) { + tst_brk_(file, lineno, TBROK | TERRNO, + "epoll_wait(%d, ..., %d, %d)", + epfd, maxevents, timeout); + } + + return ret; +} +