Feature request to rc.d: managing subsets of scripts
Brooks Davis
brooks at one-eyed-alien.net
Tue Aug 10 17:08:01 PDT 2004
On Sat, Aug 07, 2004 at 02:43:02PM -0700, Jon Passki wrote:
> Hello All,
>
> I wish accomplish the following with rc.d scripts:
>
> 1) Scripts can be assigned to a subset;
> 2) Subsets can be ordered, with this order honored by rcorder;
> 3) Subsets can be independently started and stopped after the
> initial system startup;
>
> For me, the usage would be in situations where I have a bunch of
> interdependent scripts that would need a stop/start when for
> example I'm remounting a file system or reassigning daemons to a
> different network interface. This way, I could assign scripts to
> subsets if I know that they utilize common interfaces or mounts.
> It is implied that if a script wasn't placed in a subset it should
> continue to function even though it may depend on or be a dependent
> of a subset that was stopped. It is the responsibility of the
> sysadmin to properly segment subsets.
>
> 1) & 2) can be accomplished with the REQUIRE, PROVIDE and BEFORE
> lines. This would also make me alter each rc.d script I wish to
> manage, but that is acceptable. It's unknown to me if subsets
> should be disjointed.
>
> It isn't obvious to me, though, if 3) could work that way. I still
> would see rcorder doing it's magic, but it would need a filter to
> only order that subset. The KEYWORD line could be used in addition
> to the other lines, but adds some redundancy. According to [1],
> rcorder logically OR's keep list switches. It would have to AND
> them in this case to handle a) the FreeBSD switch and b) more
> importantly, manage more than one subset.
I want this feature. What I want it for is to have a set of scripts
that run before the standard ones so initdiskless can add scripts to
/etc/rc.d (and thus I can keep /etc/rc.d stock). What I'm planning to
do is to add a -K option to rcorder which will make keywords evaluate
ANDed. Keywords will still be passed with -k, just the evaluation
function will change. Here's a patch for rcorder that adds this
function. A patch to /etc/rc is also needed to handle the subsets. I'm
not 100% sure how to do this given my desire to have an "early" set that
runs before everything. Maybe we should just hardcode that one.
-- Brooks
==== //depot/user/brooks/cleanup/sbin/rcorder/rcorder.8#2 - /home/brooks/working/freebsd/p4/cleanup/sbin/rcorder/rcorder.8 ====
@@ -39,6 +39,7 @@
.Nd print a dependency ordering of interdependent files
.Sh SYNOPSIS
.Nm
+.Op Fl K
.Op Fl k Ar keep
.Op Fl s Ar skip
.Ar
@@ -92,12 +93,23 @@
.Pp
The options are as follows:
.Bl -tag -width indent
+.It Fl K
+Require all keywords in the
+.Dq "keep list"
+to be in each file.
+The default is to require one or more.
.It Fl k
Add the specified keyword to the
.Dq "keep list" .
If any
.Fl k
-option is given, only those files containing the matching keyword are listed.
+option is given, only those files containing one or more of the matching
+keyword are listed.
+The
+.Fl K
+option causes all keywords in the
+.Dq "keep list"
+to be required.
.It Fl s
Add the specified keyword to the
.Dq "skip list" .
==== //depot/user/brooks/cleanup/sbin/rcorder/rcorder.c#1 - /home/brooks/working/freebsd/p4/cleanup/sbin/rcorder/rcorder.c ====
@@ -69,6 +69,7 @@
#define KEYWORDS_STR "# KEYWORDS:"
#define KEYWORDS_LEN (sizeof(KEYWORDS_STR) - 1)
+int keyword_or = 1;
int exit_code;
int file_count;
char **file_list;
@@ -155,7 +156,7 @@
{
int ch;
- while ((ch = getopt(argc, argv, "dk:s:")) != -1)
+ while ((ch = getopt(argc, argv, "dKk:s:")) != -1)
switch (ch) {
case 'd':
#ifdef DEBUG
@@ -164,6 +165,9 @@
warnx("debugging not compiled in, -d ignored");
#endif
break;
+ case 'K':
+ keyword_or = 0;
+ break;
case 'k':
strnode_add(&keep_list, optarg, 0);
break;
@@ -704,13 +708,25 @@
strnodelist *s;
strnodelist *k;
- for (s = keep_list; s; s = s->next)
- for (k = fnode->keyword_list; k; k = k->next)
- if (strcmp(k->s, s->s) == 0)
- return (1);
+ for (s = keep_list; s; s = s->next) {
+ for (k = fnode->keyword_list; k; k = k->next) {
+ if (strcmp(k->s, s->s) == 0) {
+ if (keyword_or)
+ return (1);
+ else
+ break;
+ }
+ }
+ if (!keyword_or && k == NULL)
+ return (0);
+ }
- /* an empty keep_list means every one */
- return (!keep_list);
+ if (keyword_or) {
+ /* an empty keep_list means every one */
+ return (!keep_list);
+ } else {
+ return (1);
+ }
}
/*
--
Any statement of the form "X is the one, true Y" is FALSE.
PGP fingerprint 655D 519C 26A7 82E7 2529 9BF0 5D8E 8BE9 F238 1AD4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-rc/attachments/20040810/2ad98f09/attachment.bin
More information about the freebsd-rc
mailing list