Commit 53d719c3 authored by Rasmus Thomsen's avatar Rasmus Thomsen

community/openrc-settingsd: fix setting /etc/localtime if its a symlink

fixes #11616
parent 8fcf08cd
Upstream: No, upstream is dead unfortunately
From c72e431ba98990c34cce0b87231bd0092586955c Mon Sep 17 00:00:00 2001
From: Rasmus Thomsen <oss@cogitri.dev>
Date: Sat, 6 Jun 2020 12:37:12 +0200
Subject: [PATCH] Make /etc/localtime a symlink if it doesn't exist yet or
already is a symlink
Previously we always tried to write the contents of the file in
/usr/share/zoneinfo to /etc/localtime, but that doesn't work if it
doesn't exist or if /etc/localtime is a symlink. As such, we should just
make it a symlink if it doesn't exist or already is one.
---
src/timedated.c | 34 +++++++++++++++++++++++++++-------
1 file changed, 27 insertions(+), 7 deletions(-)
diff --git a/src/timedated.c b/src/timedated.c
index 07c29da..a3402b1 100644
--- a/src/timedated.c
+++ b/src/timedated.c
@@ -139,13 +139,33 @@ set_timezone (const gchar *_timezone_name,
localtime_filename = g_file_get_path (localtime_file);
localtime2_filename = g_strdup_printf (DATADIR "/zoneinfo/%s", _timezone_name);
localtime2_file = g_file_new_for_path (localtime2_filename);
- if (!g_file_load_contents (localtime2_file, NULL, &filebuf, &length, NULL, error)) {
- g_prefix_error (error, "Unable to read '%s':", localtime2_filename);
- goto out;
- }
- if (!g_file_replace_contents (localtime_file, filebuf, length, NULL, FALSE, 0, NULL, NULL, error)) {
- g_prefix_error (error, "Unable to write '%s':", localtime_filename);
- goto out;
+
+ if (g_file_test(localtime_filename, G_FILE_TEST_IS_SYMLINK)) {
+ if (!g_file_delete (localtime_file, NULL, error)) {
+ g_prefix_error (error, "Unable to delete file to make new symlink %s:", localtime_filename);
+ goto out;
+ }
+ if (!g_file_make_symbolic_link (localtime_file, localtime2_filename, NULL, error)) {
+ g_error("Failed to make symlink %s", (*error)->message);
+ g_prefix_error (error, "Unable to create symlink %s -> %s:", localtime_filename, localtime2_filename);
+ goto out;
+ }
+ } else if (g_file_test(localtime_filename, G_FILE_TEST_IS_REGULAR)) {
+ if (!g_file_load_contents (localtime2_file, NULL, &filebuf, &length, NULL, error)) {
+ g_prefix_error (error, "Unable to read '%s':", localtime2_filename);
+ goto out;
+ }
+ if (!g_file_replace_contents (localtime_file, filebuf, length, NULL, FALSE, 0, NULL, NULL, error)) {
+ g_prefix_error (error, "Unable to write '%s':", localtime_filename);
+ goto out;
+ }
+ } else {
+ // File doesn't exist yet -> make a new symlink
+ if (!g_file_make_symbolic_link (localtime_file, localtime2_filename, NULL, error)) {
+ g_error("Failed to make symlink %s", (*error)->message);
+ g_prefix_error (error, "Unable to create symlink %s -> %s:", localtime_filename, localtime2_filename);
+ goto out;
+ }
}
ret = TRUE;
--
2.27.0
......@@ -2,7 +2,7 @@
# Maintainer: Rasmus Thomsen <oss@cogitri.dev>
pkgname=openrc-settingsd
pkgver=1.0.1
pkgrel=3
pkgrel=4
pkgdesc="System settings D-Bus service for OpenRC"
url="https://gitweb.gentoo.org/proj/openrc-settingsd.git"
arch="all"
......@@ -12,7 +12,9 @@ makedepends="glib-dev dbus-dev openrc-dev polkit-dev libdaemon-dev automake auto
libtool bash"
subpackages="$pkgname-doc $pkgname-openrc"
source="https://gitweb.gentoo.org/proj/openrc-settingsd.git/snapshot/openrc-settingsd-$pkgver.tar.gz
use-profiled-instead-of-envd.patch"
use-profiled-instead-of-envd.patch
0001-Make-etc-localtime-a-symlink-if-it-doesn-t-exist-yet.patch
"
prepare() {
default_prepare
......@@ -43,4 +45,5 @@ package() {
}
sha512sums="bca589de7d2c96d8d15d93882b7296523a0d6301fe1d33f7fc03386544b5c050f2d819b9e1f005ee10a794883175ea1b1172411aad3598f967a6a5677a5c4aad openrc-settingsd-1.0.1.tar.gz
d06d691c1ef52c0e4c5d68ad7d25eba73ad8fffa3d3675f5c79ff93808131c11f4dbbd13db64c463bb87ec8ebed143878703ba281e1241947d66fcad48063e56 use-profiled-instead-of-envd.patch"
d06d691c1ef52c0e4c5d68ad7d25eba73ad8fffa3d3675f5c79ff93808131c11f4dbbd13db64c463bb87ec8ebed143878703ba281e1241947d66fcad48063e56 use-profiled-instead-of-envd.patch
7ea84475fe6558d7b26726eefd452e89cb407a9e9beeff70163c1ec1f236988ae0b7e85644ca2baad7238d0c304bc54d899889605dd08e5cc60cbaf8b5e9abe5 0001-Make-etc-localtime-a-symlink-if-it-doesn-t-exist-yet.patch"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment