diff options
author | Dan Nicholson <dbn.lists@gmail.com> | 2008-05-28 18:40:20 -0700 |
---|---|---|
committer | Dan Nicholson <dbn.lists@gmail.com> | 2008-05-28 18:40:20 -0700 |
commit | 60e5cb09b3f38afc768fbd646f2cb58c33defaf9 (patch) | |
tree | d2db34f464390c70beeabb24d8cf02a6d106f0ce | |
parent | 78d5e1b0c3ee9be8fc71389a57d0637f16b99c97 (diff) |
Handle rc bits more correctly when installing and removing links
A few changes in the installrm functions:
- When removing an existing symlink, we clear the active bit for that
level.
- When installing a new link, we set the active bit for that level.
- Before installing a new link, we check that the script is supposed to
start in that level and that it's not marked for removal.
-rw-r--r-- | lib/installrm.c | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/lib/installrm.c b/lib/installrm.c index abea9ac..d11eae5 100644 --- a/lib/installrm.c +++ b/lib/installrm.c @@ -17,7 +17,8 @@ static bool installrm_verbose = false; static void install_level_links(const initd_list_t *ilp, const struct rcpair *rcp, initd_sk_t sk); -static void remove_existing_link(const initd_t *ip, const char *rdir, +static void remove_existing_link(const initd_t *ip, + const struct rcpair *rcp, initd_sk_t sk); static void install_new_link(const initd_t *ip, const struct rcpair *rcp, initd_sk_t sk, int *prio); @@ -107,7 +108,7 @@ static void install_level_links(const initd_list_t *ilp, if (!initd_is_active(ip, rc, KEY_ASTART)) continue; - remove_existing_link(ip, dir, sk); + remove_existing_link(ip, rcp, sk); } } else { for (ip = ilp->last; ip; ip = ip->prev) { @@ -115,7 +116,7 @@ static void install_level_links(const initd_list_t *ilp, if (!initd_is_active(ip, rc, KEY_ASTOP)) continue; - remove_existing_link(ip, dir, sk); + remove_existing_link(ip, rcp, sk); } } @@ -129,16 +130,23 @@ static void install_level_links(const initd_list_t *ilp, } } -static void remove_existing_link(const initd_t *ip, const char *rdir, +static void remove_existing_link(const initd_t *ip, + const struct rcpair *rcp, initd_sk_t sk) { + initd_key_t key; strarg_t *links; int n, nlinks; + initd_rc_t rc = rcp->rc; + char *rdir = rcp->dir; - if (sk == SK_START) + if (sk == SK_START) { + key = KEY_ASTART; links = ip->astart_links; - else + } else { + key = KEY_ASTOP; links = ip->astop_links; + } /* See if any of the links exist in this directory */ nlinks = strarg_get_num(links); @@ -157,6 +165,9 @@ static void remove_existing_link(const initd_t *ip, const char *rdir, if (errno != ENOENT) error(1, errno, "%s", path); } + + /* Clear the active bit for this level */ + initd_clear_rc(ip, key, rc); } } } @@ -168,15 +179,29 @@ static void install_new_link(const initd_t *ip, const struct rcpair *rcp, char path[PATH_MAX]; char *tname; char skc; - initd_rc_t rc, match; + initd_rc_t rc; + initd_key_t akey, ckey, dkey; if (!ip || !rcp) return; - /* Check if this service should be added to this level */ rc = rcp->rc; - match = (sk == SK_START) ? ip->dstart : ip->dstop; - if (!(match & rc)) + if (sk == SK_START) { + akey = KEY_ASTART; + ckey = KEY_CSTART; + dkey = KEY_DSTART; + } else { + akey = KEY_ASTOP; + ckey = KEY_CSTOP; + dkey = KEY_DSTOP; + } + + /* Check if this service should be run in this level */ + 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)) return; /* Set the current priority */ @@ -198,6 +223,9 @@ static void install_new_link(const initd_t *ip, const struct rcpair *rcp, } if (symlink(target, path) < 0) error(1, errno, "%s -> %s", path, target); + + /* Set the active bit for this level */ + initd_set_rc(ip, akey, rc); } #define PRIOPATLEN 17 |