diff options
author | Dan Nicholson <dbn.lists@gmail.com> | 2008-06-12 02:41:12 -0700 |
---|---|---|
committer | Dan Nicholson <dbn.lists@gmail.com> | 2008-06-12 02:41:12 -0700 |
commit | 339b2f23accfab28dc1a255f75fb69b52657bf18 (patch) | |
tree | f859cf82cebca84348a0bba4ef40a814dd4c4699 | |
parent | 1cc0d042fb265bc429800f6e645ce997cbb05de9 (diff) |
Create the rc*.d directories if necessary when creating links
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.
-rw-r--r-- | lib/installrm.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/installrm.c b/lib/installrm.c index 9ab9fdc..22fa4db 100644 --- a/lib/installrm.c +++ b/lib/installrm.c @@ -98,8 +98,20 @@ static void install_level_links(const initd_list_t *ilp, #endif /* Change to the rc directory */ - if (chdir(dir) != 0) - error(1, errno, "%s", dir); + if (chdir(dir) < 0) { + /* Create it if it doesn't exist */ + if (errno == ENOENT) { + errno = 0; + mode_t dirmode = (S_IRWXU|S_IRWXG|S_IRWXO); + if (mkdir(dir, dirmode) < 0) + error(1, errno, "%s", dir); + /* Change to the created directory */ + if (chdir(dir) < 0) + error(1, errno, "%s", dir); + } else { + error(1, errno, "%s", dir); + } + } /* First remove existing links, beginning with the head of the * list for start links. */ |