summaryrefslogtreecommitdiff
path: root/lib
AgeCommit message (Collapse)AuthorFilesLines
2008-11-27Fix previous broken commitinitd-tools-0.1.3Dan Nicholson1-1/+1
Wasn't even build tested, apparently.
2008-11-02Report errors with more useful messagesDan Nicholson7-38/+41
This still doesn't do a great job of handling errors, but at least the user may see some reasonable information if they occur.
2008-11-02Add reference count to initd typeDan Nicholson3-3/+14
Since we can now have an arbitrary number of nodes pointing to the same initd type, a reference count is added so that the initd is only destroyed when there are no references left.
2008-11-02Use nodes in list instead of duplicating all initd typesDan Nicholson6-42/+121
Currently, the entire initd structure is duplicated each time a list is copied. Since the initd is not specific to each list, this could cause problems where changing a value in one initd would not be reflected in the equivalent initd in another list. This also wastes memory as each initd duplicated when only one copy is needed. This change introduces the initd_node type. It points to an initd type and contains the list pointers for inclusion in an initd_list type. The typical constructors and destructors have been added for handling these types in lists. Quite a few places needed to be changed where there were iterations over lists. We should really add accessor functions and use those whenever we need access to members of a list.
2008-11-02Also reset errno for the symlink reading loopDan Nicholson1-0/+1
2008-11-02Reset errno before readdir to avoid false errorsDan Nicholson1-0/+1
After readdir completes, errno is check to see if any errors were produced. However, if readdir is successful, it will not change the current errno value. Reset it before the loop to ensure any errors are due to the readdir calls.
2008-09-01Fix handling of optional dependenciesinitd-tools-0.1.2DJ Lucas1-2/+4
When an missing dependency from Should-Start or Should-Stop was encountered, all the processing was being skipped instead just moving to the next dependency.
2008-09-01Correct stop link orderingDJ Lucas1-7/+2
The logic for writing new stop links was walking through the ordered list backwards, causing the stop links to be created incorrectly.
2008-08-31Tear out the buggy dirent d_type code for nowDan Nicholson1-7/+0
Trying to use the d_type field from the dirent structure returns DT_UNKNOWN sometimes causing the pool to never be populated. Remove it for now in favor of the more portable stat() usage.
2008-06-12Create the rc*.d directories if necessary when creating linksDan Nicholson1-2/+14
When the user is installing links, they may not have the rc*.d directories created yet. This changes the behavior to attempt to create the directory if it doesn't exist.
2008-06-04Rename libinitd headers with initd- prefix to avoid conflictsDan Nicholson17-41/+41
Since the libinitd headers are used throughout the tree, we want to avoid naming conflicts, such as util.h.
2008-06-04Include all the libinitd headers from initd.hDan Nicholson5-2/+6
Rather than having all the programs include each header they need, just have initd.h include all the headers that define interfaces in libinitd.
2008-06-04Add basename and dirname wrapper utilitiesDan Nicholson4-5/+65
Added wrappers for the basename() and dirname() functions that handle the copying of the strings correctly. The initd_parse routine has been adjusted to use this wrapper instead of the libc version.
2008-05-29Don't add scripts to the remove list when they're not activeDan Nicholson1-4/+15
The dep removal logic was always adding the requested services to the remove list, causing all links to be rewritten. Now, check if it's active before adding it. This means that requesting to remove an inactive script will just do nothing.
2008-05-29Actually remove the requested servicesDan Nicholson1-1/+9
Fixed a bug where the removal process didn't actually include the requested service in the set to be removed.
2008-05-29Use two fields for storing installation/removal statusDan Nicholson5-52/+72
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.
2008-05-28verify_level: Don't set changed bits to activeDan Nicholson1-6/+0
There's no sane way to set the changed bits to active without destroying valid deactived levels in some cases. Instead, we just have to rely on the fact that they'll be correct already.
2008-05-28Handle rc bits more correctly when installing and removing linksDan Nicholson1-10/+38
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.
2008-05-28Also allow dstart/dstop keys in initd_is_activeDan Nicholson1-0/+6
2008-05-28Add function initd_clear_rc and refactor with initd_set_rcDan Nicholson2-15/+49
Added the initd_clear_rc function as the complement to initd_set_rc. It clears level bits from an rc type in the initd. Refactored the rc_t evaluation into a separate function, initd_get_rc_from_key.
2008-05-28Use changed fields to fix dep solver in remove caseDan Nicholson1-42/+68
When told to remove services through initd_remove_recurse_deps, their changed fields are cleared to indicate that they will no longer be available. This is an improvement over the previous hack where the active bits were being cleared and then restored at the end of the function. With the changed fields cleared, we can skip services that are currently active, but will be going away in add_all_actives. This fixes a bug where a service can be asked to be removed, but then added right back in because it's currently active. When each rc level is verified after recursion has completed, the added services are checked to see if they are marked for removal. This fixes a bug where a service was asked to be removed, but added back because it was a dependency of another service. When each service is verified at that level, it is marked to change to active. Using the changed field clearing in remove_recurse_deps and the setting in verify_level, we should be able to install and remove scripts just by checking the changed field. Finally, fixed two tests which were passing with false positives due to these bugs.
2008-05-28Introduce rc change fields, cstart and cstopDan Nicholson3-2/+26
To differentiate between currently active rc levels and to-be-changed rc levels, new members cstart and cstop have been added to the initd_t type. These will be used in the dep solver to test for deps that are marked for removal.
2008-05-27initd_is_active: Take key type instead of sk typeDan Nicholson4-17/+29
Another active field will be added, so we need to allow initd_is_active to differentiate between them. Just using the sk type is not enough, so now it takes the key name, returning false if an invalid key type was passed.
2008-05-26recurse_deps: Return NULL on errors, empty list is not errorDan Nicholson1-47/+51
The recurse_deps functions are now consistent in returning errors. Since there are valid cases where an empty list may be returned, an error is only indicated by returning NULL. This means callers of recurse_deps must check that the list is not empty before iterating the members.
2008-05-22Merge branch 'master' into addDan Nicholson1-0/+3
2008-05-22Don't derefernce members of NULL structuresDan Nicholson1-0/+3
2008-05-22Add functions for installing and removing init.d symlinksDan Nicholson3-1/+244
This adds the initd_installrm_links function and its helpers for installing and removing symlinks. The function takes an ordered start or kill list and the init.d directory to operate on. There is just a single entry point since the determination of removal or addition is done in the dependency ordering.
2008-05-20Move rcpair definitions into separate rc internal headerDan Nicholson2-26/+31
The rcpair struct and the static instances rcdirs and rcsdirs will be reused, so they're moved into a separate internal header.
2008-05-20Cache active links when scanning rc?.d directoriesDan Nicholson1-0/+37
When scanning the rc?.d directories to find which services are active, we now add paths to the active links in the initd_t astart_links and astop_links fields. These paths are relative to the init.d directory, e.g., ../rc1.d/S20foo.
2008-05-15New initd members: active start and stop symlinksDan Nicholson3-0/+14
When the rc?.d directories are walked, we'd like to cache the names of the links in addition to just flagging the active levels. The names can be used later when adding or removing links. To this effect, two new members have been added to initd_t: astart_links and astop_links.
2008-05-02rdep: Recurse and verify dependencies when removingDan Nicholson2-4/+93
Added a new function, initd_remove_recurse_deps, which verifies that the dependencies of the active services are still valid if specified services are removed. There is a bit of hackery to play with the active flags of the to-be-removed services and then restoring them. A new test program, tremove, has been added to exercise this function. It is basically the compliment to tverify (should be tinstall).
2008-05-01initd_copy: Also copy active start/kill levelsDan Nicholson1-0/+2
Forgot to add these before...
2008-05-01Rename initd_recurse_deps in preparation for removalDan Nicholson2-4/+4
Renamed initd_recurse_deps to initd_add_recurse_deps in anticipation of the recursive removal function, initd_remove_recurse_deps.
2008-05-01Change initd_sk_t enum to SK_{START,STOP} to differentiate from RCDan Nicholson3-15/+15
Made the enumerations for rc and sk clearer by changing the initd_sk_t names to SK_START and SK_STOP.
2008-05-01Set active levels after parsing from scriptsDan Nicholson1-0/+3
After parsing the init.d directory with initd_list_from_dir, we call initd_list_set_actives so it doesn't need to be explicitly called.
2008-04-29Merge branch 'master' into depsDan Nicholson1-25/+26
2008-04-29parse: Only convert rc token to integer when it's a single digitDan Nicholson1-25/+26
Parsing for the sysinit level in Default-Start/Stop was broken because the unconditional atoi() would result in a valid level 0 for any input. Now we check that the token is a single digit before converting it and skip on to the sysinit checks otherwise.
2008-04-29rdep: Verify the scripts for start/stop at each levelDan Nicholson2-0/+131
Added new function initd_list_verify_deps, which takes an ordered list of deps and verifies that they are valid for starting or stopping at each level. Currently, this is just called from initd_recurse_deps. The test program trdeps has been adjusted to set valid start and stop levels to exercise this functionality.
2008-04-26New utility function initd_rc_level_charDan Nicholson2-0/+37
Add the utility function initd_rc_level_char for converting an rc_t to a char.
2008-04-26Merge branch 'master' into depsDan Nicholson3-19/+24
Conflicts: lib/initd-list.c lib/initd.h
2008-04-26Constify more functionsDan Nicholson3-17/+20
2008-04-24rdep: Operate on provides rather than nameDan Nicholson1-16/+49
Services depend on each other by their provided services, not by their names.
2008-04-24Move initd_provides into initd.c where it belongsDan Nicholson2-20/+20
2008-04-24Make scripts implicitly provide their names as servicesDan Nicholson3-1/+15
Usually, a script will just provide the services listed in the Provides field in the LSB header. However, there may be cases where other scripts depend on it by its name, rather than by the service it provides. This adds the script's name to its provides member if it is not already included. This also solves the problem where we want to add a service by name, but the dep solver operates on provided services.
2008-04-23rdep: Append all active services to the requested servicesDan Nicholson1-4/+27
The final order of the dependencies matters when processing recursively as this will eventually determine the order of the S and K links. Since this may cause an unchanged link to become out of order when one of its dependents changes, we add all currently active services to the requested set. This should ensure that the final order is correct.
2008-04-23rdep: Convert to operating on initd listsDan Nicholson2-36/+37
The recursive deps function has been converted to operating on initd list structures instead of just dep lists. This will help when we start considering the "Provides" field instead of just the name.
2008-04-23Add RC_ALL macro to mask all RC levelsDan Nicholson1-0/+2
2008-04-23Add initd_is_active for checking if a script is activeDan Nicholson2-0/+23
Added the initd_is_active function for checking whether a script is active in a given level. A third parameter specifies whether it is a start or stop link.
2008-04-22Add push macros to mirror pop functionsDan Nicholson3-0/+4
Since push is the opposite of pop, macros have been added to alias the various add functions.
2008-04-22list: Add function initd_list_pop for removing last elementDan Nicholson2-0/+20
Added the initd_list_pop function for popping the last list element off an initd_list.