run: When creating /etc symlinks, don't make symlinks to symlinks

Instead we just copy the original symlink. This makes things like
/etc/localtime symlink value parsing work.
tingping/wmclass
Alexander Larsson 2015-09-21 10:43:10 +02:00
parent f22c0edfd8
commit 3334c08f6e
1 changed files with 29 additions and 6 deletions

View File

@ -1368,21 +1368,44 @@ link_extra_etc_dirs ()
{
char *dst_path;
char *src_path;
char *target;
struct stat st;
src_path = strconcat ("etc/", dirent->d_name);
if (stat (src_path, &st) == 0)
if (lstat (src_path, &st) == 0)
{
free (src_path);
continue;
}
dst_path = strconcat ("/usr/etc/", dirent->d_name);
if (symlink (dst_path, src_path) != 0)
die_with_error ("symlink %s", src_path);
dst_path = strconcat ("usr/etc/", dirent->d_name);
if (lstat (dst_path, &st) != 0)
{
free (src_path);
free (dst_path);
continue;
}
free (dst_path);
free (src_path);
/* For symlinks we copy the actual symlink value, to correctly handle
things like /etc/localtime symlinks */
if (S_ISLNK (st.st_mode))
{
ssize_t r;
target = xmalloc (st.st_size + 1);
r = readlink (dst_path, target, st.st_size + 1);
if (r == -1)
die_with_error ("readlink %s", dst_path);
}
else
target = strconcat ("/usr/etc/", dirent->d_name);
if (symlink (target, src_path) != 0)
die_with_error ("symlink %s", src_path);
free (dst_path);
free (src_path);
free (target);
}
}
}