From patchwork Thu Jun 21 14:16:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 932754 X-Patchwork-Delegate: petr.vorel@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.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: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41BP0G6qkjz9s2R for ; Fri, 22 Jun 2018 00:17:02 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 1DC793E7469 for ; Thu, 21 Jun 2018 16:17:00 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [217.194.8.5]) by picard.linux.it (Postfix) with ESMTP id B240C3E62C3 for ; Thu, 21 Jun 2018 16:16:58 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id 4DAE160CB90 for ; Thu, 21 Jun 2018 16:16:57 +0200 (CEST) Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 9BB5EAECD for ; Thu, 21 Jun 2018 14:16:57 +0000 (UTC) From: Petr Vorel To: ltp@lists.linux.it Date: Thu, 21 Jun 2018 16:16:46 +0200 Message-Id: <20180621141648.11430-1-pvorel@suse.cz> X-Mailer: git-send-email 2.17.1 X-Virus-Scanned: clamav-milter 0.99.2 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-5.smtp.seeweb.it Subject: [LTP] [PATCH v3 1/3] lib: Add SAFE_CHROOT(path) macro X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Petr Vorel --- include/tst_safe_macros.h | 6 +++++- lib/tst_safe_macros.c | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h index 75c2a0803..1ad9c71b2 100644 --- a/include/tst_safe_macros.h +++ b/include/tst_safe_macros.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2015 Linux Test Project + * Copyright (c) 2010-2018 Linux Test Project * Copyright (c) 2011-2015 Cyril Hrubis * * This program is free software: you can redistribute it and/or modify @@ -48,6 +48,10 @@ #define SAFE_CREAT(pathname, mode) \ safe_creat(__FILE__, __LINE__, NULL, (pathname), (mode)) +#define SAFE_CHROOT(path) \ + safe_chroot(__FILE__, __LINE__, (path)) +int safe_chroot(const char *file, const int lineno, const char *path); + #define SAFE_DIRNAME(path) \ safe_dirname(__FILE__, __LINE__, NULL, (path)) diff --git a/lib/tst_safe_macros.c b/lib/tst_safe_macros.c index e152bff7f..17384f32c 100644 --- a/lib/tst_safe_macros.c +++ b/lib/tst_safe_macros.c @@ -152,3 +152,16 @@ struct group *safe_getgrnam(const char *file, const int lineno, return rval; } + +int safe_chroot(const char *file, const int lineno, const char *path) +{ + int rval; + + rval = chroot(path); + if (rval == -1) { + tst_brk_(file, lineno, TBROK | TERRNO, + "chroot(%s) failed", path); + } + + return rval; +}