| Message ID | 20250603134542.67627-2-andrea.ricchi@amarulasolutions.com |
|---|---|
| State | New |
| Headers |
Return-Path:
<linux-amarula+bncBCNLLXPH5QJRBEPZ7PAQMGQE57VVN2I@amarulasolutions.com>
X-Original-To: linux-amarula@patchwork.amarulasolutions.com
Delivered-To: linux-amarula@patchwork.amarulasolutions.com
Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com
[209.85.221.71])
by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 68CFC3F13D
for <linux-amarula@patchwork.amarulasolutions.com>;
Tue, 3 Jun 2025 15:45:54 +0200 (CEST)
Received: by mail-wr1-f71.google.com with SMTP id
ffacd0b85a97d-3a4f6ba526esf2986111f8f.1
for <linux-amarula@patchwork.amarulasolutions.com>;
Tue, 03 Jun 2025 06:45:54 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1748958354; cv=pass;
d=google.com; s=arc-20240605;
b=gvRfh6KN7YEVIuSNkaoMa2ZbOOO5XBMyQ9yPa8gDSLAuipYwitQ8vMjM4sOz+tK5k8
Ov62u5XYgvXQ6ecS4h8IIJJPl2XUa3bCdH/HsvDDb6aDYIb6PPgeWjHZOPhPf32p9ze3
eBacM7n0yf3GUEl8hCzgHVqD0/XChRjXaAiPoPi1a8H+G57wC1C3Tvopf+zBuabgjjzY
kkjGFwLPf+kpR6Y791LB7wJvC7LcfCcd5on8rUtqimvZoxWtZ+CPWwTRrKJC57m0aDRo
3qDwcbbd1VcuzhJHgR8p9hZkGk8KF//OW05BEFAOe9vjrXxU5SGsBEDfrCupgY6dR3jn
ug1w==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com;
s=arc-20240605;
h=list-unsubscribe:list-archive:list-help:list-post:list-id
:mailing-list:precedence:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:dkim-signature;
bh=J30T9VZ8Pd4IcKYY7+rYOxzkxC5G5XeBetut9UMCc3I=;
fh=Tc9V3T/BYEQhG1w84LCFKykQE8m048I59Gymh/N4tFg=;
b=GC6u3+ckzrhAVwF0ky6IdNxPRy+g5+EgKg5ScLfXrB/M7k3WBSJp9agLuHRmn1PhGY
bLmq5rVC9SCvXd2frB2aGKeTNUJX0sYgrfWNhDvXOCQnItE7D2/DE7ZlwSKnJMQMBZRP
QUW9zU0UNRXWERiJeG1hTlLv0RNo2oEp2euCHwSwAkQfPRXf6gDeFv0UmuSrFDP8thuO
uSMCZ4d+h8/TKzVyulobHefz5UvBBQ4Rv/79c9ZGXOQ+14q9BSnE8QxBKBeph+cX6QMy
QVSpQ9zhAnMc6HjDS6sXs2QumPQvI2l8U9EqErHE1gbWMkCpLtYBzRxaz5OfbWGBHx8j
huEw==;
darn=patchwork.amarulasolutions.com
ARC-Authentication-Results: i=2; mx.google.com;
dkim=pass header.i=@amarulasolutions.com header.s=google
header.b=YqSCn4Z9;
spf=pass (google.com: domain of andrea.ricchi@amarulasolutions.com
designates 209.85.220.41 as permitted sender)
smtp.mailfrom=andrea.ricchi@amarulasolutions.com;
dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com;
dara=pass header.i=@amarulasolutions.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=amarulasolutions.com; s=google; t=1748958354; x=1749563154;
darn=patchwork.amarulasolutions.com;
h=list-unsubscribe:list-archive:list-help:list-post:list-id
:mailing-list:precedence:x-original-authentication-results
:x-original-sender:mime-version:references:in-reply-to:message-id
:date:subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to;
bh=J30T9VZ8Pd4IcKYY7+rYOxzkxC5G5XeBetut9UMCc3I=;
b=TiEaXfeJyHGTzACZlPKpbzUd+ZoCFsBPiyU+5FFtPgzq/zPBLHtosRTcjv/bHHZdvo
FqTlg9Ni/NiiF90G/8fFH0e4rPK+zcdq70M2ezbTBdP0mVEMUsvHGV2NHus4GS5EWBa1
jbJdifw65abkJOyHbTz4+YhnHzqPtD5Irl8qg=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1748958354; x=1749563154;
h=list-unsubscribe:list-archive:list-help:list-post
:x-spam-checked-in-group:list-id:mailing-list:precedence
:x-original-authentication-results:x-original-sender:mime-version
:references:in-reply-to:message-id:date:subject:cc:to:from
:x-beenthere:x-gm-message-state:from:to:cc:subject:date:message-id
:reply-to;
bh=J30T9VZ8Pd4IcKYY7+rYOxzkxC5G5XeBetut9UMCc3I=;
b=QSEDyYK3GgdI+Ey776EyGJ8MMIp3VI6jNTHNHaWEgULHuw65qdNP8W5QqE4yR8CyLe
odxLO4R0H2f+H7qmf/0pxMZnq21sDPU7PFvIt+jsMwitl/1jMl9u3s21qVL9aNlSIJvL
jr9I0ruMtxyqXxnxS9lxBWmArWUqgYDGtH8xVUVgFs2sPOaD9CMJKoGQ1ZFUemsfOP9Q
9PMj7ReKaWssWNhIg9QnfJPjMmoD9lHI1CiSms/8KbG+tVOFcZvnVojOTUzIphArtgML
nHzrIFTORqhqsHCz6i/W/aQjs5DCVWiL9ujSO3W+WRPtbWR1T8i5gEMHxdO2sA2ehgov
scKA==
X-Forwarded-Encrypted: i=2;
AJvYcCUjeMGIEb7Jyuewn3/MkzcIdp8PhTGUj5zQMpXF6g+pshCP15DwML9MTJbdXLN5vS6gqtTUueiBgHLmn90u@patchwork.amarulasolutions.com
X-Gm-Message-State: AOJu0YyD0EU2oA1x7yKilHy9SaDby5UD6fpEcnOWqUyoT+k2r8Xv6o3r
Ax+iDWlU28bphdkvTqFW62zLdJm5QIUGBbWyJYtNDb+bvf6MSLVkULEUnktLrbHMpWrdlA==
X-Google-Smtp-Source:
AGHT+IHZ3eENgdszwZImPQ3Dah//8GoL8PofVsrI7gBhty+aiyGxnmCS3OUZu2rwQPIF4XhvajSIIQ==
X-Received: by 2002:a05:6000:4313:b0:3a4:dc0a:5c03 with SMTP id
ffacd0b85a97d-3a4f89d68a2mr14346926f8f.39.1748958353915;
Tue, 03 Jun 2025 06:45:53 -0700 (PDT)
X-BeenThere: linux-amarula@amarulasolutions.com;
h=AZMbMZfpNSl/nnF3Vf9CS1EBE5CKfKFeNDQi3GMllXnnXtjIsQ==
Received: by 2002:a05:600c:4e13:b0:43c:fb0f:d9ae with SMTP id
5b1f17b1804b1-450cebb5a83ls32113615e9.0.-pod-prod-05-eu; Tue, 03 Jun 2025
06:45:52 -0700 (PDT)
X-Forwarded-Encrypted: i=2;
AJvYcCX7sOCbT8T36IoDhbjtw1PgcXzjK8WM40cVhcFZUvVu+LHLEe/7ADXjaI8xJeD2lxbeU14z/T0uIO2pPpJH@amarulasolutions.com
X-Received: by 2002:a05:600c:3e83:b0:442:f8e7:25ef with SMTP id
5b1f17b1804b1-450d880c993mr151875595e9.11.1748958351819;
Tue, 03 Jun 2025 06:45:51 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1748958351; cv=none;
d=google.com; s=arc-20240605;
b=bMmfRPwrKEucVZYNw9mhzfq+5HuaECV4tngp9tQSGHBQcJG/5Gc5US8cauUwfEmcad
QLk5rjN3QjCmFKj+e6k533jeFbdsv/PNPrq5ZbDC2k1ReI9FYDcnW0PfUQoDL/jaOUX1
F2HTAiM9FGLaItj7iKXDs41JpXWvJzX2kNAJv8VUxTiexpXt4CkSNDmiTHQPsyXNWY/S
y/3dv9/eBCZsdBWNf2SytTTdWNz0sBh//A7w/AwRkEAsdE7ge7rtHXn6T3X+qJM5qC5c
XE3Rg+8nxgt0FKec8HYTp8C85dugv2FyX3+gdEOLl6pcWdc5I+4JgeNLmOgbtTyWCH1e
mPkQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;
s=arc-20240605;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:dkim-signature;
bh=xZzP51eVJYRSAvjqHR3U+vrKowTxxoMgdXUbX7xOG8g=;
fh=9rh2Fxctdk7FoIMtYx/pr0LCwvrI61xz5zSQ+qMP1ag=;
b=fs2Cu27daRQWEP2DSmjgcvyzpeBOl5WZil6BrP1ZwQlU+6+aPmP0hkO5It/F04tmEH
kt4M1OA5rJlAdMqKUuK4nz0pPC0cXydkYMioJPaHYZsCfpKUTOH6V29oPAT1JHeR1tH8
zDnP/POPrPMw/QB0yHA425i17gQZkVi7cDfTkze4uZ2LVxDySygm+5YBefE+5jVPUYAF
yiirnnYBUxz10aSz0hqfkHOsSIZ2fHY508OHKFC6K5EDkojx+/48XhmsggTRR+IeKcWr
ZJg4BN4Mb2sogr97pJn5jEIR+Uzco96EXp0m/cXTK1bTSkQtn8GbQNayedllaRZQWlE4
tHCw==;
dara=google.com
ARC-Authentication-Results: i=1; mx.google.com;
dkim=pass header.i=@amarulasolutions.com header.s=google
header.b=YqSCn4Z9;
spf=pass (google.com: domain of andrea.ricchi@amarulasolutions.com
designates 209.85.220.41 as permitted sender)
smtp.mailfrom=andrea.ricchi@amarulasolutions.com;
dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com;
dara=pass header.i=@amarulasolutions.com
Received: from mail-sor-f41.google.com (mail-sor-f41.google.com.
[209.85.220.41])
by mx.google.com with SMTPS id
5b1f17b1804b1-450d71f5b62sor36500605e9.10.2025.06.03.06.45.51
for <linux-amarula@amarulasolutions.com>
(Google Transport Security);
Tue, 03 Jun 2025 06:45:51 -0700 (PDT)
Received-SPF: pass (google.com: domain of andrea.ricchi@amarulasolutions.com
designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41;
X-Forwarded-Encrypted: i=1;
AJvYcCXp74xySY+dn9N+Q2E6qi9qaLMhU96IjCOJuW5JJmqEjsYsjbELjBnGpIQ8VLDTWTkjXcQg+IaykWeWLoCf@amarulasolutions.com
X-Gm-Gg: ASbGncssys60e1mc/bZt/1bbyiFe7JQMyy9mxGovdmivQdA6hw79tXT1zUU9/ORQ5Ib
axKih+i/YhPaPTu9Noyj7vGLzceChK9hz3Stg9fRsbmNN+f5e++/dxmzDVROVsGjV5IlHEYzCto
AS8RA8CmIqfNRz8LzyryrtdaQISK0a6GT/pMhs3L5WvKUy/4nkNzRg18SXZh+J9FIix4Gn73jed
PJ1zLyXdpcfslcEljo4/ZQgLQDqyrX4ifBLtyrypmPV+FpurFPOZ5sWnTmXKajHpaYgHGSQxCVp
swHBFLV5M1mnjzq5ziJ8vcRCG/LJ9Eju2RvEDe+gvAS1hPEGUTE9TT9JHsIsPOC7s5GELXMK7QA
yYkRZIQWlz+uZWLD1+btYIw==
X-Received: by 2002:a05:600c:4f87:b0:442:cd03:3e2 with SMTP id
5b1f17b1804b1-450d87fd991mr157437025e9.2.1748958351420;
Tue, 03 Jun 2025 06:45:51 -0700 (PDT)
Received: from localhost.localdomain
([2001:b07:6474:ebbf:a6f7:2a98:84af:9b39])
by smtp.gmail.com with ESMTPSA id
5b1f17b1804b1-450d8013e0esm161438535e9.39.2025.06.03.06.45.49
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Tue, 03 Jun 2025 06:45:50 -0700 (PDT)
From: Andrea Ricchi <andrea.ricchi@amarulasolutions.com>
To: connman@lists.linux.dev
Cc: denkenz@gmail.com,
linux-amarula@amarulasolutions.com,
michael@amarulasolutions.com,
jussi.laakkonen@jolla.com,
Andrea Ricchi <andrea.ricchi@amarulasolutions.com>
Subject: [PATCH v3 2/2] timezone: Replace Localtime file copy with symbolic
link
Date: Tue, 3 Jun 2025 15:45:42 +0200
Message-Id: <20250603134542.67627-2-andrea.ricchi@amarulasolutions.com>
X-Mailer: git-send-email 2.34.1
In-Reply-To: <20250603134542.67627-1-andrea.ricchi@amarulasolutions.com>
References: <20250603134542.67627-1-andrea.ricchi@amarulasolutions.com>
MIME-Version: 1.0
X-Original-Sender: andrea.ricchi@amarulasolutions.com
X-Original-Authentication-Results: mx.google.com; dkim=pass
header.i=@amarulasolutions.com header.s=google header.b=YqSCn4Z9;
spf=pass (google.com: domain of andrea.ricchi@amarulasolutions.com
designates 209.85.220.41 as permitted sender)
smtp.mailfrom=andrea.ricchi@amarulasolutions.com;
dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com;
dara=pass header.i=@amarulasolutions.com
Content-Type: text/plain; charset="UTF-8"
Precedence: list
Mailing-list: list linux-amarula@amarulasolutions.com;
contact linux-amarula+owners@amarulasolutions.com
List-ID: <linux-amarula.amarulasolutions.com>
X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com
X-Google-Group-Id: 476853432473
List-Post:
<https://groups.google.com/a/amarulasolutions.com/group/linux-amarula/post>,
<mailto:linux-amarula@amarulasolutions.com>
List-Help:
<https://support.google.com/a/amarulasolutions.com/bin/topic.py?topic=25838>,
<mailto:linux-amarula+help@amarulasolutions.com>
List-Archive:
<https://groups.google.com/a/amarulasolutions.com/group/linux-amarula/>
List-Unsubscribe:
<mailto:googlegroups-manage+476853432473+unsubscribe@googlegroups.com>,
<https://groups.google.com/a/amarulasolutions.com/group/linux-amarula/subscribe>
|
| Series |
[v3,1/2] Revert "timezone: Fix compare_file comparison in timezone checking"
|
|
Commit Message
Andrea Ricchi
June 3, 2025, 1:45 p.m. UTC
Based on the `man 5 localtime` documentation the `/etc/localtime`
file is expected to be a symbolic link, not a standalone
regular file.
This change replaces `write_file` with `write_symlink`, avoiding
unnecessary file I/O and memory mapping. It ensures Localtime accurately
reflects the selected timezone without duplicating data. This also
fixes `__connman_timezone_lookup()`, which requires Localtime to be a
symlink to function correctly.
Signed-off-by: Andrea Ricchi <andrea.ricchi@amarulasolutions.com>
---
Changes v2 -> v3:
- Splitted commit
Changes v1 -> v2:
- Change commit message
src/timezone.c | 49 +++++++++++++------------------------------------
1 file changed, 13 insertions(+), 36 deletions(-)
Comments
Hi Andrea, On 6/3/25 8:45 AM, Andrea Ricchi wrote: > Based on the `man 5 localtime` documentation the `/etc/localtime` > file is expected to be a symbolic link, not a standalone > regular file. > > This change replaces `write_file` with `write_symlink`, avoiding > unnecessary file I/O and memory mapping. It ensures Localtime accurately > reflects the selected timezone without duplicating data. This also > fixes `__connman_timezone_lookup()`, which requires Localtime to be a > symlink to function correctly. > > Signed-off-by: Andrea Ricchi <andrea.ricchi@amarulasolutions.com> nit: ConnMan doesn't use this tag, so please leave it out. > --- > > Changes v2 -> v3: > - Splitted commit > > Changes v1 -> v2: > - Change commit message > > src/timezone.c | 49 +++++++++++++------------------------------------ > 1 file changed, 13 insertions(+), 36 deletions(-) > > diff --git a/src/timezone.c b/src/timezone.c > index 89c44895..9b820477 100644 > --- a/src/timezone.c > +++ b/src/timezone.c > @@ -507,28 +507,20 @@ done: > return zone; > } > > -static int write_file(void *src_map, struct stat *src_st, const char *pathname) > +static int write_symlink(const char *target, const char *link) > { > struct stat st; > - int fd; > - ssize_t written; > > - DBG("pathname %s", pathname); > + DBG("pathname %s", link); > > - if (lstat(pathname, &st) == 0) { > - if (S_ISLNK(st.st_mode)) > - unlink(pathname); > + // Remove existing file or symlink if it exists No C++ style comments please > + if (lstat(link, &st) == 0) { > + if (S_ISLNK(st.st_mode) || S_ISREG(st.st_mode)) > + unlink(link); > } > > - fd = open(pathname, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); > - if (fd < 0) > - return -EIO; > - > - written = write(fd, src_map, src_st->st_size); > - > - close(fd); > - > - if (written < 0) > + // Create the symbolic link > + if (symlink(target, link) < 0) > return -EIO; > > return 0; > @@ -537,33 +529,18 @@ static int write_file(void *src_map, struct stat *src_st, const char *pathname) > int __connman_timezone_change(const char *zone) > { > struct stat st; > - char *map, pathname[PATH_MAX]; > - int fd, err; > + char pathname[PATH_MAX]; > + int err; > > DBG("zone %s", zone); > > snprintf(pathname, PATH_MAX, "%s/%s", USR_SHARE_ZONEINFO, zone); > It is really unlikely that the use of snprintf will cause problems, but generally its use along with PATH_MAX is discouraged. Given that this is off the hot path, I'd recommend using something like: g_autofree char *pathname = NULL; ... pathname = g_strdup_printf("%s/%s", USR_SHARE_ZONEINFO, zone); > - fd = open(pathname, O_RDONLY | O_CLOEXEC); > - if (fd < 0) > + // Just check that the file exists and is a regular file C++ comments again :) > + if (stat(pathname, &st) < 0 || !S_ISREG(st.st_mode)) > return -EINVAL; > > - if (fstat(fd, &st) < 0) { > - close(fd); > - return -EIO; > - } > - > - map = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0); > - if (!map || map == MAP_FAILED) { > - close(fd); > - return -EIO; > - } > - > - err = write_file(map, &st, connman_setting_get_string("Localtime")); > - > - munmap(map, st.st_size); > - > - close(fd); > + err = write_symlink(pathname, connman_setting_get_string("Localtime")); Might as well just use: return write_symlink(...) and drop 'err' variable entirely. > > return err; > } Regards, -Denis To unsubscribe from this group and stop receiving emails from it, send an email to linux-amarula+unsubscribe@amarulasolutions.com.
diff --git a/src/timezone.c b/src/timezone.c index 89c44895..9b820477 100644 --- a/src/timezone.c +++ b/src/timezone.c @@ -507,28 +507,20 @@ done: return zone; } -static int write_file(void *src_map, struct stat *src_st, const char *pathname) +static int write_symlink(const char *target, const char *link) { struct stat st; - int fd; - ssize_t written; - DBG("pathname %s", pathname); + DBG("pathname %s", link); - if (lstat(pathname, &st) == 0) { - if (S_ISLNK(st.st_mode)) - unlink(pathname); + // Remove existing file or symlink if it exists + if (lstat(link, &st) == 0) { + if (S_ISLNK(st.st_mode) || S_ISREG(st.st_mode)) + unlink(link); } - fd = open(pathname, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644); - if (fd < 0) - return -EIO; - - written = write(fd, src_map, src_st->st_size); - - close(fd); - - if (written < 0) + // Create the symbolic link + if (symlink(target, link) < 0) return -EIO; return 0; @@ -537,33 +529,18 @@ static int write_file(void *src_map, struct stat *src_st, const char *pathname) int __connman_timezone_change(const char *zone) { struct stat st; - char *map, pathname[PATH_MAX]; - int fd, err; + char pathname[PATH_MAX]; + int err; DBG("zone %s", zone); snprintf(pathname, PATH_MAX, "%s/%s", USR_SHARE_ZONEINFO, zone); - fd = open(pathname, O_RDONLY | O_CLOEXEC); - if (fd < 0) + // Just check that the file exists and is a regular file + if (stat(pathname, &st) < 0 || !S_ISREG(st.st_mode)) return -EINVAL; - if (fstat(fd, &st) < 0) { - close(fd); - return -EIO; - } - - map = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0); - if (!map || map == MAP_FAILED) { - close(fd); - return -EIO; - } - - err = write_file(map, &st, connman_setting_get_string("Localtime")); - - munmap(map, st.st_size); - - close(fd); + err = write_symlink(pathname, connman_setting_get_string("Localtime")); return err; }