aboutsummaryrefslogtreecommitdiff
path: root/rcynic/rcynic.c
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2011-10-14 21:18:34 +0000
committerRob Austein <sra@hactrn.net>2011-10-14 21:18:34 +0000
commitd93ab207f73efa0ce208aba8778e4a5aaf8e5689 (patch)
tree7dc9398ac336a6caad69c4a49ef9c727124c33bf /rcynic/rcynic.c
parentdfd93950a5386e6cb38f9ba56fee872655f91ce2 (diff)
Add authenticated.old symlink for convenience of programs attempting
to understand rcynic's output. svn path=/trunk/; revision=4043
Diffstat (limited to 'rcynic/rcynic.c')
-rw-r--r--rcynic/rcynic.c48
1 files changed, 30 insertions, 18 deletions
diff --git a/rcynic/rcynic.c b/rcynic/rcynic.c
index 904e5f4b..6869a72b 100644
--- a/rcynic/rcynic.c
+++ b/rcynic/rcynic.c
@@ -1274,9 +1274,8 @@ static int construct_directory_names(rcynic_ctx_t *rc)
*/
static int finalize_directories(const rcynic_ctx_t *rc)
{
- path_t path, sym, real_old, real_new;
+ path_t path, real_old, real_new;
const char *dir;
- size_t n;
glob_t g;
int i;
@@ -1284,38 +1283,51 @@ static int finalize_directories(const rcynic_ctx_t *rc)
real_old.s[0] = '\0';
if (!realpath(rc->new_authenticated.s, real_new.s))
- real_old.s[0] = '\0';
-
- path = rc->new_authenticated;
+ real_new.s[0] = '\0';
- n = strlen(path.s);
- assert(n > 1 && path.s[n - 1] == '/');
- path.s[n - 1] = '\0';
+ assert(real_new.s[0] && real_new.s[strlen(real_new.s) - 1] != '/');
- if ((dir = strrchr(path.s, '/')) == NULL)
- dir = path.s;
+ if ((dir = strrchr(real_new.s, '/')) == NULL)
+ dir = real_new.s;
else
dir++;
- sym = rc->authenticated;
+ path = rc->authenticated;
- assert(strlen(sym.s) + sizeof(authenticated_symlink_suffix) < sizeof(sym.s));
- strcat(sym.s, authenticated_symlink_suffix);
+ if (strlen(path.s) + sizeof(authenticated_symlink_suffix) >= sizeof(path.s))
+ return 0;
+ strcat(path.s, authenticated_symlink_suffix);
- (void) unlink(sym.s);
+ (void) unlink(path.s);
- if (symlink(dir, sym.s) < 0) {
+ if (symlink(dir, path.s) < 0) {
logmsg(rc, log_sys_err, "Couldn't link %s to %s: %s",
- sym.s, dir, strerror(errno));
+ path.s, dir, strerror(errno));
return 0;
}
- if (rename(sym.s, rc->authenticated.s) < 0) {
+ if (rename(path.s, rc->authenticated.s) < 0) {
logmsg(rc, log_sys_err, "Couldn't rename %s to %s: %s",
- sym.s, rc->authenticated.s, strerror(errno));
+ path.s, rc->authenticated.s, strerror(errno));
return 0;
}
+ if (real_old.s[0] && strlen(rc->authenticated.s) + sizeof(".old") < sizeof(path.s)) {
+ assert(real_old.s[strlen(real_old.s) - 1] != '/');
+
+ path = rc->authenticated;
+ strcat(path.s, ".old");
+
+ (void) unlink(path.s);
+
+ if ((dir = strrchr(real_old.s, '/')) == NULL)
+ dir = real_old.s;
+ else
+ dir++;
+
+ (void) symlink(dir, path.s);
+ }
+
path = rc->authenticated;
assert(strlen(path.s) + sizeof(".*") < sizeof(path.s));
strcat(path.s, ".*");