From patchwork Sat Apr 11 13:40:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Angelo Compagnucci X-Patchwork-Id: 460375 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 82C0E14018C for ; Sat, 11 Apr 2015 23:40:56 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="verification failed; unprotected key" header.d=gmail.com header.i=@gmail.com header.b=YR+UxIJU; dkim-adsp=none (unprotected policy); dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id C8D3792107; Sat, 11 Apr 2015 13:40:55 +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 en-VfVHAMzf8; Sat, 11 Apr 2015 13:40:55 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by hemlock.osuosl.org (Postfix) with ESMTP id 26A2793745; Sat, 11 Apr 2015 13:40:55 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (whitealder.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 7A64A1BF978 for ; Sat, 11 Apr 2015 13:40:54 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 74C358BCB8 for ; Sat, 11 Apr 2015 13:40:54 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id j-itW+zeqJRi for ; Sat, 11 Apr 2015 13:40:53 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wi0-f182.google.com (mail-wi0-f182.google.com [209.85.212.182]) by whitealder.osuosl.org (Postfix) with ESMTPS id 99D7D8BC56 for ; Sat, 11 Apr 2015 13:40:53 +0000 (UTC) Received: by widdi4 with SMTP id di4so9529186wid.0 for ; Sat, 11 Apr 2015 06:40:52 -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=Lhc5Gcm8rix0GgbWOf8MVWruSPW72gRlshUnXyS/+L8=; b=YR+UxIJUgP97pBU4gItFOUqDSGfGCSjXrgmbJqh/xwX9asETmORJd6xuXLRfMyqNVK R2NS0Z1pGGsr2sxy3i2s0z8DfWN/MRnpLblNmzERsm7y0Wpzp1wPao/5km5R16+BBQWT dhfu1uXmBoth2e66P39GEPjCe/umEVTyIpuxxs9O36s+Fu/MASaTJApOar41P9uhEIjW d/JaNgcXiK8q6fxNJJaLmlkLkkxxH5i6VOTdvvo2nWv3nXXEhCaQpc8gGq2fWbAEHgq4 eCvLG9LReNyh/9gd4u/isx+NSxLJ3rsF+nRXXaENzjw2GBePCY5kIt+Mgucx6ibSN6g3 J0Gw== X-Received: by 10.194.8.99 with SMTP id q3mr11808184wja.88.1428759652336; Sat, 11 Apr 2015 06:40:52 -0700 (PDT) Received: from localhost.localdomain ([89.202.204.147]) by mx.google.com with ESMTPSA id ed14sm4134670wic.11.2015.04.11.06.40.50 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 11 Apr 2015 06:40:51 -0700 (PDT) From: Angelo Compagnucci To: buildroot@buildroot.net Date: Sat, 11 Apr 2015 15:40:31 +0200 Message-Id: <1428759632-17060-2-git-send-email-angelo.compagnucci@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1428759632-17060-1-git-send-email-angelo.compagnucci@gmail.com> References: <1428759632-17060-1-git-send-email-angelo.compagnucci@gmail.com> Subject: [Buildroot] [PATCH v2 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 option to change owner/permission of a folder recursively. Signed-off-by: Angelo Compagnucci Tested-by: "Yann E. MORIN" Reviewed-by: "Yann E. MORIN" --- Changelog: v1 -> v2: - Code refactoring to avoid nested functions as suggested by Peter Korsgaard package/makedevs/makedevs.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/package/makedevs/makedevs.c b/package/makedevs/makedevs.c index ab90b93..ee0f9fb 100644 --- a/package/makedevs/makedevs.c +++ b/package/makedevs/makedevs.c @@ -34,8 +34,12 @@ #ifndef __APPLE__ #include /* major() and minor() */ #endif +#include const char *bb_applet_name; +uid_t recursive_uid; +gid_t recursive_gid; +unsigned int recursive_mode; void bb_verror_msg(const char *s, va_list p) { @@ -332,6 +336,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 +369,23 @@ void bb_show_usage(void) exit(1); } +bb_recursive(const char *fpath, const struct stat *sb, + int tflag, struct FTW *ftwbuf){ + + if (chown(fpath, recursive_uid, recursive_gid) == -1) { + bb_perror_msg("chown failed for %s", fpath); + return -1; + } + if (recursive_mode != -1) { + if (chmod(fpath, recursive_mode) < 0) { + bb_perror_msg("chmod failed for %s", fpath); + return -1; + } + } + + return 0; +} + int main(int argc, char **argv) { int opt; @@ -474,6 +496,15 @@ int main(int argc, char **argv) ret = EXIT_FAILURE; goto loop; } + } else if (type == 'r') { + recursive_uid = uid; + recursive_gid = gid; + recursive_mode = mode; + if (nftw(full_name, bb_recursive, 20, FTW_MOUNT | FTW_PHYS) < 0) { + bb_perror_msg("line %d: recursive failed for %s", linenum, full_name); + ret = EXIT_FAILURE; + goto loop; + } } else { dev_t rdev;