Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm using pam_exec to do some root tasks. They take some time, and I'd like to tell the user to wait a moment.

I'm doing the tasks there, and not later, because I need:

  • Root permissions
  • To rsync the home files from a server BEFORE anything gets loaded on the desktop

My problem is: I can't show a window displaying anything. i'm loading this script from pam_exec to test whether this is a $DISPLAY issue or a user issue:

#!/bin/bash

case "$PAM_TYPE" in

    'open_session')

    echo Plain exec &> /tmp/pamexec_output
    yad &>> /tmp/pamexec_output
    echo Set display &>> /tmp/pamexec_output
    DISPLAY=:0 yad &>> /tmp/pamexec_output
    echo Set user lightdm &>> /tmp/pamexec_output
        sudo -u lightdm yad &>> /tmp/pamexec_output
    echo Set user $PAM_USER &>> /tmp/pamexec_output
        sudo -u $PAM_USER yad &>> /tmp/pamexec_output
    echo Set user lightdm and display &>> /tmp/pamexec_output
    DISPLAY=:0 sudo -u lightdm yad &>> /tmp/pamexec_output
    echo Set user $PAM_USER and display &>> /tmp/pamexec_output
    DISPLAY=:0 sudo -u $PAM_USER yad &>> /tmp/pamexec_output
    echo PS AUX &>> /tmp/pamexec_output
    ps aux &>> /tmp/pamexec_output

    ;;

esac

I couldn't get my answer No windows are being shown, and the output:

Plain exec
No protocol specified
No protocol specified

(yad:25314): Gtk-WARNING **: cannot open display: :0
Set display
No protocol specified
No protocol specified

(yad:25317): Gtk-WARNING **: cannot open display: :0
Set user lightdm
No protocol specified
No protocol specified

(yad:25321): Gtk-WARNING **: cannot open display: :0
Set user jorge.suarez
No protocol specified
No protocol specified

(yad:25325): Gtk-WARNING **: cannot open display: :0
Set user lightdm and display
No protocol specified
No protocol specified

(yad:25328): Gtk-WARNING **: cannot open display: :0
Set user jorge.suarez and display
No protocol specified
No protocol specified

(yad:25331): Gtk-WARNING **: cannot open display: :0

As a bonus, here is the final output, from ps aux. Maybe that could help:

PS AUX
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.2  26684  2488 ?        Ss   Jan24   0:01 /sbin/init
root         2  0.0  0.0      0     0 ?        S    Jan24   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    Jan24   0:00 [ksoftirqd/0]
root         5  0.0  0.0      0     0 ?        S    Jan24   0:00 [kworker/u:0]
root         6  0.0  0.0      0     0 ?        S    Jan24   0:00 [migration/0]
root         7  0.0  0.0      0     0 ?        S    Jan24   0:00 [watchdog/0]
root         8  0.0  0.0      0     0 ?        S<   Jan24   0:00 [cpuset]
root         9  0.0  0.0      0     0 ?        S<   Jan24   0:00 [khelper]
root        10  0.0  0.0      0     0 ?        S    Jan24   0:00 [kdevtmpfs]
root        11  0.0  0.0      0     0 ?        S<   Jan24   0:00 [netns]
root        12  0.0  0.0      0     0 ?        S    Jan24   0:00 [sync_supers]
root        13  0.0  0.0      0     0 ?        S    Jan24   0:00 [bdi-default]
root        14  0.0  0.0      0     0 ?        S<   Jan24   0:00 [kintegrityd]
root        15  0.0  0.0      0     0 ?        S<   Jan24   0:00 [kblockd]
root        16  0.0  0.0      0     0 ?        S<   Jan24   0:00 [ata_sff]
root        17  0.0  0.0      0     0 ?        S    Jan24   0:00 [khubd]
root        18  0.0  0.0      0     0 ?        S<   Jan24   0:00 [md]
root        21  0.0  0.0      0     0 ?        S    Jan24   0:00 [khungtaskd]
root        22  0.0  0.0      0     0 ?        S    Jan24   0:00 [kswapd0]
root        23  0.0  0.0      0     0 ?        SN   Jan24   0:00 [ksmd]
root        24  0.0  0.0      0     0 ?        SN   Jan24   0:00 [khugepaged]
root        25  0.0  0.0      0     0 ?        S    Jan24   0:00 [fsnotify_mark]
root        26  0.0  0.0      0     0 ?        S    Jan24   0:00 [ecryptfs-kthrea]
root        27  0.0  0.0      0     0 ?        S<   Jan24   0:00 [crypto]
root        35  0.0  0.0      0     0 ?        S<   Jan24   0:00 [kthrotld]
root        36  0.0  0.0      0     0 ?        S    Jan24   0:00 [scsi_eh_0]
root        37  0.0  0.0      0     0 ?        S    Jan24   0:08 [scsi_eh_1]
root        38  0.0  0.0      0     0 ?        S    Jan24   0:00 [kworker/u:2]
root        59  0.0  0.0      0     0 ?        S<   Jan24   0:00 [devfreq_wq]
root       206  0.0  0.0      0     0 ?        S    Jan24   0:02 [jbd2/vda5-8]
root       207  0.0  0.0      0     0 ?        S<   Jan24   0:00 [ext4-dio-unwrit]
root       227  0.0  0.1  30844  1256 ?        S    Jan24   0:00 mountall --daemon
root       302  0.0  0.0  17224   640 ?        S    Jan24   0:00 upstart-udev-bridge --daemon
root       305  0.0  0.2  24524  2172 ?        Ss   Jan24   0:00 /sbin/udevd --daemon
root       431  0.0  0.0      0     0 ?        S<   Jan24   0:00 [kpsmoused]
root       504  0.0  0.1  19192  1032 ?        Ss   Jan24   0:00 rpcbind -w
root       513  0.0  0.0      0     0 ?        S    Jan24   0:00 [jbd2/vda6-8]
root       514  0.0  0.0      0     0 ?        S<   Jan24   0:00 [ext4-dio-unwrit]
root       532  0.0  0.0  15180   404 ?        S    Jan24   0:00 upstart-socket-bridge --daemon
root       570  0.0  0.0      0     0 ?        S    Jan24   0:00 [jbd2/vda7-8]
root       573  0.0  0.0      0     0 ?        S<   Jan24   0:00 [ext4-dio-unwrit]
root       655  0.0  0.0      0     0 ?        S<   Jan24   0:00 [rpciod]
root       658  0.0  0.0      0     0 ?        S<   Jan24   0:00 [nfsiod]
root       669  0.0  0.2  49948  2716 ?        Ss   Jan24   0:00 /usr/sbin/sshd -D
102        679  0.0  0.2  27184  2536 ?        Ss   Jan24   0:17 dbus-daemon --system --fork --activation=upstart
root       709  0.0  0.3  79036  3096 ?        Ss   Jan24   0:00 /usr/sbin/modem-manager
root       717  0.0  0.1  21180  1692 ?        Ss   Jan24   0:00 /usr/sbin/bluetoothd
syslog     733  0.0  0.1 249464  1404 ?        Sl   Jan24   0:02 rsyslogd -c5
root       738  0.0  0.5 229848  5260 ?        Ssl  Jan24   0:05 NetworkManager
root       746  0.0  0.0      0     0 ?        S<   Jan24   0:00 [krfcommd]
root       756  0.0  0.6 188336  5844 ?        Sl   Jan24   0:23 /usr/lib/policykit-1/polkitd --no-debug
statd      773  0.0  0.1  21496  1312 ?        Ss   Jan24   0:00 rpc.statd -L
avahi      780  0.0  0.1  34396  1716 ?        S    Jan24   0:00 avahi-daemon: registering [ctdeskxyy.local]
avahi      781  0.0  0.0  34268   472 ?        S    Jan24   0:00 avahi-daemon: chroot helper
root       787  0.0  0.1   7256  1508 ?        S    Jan24   0:00 /sbin/dhclient -d -4 -sf /usr/lib/NetworkManager/nm-dhcp-client.action -pf /var/run/sendsigs.omit.d/network-manager.dhclient-eth0.pid -lf /var/lib/dhcp/dhclient-05584152-142d-425d-b5b9-1e63697e0637-eth0.lease -cf /var/run/nm-dhclient-eth0.conf eth0
colord     808  0.0  1.2 491876 11588 ?        Sl   Jan24   0:01 /usr/lib/x86_64-linux-gnu/colord/colord
root       938  0.0  0.0  19980   932 tty4     Ss+  Jan24   0:00 /sbin/getty -8 38400 tty4
root       948  0.0  0.0  19980   940 tty5     Ss+  Jan24   0:00 /sbin/getty -8 38400 tty5
root       961  0.0  0.2  69768  1904 tty3     Ss   Jan24   0:00 /bin/login --             
root       964  0.0  0.0  19980   936 tty6     Ss+  Jan24   0:00 /sbin/getty -8 38400 tty6
root       983  0.0  0.0   4452   812 ?        Ss   Jan24   0:00 acpid -c /etc/acpi/events -s /var/run/acpid.socket
root       984  0.0  0.1  19104  1024 ?        Ss   Jan24   0:00 cron
daemon     985  0.0  0.0  16900   372 ?        Ss   Jan24   0:00 atd
root       991  0.0  0.3 262560  3396 ?        Ssl  Jan24   0:01 lightdm
whoopsie   993  0.0  0.5 202176  5024 ?        Ssl  Jan24   0:01 whoopsie
nobody    1001  0.0  0.1  33016  1252 ?        S    Jan24   0:00 /usr/sbin/dnsmasq --no-resolv --keep-in-foreground --no-hosts --bind-interfaces --pid-file=/var/run/sendsigs.omit.d/network-manager.dnsmasq.pid --listen-address=127.0.0.1 --conf-file=/var/run/nm-dns-dnsmasq.conf --cache-size=0 --proxy-dnssec
root      1023  0.0  0.1 701376  1192 ?        Ssl  Jan24   0:00 /usr/sbin/nscd
nslcd     1111  0.0  0.2 443796  1916 ?        Ssl  Jan24   0:00 /usr/sbin/nslcd
root      1254  0.0  0.4 586496  4152 ?        Sl   Jan24   0:08 /usr/sbin/console-kit-daemon --no-daemon
root      1362  0.0  0.0      0     0 ?        S    Jan24   0:01 [flush-253:0]
root      1534  0.0  0.2  76052  2032 tty1     Ss   Jan24   0:00 /bin/login --              
root      1536  0.0  0.4 219940  4272 ?        Sl   Jan24   0:01 /usr/lib/upower/upowerd
rtkit     1567  0.0  0.1 160644  1136 ?        SNl  Jan24   0:00 /usr/lib/rtkit/rtkit-daemon
1000      1782  0.0  0.4  19556  4676 tty1     S    Jan24   0:00 -bash
root      1930  0.0  0.2  66712  1904 tty1     S    Jan24   0:00 sudo su
root      1931  0.0  0.1  66472  1816 tty1     S    Jan24   0:00 su
root      1941  0.0  0.2  17260  2324 tty1     S+   Jan24   0:01 bash
root      1965  0.0  0.0      0     0 ?        S    Jan24   0:00 [lockd]
root      2505  0.0  0.3 193524  3628 ?        Sl   Jan24   0:01 /usr/lib/udisks/udisks-daemon
root      2506  0.0  0.0  45512   804 ?        S    Jan24   0:00 udisks-daemon: not polling any devices
root      5436  0.0  0.4  98476  4256 ?        Ss   08:01   0:00 /usr/sbin/cupsd -F
root     11778  0.0  0.0      0     0 ?        S<   08:01   0:00 [xfs_mru_cache]
root     11779  0.0  0.0      0     0 ?        S<   08:01   0:00 [xfslogd]
root     11780  0.0  0.0      0     0 ?        S<   08:01   0:00 [xfsdatad]
root     11781  0.0  0.0      0     0 ?        S<   08:01   0:00 [xfsconvertd]
root     11784  0.0  0.0      0     0 ?        S    08:01   0:00 [jfsIO]
root     11785  0.0  0.0      0     0 ?        S    08:01   0:00 [jfsCommit]
root     11786  0.0  0.0      0     0 ?        S    08:01   0:00 [jfsSync]
root     13718  0.0  0.0      0     0 ?        Z    Jan24   0:00 [lightdm] <defunct>
root     14197  0.0  0.1  24520  1640 ?        S    08:03   0:00 /sbin/udevd --daemon
root     14198  0.0  0.0      0     0 ?        S<   08:03   0:00 [iprt]
root     16911  0.0  0.2  69768  1904 tty2     Ss   Jan24   0:00 /bin/login --             
root     18750  0.0  0.3 124052  3712 ?        Sl   09:12   0:00 /usr/lib/accountsservice/accounts-daemon
root     21715  0.0  0.0      0     0 ?        Z    09:20   0:00 [lightdm] <defunct>
4004     23593  0.0  0.3 207504  3592 ?        Sl   09:35   0:00 /usr/lib/deja-dup/deja-dup/deja-dup-monitor
root     24087  0.0  0.0      0     0 ?        S    09:42   0:00 [kworker/0:1]
root     24355  0.0  0.0      0     0 ?        S    09:47   0:00 [kworker/0:2]
root     24581  0.1  2.6 122056 24912 ?        SN   09:48   0:00 /usr/bin/python /usr/sbin/aptd
root     25026  0.1  0.0      0     0 ?        S    09:52   0:00 [kworker/0:0]
root     25134  1.8  2.6 148396 25280 tty7     Ss+  09:53   0:00 /usr/bin/X :0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch
root     25226  0.0  0.3 155028  3136 ?        Sl   09:53   0:00 lightdm --session-child 12 385
lightdm  25258  0.1  0.5 344020  5200 ?        S<l  09:53   0:00 /usr/bin/pulseaudio --start --log-target=syslog
lightdm  25263  0.0  0.3  95984  3240 ?        S    09:53   0:00 /usr/lib/pulseaudio/pulse/gconf-helper
root     25313  0.0  0.1  16516  1376 ?        Ss   09:54   0:00 /bin/bash /usr/local/lib/puppet-files/gestion-sesiones.sh log=/tmp/cosaaaa
root     25334  0.0  0.1  14144  1020 ?        R    09:54   0:00 ps aux
4004     26833  0.0  0.5 362740  5676 ?        S<l  Jan24   0:01 /usr/bin/pulseaudio --start --log-target=syslog
4004     26836  0.0  0.3  95968  3256 ?        S    Jan24   0:00 /usr/lib/pulseaudio/pulse/gconf-helper
root     28396  0.0  0.0      0     0 ?        Z    Jan24   0:00 [lightdm] <defunct>
4004     29073  0.0  0.4  19536  4660 tty2     S+   Jan24   0:00 -bash
4004     29256  0.0  0.4  19488  4468 tty3     S+   Jan24   0:00 -bash

Another interesting finding. This script:

#!/bin/bash

case "$PAM_TYPE" in

    'open_session')

    (
         sleep 5
         yad &> /tmp/pam_output
    ) &

    ;;

esac

It works, but the window is being showed way after the desktop is loaded. So that won't help.

It also works at logout, no problem there.

Any ideas on how to solve this problem?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Instead of having the notifications occur in pam_exec, you could have pam_exec write to a file (like you are, with /tmp/pam_output), and have a separate daemon executed by lightdm before the user logs in, which monitors /tmp/pam_output and pops up a note when it sees new output. The background process run by lightdm would have the X environment and X11 cookies set up already, and would be run in the context of the lightdm user instead of root, which is more secure anyway. See this documentation on starting a script when the greeter starts.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.