chkconfig/chkconfig-1.3.34-alternatives_fixlinks.patch

66 lines
2.1 KiB
Diff

diff -u chkconfig-1.3.34/alternatives.c chkconfig-1.3.34.patched/alternatives.c
--- chkconfig-1.3.34/alternatives.c 2006-09-07 20:58:40.000000000 +0200
+++ chkconfig-1.3.34.patched/alternatives.c 2007-08-03 18:26:31.000000000 +0200
@@ -376,20 +376,47 @@
}
static int makeLinks(struct linkSet * l, const char * altDir, int flags) {
- char * sl;
+ char * sl, * sol;
struct stat sb;
+ int stlen;
+
+ stlen = strlen(altDir) + strlen(l->title) + 2;
+
+ sl = alloca(stlen);
+ sol = alloca(stlen+1);
- sl = alloca(strlen(altDir) + strlen(l->title) + 2);
sprintf(sl, "%s/%s", altDir, l->title);
- if (lstat(l->facility, &sb)) {
+
+ if (lstat(l->facility, &sb) || S_ISLNK(sb.st_mode)) {
+
if (FL_TEST(flags)) {
printf(_("would link %s -> %s\n"), l->facility, sl);
} else {
-
- if (symlink(sl, l->facility)) {
+ if (S_ISLNK(sb.st_mode)) {
+ if ((stlen=readlink(l->facility,sol,stlen)) == -1)
+ fprintf(stderr, _("failed to read link %s: %s\n"),
+ l->facility, strerror(errno));
+ sol[stlen]='\0';
+
+ if (strcmp(sl,sol)) {
+ /* symlink is not correct, reset it */
+ if (unlink(l->facility) && errno != ENOENT){
+ fprintf(stderr, _("failed to remove link %s: %s\n"),
+ l->facility, strerror(errno));
+ return 1;
+ }
+ if (symlink(sl, l->facility)) {
fprintf(stderr, _("failed to link %s -> %s: %s\n"),
l->facility, sl, strerror(errno));
return 1;
+ }
+ }
+ } else {
+ if (symlink(sl, l->facility)) {
+ fprintf(stderr, _("failed to link %s -> %s: %s\n"),
+ l->facility, sl, strerror(errno));
+ return 1;
+ }
}
}
}
@@ -637,7 +664,7 @@
set.numAlts++;
}
- if (writeState(&set, altDir, stateDir, 0, flags)) return 2;
+ if (writeState(&set, altDir, stateDir, 1, flags)) return 2;
return 0;
}