Fix boot sequence errors, enable instant Chrony online sync, and add timezone UI

- Boot sequence cleanups:
  - Scope ModemManager's musl shared-plugin LD_PRELOAD to the child daemon via
    supervise_daemon_args="--env LD_PRELOAD=..." so OpenRC helpers and plugins
    start cleanly with zero "symbol not found" errors.
  - Link XLibre fbdev_drv.so against libfbdevhw.so and libshadow.so, pin
    libxfont2 in rootfs-packages.txt, populate /usr/share/fonts/*/fonts.dir,
    provide XKeysymDB entries, create ~/.cache before dmenu_run, disable TearFree
    for ShadowFB modesetting, and avoid D-Bus autolaunch collision with
    ModemManager.
  - Enable CONFIG_SYN_COOKIES=y and disable IPMI_HANDLER in
    geminux-mt6797x.config, add /etc/sysctl.d/00-alpine.conf, drop x86
    kernel.nmi_watchdog from 99-geminux-power.conf, and disable module
    load/unload in zram-init for built-in zram.
  - Add MT6797 ALSA UCM2 DL2/DL3/UL2/UL3/UL_MONO_1 backend DAI routes in
    HiFi.conf and apply 0006-mt6797-boot-cleanups.patch (stk3310 ID 0x11,
    mt6797-fm firmware search path, mt6797_mac_wq, and pre-auth TX abort).
- Chrony immediate online time sync:
  - Enable FAST_STARTUP, configure makestep 1.0 -1 with sourcedir
    /etc/chrony/sources.d, and trigger burst/waitsync/makestep/hwclock on
    NetworkManager interface up via 30-geminux-chrony.
- Date, Time & Timezone UI:
  - Add geminux-datetime libgemui X11 utility with zoneinfo browser, live
    search, region filters, and NTP sync trigger.
  - Add doas-authorized geminux-tzctl helper with zoneinfo validation and
    update geminux-statusd to reload /etc/timezone cleanly under musl.
This commit is contained in:
Luxferre committed 2026-11-22 23:34:44 +02:00
1 parent 6aea73cbeb
commit 8843558f3b
65 files changed
+1060 -37

No files matched your search

+2 -3
View File
@@ -566,9 +566,8 @@ CONFIG_INPUT_FF_MEMLESS=y
CONFIG_INPUT_PWM_BEEPER=y CONFIG_INPUT_PWM_BEEPER=y
CONFIG_INPUT_PWM_VIBRA=y CONFIG_INPUT_PWM_VIBRA=y
CONFIG_INPUT_SPARSEKMAP=y CONFIG_INPUT_SPARSEKMAP=y
CONFIG_IPMI_DEVICE_INTERFACE=y # CONFIG_IPMI_HANDLER is not set
CONFIG_IPMI_HANDLER=y CONFIG_SYN_COOKIES=y
CONFIG_IPMI_SI=y
CONFIG_IR_GPIO_CIR=y CONFIG_IR_GPIO_CIR=y
CONFIG_KEYBOARD_GPIO_POLLED=y CONFIG_KEYBOARD_GPIO_POLLED=y
CONFIG_KEYBOARD_MTK_PMIC=y CONFIG_KEYBOARD_MTK_PMIC=y
@@ -0,0 +1,23 @@
#!/bin/sh
# Trigger immediate Chrony DNS re-resolution, rapid burst, and clock/RTC step upon getting online.
IFACE="${1:-}"
ACTION="${2:-}"
[ "$IFACE" = "lo" ] && exit 0
case "$ACTION" in
up|dhcp4-change|dhcp6-change|connectivity-change)
(
ip route show default 2>/dev/null | grep -q '^default ' || exit 0
rc-service chronyd status >/dev/null 2>&1 || rc-service chronyd start >/dev/null 2>&1 || true
chronyc reload sources >/dev/null 2>&1 || true
chronyc online >/dev/null 2>&1 || true
chronyc burst 4/4 >/dev/null 2>&1 || true
chronyc waitsync 20 0 0 0.5 >/dev/null 2>&1 || true
chronyc makestep >/dev/null 2>&1 || true
hwclock -w -u >/dev/null 2>&1 || true
pkill -USR1 geminux-statusd 2>/dev/null || true
) >/dev/null 2>&1 &
;;
esac
exit 0
@@ -5,6 +5,7 @@ Section "OutputClass"
Option "PrimaryGPU" "true" Option "PrimaryGPU" "true"
Option "SWcursor" "true" Option "SWcursor" "true"
Option "AccelMethod" "none" Option "AccelMethod" "none"
Option "TearFree" "false"
Option "ShadowFB" "true" Option "ShadowFB" "true"
Option "PageFlip" "false" Option "PageFlip" "false"
EndSection EndSection
@@ -16,6 +17,7 @@ Section "OutputClass"
Option "PrimaryGPU" "true" Option "PrimaryGPU" "true"
Option "SWcursor" "true" Option "SWcursor" "true"
Option "AccelMethod" "none" Option "AccelMethod" "none"
Option "TearFree" "false"
Option "ShadowFB" "true" Option "ShadowFB" "true"
Option "PageFlip" "false" Option "PageFlip" "false"
EndSection EndSection
+9
View File
@@ -0,0 +1,9 @@
confdir /etc/chrony/conf.d
sourcedir /etc/chrony/sources.d
driftfile /var/lib/chrony/chrony.drift
ntsdumpdir /var/lib/chrony
logdir /var/log/chrony
maxupdateskew 100.0
rtcsync
makestep 1.0 -1
cmdport 0
@@ -0,0 +1,2 @@
pool pool.ntp.org iburst maxpoll 10
pool time.cloudflare.com iburst maxpoll 10
+1
View File
@@ -0,0 +1 @@
FAST_STARTUP="yes"
+4
View File
@@ -0,0 +1,4 @@
MM_SHARED="/usr/lib/ModemManager/libmm-shared-fibocom.so:/usr/lib/ModemManager/libmm-shared-foxconn.so:/usr/lib/ModemManager/libmm-shared-icera.so:/usr/lib/ModemManager/libmm-shared-mtk.so:/usr/lib/ModemManager/libmm-shared-novatel.so:/usr/lib/ModemManager/libmm-shared-option.so:/usr/lib/ModemManager/libmm-shared-quectel.so:/usr/lib/ModemManager/libmm-shared-sierra.so:/usr/lib/ModemManager/libmm-shared-telit.so:/usr/lib/ModemManager/libmm-shared-xmm.so"
supervise_daemon_args="--env LD_PRELOAD=${MM_SHARED}"
output_log="/var/log/modemmanager.log"
error_log="/var/log/modemmanager.log"
+3
View File
@@ -1 +1,4 @@
rc_need="polkit" rc_need="polkit"
rc_after="modemmanager"
output_log="/var/log/networkmanager.log"
error_log="/var/log/networkmanager.log"
+2 -2
View File
@@ -1,6 +1,6 @@
# ZRAM swap configuration for Geminux (2 GiB LZ4 hardware-friendly compressed swap) # ZRAM swap configuration for Geminux (2 GiB LZ4 hardware-friendly compressed swap)
load_on_start=yes load_on_start=no
unload_on_stop=yes unload_on_stop=no
num_devices=1 num_devices=1
type0=swap type0=swap
@@ -1,5 +1,6 @@
permit persist :wheel permit persist :wheel
permit nopass :wheel as root cmd /usr/bin/geminux-power-ctl permit nopass :wheel as root cmd /usr/bin/geminux-power-ctl
permit nopass :wheel as root cmd /usr/sbin/geminux-checkpw permit nopass :wheel as root cmd /usr/sbin/geminux-checkpw
permit nopass :wheel as root cmd /usr/sbin/geminux-tzctl
permit nopass :wheel as root cmd /sbin/poweroff permit nopass :wheel as root cmd /sbin/poweroff
permit nopass :wheel as root cmd /sbin/reboot permit nopass :wheel as root cmd /sbin/reboot
@@ -0,0 +1,17 @@
# Geminux override of /usr/lib/sysctl.d/00-alpine.conf
# (net.ipv4.tcp_syncookies defaults to 1 via CONFIG_SYN_COOKIES=y)
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.ping_group_range = 999 59999
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.secure_redirects = 1
net.ipv6.conf.all.accept_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv6.conf.all.accept_source_route = 0
net.ipv4.tcp_rfc1337 = 1
net.ipv6.conf.default.use_tempaddr = 2
net.ipv6.conf.all.use_tempaddr = 2
kernel.panic = 120
fs.protected_hardlinks = 1
fs.protected_symlinks = 1
kernel.unprivileged_bpf_disabled = 1
@@ -4,4 +4,3 @@ vm.page-cluster = 0
vm.dirty_writeback_centisecs = 1500 vm.dirty_writeback_centisecs = 1500
vm.dirty_expire_centisecs = 3000 vm.dirty_expire_centisecs = 3000
vm.vfs_cache_pressure = 50 vm.vfs_cache_pressure = 50
kernel.nmi_watchdog = 0
+1 -1
View File
@@ -33,7 +33,7 @@ fi
# Signal live applications (dwm, st, libgemui apps) to reload .Xresources via SIGUSR1 # Signal live applications (dwm, st, libgemui apps) to reload .Xresources via SIGUSR1
for proc in dwm st geminux-dialer geminux-callscreen geminux-sms geminux-contacts \ for proc in dwm st geminux-dialer geminux-callscreen geminux-sms geminux-contacts \
geminux-net geminux-camera geminux-control geminux-themes geminux-lock; do geminux-net geminux-audio geminux-camera geminux-control geminux-datetime geminux-themes geminux-lock; do
for pid in $(pidof "$proc" 2>/dev/null || true); do for pid in $(pidof "$proc" 2>/dev/null || true); do
kill -USR1 "$pid" 2>/dev/null || true kill -USR1 "$pid" 2>/dev/null || true
done done
+1
View File
@@ -27,6 +27,7 @@ LAUNCHER_LIST="
󰕾 Sound & Mixer|geminux-audio 󰕾 Sound & Mixer|geminux-audio
 Camera|geminux-camera  Camera|geminux-camera
 Control Center|geminux-control  Control Center|geminux-control
󰥔 Date & Timezone|geminux-datetime
 Themes|geminux-themes  Themes|geminux-themes
 Lock Screen|geminux-lock  Lock Screen|geminux-lock
󰤄 Suspend Now|doas /usr/bin/geminux-power-ctl suspend 󰤄 Suspend Now|doas /usr/bin/geminux-power-ctl suspend
+1
View File
@@ -7,6 +7,7 @@ if [ -z "${DBUS_SESSION_BUS_ADDRESS:-}" ] && command -v dbus-run-session >/dev/n
fi fi
HOME_DIR="${HOME:-/home/user}" HOME_DIR="${HOME:-/home/user}"
mkdir -p "$HOME_DIR/.cache"
if [ -r /etc/profile.d/10-geminux-env.sh ]; then if [ -r /etc/profile.d/10-geminux-env.sh ]; then
. /etc/profile.d/10-geminux-env.sh . /etc/profile.d/10-geminux-env.sh
fi fi
+5
View File
@@ -0,0 +1,5 @@
XF86ElectronicPrivacyScreenOn :10081276
XF86ElectronicPrivacyScreenOff :10081277
XF86ActionOnSelection :10081278
XF86ContextualInsert :10081279
XF86ContextualQuery :1008127A
@@ -4,12 +4,21 @@ SectionVerb {
EnableSequence [ EnableSequence [
cset "name='ADDA_DL_CH1 DL1_CH1' on" cset "name='ADDA_DL_CH1 DL1_CH1' on"
cset "name='ADDA_DL_CH2 DL1_CH2' on" cset "name='ADDA_DL_CH2 DL1_CH2' on"
cset "name='ADDA_DL_CH1 DL2_CH1' on"
cset "name='ADDA_DL_CH2 DL2_CH2' on"
cset "name='ADDA_DL_CH1 DL3_CH1' on"
cset "name='ADDA_DL_CH2 DL3_CH2' on"
cset "name='DAC In Mux' 'Normal Path'" cset "name='DAC In Mux' 'Normal Path'"
cset "name='HPL Mux' 'Audio Playback'" cset "name='HPL Mux' 'Audio Playback'"
cset "name='HPR Mux' 'Audio Playback'" cset "name='HPR Mux' 'Audio Playback'"
cset "name='Headphone Volume' 14,14" cset "name='Headphone Volume' 14,14"
cset "name='UL1_CH1 ADDA_UL_CH1' on" cset "name='UL1_CH1 ADDA_UL_CH1' on"
cset "name='UL1_CH2 ADDA_UL_CH2' on" cset "name='UL1_CH2 ADDA_UL_CH2' on"
cset "name='UL2_CH1 ADDA_UL_CH1' on"
cset "name='UL2_CH2 ADDA_UL_CH2' on"
cset "name='UL3_CH1 ADDA_UL_CH1' on"
cset "name='UL3_CH2 ADDA_UL_CH2' on"
cset "name='UL_MONO_1_CH1 ADDA_UL_CH1' on"
cset "name='AIF Out Mux' 'Normal Path'" cset "name='AIF Out Mux' 'Normal Path'"
cset "name='ADC L Mux' 'Left Preamplifier'" cset "name='ADC L Mux' 'Left Preamplifier'"
cset "name='ADC R Mux' 'Right Preamplifier'" cset "name='ADC R Mux' 'Right Preamplifier'"
@@ -28,8 +37,17 @@ SectionVerb {
cset "name='ADC R Mux' 'Idle'" cset "name='ADC R Mux' 'Idle'"
cset "name='ADDA_DL_CH1 DL1_CH1' off" cset "name='ADDA_DL_CH1 DL1_CH1' off"
cset "name='ADDA_DL_CH2 DL1_CH2' off" cset "name='ADDA_DL_CH2 DL1_CH2' off"
cset "name='ADDA_DL_CH1 DL2_CH1' off"
cset "name='ADDA_DL_CH2 DL2_CH2' off"
cset "name='ADDA_DL_CH1 DL3_CH1' off"
cset "name='ADDA_DL_CH2 DL3_CH2' off"
cset "name='UL1_CH1 ADDA_UL_CH1' off" cset "name='UL1_CH1 ADDA_UL_CH1' off"
cset "name='UL1_CH2 ADDA_UL_CH2' off" cset "name='UL1_CH2 ADDA_UL_CH2' off"
cset "name='UL2_CH1 ADDA_UL_CH1' off"
cset "name='UL2_CH2 ADDA_UL_CH2' off"
cset "name='UL3_CH1 ADDA_UL_CH1' off"
cset "name='UL3_CH2 ADDA_UL_CH2' off"
cset "name='UL_MONO_1_CH1 ADDA_UL_CH1' off"
] ]
} }
@@ -0,0 +1,117 @@
--- a/drivers/iio/light/stk3310.c
+++ b/drivers/iio/light/stk3310.c
@@ -53,6 +53,7 @@
#define STK3311A_CHIP_ID_VAL 0x15
#define STK3311S34_CHIP_ID_VAL 0x1E
#define STK3311X_CHIP_ID_VAL 0x12
+#define STK3331_CHIP_ID_VAL 0x11
#define STK3335_CHIP_ID_VAL 0x51
#define STK3310_PSINT_EN 0x01
#define STK3310_PS_MAX_VAL 0xFFFF
@@ -101,6 +102,7 @@
STK3311S34_CHIP_ID_VAL,
STK3311X_CHIP_ID_VAL,
STK3311_CHIP_ID_VAL,
+ STK3331_CHIP_ID_VAL,
STK3335_CHIP_ID_VAL,
};
--- a/drivers/media/radio/radio-mt6797.c
+++ b/drivers/media/radio/radio-mt6797.c
@@ -640,7 +640,7 @@
unsigned int count, i, n;
int ret;
- ret = request_firmware(&fw, name, fm->dev);
+ ret = firmware_request_nowarn(&fw, name, fm->dev);
if (ret)
return ret;
sha256(fw->data, fw->size, digest);
@@ -965,9 +965,21 @@
/* Mutex held. First open. */
static int mt6797_fm_on(struct mt6797_fm *fm)
{
+ const struct firmware *fw = NULL;
u16 id = 0;
int ret;
+ /* Fail open without waking CONSYS WMT when optional FM blobs are absent. */
+ ret = firmware_request_nowarn(&fw, FM_PATCH_NAME, fm->dev);
+ if (ret)
+ return ret;
+ release_firmware(fw);
+ fw = NULL;
+ ret = firmware_request_nowarn(&fw, FM_COEFF_NAME, fm->dev);
+ if (ret)
+ return ret;
+ release_firmware(fw);
+
fm->bytes = 0;
fm->events = 0;
fm->unexpected = 0;
--- a/drivers/net/wireless/mediatek/mt6797/main.c
+++ b/drivers/net/wireless/mediatek/mt6797/main.c
@@ -25,7 +25,7 @@
disable_irq_nosync(irq);
atomic_set(&mac->irq_masked, 1);
- mod_delayed_work(system_wq, &mac->join_work, 0);
+ mod_delayed_work(system_percpu_wq, &mac->join_work, 0);
return IRQ_HANDLED;
}
@@ -1561,16 +1561,45 @@
bool admitted;
mutex_lock(&mac->mutex);
- if (mac->join_cleanup_requested || mac->join_cleanup_done) {
- /* mac80211's own deauthentication or disassociation during the
- * data phase (the supplicant or userspace disconnecting) ends the
- * phase; the driver-owned deauthentication goes out and mac80211's
- * frame is not admitted by the queue gate.
- */
- if (vif == mac->vif && mac->join_data_phase && !mac->join_data_ended &&
- (info->subtype == IEEE80211_STYPE_DEAUTH ||
- info->subtype == IEEE80211_STYPE_DISASSOC))
+ if (vif == mac->vif &&
+ (info->subtype == IEEE80211_STYPE_DEAUTH ||
+ info->subtype == IEEE80211_STYPE_DISASSOC)) {
+ struct sk_buff_head discard;
+ struct sk_buff *skb, *tmp;
+
+ skb_queue_head_init(&discard);
+ spin_lock_irqsave(&mac->join_queue.lock, flags);
+ mac->join_open = false;
+ mac->join_tx_allowed = 0;
+ skb_queue_walk_safe(&mac->join_queue, skb, tmp) {
+ if (skb == mac->join_internal)
+ continue;
+ __skb_unlink(skb, &mac->join_queue);
+ mac->join_queue_bytes -= skb->len;
+ __skb_queue_tail(&discard, skb);
+ }
+ spin_unlock_irqrestore(&mac->join_queue.lock, flags);
+ if (mac->join_data_phase && !mac->join_data_ended) {
mt6797_mac_join_end_data(mac, "disconnect");
+ } else if (!mac->join_cleanup_requested &&
+ !mac->join_cleanup_done && mac->join_peer_used &&
+ !mac->join_retired && !mac->first_error &&
+ !mac->closing) {
+ int ret = mt6797_mac_join_request_cleanup(mac);
+
+ if (!ret)
+ schedule_delayed_work(&mac->join_work, 0);
+ else {
+ mac->first_error = ret;
+ mac->closing = true;
+ }
+ }
+ mutex_unlock(&mac->mutex);
+ while ((skb = __skb_dequeue(&discard)))
+ ieee80211_free_txskb(hw, skb);
+ return;
+ }
+ if (mac->join_cleanup_requested || mac->join_cleanup_done) {
mutex_unlock(&mac->mutex);
return;
}
+1
View File
@@ -3,3 +3,4 @@
0003-arm64-dts-mediatek-geminux-gemini-pda.patch 0003-arm64-dts-mediatek-geminux-gemini-pda.patch
0004-gemini-ssd2092-display-and-touch.patch 0004-gemini-ssd2092-display-and-touch.patch
0005-mt6797-consys-wifi-factory-firmware.patch 0005-mt6797-consys-wifi-factory-firmware.patch
0006-mt6797-boot-cleanups.patch
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+2 -12
View File
@@ -1091,7 +1091,7 @@ CONFIG_INET=y
# CONFIG_NET_IPIP is not set # CONFIG_NET_IPIP is not set
# CONFIG_NET_IPGRE_DEMUX is not set # CONFIG_NET_IPGRE_DEMUX is not set
CONFIG_NET_IP_TUNNEL=m CONFIG_NET_IP_TUNNEL=m
# CONFIG_SYN_COOKIES is not set CONFIG_SYN_COOKIES=y
# CONFIG_NET_IPVTI is not set # CONFIG_NET_IPVTI is not set
CONFIG_NET_UDP_TUNNEL=m CONFIG_NET_UDP_TUNNEL=m
# CONFIG_NET_FOU is not set # CONFIG_NET_FOU is not set
@@ -2299,15 +2299,7 @@ CONFIG_HVC_DRIVER=y
CONFIG_SERIAL_DEV_BUS=y CONFIG_SERIAL_DEV_BUS=y
CONFIG_SERIAL_DEV_CTRL_TTYPORT=y CONFIG_SERIAL_DEV_CTRL_TTYPORT=y
CONFIG_VIRTIO_CONSOLE=y CONFIG_VIRTIO_CONSOLE=y
CONFIG_IPMI_HANDLER=y # CONFIG_IPMI_HANDLER is not set
CONFIG_IPMI_PLAT_DATA=y
# CONFIG_IPMI_PANIC_EVENT is not set
CONFIG_IPMI_DEVICE_INTERFACE=y
CONFIG_IPMI_SI=y
# CONFIG_IPMI_SI_ASYNC_INIT is not set
# CONFIG_IPMI_SSIF is not set
# CONFIG_IPMI_WATCHDOG is not set
# CONFIG_IPMI_POWEROFF is not set
# CONFIG_ASPEED_KCS_IPMI_BMC is not set # CONFIG_ASPEED_KCS_IPMI_BMC is not set
# CONFIG_ASPEED_BT_IPMI_BMC is not set # CONFIG_ASPEED_BT_IPMI_BMC is not set
CONFIG_HW_RANDOM=y CONFIG_HW_RANDOM=y
@@ -2721,8 +2713,6 @@ CONFIG_SENSORS_GPIO_FAN=y
# CONFIG_SENSORS_HIH6130 is not set # CONFIG_SENSORS_HIH6130 is not set
# CONFIG_SENSORS_HS3001 is not set # CONFIG_SENSORS_HS3001 is not set
# CONFIG_SENSORS_HTU31 is not set # CONFIG_SENSORS_HTU31 is not set
# CONFIG_SENSORS_IBMAEM is not set
# CONFIG_SENSORS_IBMPEX is not set
# CONFIG_SENSORS_IIO_HWMON is not set # CONFIG_SENSORS_IIO_HWMON is not set
# CONFIG_SENSORS_ISL28022 is not set # CONFIG_SENSORS_ISL28022 is not set
# CONFIG_SENSORS_IT87 is not set # CONFIG_SENSORS_IT87 is not set
@@ -168,9 +168,6 @@ kernel/drivers/video/fbdev/core/sysfillrect.ko
kernel/drivers/video/fbdev/core/syscopyarea.ko kernel/drivers/video/fbdev/core/syscopyarea.ko
kernel/drivers/video/fbdev/core/sysimgblt.ko kernel/drivers/video/fbdev/core/sysimgblt.ko
kernel/drivers/video/fbdev/core/fb_sys_fops.ko kernel/drivers/video/fbdev/core/fb_sys_fops.ko
kernel/drivers/char/ipmi/ipmi_msghandler.ko
kernel/drivers/char/ipmi/ipmi_devintf.ko
kernel/drivers/char/ipmi/ipmi_si.ko
kernel/drivers/clk/clk-pwm.ko kernel/drivers/clk/clk-pwm.ko
kernel/drivers/clk/scmi-clk.ko kernel/drivers/clk/scmi-clk.ko
kernel/drivers/clk/mediatek/clk-mtk.ko kernel/drivers/clk/mediatek/clk-mtk.ko
Binary file not shown.
+24 -1
View File
@@ -162,6 +162,22 @@ for svc in geminux-hwinit geminux-ccci geminux-powerd geminux-leds bluetooth pol
fi fi
done done
for fdir in misc TTF OTF; do
mkdir -p "$TARGET_ROOTFS/usr/share/fonts/$fdir"
if [ ! -f "$TARGET_ROOTFS/usr/share/fonts/$fdir/fonts.dir" ]; then
printf '0\n' > "$TARGET_ROOTFS/usr/share/fonts/$fdir/fonts.dir"
fi
done
if [ -f "$TARGET_ROOTFS/usr/share/dbus-1/system-services/org.freedesktop.ModemManager1.service" ]; then
sed -i 's|^Exec=.*|Exec=/bin/false|' \
"$TARGET_ROOTFS/usr/share/dbus-1/system-services/org.freedesktop.ModemManager1.service"
fi
if [ -f "$TARGET_ROOTFS/etc/rc.conf" ] && ! grep -q '^rc_logger=' "$TARGET_ROOTFS/etc/rc.conf"; then
printf '\nrc_logger="YES"\n' >> "$TARGET_ROOTFS/etc/rc.conf"
fi
if [ -x "$BASE_DIR/scripts/version.sh" ]; then if [ -x "$BASE_DIR/scripts/version.sh" ]; then
"$BASE_DIR/scripts/version.sh" "$TARGET_ROOTFS" "$BASE_DIR/scripts/version.sh" "$TARGET_ROOTFS"
fi fi
@@ -186,7 +202,8 @@ for f in .bashrc .profile .bash_profile; do
done done
echo "[4/4] Populating /home/user skel and setting permissions..." echo "[4/4] Populating /home/user skel and setting permissions..."
mkdir -p "$TARGET_ROOTFS/home/user/.config" "$TARGET_ROOTFS/home/user/.local/share/geminux" \ mkdir -p "$TARGET_ROOTFS/home/user/.cache" "$TARGET_ROOTFS/home/user/.config" \
"$TARGET_ROOTFS/home/user/.local/share/geminux" \
"$TARGET_ROOTFS/home/user/Pictures" "$TARGET_ROOTFS/home/user/Videos" \ "$TARGET_ROOTFS/home/user/Pictures" "$TARGET_ROOTFS/home/user/Videos" \
"$TARGET_ROOTFS/home/user/Downloads" "$TARGET_ROOTFS/home/user/Downloads"
if [ -d "$TARGET_ROOTFS/etc/skel" ]; then if [ -d "$TARGET_ROOTFS/etc/skel" ]; then
@@ -195,5 +212,11 @@ fi
chown -R 10000:10000 "$TARGET_ROOTFS/home/user" 2>/dev/null || true chown -R 10000:10000 "$TARGET_ROOTFS/home/user" 2>/dev/null || true
chmod 0600 "$TARGET_ROOTFS/etc/NetworkManager/system-connections/"*.nmconnection \ chmod 0600 "$TARGET_ROOTFS/etc/NetworkManager/system-connections/"*.nmconnection \
"$TARGET_ROOTFS/usr/lib/NetworkManager/system-connections/"*.nmconnection 2>/dev/null || true "$TARGET_ROOTFS/usr/lib/NetworkManager/system-connections/"*.nmconnection 2>/dev/null || true
chown 0:0 "$TARGET_ROOTFS/etc/NetworkManager/dispatcher.d/"* 2>/dev/null || true
chmod 0755 "$TARGET_ROOTFS/etc/NetworkManager/dispatcher.d/"* 2>/dev/null || true
if [ ! -f "$TARGET_ROOTFS/etc/timezone" ] && [ -f "$TARGET_ROOTFS/usr/share/zoneinfo/UTC" ]; then
printf 'UTC\n' > "$TARGET_ROOTFS/etc/timezone"
ln -sfn /usr/share/zoneinfo/UTC "$TARGET_ROOTFS/etc/localtime"
fi
chmod 0640 "$TARGET_ROOTFS/etc/doas.d/"* 2>/dev/null || true chmod 0640 "$TARGET_ROOTFS/etc/doas.d/"* 2>/dev/null || true
echo "Applied Geminux overlay and @geminux APKs for $DEVICE." echo "Applied Geminux overlay and @geminux APKs for $DEVICE."
+4
View File
@@ -253,6 +253,10 @@ EOF
-I"$SYSROOT/usr/include/X11/dri" \ -I"$SYSROOT/usr/include/X11/dri" \
-I"$SYSROOT/usr/include/libdrm" \ -I"$SYSROOT/usr/include/libdrm" \
"$XF86_FBDEV_SRC/src/fbdev.c" \ "$XF86_FBDEV_SRC/src/fbdev.c" \
-Wl,-rpath,"$ABI_MOD_DIR" \
-L"/geminux/prebuilt/xlibre$ABI_MOD_DIR" \
-l:libfbdevhw.so \
-l:libshadow.so \
-o "/geminux/prebuilt/xlibre$ABI_MOD_DIR/drivers/fbdev_drv.so" -o "/geminux/prebuilt/xlibre$ABI_MOD_DIR/drivers/fbdev_drv.so"
fi fi
+4 -1
View File
@@ -196,7 +196,10 @@ for req_rel in ("etc/pam.d/autologin", "etc/init.d/geminux-hwinit",
"usr/lib/dri/simpledrm_dri.so", "etc/runlevels/boot/geminux-usb-gadget", "usr/lib/dri/simpledrm_dri.so", "etc/runlevels/boot/geminux-usb-gadget",
"usr/share/X11/xkb/types/custom", "usr/sbin/dnsmasq", "usr/share/X11/xkb/types/custom", "usr/sbin/dnsmasq",
"etc/NetworkManager/conf.d/20-geminux-wifi.conf", "etc/shells", "etc/NetworkManager/conf.d/20-geminux-wifi.conf", "etc/shells",
"usr/sbin/geminux-wifi-nvram", "etc/polkit-1/rules.d/10-geminux.rules"): "usr/sbin/geminux-wifi-nvram", "usr/sbin/geminux-tzctl",
"usr/bin/geminux-datetime",
"etc/NetworkManager/dispatcher.d/30-geminux-chrony",
"etc/polkit-1/rules.d/10-geminux.rules"):
if not os.path.lexists(os.path.join(rootfs, req_rel)): if not os.path.lexists(os.path.join(rootfs, req_rel)):
raise SystemExit(f"FAIL: missing required path {os.path.join(rootfs, req_rel)}") raise SystemExit(f"FAIL: missing required path {os.path.join(rootfs, req_rel)}")
if os.path.lexists(os.path.join(rootfs, "etc/runlevels/sysinit/hwdrivers")): if os.path.lexists(os.path.join(rootfs, "etc/runlevels/sysinit/hwdrivers")):
+3
View File
@@ -255,6 +255,9 @@ make_pkg(
"alpine-baselayout-data", "alpine-baselayout-data",
"alpine-release", "alpine-release",
"bluez", "bluez",
"chrony",
"chrony-common",
"chrony-openrc",
"tinydm", "tinydm",
"tinydm-openrc", "tinydm-openrc",
"xinit", "xinit",
+1
View File
@@ -71,6 +71,7 @@ libpng
libva libva
libva-utils libva-utils
libxcvt libxcvt
libxfont2
libxft libxft
libxi libxi
libxinerama libxinerama
+33
View File
@@ -34,6 +34,7 @@ C_TEST = r"""
#include "geminux-wifi-list.h" #include "geminux-wifi-list.h"
#include "geminux-bt-list.h" #include "geminux-bt-list.h"
#include "geminux-audio-parse.h" #include "geminux-audio-parse.h"
#include "geminux-tz-valid.h"
static int count_decision(const geminux_gesture_action_t *a, int mode) { static int count_decision(const geminux_gesture_action_t *a, int mode) {
int c = 0; int c = 0;
@@ -288,6 +289,38 @@ int main(void) {
assert(strcmp(profs[1].card_label, "WH-1000XM5") == 0); assert(strcmp(profs[1].card_label, "WH-1000XM5") == 0);
assert(profs[1].active && profs[1].available); assert(profs[1].active && profs[1].available);
assert(!profs[2].active && strcmp(profs[2].profile_name, "headset-head-unit") == 0); assert(!profs[2].active && strcmp(profs[2].profile_name, "headset-head-unit") == 0);
assert(geminux_tz_name_valid("UTC"));
assert(geminux_tz_name_valid("Europe/Berlin"));
assert(geminux_tz_name_valid("America/Argentina/Buenos_Aires"));
assert(geminux_tz_name_valid("Etc/GMT+2"));
assert(!geminux_tz_name_valid(""));
assert(!geminux_tz_name_valid("/UTC"));
assert(!geminux_tz_name_valid("Europe/"));
assert(!geminux_tz_name_valid("../etc/passwd"));
assert(!geminux_tz_name_valid("Europe//Berlin"));
assert(!geminux_tz_name_valid("UTC;id"));
char tzdir[128];
snprintf(tzdir, sizeof(tzdir), "/tmp/geminux-tz-test-%ld", (long)getpid());
mkdir(tzdir, 0755);
char okp[256], badp[256];
snprintf(okp, sizeof(okp), "%s/GoodZone", tzdir);
snprintf(badp, sizeof(badp), "%s/BadZone", tzdir);
FILE *zf = fopen(okp, "wb");
assert(zf != NULL);
fwrite("TZif2\0", 1, 6, zf);
fclose(zf);
zf = fopen(badp, "wb");
assert(zf != NULL);
fwrite("BAD!\0", 1, 5, zf);
fclose(zf);
assert(geminux_tz_file_valid(tzdir, "GoodZone"));
assert(!geminux_tz_file_valid(tzdir, "BadZone"));
assert(!geminux_tz_file_valid(tzdir, "MissingZone"));
unlink(okp);
unlink(badp);
rmdir(tzdir);
return 0; return 0;
} }
""" """
+1
View File
@@ -34,6 +34,7 @@ static const Rule rules[] = {
{ "geminux-lock", NULL, NULL, ~0U, 1, -1 }, { "geminux-lock", NULL, NULL, ~0U, 1, -1 },
{ "geminux-control", NULL, NULL, 0, 1, -1 }, { "geminux-control", NULL, NULL, 0, 1, -1 },
{ "geminux-audio", NULL, NULL, 0, 1, -1 }, { "geminux-audio", NULL, NULL, 0, 1, -1 },
{ "geminux-datetime", NULL, NULL, 0, 1, -1 },
{ "geminux-themes", NULL, NULL, 0, 1, -1 }, { "geminux-themes", NULL, NULL, 0, 1, -1 },
}; };
+2
View File
@@ -33,6 +33,8 @@ static const Rule rules[] = {
{ "geminux-callscreen", NULL, NULL, ~0U, 0, -1 }, { "geminux-callscreen", NULL, NULL, ~0U, 0, -1 },
{ "geminux-lock", NULL, NULL, ~0U, 1, -1 }, { "geminux-lock", NULL, NULL, ~0U, 1, -1 },
{ "geminux-control", NULL, NULL, 0, 1, -1 }, { "geminux-control", NULL, NULL, 0, 1, -1 },
{ "geminux-audio", NULL, NULL, 0, 1, -1 },
{ "geminux-datetime", NULL, NULL, 0, 1, -1 },
{ "geminux-themes", NULL, NULL, 0, 1, -1 }, { "geminux-themes", NULL, NULL, 0, 1, -1 },
}; };
+4
View File
@@ -17,10 +17,14 @@ APPS = \
geminux-camera \ geminux-camera \
geminux-control \ geminux-control \
geminux-themes \ geminux-themes \
geminux-datetime \
geminux-lock geminux-lock
all: $(APPS) all: $(APPS)
geminux-datetime: geminux-datetime.c ../geminux-daemons/geminux-tz-valid.h ../libgemui/gemui.h
$(CC) $(CFLAGS) -o $@ $< $(LIBS)
geminux-camera: geminux-camera.c ../libgemui/gemui.h geminux-camera: geminux-camera.c ../libgemui/gemui.h
$(CC) $(CFLAGS) -o $@ $< $(LIBS) -ljpeg $(CC) $(CFLAGS) -o $@ $< $(LIBS) -ljpeg
+14 -8
View File
@@ -10,11 +10,12 @@
#define HIT_VOL 2 #define HIT_VOL 2
#define HIT_PROF 3 #define HIT_PROF 3
#define HIT_LED 4 #define HIT_LED 4
#define HIT_LOCK 5 #define HIT_LOCK 5
#define HIT_SUSPEND 6 #define HIT_SUSPEND 6
#define HIT_REBOOT 7 #define HIT_REBOOT 7
#define HIT_POWER 8 #define HIT_POWER 8
#define HIT_MIXER 9 #define HIT_MIXER 9
#define HIT_DATETIME 10
typedef struct { typedef struct {
gemui_app_t *app; gemui_app_t *app;
@@ -94,7 +95,7 @@ static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
ctrl_state_t *st = ud; ctrl_state_t *st = ud;
const gemui_theme_t *t = gemui_theme(app); const gemui_theme_t *t = gemui_theme(app);
gemui_draw_header(app, cr, "\xef\x80\x93", "Geminux Control Center", "Power, Audio, Display & LEDs"); gemui_draw_header(app, cr, "\xef\x80\x93", "Geminux Control Center", "Power, Audio, Display, Time & LEDs");
int pad = 24; int pad = 24;
int cw = (w - pad * 2); int cw = (w - pad * 2);
@@ -105,12 +106,14 @@ static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
snprintf(btxt, sizeof(btxt), "%d%%", (int)(bnorm * 100.0 + 0.5)); snprintf(btxt, sizeof(btxt), "%d%%", (int)(bnorm * 100.0 + 0.5));
gemui_draw_slider(app, cr, st->bri_rect, "Display Backlight", bnorm, btxt, HIT_BRI, 0, false); gemui_draw_slider(app, cr, st->bri_rect, "Display Backlight", bnorm, btxt, HIT_BRI, 0, false);
st->vol_rect = (gemui_rect_t){pad, 210, cw - 240, 104}; st->vol_rect = (gemui_rect_t){pad, 210, cw - 468, 104};
char vtxt[32]; char vtxt[32];
snprintf(vtxt, sizeof(vtxt), "%d%%", st->vol_pct); snprintf(vtxt, sizeof(vtxt), "%d%%", st->vol_pct);
gemui_draw_slider(app, cr, st->vol_rect, "Master Audio Volume", st->vol_pct / 100.0, vtxt, HIT_VOL, 0, false); gemui_draw_slider(app, cr, st->vol_rect, "Master Audio Volume", st->vol_pct / 100.0, vtxt, HIT_VOL, 0, false);
gemui_draw_button(app, cr, (gemui_rect_t){pad + cw - 228, 210, 228, 104}, gemui_draw_button(app, cr, (gemui_rect_t){pad + cw - 456, 210, 222, 104},
"Audio Mixer", HIT_MIXER, 0, true, false, false); "Audio Mixer", HIT_MIXER, 0, true, false, false);
gemui_draw_button(app, cr, (gemui_rect_t){pad + cw - 222, 210, 222, 104},
"Time & Zone", HIT_DATETIME, 0, false, false, false);
gemui_draw_text(cr, t, (gemui_rect_t){pad, 330, cw, 40}, gemui_draw_text(cr, t, (gemui_rect_t){pad, 330, cw, 40},
"MT6797X Power Profile (A72 Big Cluster + Schedutil)", "MT6797X Power Profile (A72 Big Cluster + Schedutil)",
@@ -181,6 +184,9 @@ static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, v
} else if (hit->id == HIT_MIXER) { } else if (hit->id == HIT_MIXER) {
const char *cmd[] = {"geminux-audio", NULL}; const char *cmd[] = {"geminux-audio", NULL};
gemui_spawn_detached(cmd); gemui_spawn_detached(cmd);
} else if (hit->id == HIT_DATETIME) {
const char *cmd[] = {"geminux-datetime", NULL};
gemui_spawn_detached(cmd);
} else if (hit->id == HIT_PROF) { } else if (hit->id == HIT_PROF) {
static const char *pnames[3] = {"eco", "balanced", "performance"}; static const char *pnames[3] = {"eco", "balanced", "performance"};
st->profile = hit->val; st->profile = hit->val;
+564
View File
@@ -0,0 +1,564 @@
#define _POSIX_C_SOURCE 200809L
#include "gemui.h"
#include "../geminux-daemons/geminux-tz-valid.h"
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#define MAX_ZONES 1024
#define HIT_SEARCH 1
#define HIT_FILTER 2
#define HIT_ZONE 3
#define HIT_APPLY 4
#define HIT_SYNC 5
typedef struct {
char name[96];
} tz_entry_t;
typedef struct {
gemui_app_t *app;
tz_entry_t zones[MAX_ZONES];
int num_zones;
int filt_idx[MAX_ZONES];
int num_filt;
int sel_filt;
int scroll_off;
int region_filter; /* 0=All, 1=Europe, 2=America, 3=Asia, 4=Pacific/Aus, 5=UTC/Etc */
char query[64];
char active_zone[96];
char ntp_status[128];
int ntp_tick;
bool sync_running;
pid_t sync_pid;
int sync_fd;
} dt_state_t;
static int cmp_zone(const void *a, const void *b) {
const tz_entry_t *za = a;
const tz_entry_t *zb = b;
return strcmp(za->name, zb->name);
}
static bool str_icontains(const char *hay, const char *needle) {
if (!needle || !needle[0]) return true;
size_t nlen = strlen(needle);
for (const char *p = hay; *p; p++) {
size_t i = 0;
while (i < nlen && p[i] &&
tolower((unsigned char)p[i]) == tolower((unsigned char)needle[i])) {
i++;
}
if (i == nlen) return true;
}
return false;
}
static void add_zone(dt_state_t *st, const char *name) {
if (st->num_zones >= MAX_ZONES || !geminux_tz_file_valid("/usr/share/zoneinfo", name)) {
return;
}
for (int i = 0; i < st->num_zones; i++) {
if (strcmp(st->zones[i].name, name) == 0) return;
}
snprintf(st->zones[st->num_zones++].name, 96, "%s", name);
}
static void scan_zone_dir(dt_state_t *st, const char *prefix, int depth) {
if (depth > 3 || st->num_zones >= MAX_ZONES) return;
char dirpath[512];
snprintf(dirpath, sizeof(dirpath), "/usr/share/zoneinfo/%s", prefix);
DIR *d = opendir(dirpath);
if (!d) return;
struct dirent *de;
while ((de = readdir(d)) != NULL && st->num_zones < MAX_ZONES) {
if (de->d_name[0] == '.') continue;
char rel[128];
int n = snprintf(rel, sizeof(rel), "%s/%s", prefix, de->d_name);
if (n < 0 || (size_t)n >= sizeof(rel)) continue;
char full[512];
snprintf(full, sizeof(full), "/usr/share/zoneinfo/%s", rel);
struct stat sb;
if (stat(full, &sb) != 0) continue;
if (S_ISDIR(sb.st_mode)) {
scan_zone_dir(st, rel, depth + 1);
} else if (S_ISREG(sb.st_mode)) {
add_zone(st, rel);
}
}
closedir(d);
}
static void read_active_zone(dt_state_t *st) {
char buf[128] = {0};
if (gemui_read_file_line("/etc/timezone", buf, sizeof(buf)) == 0 &&
geminux_tz_name_valid(buf)) {
snprintf(st->active_zone, sizeof(st->active_zone), "%s", buf);
return;
}
char linkbuf[512];
ssize_t n = readlink("/etc/localtime", linkbuf, sizeof(linkbuf) - 1);
if (n > 0) {
linkbuf[n] = '\0';
const char *pfx = "/usr/share/zoneinfo/";
const char *p = strstr(linkbuf, pfx);
if (p) {
p += strlen(pfx);
if (geminux_tz_name_valid(p)) {
snprintf(st->active_zone, sizeof(st->active_zone), "%s", p);
return;
}
}
}
snprintf(st->active_zone, sizeof(st->active_zone), "UTC");
}
static void load_zones(dt_state_t *st) {
static const char *const regions[] = {
"Africa", "America", "Antarctica", "Arctic", "Asia", "Atlantic",
"Australia", "Brazil", "Canada", "Chile", "Etc", "Europe",
"Indian", "Mexico", "Pacific", "US"
};
st->num_zones = 0;
add_zone(st, "UTC");
add_zone(st, "GMT");
for (size_t i = 0; i < sizeof(regions) / sizeof(regions[0]); i++) {
scan_zone_dir(st, regions[i], 1);
}
if (st->num_zones > 1) {
qsort(st->zones, (size_t)st->num_zones, sizeof(st->zones[0]), cmp_zone);
}
read_active_zone(st);
}
static bool match_region(const char *z, int reg) {
if (reg == 0) return true;
if (reg == 1) return strncmp(z, "Europe/", 7) == 0;
if (reg == 2) return strncmp(z, "America/", 8) == 0 ||
strncmp(z, "US/", 3) == 0 ||
strncmp(z, "Canada/", 7) == 0 ||
strncmp(z, "Brazil/", 7) == 0 ||
strncmp(z, "Mexico/", 7) == 0 ||
strncmp(z, "Chile/", 6) == 0;
if (reg == 3) return strncmp(z, "Asia/", 5) == 0 || strncmp(z, "Indian/", 7) == 0;
if (reg == 4) return strncmp(z, "Pacific/", 8) == 0 || strncmp(z, "Australia/", 10) == 0;
return strcmp(z, "UTC") == 0 || strcmp(z, "GMT") == 0 || strncmp(z, "Etc/", 4) == 0;
}
static int dt_visible_rows(const dt_state_t *st) {
int h = st->app ? gemui_height(st->app) : 920;
int list_h = h - 242;
int vis = (list_h - 16) / 62;
return vis > 0 ? vis : 1;
}
static void clamp_scroll(dt_state_t *st) {
int vis = dt_visible_rows(st);
int max_off = st->num_filt > vis ? st->num_filt - vis : 0;
if (st->scroll_off < 0) st->scroll_off = 0;
if (st->scroll_off > max_off) st->scroll_off = max_off;
if (st->sel_filt >= 0 && st->sel_filt < st->num_filt) {
if (st->sel_filt < st->scroll_off) st->scroll_off = st->sel_filt;
else if (st->sel_filt >= st->scroll_off + vis) st->scroll_off = st->sel_filt - vis + 1;
}
}
static void rebuild_filter(dt_state_t *st, const char *prefer_zone) {
char keep[96] = {0};
if (prefer_zone && prefer_zone[0]) {
snprintf(keep, sizeof(keep), "%s", prefer_zone);
} else if (st->sel_filt >= 0 && st->sel_filt < st->num_filt) {
snprintf(keep, sizeof(keep), "%s", st->zones[st->filt_idx[st->sel_filt]].name);
}
st->num_filt = 0;
st->sel_filt = -1;
for (int i = 0; i < st->num_zones; i++) {
const char *z = st->zones[i].name;
if (!match_region(z, st->region_filter)) continue;
if (!str_icontains(z, st->query)) continue;
if (keep[0] && strcmp(z, keep) == 0) st->sel_filt = st->num_filt;
st->filt_idx[st->num_filt++] = i;
}
if (st->sel_filt < 0 && st->num_filt > 0) st->sel_filt = 0;
clamp_scroll(st);
}
static void refresh_ntp(dt_state_t *st) {
char out[512] = {0};
const char *cmd[] = {"chronyc", "-c", "tracking", NULL};
if (gemui_run_cmd_timeout(cmd, out, sizeof(out), 300) != 0 || !out[0]) {
snprintf(st->ntp_status, sizeof(st->ntp_status), "chronyd not running / offline");
return;
}
char *nl = strpbrk(out, "\r\n");
if (nl) *nl = '\0';
char *fields[6] = {0};
int nf = 0;
char *save = NULL;
for (char *tok = strtok_r(out, ",", &save); tok && nf < 6; tok = strtok_r(NULL, ",", &save)) {
fields[nf++] = tok;
}
int stratum = (nf >= 3) ? atoi(fields[2]) : 0;
const char *refip = (nf >= 2) ? fields[1] : "";
if (stratum > 0 && stratum < 16 && refip[0] && strcmp(refip, "0.0.0.0") != 0) {
snprintf(st->ntp_status, sizeof(st->ntp_status), "Synced (Stratum %d · %s)", stratum, refip);
} else {
snprintf(st->ntp_status, sizeof(st->ntp_status), "Unsynced (waiting for network/NTP)");
}
}
static void format_time_for_zone(const char *zone, const char *restore_zone,
time_t now, char *out, size_t out_sz) {
struct tm tm;
if (zone && zone[0]) {
setenv("TZ", zone, 1);
tzset();
localtime_r(&now, &tm);
} else {
gmtime_r(&now, &tm);
}
strftime(out, out_sz, "%Y-%m-%d %H:%M:%S (%Z / UTC%z)", &tm);
if (restore_zone && restore_zone[0]) {
setenv("TZ", restore_zone, 1);
tzset();
}
}
static const char *selected_zone(const dt_state_t *st) {
if (st->sel_filt >= 0 && st->sel_filt < st->num_filt) {
return st->zones[st->filt_idx[st->sel_filt]].name;
}
return st->active_zone[0] ? st->active_zone : "UTC";
}
static void apply_selected(dt_state_t *st) {
const char *zone = selected_zone(st);
const char *cmd[] = {"doas", "/usr/sbin/geminux-tzctl", "set", zone, NULL};
int rc = gemui_run_cmd_timeout(cmd, NULL, 0, 2000);
if (rc == 0) {
snprintf(st->active_zone, sizeof(st->active_zone), "%s", zone);
setenv("TZ", st->active_zone, 1);
tzset();
gemui_show_toast(st->app, "Timezone updated", 2000);
} else {
gemui_show_toast(st->app, "Failed to update timezone", 2500);
}
gemui_request_redraw(st->app);
}
static void on_sync_fd(gemui_app_t *app, int fd, void *ud) {
dt_state_t *st = ud;
char buf[256];
bool eof = false;
while (1) {
ssize_t n = read(fd, buf, sizeof(buf));
if (n == 0) {
eof = true;
break;
}
if (n < 0) {
if (errno == EINTR) continue;
if (errno == EAGAIN || errno == EWOULDBLOCK) break;
eof = true;
break;
}
}
if (!eof) return;
gemui_del_fd(app, fd);
close(fd);
st->sync_fd = -1;
int status = 0;
if (st->sync_pid > 0) {
while (waitpid(st->sync_pid, &status, 0) < 0 && errno == EINTR) {}
}
st->sync_pid = 0;
st->sync_running = false;
int rc = WIFEXITED(status) ? WEXITSTATUS(status) : 1;
refresh_ntp(st);
gemui_show_toast(app, rc == 0 ? "NTP clock synchronized" : "NTP sync failed (offline or unreachable)", 2600);
gemui_request_redraw(app);
}
static void start_ntp_sync(dt_state_t *st) {
if (st->sync_running) {
gemui_show_toast(st->app, "NTP sync already in progress...", 1400);
return;
}
int pfd[2];
if (pipe(pfd) != 0) {
gemui_show_toast(st->app, "Failed to start NTP sync", 2000);
return;
}
pid_t pid = fork();
if (pid < 0) {
close(pfd[0]);
close(pfd[1]);
gemui_show_toast(st->app, "Failed to start NTP sync", 2000);
return;
}
if (pid == 0) {
close(pfd[0]);
int devnull = open("/dev/null", O_RDONLY);
if (devnull >= 0) {
dup2(devnull, STDIN_FILENO);
close(devnull);
}
dup2(pfd[1], STDOUT_FILENO);
dup2(pfd[1], STDERR_FILENO);
close(pfd[1]);
const char *argv[] = {"doas", "/usr/sbin/geminux-tzctl", "sync", NULL};
execvp(argv[0], (char *const *)argv);
_exit(127);
}
close(pfd[1]);
fcntl(pfd[0], F_SETFD, fcntl(pfd[0], F_GETFD) | FD_CLOEXEC);
fcntl(pfd[0], F_SETFL, fcntl(pfd[0], F_GETFL) | O_NONBLOCK);
st->sync_pid = pid;
st->sync_fd = pfd[0];
st->sync_running = true;
gemui_add_fd(st->app, st->sync_fd, on_sync_fd, st);
gemui_show_toast(st->app, "Syncing clock via NTP...", 1600);
gemui_request_redraw(st->app);
}
static void on_tick(gemui_app_t *app, void *ud) {
dt_state_t *st = ud;
st->ntp_tick++;
if ((st->ntp_tick % 5) == 0 && !st->sync_running) refresh_ntp(st);
gemui_request_redraw(app);
}
static void on_draw(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud) {
dt_state_t *st = ud;
const gemui_theme_t *t = gemui_theme(app);
gemui_draw_header(app, cr, "\xf3\xb0\xa5\x94", "Date, Time & Timezone", st->active_zone);
int pad = 20;
int top = 88;
int left_w = (w - pad * 3) / 2;
int right_x = pad * 2 + left_w;
int right_w = w - right_x - pad;
gemui_draw_input(app, cr, (gemui_rect_t){pad, top, left_w, 64},
"Search zone (e.g. Berlin, New_York, Tokyo)...", st->query,
false, true, HIT_SEARCH, 0);
static const char *reg_labels[6] = {"All", "Europe", "America", "Asia", "Pacific", "UTC"};
int fw = (left_w - 5 * 8) / 6;
for (int i = 0; i < 6; i++) {
gemui_draw_button(app, cr, (gemui_rect_t){pad + i * (fw + 8), top + 74, fw, 52},
reg_labels[i], HIT_FILTER, i, false, st->region_filter == i, false);
}
gemui_rect_t list = {pad, top + 136, left_w, h - (top + 136) - pad};
gemui_fill_round(cr, list, 12, t->bg_bar);
gemui_stroke_round(cr, list, 12, 1.5, t->border);
int rh = 62;
int cap = dt_visible_rows(st);
for (int i = st->scroll_off; i < st->num_filt && (i - st->scroll_off) < cap; i++) {
const char *zname = st->zones[st->filt_idx[i]].name;
bool sel = (i == st->sel_filt);
bool active = (strcmp(zname, st->active_zone) == 0);
gemui_rect_t rr = {list.x + 10, list.y + 8 + (i - st->scroll_off) * rh, list.w - 20, rh - 6};
gemui_fill_round(cr, rr, 10, sel ? t->sel_bg : (i % 2 ? t->bg_alt_odd : t->bg_alt_even));
gemui_draw_text(cr, t, (gemui_rect_t){rr.x + 14, rr.y, rr.w - 130, rr.h},
zname, -1, sel || active, GEMUI_ALIGN_LEFT,
sel ? t->sel_fg : t->fg_bright);
if (active) {
gemui_draw_text(cr, t, (gemui_rect_t){rr.x + rr.w - 110, rr.y, 96, rr.h},
"[Active]", -2, true, GEMUI_ALIGN_RIGHT,
sel ? t->sel_fg : t->success);
}
gemui_hit_add(app, rr, HIT_ZONE, i);
}
if (st->num_filt == 0) {
gemui_draw_text(cr, t, list, "No matching timezones", 0, false, GEMUI_ALIGN_CENTER, t->fg_muted);
}
/* Right pane: live clock, preview & NTP status */
gemui_rect_t card = {right_x, top, right_w, h - top - 196};
gemui_fill_round(cr, card, 14, t->bg_bar);
gemui_stroke_round(cr, card, 14, 1.5, t->border);
time_t now = time(NULL);
char local_str[128], utc_str[128], prev_str[128];
const char *sel_name = selected_zone(st);
format_time_for_zone(st->active_zone, st->active_zone, now, local_str, sizeof(local_str));
format_time_for_zone(NULL, st->active_zone, now, utc_str, sizeof(utc_str));
format_time_for_zone(sel_name, st->active_zone, now, prev_str, sizeof(prev_str));
int cx = card.x + 24;
int cw = card.w - 48;
int cy = card.y + 20;
gemui_draw_text(cr, t, (gemui_rect_t){cx, cy, cw, 34},
"Current System Local Time", -2, true, GEMUI_ALIGN_LEFT, t->fg_muted);
gemui_draw_text(cr, t, (gemui_rect_t){cx, cy + 32, cw, 48},
local_str, 2, true, GEMUI_ALIGN_LEFT, t->fg_bright);
cy += 98;
gemui_draw_text(cr, t, (gemui_rect_t){cx, cy, cw, 34},
"Universal Time (UTC)", -2, true, GEMUI_ALIGN_LEFT, t->fg_muted);
gemui_draw_text(cr, t, (gemui_rect_t){cx, cy + 32, cw, 42},
utc_str, 0, false, GEMUI_ALIGN_LEFT, t->fg_main);
cy += 92;
char prev_hdr[128];
snprintf(prev_hdr, sizeof(prev_hdr), "Selected Zone Preview: %s", sel_name);
gemui_draw_text(cr, t, (gemui_rect_t){cx, cy, cw, 34},
prev_hdr, -2, true, GEMUI_ALIGN_LEFT, t->info);
gemui_draw_text(cr, t, (gemui_rect_t){cx, cy + 32, cw, 46},
prev_str, 1, true, GEMUI_ALIGN_LEFT, t->accent);
cy += 96;
gemui_draw_text(cr, t, (gemui_rect_t){cx, cy, cw, 34},
"Chrony NTP Synchronization", -2, true, GEMUI_ALIGN_LEFT, t->fg_muted);
gemui_draw_text(cr, t, (gemui_rect_t){cx, cy + 32, cw, 42},
st->ntp_status, -1, true, GEMUI_ALIGN_LEFT,
strncmp(st->ntp_status, "Synced", 6) == 0 ? t->success : t->warning);
gemui_draw_button(app, cr, (gemui_rect_t){right_x, h - 180, right_w, 74},
"Apply Selected Timezone", HIT_APPLY, 0, true, false, false);
gemui_draw_button(app, cr, (gemui_rect_t){right_x, h - 94, right_w, 74},
st->sync_running ? "Syncing NTP..." : "Sync Clock Now (NTP)",
HIT_SYNC, 0, false, st->sync_running, false);
}
static void on_key(gemui_app_t *app, KeySym ks, unsigned int state, const char *utf8, void *ud) {
dt_state_t *st = ud;
if (ks == XK_Escape) {
gemui_quit(app, 0);
} else if ((state & ControlMask) && (ks == XK_s || ks == XK_S)) {
start_ntp_sync(st);
} else if ((state & ControlMask) && (ks == XK_u || ks == XK_U)) {
if (st->query[0]) {
st->query[0] = '\0';
rebuild_filter(st, NULL);
gemui_request_redraw(app);
}
} else if (ks == XK_Up && st->sel_filt > 0) {
st->sel_filt--;
clamp_scroll(st);
gemui_request_redraw(app);
} else if (ks == XK_Down && st->sel_filt + 1 < st->num_filt) {
st->sel_filt++;
clamp_scroll(st);
gemui_request_redraw(app);
} else if (ks == XK_Page_Up) {
int vis = dt_visible_rows(st);
st->sel_filt -= vis;
if (st->sel_filt < 0) st->sel_filt = 0;
clamp_scroll(st);
gemui_request_redraw(app);
} else if (ks == XK_Page_Down && st->num_filt > 0) {
int vis = dt_visible_rows(st);
st->sel_filt += vis;
if (st->sel_filt >= st->num_filt) st->sel_filt = st->num_filt - 1;
clamp_scroll(st);
gemui_request_redraw(app);
} else if (ks == XK_Return || ks == XK_KP_Enter) {
apply_selected(st);
} else if (ks == XK_BackSpace) {
if (st->query[0]) {
gemui_utf8_pop_char(st->query);
rebuild_filter(st, NULL);
gemui_request_redraw(app);
}
} else if (ks == XK_Delete) {
if (st->query[0]) {
st->query[0] = '\0';
rebuild_filter(st, NULL);
gemui_request_redraw(app);
}
} else if (!(state & ControlMask) && utf8 && utf8[0]) {
size_t cur = strlen(st->query), add = strlen(utf8);
if (cur + add < sizeof(st->query)) {
memcpy(st->query + cur, utf8, add + 1);
rebuild_filter(st, NULL);
gemui_request_redraw(app);
}
}
}
static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, void *ud) {
(void)btn;
dt_state_t *st = ud;
if (type == GEMUI_PTR_SCROLL_UP) {
if (st->scroll_off > 0) {
st->scroll_off--;
gemui_request_redraw(app);
}
return;
}
if (type == GEMUI_PTR_SCROLL_DOWN) {
int vis = dt_visible_rows(st);
if (st->scroll_off + vis < st->num_filt) {
st->scroll_off++;
gemui_request_redraw(app);
}
return;
}
if (type != GEMUI_PTR_DOWN) return;
const gemui_hit_t *hit = gemui_hit_test(app, x, y);
if (!hit) return;
if (hit->id == HIT_FILTER) {
st->region_filter = hit->val;
rebuild_filter(st, NULL);
gemui_request_redraw(app);
} else if (hit->id == HIT_ZONE) {
st->sel_filt = hit->val;
gemui_request_redraw(app);
} else if (hit->id == HIT_APPLY) {
apply_selected(st);
} else if (hit->id == HIT_SYNC) {
start_ntp_sync(st);
}
}
int main(void) {
static dt_state_t st;
memset(&st, 0, sizeof(st));
st.sync_fd = -1;
load_zones(&st);
if (st.active_zone[0]) {
setenv("TZ", st.active_zone, 1);
tzset();
}
rebuild_filter(&st, st.active_zone);
refresh_ntp(&st);
st.app = gemui_create("geminux-datetime", "Geminux Date & Timezone", 1900, 920, false);
if (!st.app) return 1;
gemui_handlers_t h = { .on_draw = on_draw, .on_key = on_key, .on_ptr = on_ptr };
gemui_set_handlers(st.app, &h, &st);
gemui_set_timer_ms(st.app, 1000, on_tick, &st);
int rc = gemui_run(st.app);
if (st.sync_pid > 0) {
kill(st.sync_pid, SIGTERM);
waitpid(st.sync_pid, NULL, 0);
}
if (st.sync_fd >= 0) close(st.sync_fd);
gemui_destroy(st.app);
return rc;
}
+6 -2
View File
@@ -23,7 +23,8 @@ BINS = \
geminux-leds \ geminux-leds \
geminux-power-audit \ geminux-power-audit \
geminux-checkpw \ geminux-checkpw \
geminux-wifi-nvram geminux-wifi-nvram \
geminux-tzctl
all: $(BINS) all: $(BINS)
@@ -57,6 +58,9 @@ geminux-power-audit: geminux-power-audit.c
geminux-checkpw: geminux-checkpw.c geminux-checkpw: geminux-checkpw.c
$(CC) $(CFLAGS) -o $@ $< $(CC) $(CFLAGS) -o $@ $<
geminux-tzctl: geminux-tzctl.c geminux-tz-valid.h
$(CC) $(CFLAGS) -o $@ geminux-tzctl.c
geminux-wifi-nvram: geminux-wifi-nvram.c geminux-wifi-nvram-core.c geminux-wifi-nvram-core.h geminux-wifi-nvram: geminux-wifi-nvram.c geminux-wifi-nvram-core.c geminux-wifi-nvram-core.h
$(CC) $(CFLAGS) -o $@ geminux-wifi-nvram.c geminux-wifi-nvram-core.c $(CC) $(CFLAGS) -o $@ geminux-wifi-nvram.c geminux-wifi-nvram-core.c
@@ -65,7 +69,7 @@ install: all
cp -f geminux-power-ctl geminux-statusd geminux-touchd geminux-modem-ctl \ cp -f geminux-power-ctl geminux-statusd geminux-touchd geminux-modem-ctl \
geminux-bt-obex geminux-power-audit $(DESTDIR)$(PREFIX)/bin/ geminux-bt-obex geminux-power-audit $(DESTDIR)$(PREFIX)/bin/
cp -f geminux-powerd geminux-ccci-daemon geminux-leds \ cp -f geminux-powerd geminux-ccci-daemon geminux-leds \
geminux-checkpw geminux-wifi-nvram $(DESTDIR)$(PREFIX)/sbin/ geminux-checkpw geminux-wifi-nvram geminux-tzctl $(DESTDIR)$(PREFIX)/sbin/
chmod 0755 $(DESTDIR)$(PREFIX)/bin/geminux-* $(DESTDIR)$(PREFIX)/sbin/geminux-* chmod 0755 $(DESTDIR)$(PREFIX)/bin/geminux-* $(DESTDIR)$(PREFIX)/sbin/geminux-*
clean: clean:
+17 -3
View File
@@ -16,6 +16,7 @@
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include "geminux-tz-valid.h"
static int read_line(const char *path, char *buf, size_t sz) { static int read_line(const char *path, char *buf, size_t sz) {
FILE *f = fopen(path, "r"); FILE *f = fopen(path, "r");
@@ -89,6 +90,14 @@ static void update_status(Display *dpy) {
else if (iface_up("ccmni0") || iface_up("ccmni1")) snprintf(net, sizeof(net), "LTE:UP"); else if (iface_up("ccmni0") || iface_up("ccmni1")) snprintf(net, sizeof(net), "LTE:UP");
else snprintf(net, sizeof(net), "Net:OFF"); else snprintf(net, sizeof(net), "Net:OFF");
char tz[128] = {0};
if (read_line("/etc/timezone", tz, sizeof(tz)) == 0 && geminux_tz_name_valid(tz)) {
setenv("TZ", tz, 1);
} else {
unsetenv("TZ");
}
tzset();
time_t now = time(NULL); time_t now = time(NULL);
struct tm tm; struct tm tm;
localtime_r(&now, &tm); localtime_r(&now, &tm);
@@ -167,14 +176,18 @@ int main(void) {
if (errno == EINTR) continue; if (errno == EINTR) continue;
break; break;
} }
bool dirty = false; bool dirty = false, realign = false;
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
int fd = events[i].data.fd; int fd = events[i].data.fd;
if (fd == sig_fd) { if (fd == sig_fd) {
struct signalfd_siginfo si; struct signalfd_siginfo si;
while (read(sig_fd, &si, sizeof(si)) > 0) { while (read(sig_fd, &si, sizeof(si)) > 0) {
if (si.ssi_signo == SIGUSR1) dirty = true; if (si.ssi_signo == SIGUSR1) {
else running = false; dirty = true;
realign = true;
} else {
running = false;
}
} }
} else { } else {
char drain[1024]; char drain[1024];
@@ -182,6 +195,7 @@ int main(void) {
dirty = true; dirty = true;
} }
} }
if (running && realign && tmr_fd >= 0) arm_minute_timer(tmr_fd);
if (running && dirty) update_status(dpy); if (running && dirty) update_status(dpy);
} }
+42
View File
@@ -0,0 +1,42 @@
#ifndef GEMINUX_TZ_VALID_H
#define GEMINUX_TZ_VALID_H
#include <fcntl.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
static inline bool geminux_tz_name_valid(const char *tz) {
size_t len;
if (!tz) return false;
len = strlen(tz);
if (len == 0 || len > 95) return false;
if (tz[0] == '/' || tz[len - 1] == '/') return false;
if (strstr(tz, "..") != NULL || strstr(tz, "//") != NULL) return false;
for (size_t i = 0; i < len; i++) {
unsigned char c = (unsigned char)tz[i];
bool ok = (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') ||
(c >= '0' && c <= '9') || c == '_' || c == '+' || c == '-' || c == '/';
if (!ok) return false;
}
return true;
}
static inline bool geminux_tz_file_valid(const char *zoneinfo_root, const char *tz) {
if (!zoneinfo_root || !zoneinfo_root[0] || !geminux_tz_name_valid(tz)) return false;
char path[512];
int n = snprintf(path, sizeof(path), "%s/%s", zoneinfo_root, tz);
if (n < 0 || (size_t)n >= sizeof(path)) return false;
struct stat st;
if (stat(path, &st) != 0 || !S_ISREG(st.st_mode)) return false;
int fd = open(path, O_RDONLY);
if (fd < 0) return false;
char hdr[4];
ssize_t r = read(fd, hdr, sizeof(hdr));
close(fd);
return r == 4 && memcmp(hdr, "TZif", 4) == 0;
}
#endif
+129
View File
@@ -0,0 +1,129 @@
#define _POSIX_C_SOURCE 200809L
#include "geminux-tz-valid.h"
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
static int run_argv(const char *const argv[], bool quiet) {
pid_t pid = fork();
if (pid < 0) return -1;
if (pid == 0) {
if (quiet) {
int devnull = open("/dev/null", O_RDWR);
if (devnull >= 0) {
dup2(devnull, STDOUT_FILENO);
dup2(devnull, STDERR_FILENO);
close(devnull);
}
}
execvp(argv[0], (char *const *)argv);
_exit(127);
}
int status = 0;
while (waitpid(pid, &status, 0) < 0) {
if (errno != EINTR) return -1;
}
if (WIFEXITED(status)) return WEXITSTATUS(status);
return 1;
}
static int write_file_atomic(const char *path, const char *content, mode_t mode) {
char tmp[512];
snprintf(tmp, sizeof(tmp), "%s.tmp", path);
int fd = open(tmp, O_WRONLY | O_CREAT | O_TRUNC, mode);
if (fd < 0) return -1;
size_t len = strlen(content);
size_t off = 0;
while (off < len) {
ssize_t w = write(fd, content + off, len - off);
if (w < 0) {
if (errno == EINTR) continue;
close(fd);
unlink(tmp);
return -1;
}
off += (size_t)w;
}
close(fd);
chmod(tmp, mode);
if (rename(tmp, path) != 0) {
unlink(tmp);
return -1;
}
return 0;
}
static int cmd_set(const char *tz) {
if (!geminux_tz_file_valid("/usr/share/zoneinfo", tz)) {
fprintf(stderr, "geminux-tzctl: invalid timezone '%s'\n", tz ? tz : "");
return 1;
}
char target[512];
snprintf(target, sizeof(target), "/usr/share/zoneinfo/%s", tz);
unlink("/etc/localtime.tmp");
if (symlink(target, "/etc/localtime.tmp") != 0 ||
rename("/etc/localtime.tmp", "/etc/localtime") != 0) {
unlink("/etc/localtime.tmp");
perror("geminux-tzctl: localtime");
return 1;
}
char line[128];
snprintf(line, sizeof(line), "%s\n", tz);
if (write_file_atomic("/etc/timezone", line, 0644) != 0) {
perror("geminux-tzctl: /etc/timezone");
return 1;
}
mkdir("/run/geminux", 0755);
write_file_atomic("/run/geminux/timezone", line, 0644);
const char *pk[] = {"pkill", "-USR1", "geminux-statusd", NULL};
run_argv(pk, true);
return 0;
}
static int cmd_sync(void) {
const char *st_argv[] = {"rc-service", "chronyd", "status", NULL};
if (run_argv(st_argv, true) != 0) {
const char *start_argv[] = {"rc-service", "chronyd", "start", NULL};
run_argv(start_argv, true);
}
const char *reload_argv[] = {"chronyc", "reload", "sources", NULL};
run_argv(reload_argv, true);
const char *online_argv[] = {"chronyc", "online", NULL};
run_argv(online_argv, true);
const char *burst_argv[] = {"chronyc", "burst", "4/4", NULL};
run_argv(burst_argv, true);
const char *wait_argv[] = {"chronyc", "waitsync", "20", "0", "0", "0.5", NULL};
int wrc = run_argv(wait_argv, true);
const char *step_argv[] = {"chronyc", "makestep", NULL};
int src = run_argv(step_argv, true);
const char *hw_argv[] = {"hwclock", "-w", "-u", NULL};
run_argv(hw_argv, true);
const char *pk[] = {"pkill", "-USR1", "geminux-statusd", NULL};
run_argv(pk, true);
return (wrc == 0 && src == 0) ? 0 : 1;
}
int main(int argc, char **argv) {
if (argc == 3 && strcmp(argv[1], "set") == 0) {
return cmd_set(argv[2]);
}
if (argc == 2 && strcmp(argv[1], "sync") == 0) {
return cmd_sync();
}
fprintf(stderr, "Usage: %s <set TIMEZONE | sync>\n", argv[0]);
return 1;
}