-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathidle_detect_wrapper.sh.in
More file actions
executable file
·69 lines (56 loc) · 2.74 KB
/
idle_detect_wrapper.sh.in
File metadata and controls
executable file
·69 lines (56 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/sh
# Wrapper script to wait for necessary session environment variables
# before executing the actual idle_detect binary.
# Configuration
MAX_WAIT_SECONDS=30 # Total time to wait (e.g., 30 seconds)
WAIT_INTERVAL=2 # Time between checks (e.g., 2 seconds)
CONFIG_FILE_ARG="$1" # Capture potential config file argument
# Function to log messages (optional, adjust as needed)
log_message() {
echo "idle_detect_wrapper: $1" >&2 # Log to stderr
}
# Wait loop
SECONDS_WAITED=0
ENV_READY=0
while [ $SECONDS_WAITED -lt $MAX_WAIT_SECONDS ]; do
log_message "Checking environment (waited ${SECONDS_WAITED}s)..."
# Check for D-Bus Address using systemctl show-environment
DBUS_ADDR=$(systemctl --user show-environment | grep '^DBUS_SESSION_BUS_ADDRESS=')
# Check for either DISPLAY or WAYLAND_DISPLAY using systemctl show-environment
DISP_VAR=$(systemctl --user show-environment | grep -q -E '^(DISPLAY=|WAYLAND_DISPLAY=)' && echo "found")
# Check if both conditions are met
if [ -n "$DBUS_ADDR" ] && [ -n "$DISP_VAR" ]; then
log_message "Found DBUS_SESSION_BUS_ADDRESS and DISPLAY/WAYLAND_DISPLAY."
# Correctly log the variables found by systemctl for accuracy
log_message " -> $(systemctl --user show-environment | grep '^DBUS_SESSION_BUS_ADDRESS=')"
log_message " -> $(systemctl --user show-environment | grep '^DISPLAY=')"
log_message " -> $(systemctl --user show-environment | grep '^WAYLAND_DISPLAY=')"
ENV_READY=1
break
fi
# Log specific missing variables for debugging
if [ -z "$DBUS_ADDR" ]; then log_message " DBUS_SESSION_BUS_ADDRESS missing"; fi
if [ -z "$DISP_VAR" ]; then log_message " DISPLAY/WAYLAND_DISPLAY missing"; fi
sleep $WAIT_INTERVAL
SECONDS_WAITED=$((SECONDS_WAITED + WAIT_INTERVAL))
done
# Check if loop timed out
if [ "$ENV_READY" -eq 0 ]; then
log_message "ERROR: Timed out after ${SECONDS_WAITED}s waiting for session environment variables. Exiting."
exit 1
fi
# Environment seems ready, execute the main program
log_message "Environment ready. Executing @CMAKE_INSTALL_FULL_BINDIR@/idle_detect..."
# Pass the config file argument ONLY if it was provided to the wrapper.
if [ -n "$CONFIG_FILE_ARG" ]; then
log_message " (with specified config file: $CONFIG_FILE_ARG)"
# Use exec to replace this script process with the idle_detect process
exec @CMAKE_INSTALL_FULL_BINDIR@/idle_detect "$CONFIG_FILE_ARG"
else
log_message " (with no config file specified, using default path logic)"
# Execute idle_detect with NO arguments
exec @CMAKE_INSTALL_FULL_BINDIR@/idle_detect
fi
# This part of the script is only reached if 'exec' itself fails.
log_message "ERROR: Failed to exec @CMAKE_INSTALL_FULL_BINDIR@/idle_detect. Exiting."
exit 1