From patchwork Fri Mar 13 10:50:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Angelo Compagnucci X-Patchwork-Id: 449910 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from hemlock.osuosl.org (hemlock.osuosl.org [140.211.166.133]) by ozlabs.org (Postfix) with ESMTP id EF76614009B for ; Fri, 13 Mar 2015 21:50:31 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="verification failed; unprotected key" header.d=gmail.com header.i=@gmail.com header.b=GE2BFjSA; dkim-adsp=none (unprotected policy); dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 16650958A5; Fri, 13 Mar 2015 10:50:30 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dILdXOCX2QKO; Fri, 13 Mar 2015 10:50:27 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by hemlock.osuosl.org (Postfix) with ESMTP id 05F829589E; Fri, 13 Mar 2015 10:50:27 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from silver.osuosl.org (silver.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id 06AE61BFA63 for ; Fri, 13 Mar 2015 10:50:26 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 0208E33AA8 for ; Fri, 13 Mar 2015 10:50:26 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id X5ejRBa5kCzc for ; Fri, 13 Mar 2015 10:50:24 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wg0-f47.google.com (mail-wg0-f47.google.com [74.125.82.47]) by silver.osuosl.org (Postfix) with ESMTPS id A514F33A92 for ; Fri, 13 Mar 2015 10:50:24 +0000 (UTC) Received: by wggx12 with SMTP id x12so22280937wgg.10 for ; Fri, 13 Mar 2015 03:50:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=i6hoIkSs/b6o6adjpiPfeI8U/IqzFvRH6O2AtHMBtBI=; b=GE2BFjSAIkse5d+3r0EZbdb8LtOuEl3Gq/u+14AQZDlY1p6SHFtIp0y0AF7tW57DY0 5VZHrCpQQuyIu67gNyCHMjCma2BR88vBkRJnwQ6fOphg3sYmae2VkQC6B7lAUZB79pSC QbqxCs3Q36LZIX0gohZgFEMhaqCEhCqs6VTJpOz9DjCNjd01I3qrR/NFJKlGeZsIfv64 GuQTGUATIiVqyzXhfTZS1ANAyawJ82aMRiFm+2KULlWRUE65W3upVIp6l35tSBRYJwBt ebWW1qhUktxp9tS0mCUI5wwaaRaPCZAMrmWe7RjnzBTk9QxHtR2TNJtqfclb0Hh23YeS NhwA== X-Received: by 10.194.79.226 with SMTP id m2mr94840618wjx.60.1426243823066; Fri, 13 Mar 2015 03:50:23 -0700 (PDT) Received: from localhost.localdomain ([89.202.204.100]) by mx.google.com with ESMTPSA id w8sm2295110wja.4.2015.03.13.03.50.20 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 13 Mar 2015 03:50:21 -0700 (PDT) From: Angelo Compagnucci To: buildroot@buildroot.net Date: Fri, 13 Mar 2015 11:50:04 +0100 Message-Id: <1426243805-8317-2-git-send-email-angelo.compagnucci@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1426243805-8317-1-git-send-email-angelo.compagnucci@gmail.com> References: <1426243805-8317-1-git-send-email-angelo.compagnucci@gmail.com> Subject: [Buildroot] [PATCH 1/2] package/makedevs: add recursive option X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" This patch adds the possibilty to change owner/permission of a folder recursively. Signed-off-by: Angelo Compagnucci Reviewed-by: "Yann E. MORIN" --- package/makedevs/makedevs.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/package/makedevs/makedevs.c b/package/makedevs/makedevs.c index ab90b93..e575427 100644 --- a/package/makedevs/makedevs.c +++ b/package/makedevs/makedevs.c @@ -34,6 +34,8 @@ #ifndef __APPLE__ #include /* major() and minor() */ #endif +#include + const char *bb_applet_name; @@ -332,6 +334,7 @@ void bb_show_usage(void) fprintf(stderr, "Where name is the file name, type can be one of:\n"); fprintf(stderr, " f A regular file\n"); fprintf(stderr, " d Directory\n"); + fprintf(stderr, " r Directory recursively\n"); fprintf(stderr, " c Character special device file\n"); fprintf(stderr, " b Block special device file\n"); fprintf(stderr, " p Fifo (named pipe)\n"); @@ -364,6 +367,20 @@ void bb_show_usage(void) exit(1); } +bb_recursive(const char *full_name, uid_t uid, gid_t gid, unsigned int mode){ + + int chmod_chown(const char *fpath, const struct stat *sb, + int tflag, struct FTW *ftwbuf) { + if (chown(fpath, uid, gid) == -1) return -1; + if ((mode != -1)) { + if (chmod(fpath, mode) < 0) return -1; + } + return 0; + } + + return nftw(full_name, chmod_chown, 20, FTW_MOUNT | FTW_PHYS); +} + int main(int argc, char **argv) { int opt; @@ -474,6 +491,12 @@ int main(int argc, char **argv) ret = EXIT_FAILURE; goto loop; } + } else if (type == 'r') { + if (bb_recursive(full_name, uid, gid, mode) < 0) { + bb_perror_msg("line %d: recursive failed for %s", linenum, full_name); + ret = EXIT_FAILURE; + goto loop; + } } else { dev_t rdev;