Bug 154188

Summary: kdesu does not work with kde4 programs
Product: [Applications] kdesu Reporter: Gabriel C <crazy>
Component: generalAssignee: kdesu bugs tracker <kdesu-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: klaus, thomas.friedrichsmeier
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: experimental patch
fix kdesu to work with kde4 programs

Description Gabriel C 2007-12-16 21:10:34 UTC
Version:            (using KDE Devel)
Installed from:    Compiled sources
Compiler:          hcc 4.2.2 
OS:                Linux

Hi,

I noticed kdesu any_kde4_app does not do much at the moment.  I can see the process in ps but is not visible to the user.

While some things like kuser and some kcm's need kdesu I think this should be fixed for 4.0 release.

Also it does run fine with any qt3/4 , gtk* programs etc.


Regards,

Gabriel
Comment 1 Thomas Friedrichsmeier 2007-12-17 16:48:51 UTC
Hm, I just tried using kwrite (from KDE 4), but could not reproduce (neither with the kdesu von KDE 3, nor the one from KDE 4).

Could you try
# kdesu -t -c kde4_app_that_fails
from the commandline and post the output?

Thanks!
Comment 2 Gabriel C 2007-12-17 17:21:12 UTC
You'll need an pure kde4 install to get that , eg not mixed kde3/kde4 , Bille confirmed that on #kde4-devel to not work.

here it  what I get with kuser as example:

-- kdesu -t -c kuser
kdesu(7937)/kdesu (kdelibs) KDESu::PtyProcess::exec: [ /var/tmp/fst/src/kdelibs-3.97.1_747313/kdesu/process.cpp : 300 ]  Running ` "/bin/su" '
kdesu(7937)/kdesu (kdelibs) KDESu::SuProcess::ConverseSU: [ /var/tmp/fst/src/kdelibs-3.97.1_747313/kdesu/su.cpp : 254 ]  Read line < "Password: " >
kdesu(7937)/kdesu (kdelibs) KDESu::PtyProcess::exec: [ /var/tmp/fst/src/kdelibs-3.97.1_747313/kdesu/process.cpp : 300 ]  Running ` "/bin/su" '
kdesu(7937)/kdesu (kdelibs) KDESu::SuProcess::ConverseSU: [ /var/tmp/fst/src/kdelibs-3.97.1_747313/kdesu/su.cpp : 254 ]  Read line < "Password: " >
kdesu(7937)/kdesu (kdelibs) KDESu::PtyProcess::WaitSlave: [ /var/tmp/fst/src/kdelibs-3.97.1_747313/kdesu/process.cpp : 380 ]  Child pid  7946
kdesu(7937)/kdesu (kdelibs) KDESu::SuProcess::ConverseSU: [ /var/tmp/fst/src/kdelibs-3.97.1_747313/kdesu/su.cpp : 254 ]  Read line < "" >
kdesu(7937)/kdesu (kdelibs) KDESu::SuProcess::ConverseSU: [ /var/tmp/fst/src/kdelibs-3.97.1_747313/kdesu/su.cpp : 254 ]  Read line < "kdesu_stub" >
kdesu(7937)/kdesu (kdelibs) KDESu::PtyProcess::exec: [ /var/tmp/fst/src/kdelibs-3.97.1_747313/kdesu/process.cpp : 300 ]  Running ` "/bin/su" '
kdesu(7937)/kdesu (kdelibs) KDESu::SuProcess::ConverseSU: [ /var/tmp/fst/src/kdelibs-3.97.1_747313/kdesu/su.cpp : 254 ]  Read line < "Password: " >
kdesu(7937)/kdesu (kdelibs) KDESu::PtyProcess::WaitSlave: [ /var/tmp/fst/src/kdelibs-3.97.1_747313/kdesu/process.cpp : 380 ]  Child pid  7950
kdesu(7937)/kdesu (kdelibs) KDESu::SuProcess::ConverseSU: [ /var/tmp/fst/src/kdelibs-3.97.1_747313/kdesu/su.cpp : 254 ]  Read line < "" >
kdesu(7937)/kdesu (kdelibs) KDESu::SuProcess::ConverseSU: [ /var/tmp/fst/src/kdelibs-3.97.1_747313/kdesu/su.cpp : 254 ]  Read line < "kdesu_stub" >
Qt: Session management error: Authentication Rejected, reason : None of the authentication protocols specified are supported and host-based authentication failed

< hangs here >

from ps :

crazy     7937  1.1  2.6  62228 17156 pts/7    Sl+  17:05   0:00 kdesu -t -c kuser
root      7950  0.0  0.4   8400  2584 pts/11   Ss+  17:05   0:00 /usr/lib/kde4/libexec/kdesu_stub
root      7953  0.1  1.6  32640 10800 ?        Ss   17:05   0:00 kuser

but 'kuser' is not visible for user crazy.

Also I get :

..

Qt: Session management error: Authentication Rejected, reason : None of the authentication protocols specified are supported and host-based authentication failed

...

for any program but is working for non-kde4 apps just fine.

When doing as example kdesu -t -c qbittorrent ( which is pure qt4 app ) kdesu works just fine.

Comment 3 Thomas Friedrichsmeier 2007-12-20 16:37:07 UTC
Created attachment 22632 [details]
experimental patch

Thanks for clarifying. I'm still stuck with a mixed system ATM, so can't test.

This is just a wild guess, but could you try applying the attached patch in
kdelibs/kdesu/? It should make the "Qt: Session management error" go away, but
I don't know if it affects the actual problem in any way.
Comment 4 Gabriel C 2007-12-21 00:43:58 UTC
Yes the QT: .. warning gone with your patch but the problem remains.

I've tested this time on my other box which has kde4 build with debug ( just qt without atm :s ). Here is what I get when I attach gdb to kdesu when it hangs

(gdb)  thread apply all bt

 Thread 2 (Thread 0xb52c3b90 (LWP 5576)):
#0  0xb7fa0410 in __kernel_vsyscall ()
#1  0xb6e8e401 in select () from /lib/libc.so.6
#2  0xb7ec81c5 in ?? () from /usr/lib/libQtCore.so.4
#3  0x0000000a in ?? ()
#4  0xb52c32c8 in ?? ()
#5  0x00000000 in ?? ()

Thread 1 (Thread 0xb6ac68e0 (LWP 5573)):
#0  0xb7fa0410 in __kernel_vsyscall ()
#1  0xb6e8e401 in select () from /lib/libc.so.6
#2  0xb710be46 in KDESu::PtyProcess::waitForChild (this=0xbffe8b10)
    at /work/crazy/repos/playground/source/kde4/kdelibs/src/kdelibs-3.97.1_750771/kdesu/process.cpp:440
#3  0xb710e34c in KDESu::SuProcess::exec (this=0xbffe8b10, password=0x80fa798 "", check=0)
    at /work/crazy/repos/playground/source/kde4/kdelibs/src/kdelibs-3.97.1_750771/kdesu/su.cpp:232
#4  0x0804e3dd in startApp () at /work/crazy/repos/playground/source/kde4/kdebase-runtime/src/kdebase-runtime-3.97.1_750806/kdesu/kdesu/kdesu.cpp:427
#5  0x0804efbd in main (argc=4, argv=0xbffe8f54)
    at /work/crazy/repos/playground/source/kde4/kdebase-runtime/src/kdebase-runtime-3.97.1_750806/kdesu/kdesu/kdesu.cpp:132
#0  0xb7fa0410 in __kernel_vsyscall ()
(gdb) l *0xb710be46
0xb710be46 is in KDESu::PtyProcess::waitForChild() (/work/crazy/repos/playground/source/kde4/kdelibs/src/kdelibs-3.97.1_750771/kdesu/process.cpp:441).
436             // iteration. (As long as we don't consitently time out in each iteration)
437             timeval timeout;
438             timeout.tv_sec = 0;
439             timeout.tv_usec = 100000;
440             int ret = select(fd()+1, &fds, 0L, 0L, &timeout);
441             if (ret == -1)
442             {
443                 if (errno != EINTR)
444                 {
445                     kError(900) << k_lineinfo << "select(): " << perror << "\n";
(gdb) l *0xb710e34c
0xb710e34c is in KDESu::SuProcess::exec(char const*, int) (/work/crazy/repos/playground/source/kde4/kdelibs/src/kdelibs-3.97.1_750771/kdesu/su.cpp:232).
227         {
228             waitForChild();
229             return 0;
230         }
231
232         iret = waitForChild();
233         return iret;
234     }
235
236     /*
(gdb) l *0x0804e3dd
0x804e3dd is in startApp (/work/crazy/repos/playground/source/kde4/kdebase-runtime/src/kdebase-runtime-3.97.1_750806/kdesu/kdesu/kdesu.cpp:427).
422             proc.setUser(user);
423             proc.setEnvironment(env);
424             proc.setPriority(priority);
425             proc.setScheduler(scheduler);
426             proc.setCommand(command);
427             int result = proc.exec(password.toLocal8Bit());
428             return result;
429         }
430         return -1;
431     }
(gdb) l *0x0804efbd
0x804efbd is in main (/work/crazy/repos/playground/source/kde4/kdebase-runtime/src/kdebase-runtime-3.97.1_750806/kdesu/kdesu/kdesu.cpp:134).
129     #endif
130         }
131
132         int result = startApp();
133
134         if (result == 127)
135         {
136             KMessageBox::sorry(0, i18n("Command '%1' not found.", QString::fromLocal8Bit(command)));
137         }
138


If you want I can strace , ltrace kdesu and put the log files online , guessing are a bit to big to attach here :)

If you want me to test some quick patches or everything you think may be useful to find out what is going wrong you can find me on IRC as well , my nickname is 'crazy' :) .



Comment 5 Thomas Friedrichsmeier 2007-12-21 14:35:54 UTC
I don't think it's kdesu itself which hangs, here. Rather, somehow the kde4 app to start is not happy with the environment in which it is supposed to run, and does not come up. At this point kdesu just waits for the app to finish. No good idea on what to try next, for now. Perhaps you could try attaching a gdb to the invoked app to find out, where it hangs.

Comment 6 Klaus Dimde 2007-12-21 16:13:04 UTC
I have the same problem although a different output from
#kdesu -t -c kuser      
kdesu(7686)/kdesu (kdelibs) KDESu::PtyProcess::exec: [ /sources/kde4/src/kdelibs/kdesu/process.cpp : 294 ]  Running ` "/bin/su" '
kdesu(7686)/kdesu (kdelibs) KDESu::SuProcess::ConverseSU: [ /sources/kde4/src/kdelibs/kdesu/su.cpp : 254 ]  Read line < "Password: " >
kdesu(7686)/kdesu (kdelibs) KDESu::PtyProcess::exec: [ /sources/kde4/src/kdelibs/kdesu/process.cpp : 294 ]  Running ` "/bin/su" '
kdesu(7686)/kdesu (kdelibs) KDESu::SuProcess::ConverseSU: [ /sources/kde4/src/kdelibs/kdesu/su.cpp : 254 ]  Read line < "Password: " >
kdesu(7686)/kdesu (kdelibs) KDESu::PtyProcess::WaitSlave: [ /sources/kde4/src/kdelibs/kdesu/process.cpp : 374 ]  Child pid  7693
kdesu(7686)/kdesu (kdelibs) KDESu::SuProcess::ConverseSU: [ /sources/kde4/src/kdelibs/kdesu/su.cpp : 254 ]  Read line < "" >
kdesu(7686)/kdesu (kdelibs) KDESu::SuProcess::ConverseSU: [ /sources/kde4/src/kdelibs/kdesu/su.cpp : 254 ]  Read line < "kdesu_stub" >
kdesu(7686)/kdesu (kdelibs) KDESu::PtyProcess::exec: [ /sources/kde4/src/kdelibs/kdesu/process.cpp : 294 ]  Running ` "/bin/su" '
kdesu(7686)/kdesu (kdelibs) KDESu::SuProcess::ConverseSU: [ /sources/kde4/src/kdelibs/kdesu/su.cpp : 254 ]  Read line < "Password: " >
kdesu(7686)/kdesu (kdelibs) KDESu::PtyProcess::WaitSlave: [ /sources/kde4/src/kdelibs/kdesu/process.cpp : 374 ]  Child pid  7695
kdesu(7686)/kdesu (kdelibs) KDESu::SuProcess::ConverseSU: [ /sources/kde4/src/kdelibs/kdesu/su.cpp : 254 ]  Read line < "" >
kdesu(7686)/kdesu (kdelibs) KDESu::SuProcess::ConverseSU: [ /sources/kde4/src/kdelibs/kdesu/su.cpp : 254 ]  Read line < "kdesu_stub" >
QMutex::lock: Deadlock detected in thread 47774408046688

with kdesu, kdesu_stub and kuser still running
Comment 7 Klaus Dimde 2007-12-21 16:24:27 UTC
Hope this helps too (scenario as above):
gdb attach PID_OF_KUSER 
(gdb) thread apply all bt

Thread 1 (Thread 47774408046688 (LWP 7699)):
#0  0x00002b734fe0c8a9 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/libpthread.so.0
#1  0x00002b734fa6e40d in QMutexPrivate::wait (this=0x6f5bd0, timeout=-1)
    at thread/qmutex_unix.cpp:76
#2  0x00002b734fa69dc3 in QMutex::lock (this=0x6f5bb0) at thread/qmutex.cpp:211
#3  0x00002b73523d9b2f in DBusMutex::mutex_lock (mutex=0x6f5bb0) at qdbusthread.cpp:68
#4  0x00002b7357498541 in _dbus_bus_notify_shared_connection_disconnected_unlocked (
    connection=0x6f3e90) at dbus-bus.c:353
#5  0x00002b735749be3c in _dbus_connection_get_dispatch_status_unlocked (connection=0x6f3e90)
    at dbus-connection.c:3871
#6  0x00002b735749d750 in _dbus_connection_block_pending_call (pending=0x6f3740)
    at dbus-connection.c:2280
#7  0x00002b735749cd3c in dbus_connection_send_with_reply_and_block (connection=0x6f3e90,
    message=0x6f4480, timeout_milliseconds=-1, error=0x7fff5b2a7eb0) at dbus-connection.c:3269
#8  0x00002b73574988ba in dbus_bus_register (connection=0x6f5c14, error=0x7fff5b2a7eb0)
    at dbus-bus.c:646
#9  0x00002b7357498d14 in internal_bus_get (type=<value optimized out>, private=1,
    error=0x7fff5b2a7eb0) at dbus-bus.c:445
#10 0x00002b73523b633d in QDBusConnection::connectToBus (type=QDBusConnection::SessionBus,
    name=@0x7fff5b2a7f40) at qdbusconnection.cpp:328
#11 0x00002b73523b93c1 in QDBusDefaultConnection (this=0x6de040,
    type=QDBusConnection::SessionBus, name=0x2b73523ef070 "qt_default_session_bus")
    at qdbusconnection.cpp:899
#12 0x00002b73523b65b2 in _q_sessionBus () at qdbusconnection.cpp:906
#13 0x00002b73523b6672 in QDBusConnection::sessionBus () at qdbusconnection.cpp:913
#14 0x00002b7359225428 in OxygenStyle (this=0x6dd070)
    at /sources/kde4/src/kdebase/runtime/kstyles/oxygen/oxygen.cpp:102
#15 0x00002b735922b3c8 in KStyleFactory<OxygenStyle>::create (this=0x6d6b40,
    id=@0x7fff5b2a8190) at /opt/kde4/include/KDE/../kstyle.h:1581
#16 0x00002b735510b6ea in QStyleFactory::create (key=@0x7fff5b2a8240)
    at styles/qstylefactory.cpp:166
#17 0x00002b7354e9cda2 in QApplication::style () at kernel/qapplication.cpp:1186
#18 0x00002b7354e9d4e2 in QApplicationPrivate::initialize (this=0x6ab080)
    at kernel/qapplication.cpp:806
#19 0x00002b7354e9d5a0 in QApplicationPrivate::construct (this=0x6ab080, dpy=0x0, visual=0,
    cmap=0) at kernel/qapplication.cpp:710
#20 0x00002b7354e9f7dd in QApplication (this=0x7fff5b2a83f0, argc=@0x2b735046c4f0,
    argv=0x6aae00, GUIenabled=true, _internal=262915) at kernel/qapplication.cpp:667
#21 0x00002b73506561d8 in KApplication (this=0x7fff5b2a83f0, GUIenabled=<value optimized out>)
    at /sources/kde4/src/kdelibs/kdeui/kernel/kapplication.cpp:354
#22 0x00000000004318e5 in main (argc=1, argv=0x7fff5b2a8678)
    at /sources/kde4/src/kdeadmin/kuser/ku_main.cpp:54
Comment 8 Gabriel C 2007-12-21 18:57:35 UTC
Right , I got something similar but not usable qt debug output ( in mean time I'm building qt4 4.3.3 with debug ). 

Maybe thiago knows what is going on.
Comment 9 Gabriel C 2007-12-21 20:21:06 UTC
Created attachment 22646 [details]
fix kdesu to work with kde4 programs

After thiago said :

thiago> crazy: you cannot connect to the user's session bus from another UID

all was clear :)

Also this patch combine my fix and thomas fix and I've added comments on why we
do unset these things.
Comment 10 Gabriel C 2007-12-21 20:23:41 UTC
Klaus could you give it a test please ? works fine for me.

Also if you patched kdelibs with Thomas patch please revert first then use my patch.
Comment 11 Klaus Dimde 2007-12-22 17:17:21 UTC
Patch works fine for me. No problems anymore
Comment 12 Thomas Friedrichsmeier 2007-12-23 19:33:07 UTC
SVN commit 752154 by tfry:

Unset Qt and DBus sessions. Patch by Gabriel C.
CCMAIL: l.lunak@kde.org
BUG: 154188

 M  +5 -0      process.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=752154