'How to save file descriptor returned from gdbus call in bash?

I'm trying to use

#!/bin/bash
sudo gdbus call -y -d org.freedesktop.login1 \
                   -o /org/freedesktop/login1 \
                   -m org.freedesktop.login1.Manager.Inhibit \
                   sleep me because block
sleep 10

to acquire an inhibitor lock in a bash script. The introspection for this method looks like this:

Inhibit(in  s what,
        in  s who,
        in  s why,
        in  s mode,
        out h pipe_fd);

After my call to gdbus is done, no inhibitor lock is shown as acquired when listing with systemd-inhibit --list. I assume this is because the lock is acquired and then immediately released when exiting from gdbus.

How can I duplicate the returned file descriptor, pipe_fd, from the method call so it doesn't release the lock immediately after exiting from the call?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source