From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 6879313877A for ; Sun, 13 Jul 2014 19:16:04 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 7D3F3E0762; Sun, 13 Jul 2014 19:16:03 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 0CE20E0762 for ; Sun, 13 Jul 2014 19:16:02 +0000 (UTC) Received: from spoonbill.gentoo.org (spoonbill.gentoo.org [81.93.255.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 30AF433F3DB for ; Sun, 13 Jul 2014 19:16:02 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by spoonbill.gentoo.org (Postfix) with ESMTP id EDD321807D for ; Sun, 13 Jul 2014 19:16:00 +0000 (UTC) From: "William Hubbs" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "William Hubbs" Message-ID: <1405278756.71d6d61b28c4c0f285ec51459551d900dfa4ea71.williamh@OpenRC> Subject: [gentoo-commits] proj/openrc:master commit in: src/rc/ X-VCS-Repository: proj/openrc X-VCS-Files: src/rc/checkpath.c X-VCS-Directories: src/rc/ X-VCS-Committer: williamh X-VCS-Committer-Name: William Hubbs X-VCS-Revision: 71d6d61b28c4c0f285ec51459551d900dfa4ea71 X-VCS-Branch: master Date: Sun, 13 Jul 2014 19:16:00 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 3c3945bf-1c41-4ba9-844e-415f9a57326c X-Archives-Hash: d40405ba8b81f7766d2c19231408b7f1 commit: 71d6d61b28c4c0f285ec51459551d900dfa4ea71 Author: William Hubbs gmail com> AuthorDate: Sun Jul 13 19:12:36 2014 +0000 Commit: William Hubbs gentoo org> CommitDate: Sun Jul 13 19:12:36 2014 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=71d6d61b checkpath: fix logic for the writable option The -W option does not need an argument of its own; it can take the first path after all other options are processed on the command line. Also, move the processing for the -W option out of the switch so it will be in the same loop as the other processing. --- src/rc/checkpath.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/rc/checkpath.c b/src/rc/checkpath.c index 3c6c5ca..6a0f893 100644 --- a/src/rc/checkpath.c +++ b/src/rc/checkpath.c @@ -187,7 +187,7 @@ parse_owner(struct passwd **user, struct group **group, const char *owner) #include "_usage.h" #define extraopts "path1 [path2] [...]" -#define getoptstring "dDfFpm:o:W:" getoptstring_COMMON +#define getoptstring "dDfFpm:o:W" getoptstring_COMMON static const struct option longopts[] = { { "directory", 0, NULL, 'd'}, { "directory-truncate", 0, NULL, 'D'}, @@ -196,7 +196,7 @@ static const struct option longopts[] = { { "pipe", 0, NULL, 'p'}, { "mode", 1, NULL, 'm'}, { "owner", 1, NULL, 'o'}, - { "writable", 1, NULL, 'W'}, + { "writable", 0, NULL, 'W'}, longopts_COMMON }; static const char * const longopts_help[] = { @@ -225,6 +225,7 @@ checkpath(int argc, char **argv) int retval = EXIT_SUCCESS; bool trunc = false; bool chowner = false; + bool writable = false; while ((opt = getopt_long(argc, argv, getoptstring, longopts, (int *) 0)) != -1) @@ -255,9 +256,7 @@ checkpath(int argc, char **argv) applet, optarg); break; case 'W': - if (argv[optind] != NULL) - ewarn("-W/--writable takes only one path, everything else will be ignored"); - exit(!is_writable(optarg)); + writable = true; break; case_RC_COMMON_GETOPT @@ -267,8 +266,8 @@ checkpath(int argc, char **argv) if (optind >= argc) usage(EXIT_FAILURE); - if (type == inode_unknown) - eerrorx("%s: -d, -f, -p, or -W must be specified.", applet); + if (writable && type != inode_unknown) + eerrorx("%s: -W cannot be specified along with -d, -f or -p", applet); if (pw) { uid = pw->pw_uid; @@ -278,6 +277,8 @@ checkpath(int argc, char **argv) gid = gr->gr_gid; while (optind < argc) { + if (writable) + exit(!is_writable(argv[optind])); if (do_check(argv[optind], uid, gid, mode, type, trunc, chowner)) retval = EXIT_FAILURE; optind++;