From patchwork Thu Dec 6 12:31:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 1008766 X-Patchwork-Delegate: zajec5@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="UiadVQNa"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="eT8pI2mp"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="GGYoeu4j"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 439ZxD09lxz9s1c for ; Thu, 6 Dec 2018 23:42:07 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:Message-Id:Date:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=fZvOv3Su1NU/qbImDNl0sfw0T6C2HTcQXBVtEXm99gE=; b=UiadVQNaG/vkuC +nNN9W0J+5j6kgTesRrjRl4CLKNy1GDRq1aL7zXIL3Una3IdFfYWc0SgoBjtcBsc9BpHhvfGtYDQ6 nMW2y7MPYA/tMqZGBDFf4Rg8n/HDuHipAZ+Hv7xk1FWUH5n4AK0vIe7Iyu4ct52zErvK5RUu6Qzk6 0tPOSHIm08cQ7VLRkcieA5BiMabOsER15qumNzJZfUzQrOBID3kzEnxYvX4wcpW68Q3yTtBON/dVc jFNl1fqhsPxFu+zyhKEtXBsFhDbzY/xjCZN+RAVJuVSrbMsQ7t1yxezEACv5yBRJw9rs+OwUqk9Fu YaoMAbWf2bZHGVVr+thw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gUsyi-0000ub-14; Thu, 06 Dec 2018 12:42:04 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gUsyg-0000lH-NA for openwrt-devel@bombadil.infradead.org; Thu, 06 Dec 2018 12:42:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:Content-Type: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=e8CEvTsd1qxyLttKyM0Cexdem0pp4u28uy6A8e4aQ2I=; b=eT8pI2mpszhGwWGOqMu931UbK2 XKiRxjRQmhEx+716JWOSXyBL3fDTo3ADWxA88WUVZvBHYvSN0FrEaIFuAXZHTTAbjt+dsOdOhTYDy JlmEKUZVUQs/QzEcrLa8PNls6uIdtpUont1r7S+YS39/oq1R3tquRCyTf9lFkkWAH85WWEy5CIfrn fGIjf9bwsTIefs+oRfLGUPhNpAV/ilKofzzaITU6/k/MgQED3LDnZXJmGsYNoH0TrDl5IkgYrpJEg Y6UKmk5SFpmCDaBR/HAiTtrfOvuzvhslJT7ipeHG5a8Nw0N7ZHnz7cLw8wS+E8QAlhXGQqWKE7ukR u4xWUgjg==; Received: from mail-lj1-x244.google.com ([2a00:1450:4864:20::244]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gUsoq-0003X0-AB for openwrt-devel@lists.openwrt.org; Thu, 06 Dec 2018 12:31:56 +0000 Received: by mail-lj1-x244.google.com with SMTP id u6-v6so274631ljd.1 for ; Thu, 06 Dec 2018 04:31:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=e8CEvTsd1qxyLttKyM0Cexdem0pp4u28uy6A8e4aQ2I=; b=GGYoeu4jlIEr7+hdy68TmZVABjJ4KdMYiJQPVAqpPffLTPCgV6b2gxglVGf5y6wKn3 GtHQbUfqR5SNsrPs3AT7qccTC3TB0K64PorXMmx8XuaoU2zinhASeX7+ijEM8UStJSHw hXskITUK8+1gleQe9jEPi8XdjApDN6sTUVRCLEZSGb8vz8usYdoz2zeRajV+h3vPGeX+ HZX6skasVgm+XIwFnwxtWZ/y2mpDygUWsrXhMEV3gSkTEKjzsx8rzOhNtraaimQu4XQX bY69O/aqjzS53tcXEkGheynjyfi0UhWLGkdesbxs+CVG6NdHHAAPrJWuCPgQNij7/wbL vCjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=e8CEvTsd1qxyLttKyM0Cexdem0pp4u28uy6A8e4aQ2I=; b=IyLNLUGZMmOwAIvnP68QElOuY155508YhYTLsoX9gpotS1seX6yT1wA2/aKmcyE/j0 O/XruON9dx7jSfh9bJjsHm11DD04hDpPdo1/84AbwFy4zRwfitqCELg0AMAzmaMyW5jB J2oK56c6LTY5xcrhG3GLCocaPLrV3qviB26+0803v1urDEEn/i65uzWgN0IqvZKkUZ3X ipuTQ66ofwi2bxIZsKB7rQPqBIyDaeWX8iyydhmt4b0FbeyncRDke55IdbF9DWJ9jG6F 0yOhCC+oAVm/sp2NaCxDSrUH3kFFtGl6WU857YNrE2sXARnHVsuhfFV1b+YTy3UtxM8r 6L/A== X-Gm-Message-State: AA+aEWYNQQy3xBCvoMWMFPiQgNh/vaKpjPKdVDAC3IlACvkDM3qmpoDG LXRf4Cm08z3u3H6A3FhuEmEeHnI6 X-Google-Smtp-Source: AFSGD/W34w+pQ7YNlytzg8DFk+hMeeBeXk2DwGhMOwjUeluDSgp7IdwJ6rYOexPWTz4I362HLGUSPA== X-Received: by 2002:a2e:9983:: with SMTP id w3-v6mr1751276lji.133.1544099499676; Thu, 06 Dec 2018 04:31:39 -0800 (PST) Received: from linux-veee.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id j76-v6sm48174ljb.12.2018.12.06.04.31.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 06 Dec 2018 04:31:37 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: openwrt-devel@lists.openwrt.org Date: Thu, 6 Dec 2018 13:31:23 +0100 Message-Id: <20181206123123.31081-1-zajec5@gmail.com> X-Mailer: git-send-email 2.13.7 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181206_123152_361039_0A8DDDEE X-CRM114-Status: GOOD ( 17.05 ) X-Spam-Score: 0.1 (/) X-Spam-Report: SpamAssassin version 3.4.1 on casper.infradead.org summary: Content analysis details: (0.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:244 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (zajec5[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (zajec5[at]gmail.com) -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain Subject: [OpenWrt-Devel] [PATCH libubox] hotplug: add hotplug_call() helper X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Rafał Miłecki This new function imlements common code needed to run /etc/hotplug.d/ listeners. It allows specifying subsystem and environment strings as commonly used in the hotplug.d. Signed-off-by: Rafał Miłecki --- CMakeLists.txt | 2 +- hotplug.c | 35 +++++++++++++++++++++++++++++++++++ hotplug.h | 8 ++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 hotplug.c create mode 100644 hotplug.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 57804cf..aa54499 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ IF(JSONC_FOUND) INCLUDE_DIRECTORIES(${JSONC_INCLUDE_DIRS}) ENDIF() -SET(SOURCES avl.c avl-cmp.c blob.c blobmsg.c uloop.c usock.c ustream.c ustream-fd.c vlist.c utils.c safe_list.c runqueue.c md5.c kvlist.c ulog.c base64.c) +SET(SOURCES avl.c avl-cmp.c blob.c blobmsg.c uloop.c usock.c ustream.c ustream-fd.c vlist.c utils.c safe_list.c runqueue.c md5.c kvlist.c ulog.c base64.c hotplug.c) ADD_LIBRARY(ubox SHARED ${SOURCES}) ADD_LIBRARY(ubox-static STATIC ${SOURCES}) diff --git a/hotplug.c b/hotplug.c new file mode 100644 index 0000000..f3298fa --- /dev/null +++ b/hotplug.c @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: ISC +/* + * hotplug - helpers for hotplug.d events + * + * Copyright (C) 2018 Rafał Miłecki + */ + +#include "hotplug.h" + +#include +#include +#include +#include + +int hotplug_call(char *subsystem, char * const *envp) +{ + pid_t pid; + + pid = fork(); + if (!pid) { + char * const argv[] = { "hotplug-call", subsystem, NULL }; + + execve("/sbin/hotplug-call", argv, envp); + exit(-1); + } else if (pid > 0) { + int status; + + waitpid(pid, &status, 0); + if (WEXITSTATUS(status)) + return WEXITSTATUS(status); + return 0; + } else { + return -errno; + } +} diff --git a/hotplug.h b/hotplug.h new file mode 100644 index 0000000..224a764 --- /dev/null +++ b/hotplug.h @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: ISC + +#ifndef __LIBUBOX_HOTPLUG_H +#define __LIBUBOX_HOTPLUG_H + +int hotplug_call(char *subsystem, char * const *envp); + +#endif