https://bugs.kde.org/show_bug.cgi?id=518177

            Bug ID: 518177
           Summary: clearClipboardHistory() DBus method silently exits 0
                    without clearing history when called from a shell
                    script
    Classification: Plasma
           Product: plasmashell
      Version First 5.27.12
       Reported In:
          Platform: Kubuntu
                OS: Linux
            Status: REPORTED
          Severity: normal
          Priority: NOR
         Component: Clipboard widget & pop-up
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
  Target Milestone: 1.0

The DBus method org.kde.klipper.klipper.clearClipboardHistory() works correctly
when called interactively from a terminal, but silently does nothing when
called from within a shell script — even one executed by the same user in the
same session. The failure is silent: the command exits 0 with no error output.

The root cause is that shell scripts do not automatically inherit
DBUS_SESSION_BUS_ADDRESS from the calling environment. Without explicitly
exporting this variable, the qdbus call connects to the wrong or nonexistent
bus and fails without any indication.

Reported by: Jonathan Brown (GitHub: github.com/black-vajra)


ENVIRONMENT

OS: Kubuntu 24.04 LTS
Plasma version: 5.27.12
Confirmed via: qdbus org.kde.klipper /klipper (method list verified present)
DBUS_SESSION_BUS_ADDRESS value: unix:path=/run/user/1000/bus


STEPS TO REPRODUCE

Step 1 — Confirm the method exists and works interactively:
<pre>
qdbus org.kde.klipper /klipper
</pre>

Output confirms clearClipboardHistory() is present:
<pre>
method void org.kde.klipper.klipper.clearClipboardHistory()
</pre>

Step 2 — Run the command directly in a terminal with clipboard history present:
<pre>
qdbus org.kde.klipper /klipper org.kde.klipper.klipper.clearClipboardHistory
</pre>

Result: History is cleared immediately. Klipper icon disappears. Behavior is
correct.

Step 3 — Place the identical command inside a shell script and execute it as
the same user:
<pre>
#!/bin/bash
qdbus org.kde.klipper /klipper org.kde.klipper.klipper.clearClipboardHistory
</pre>

<pre>
./clear.sh
</pre>

Result: Script exits 0. No error output. Klipper history is completely
untouched.


ROOT CAUSE

DBUS_SESSION_BUS_ADDRESS is set in the interactive shell environment but is not
automatically inherited by child script processes in all execution contexts.
Without it, qdbus cannot locate the correct session bus and fails silently.

This can be confirmed by checking the variable in an interactive shell:
<pre>
echo $DBUS_SESSION_BUS_ADDRESS
# Returns: unix:path=/run/user/1000/bus
</pre>

Inside a script without the export, this variable is empty or unavailable.


WORKAROUND

Explicitly export the variable at the top of the script:
<pre>
export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$(id -u)/bus"
</pre>

With this line present, clearClipboardHistory() functions correctly from within
scripts. The $(id -u) construct makes it portable across different user
accounts.


WHY THIS MATTERS

Users writing privacy or security scripts to clear clipboard traces — a
reasonable and documented use case — will follow the DBus interface
documentation, implement the correct method call, observe silent failure, and
have no indication of what went wrong or why. The method name, path, and
interface are all correct. Only the environment variable inheritance is the
issue.

This should either be:
1. Documented explicitly in Klipper's DBus interface documentation
2. Handled gracefully by qdbus emitting a warning when no session bus is found
rather than silently exiting 0

Silent exit 0 on failure is particularly harmful here because it gives scripts
a false confirmation of success — the user believes their clipboard has been
cleared when it has not. For security-sensitive use cases this is a meaningful
risk.


COMPANION REPORT

See companion bug report: "Klipper clipboard history cannot be disabled by any
documented or discoverable method — 9 reproducible failure modes"


Jonathan Brown
GitHub: github.com/black-vajra Email:  [email protected]

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to