From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1Ppitw-00048S-EN for garchives@archives.gentoo.org; Wed, 16 Feb 2011 15:02:44 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id D69F7E0800; Wed, 16 Feb 2011 15:02:36 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 8CDC2E0800 for ; Wed, 16 Feb 2011 15:02:36 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id B7D271B4082 for ; Wed, 16 Feb 2011 15:02:35 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 0E7D28006A for ; Wed, 16 Feb 2011 15:02:35 +0000 (UTC) From: "William Hubbs" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "William Hubbs" Message-ID: Subject: [gentoo-commits] proj/openrc:master commit in: src/rc/ X-VCS-Repository: proj/openrc X-VCS-Files: src/rc/rc-applets.c src/rc/rc.c X-VCS-Directories: src/rc/ X-VCS-Committer: williamH X-VCS-Committer-Name: William Hubbs X-VCS-Revision: b512d0db98b73bfe2bbeac84c19db039dc256c4f Date: Wed, 16 Feb 2011 15:02:35 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 5322ad948c7231f74d6246830a6b2231 commit: b512d0db98b73bfe2bbeac84c19db039dc256c4f Author: William Hubbs gentoo org> AuthorDate: Tue Feb 15 14:50:44 2011 +0000 Commit: William Hubbs gentoo org> CommitDate: Wed Feb 16 15:00:38 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/openrc.git;a=3D= commit;h=3Db512d0db new implementation of applet option This reworks the implementation of the --applet option so that it is processed in run_applets() and does not require two calls to the getopts_long() function. It is based on code by Robin Johnson and Chris Richards. X-Gentoo-Bug: 351712 X-Gentoo-Bug-URL: http://bugs.gentoo.org/show_bug.cgi?id=3D351712 --- src/rc/rc-applets.c | 11 +++++++++++ src/rc/rc.c | 22 +++++++--------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/rc/rc-applets.c b/src/rc/rc-applets.c index 8381113..6068cb6 100644 --- a/src/rc/rc-applets.c +++ b/src/rc/rc-applets.c @@ -429,6 +429,17 @@ run_applets(int argc, char **argv) char *p; pid_t pid =3D 0; =20 + /* Bug 351712: We need an extra way to explicitly select an applet OTHE= R + * than trusting argv[0], as argv[0] is not going to be the applet valu= e if + * we are doing SELinux context switching. For this, we allow calls suc= h as + * 'rc --applet APPLET', and shift ALL of argv down by two array items.= */ + if (strcmp(applet, "rc") =3D=3D 0 && argc >=3D 3 && + (strcmp(argv[1],"--applet") =3D=3D 0 || strcmp(argv[1], "-a") =3D=3D= 0)) { + applet =3D argv[2]; + argv +=3D 2; + argc -=3D 2; + } + /* These are designed to be applications in their own right */ if (strcmp(applet, "fstabinfo") =3D=3D 0) exit(fstabinfo(argc, argv)); diff --git a/src/rc/rc.c b/src/rc/rc.c index 525ccdc..140667a 100644 --- a/src/rc/rc.c +++ b/src/rc/rc.c @@ -773,14 +773,16 @@ handle_bad_signal(int sig) #endif =20 #include "_usage.h" -#define getoptstring "o:s:S" getoptstring_COMMON +#define getoptstring "a:o:s:S" getoptstring_COMMON static const struct option longopts[] =3D { + { "applet", 1, NULL, 'a' }, { "override", 1, NULL, 'o' }, { "service", 1, NULL, 's' }, { "sys", 0, NULL, 'S' }, longopts_COMMON }; static const char * const longopts_help[] =3D { + "runs the applet specified by the next argument", "override the next runlevel to change into\n" "when leaving single user or boot runlevels", "runs the service specified with the rest\nof the arguments", @@ -817,20 +819,6 @@ main(int argc, char **argv) signal_setup(SIGSEGV, handle_bad_signal); #endif =20 - /* Bug 351712: We need an extra way to explicitly select an applet OTHE= R - * than trusting argv[0], as argv[0] is not going to be the applet valu= e if - * we are doing SELinux context switching. For this, we allow calls suc= h as - * 'rc --applet APPLET', and shift ALL of argv down by two array items.= */ - if (strcmp(basename_c(argv[0]), "rc") =3D=3D 0 && argc > 1 && strcmp(ar= gv[1], "--applet") =3D=3D 0) { - if (argc =3D=3D 2) - eerrorx("applet argument required"); - for (i =3D 2; i < argc; i++) - argv[i - 2] =3D argv[i]; - argv[argc - 2] =3D NULL; - argv[argc - 1] =3D NULL; - argc -=3D 2; - } - /* Now we can trust our applet value in argv[0] */ applet =3D basename_c(argv[0]); LIST_INIT(&service_pids); atexit(cleanup); @@ -858,6 +846,10 @@ main(int argc, char **argv) longopts, (int *) 0)) !=3D -1) { switch (opt) { + case 'a': + /* Do nothing, actual logic in run_applets, this + * is a placeholder */ + break; case 'o': if (*optarg =3D=3D '\0') optarg =3D NULL;