summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Nicholson <dbn.lists@gmail.com>2008-05-29 08:52:12 -0700
committerDan Nicholson <dbn.lists@gmail.com>2008-05-29 08:52:12 -0700
commitd9aaecb095a169d619c71ea337bed892ca8449dc (patch)
tree964f33e29f5dafbf37231b6bc020e2f9f9f734bb
parent20e1c19f9223e2a43e1399009adfa4a39f78e7b6 (diff)
Use two fields for storing installation/removal status
Previously, there was a single change field cstart/stop that was overloaded to contain both installation and removal status. It was difficult to differentiate between whether a service was to be removed, to be installed, or unchanged. This commit converts the change field into two dedicated fields, instart/stop and rmstart/stop to differentiate the cases better.
-rw-r--r--lib/active.c30
-rw-r--r--lib/initd.c21
-rw-r--r--lib/installrm.c10
-rw-r--r--lib/rdep.c50
-rw-r--r--lib/types.h13
5 files changed, 72 insertions, 52 deletions
diff --git a/lib/active.c b/lib/active.c
index 9f91ce1..2cc76d9 100644
--- a/lib/active.c
+++ b/lib/active.c
@@ -70,11 +70,17 @@ bool initd_is_active(const initd_t *ip, initd_rc_t rc, initd_key_t key)
case KEY_ASTOP:
match = ip->astop;
break;
- case KEY_CSTART:
- match = ip->cstart;
+ case KEY_INSTART:
+ match = ip->instart;
break;
- case KEY_CSTOP:
- match = ip->cstop;
+ case KEY_INSTOP:
+ match = ip->instop;
+ break;
+ case KEY_RMSTART:
+ match = ip->rmstart;
+ break;
+ case KEY_RMSTOP:
+ match = ip->rmstop;
break;
case KEY_DSTART:
match = ip->dstart;
@@ -194,7 +200,7 @@ static void set_active_from_symlink(initd_list_t *ilp,
const char *tbase;
size_t idlen;
initd_t *ip;
- initd_key_t key, ckey;
+ initd_key_t akey;
if (!(ilp || rcp || link || tgt))
return;
@@ -218,24 +224,20 @@ static void set_active_from_symlink(initd_list_t *ilp,
/* is this a start (S) or stop (K) link? */
if (link[0] == 'S') {
- key = KEY_ASTART;
- ckey = KEY_CSTART;
+ akey = KEY_ASTART;
} else if (link[0] == 'K') {
- key = KEY_ASTOP;
- ckey = KEY_CSTOP;
+ akey = KEY_ASTOP;
} else {
fprintf(stderr, "link %s is not a valid S or K link\n",
link);
return;
}
- /* set this level as active and match in the changed field
- * of the initd_t */
- initd_set_rc(ip, key, rcp->rc);
- initd_set_rc(ip, ckey, rcp->rc);
+ /* set this level as active */
+ initd_set_rc(ip, akey, rcp->rc);
/* add the link to the active list */
- add_active_link(ip, link, rcp, key);
+ add_active_link(ip, link, rcp, akey);
}
static void add_active_link(const initd_t *ip, const char *link,
diff --git a/lib/initd.c b/lib/initd.c
index 12b3e69..c6f9362 100644
--- a/lib/initd.c
+++ b/lib/initd.c
@@ -22,7 +22,8 @@ initd_t *initd_new(const char *name) {
ip->dstart = ip->dstop = 0;
ip->astart = ip->astop = 0;
- ip->cstart = ip->cstop = 0;
+ ip->instart = ip->instop = 0;
+ ip->rmstart = ip->rmstop = 0;
ip->astart_links = strarg_new();
ip->astop_links = strarg_new();
@@ -85,8 +86,10 @@ initd_t *initd_copy(const initd_t *source)
dest->dstop = source->dstop;
dest->astart = source->astart;
dest->astop = source->astop;
- dest->cstart = source->cstart;
- dest->cstop = source->cstop;
+ dest->instart = source->instart;
+ dest->instop = source->instop;
+ dest->rmstart = source->rmstart;
+ dest->rmstop = source->rmstop;
dest->astart_links = strarg_copy(source->astart_links);
dest->astop_links = strarg_copy(source->astop_links);
@@ -147,10 +150,14 @@ static initd_rc_t *initd_get_rc_from_key(const initd_t *ip,
return (initd_rc_t *) &ip->astart;
case KEY_ASTOP:
return (initd_rc_t *) &ip->astop;
- case KEY_CSTART:
- return (initd_rc_t *) &ip->cstart;
- case KEY_CSTOP:
- return (initd_rc_t *) &ip->cstop;
+ case KEY_INSTART:
+ return (initd_rc_t *) &ip->instart;
+ case KEY_INSTOP:
+ return (initd_rc_t *) &ip->instop;
+ case KEY_RMSTART:
+ return (initd_rc_t *) &ip->rmstart;
+ case KEY_RMSTOP:
+ return (initd_rc_t *) &ip->rmstop;
case KEY_DSTART:
return (initd_rc_t *) &ip->dstart;
case KEY_DSTOP:
diff --git a/lib/installrm.c b/lib/installrm.c
index d11eae5..dda218a 100644
--- a/lib/installrm.c
+++ b/lib/installrm.c
@@ -180,7 +180,7 @@ static void install_new_link(const initd_t *ip, const struct rcpair *rcp,
char *tname;
char skc;
initd_rc_t rc;
- initd_key_t akey, ckey, dkey;
+ initd_key_t akey, inkey, dkey;
if (!ip || !rcp)
return;
@@ -188,11 +188,11 @@ static void install_new_link(const initd_t *ip, const struct rcpair *rcp,
rc = rcp->rc;
if (sk == SK_START) {
akey = KEY_ASTART;
- ckey = KEY_CSTART;
+ inkey = KEY_INSTART;
dkey = KEY_DSTART;
} else {
akey = KEY_ASTOP;
- ckey = KEY_CSTOP;
+ inkey = KEY_INSTOP;
dkey = KEY_DSTOP;
}
@@ -200,8 +200,8 @@ static void install_new_link(const initd_t *ip, const struct rcpair *rcp,
if (!initd_is_active(ip, rc, dkey))
return;
- /* Check if this service is to be removed from this level */
- if (!initd_is_active(ip, rc, ckey))
+ /* Check if this service is to be installed at this level */
+ if (!initd_is_active(ip, rc, inkey))
return;
/* Set the current priority */
diff --git a/lib/rdep.c b/lib/rdep.c
index baedf97..2d328df 100644
--- a/lib/rdep.c
+++ b/lib/rdep.c
@@ -107,11 +107,11 @@ initd_list_t *initd_remove_recurse_deps(initd_list_t *pool,
if (initd_list_exists_name(rmlist, ip->name))
continue;
- /* Clear the change field to mark for removal */
+ /* Set the remove field for all levels */
if (sk == SK_START)
- ip->cstart = 0;
+ initd_set_rc(ip, KEY_RMSTART, RC_ALL);
else
- ip->cstop = 0;
+ initd_set_rc(ip, KEY_RMSTOP, RC_ALL);
/* Add the initd_t to the rmlist */
initd_list_add(rmlist, initd_copy(ip));
@@ -192,7 +192,7 @@ static dep_t *add_all_active(const initd_list_t *pool,
{
dep_t *active;
initd_t *ip;
- initd_key_t key, ckey;
+ initd_key_t key, rmkey;
if (!pool)
return NULL;
@@ -200,17 +200,17 @@ static dep_t *add_all_active(const initd_list_t *pool,
active = dep_copy(init);
if (sk == SK_START) {
key = KEY_ASTART;
- ckey = KEY_CSTART;
+ rmkey = KEY_RMSTART;
} else {
key = KEY_ASTOP;
- ckey = KEY_CSTOP;
+ rmkey = KEY_RMSTOP;
}
for (ip = pool->first; ip; ip = ip->next) {
/* Add services if they are active on any level and
- * they are not marked for removal on all levels */
+ * they are not marked for removal on any levels */
if (initd_is_active(ip, RC_ALL, key) &&
- initd_is_active(ip, RC_ALL, ckey))
+ !initd_is_active(ip, RC_ALL, rmkey))
dep_add(active, ip->name);
}
@@ -387,33 +387,41 @@ static bool initd_list_verify_level(const initd_list_t *ord,
bool required)
{
initd_t *ip, *dep;
- initd_rc_t iprc;
dep_t *iprcdep;
char *dstr;
int n;
bool match;
+ initd_key_t dkey, inkey, rmkey;
if (!ord)
return false;
+ if (sk == SK_START) {
+ dkey = KEY_DSTART;
+ inkey = KEY_INSTART;
+ rmkey = KEY_RMSTART;
+ } else {
+ dkey = KEY_DSTOP;
+ inkey = KEY_INSTOP;
+ rmkey = KEY_RMSTOP;
+ }
+
/* Check the deps are valid in this level */
for (ip = ord->first; ip; ip = ip->next) {
if (sk == SK_START) {
- iprc = ip->dstart;
if (required)
iprcdep = ip->rstart;
else
iprcdep = ip->sstart;
} else {
- iprc = ip->dstop;
if (required)
iprcdep = ip->rstop;
else
iprcdep = ip->sstop;
}
- /* Skip if the script isn't active at this level */
- if (!(iprc & rc))
+ /* Skip if the script shoudn't run at this level */
+ if (!initd_is_active(ip, rc, dkey))
continue;
/* Check the deps */
@@ -465,15 +473,8 @@ static bool initd_list_verify_level(const initd_list_t *ord,
}
/* Check if the required dep is marked for
- * removal. This happens when a script is
- * currently active but the changed field is
- * cleared. */
- if (sk == SK_START)
- match = (dep->astart & rc) &&
- !(dep->cstart & rc);
- else
- match = (dep->astop & rc) &&
- !(dep->cstop & rc);
+ * removal. */
+ match = initd_is_active(dep, rc, rmkey);
if (match && required) {
fprintf(stderr,
"Error: %s required dependency %s"
@@ -482,6 +483,11 @@ static bool initd_list_verify_level(const initd_list_t *ord,
return false;
}
}
+
+ /* Now that we're successful, mark this script for
+ * installation if it's not marked for removal */
+ if (!initd_is_active(ip, rc, rmkey))
+ initd_set_rc(ip, inkey, rc);
}
/* If we get here, then we were successful */
diff --git a/lib/types.h b/lib/types.h
index de96205..451df89 100644
--- a/lib/types.h
+++ b/lib/types.h
@@ -11,8 +11,10 @@ typedef enum initd_key {
KEY_PROV, /* Provides */
KEY_ASTART, /* Active Start levels */
KEY_ASTOP, /* Active Stop levels */
- KEY_CSTART, /* Changed Start levels */
- KEY_CSTOP, /* Changed Stop levels */
+ KEY_INSTART, /* Install Start levels */
+ KEY_INSTOP, /* Install Stop levels */
+ KEY_RMSTART, /* Remove Start levels */
+ KEY_RMSTOP, /* Remove Stop levels */
KEY_DSTART, /* Default-Start */
KEY_DSTOP, /* Default-Stop */
KEY_RSTART, /* Required-Start */
@@ -82,8 +84,11 @@ typedef struct initd {
initd_rc_t astart; /* Active Start levels */
initd_rc_t astop; /* Active Stop levels */
- initd_rc_t cstart; /* Changed Start levels */
- initd_rc_t cstop; /* Changed Stop levels */
+ initd_rc_t instart; /* Install Start levels */
+ initd_rc_t instop; /* Install Stop levels */
+
+ initd_rc_t rmstart; /* Remove Start levels */
+ initd_rc_t rmstop; /* Remove Stop levels */
strarg_t *astart_links; /* Active Start links */
strarg_t *astop_links; /* Active Stop links */