Changeset 1041
- Timestamp:
- 10/08/06 11:23:16 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/starting-and-stopping-dbus-with-kdm.txt
r1038 r1041 1 1 AUTHOR: Stef Bon <stef at bononline dot nl> 2 2 3 DATE: 2006-0 7-183 DATE: 2006-09-09 4 4 5 5 LICENSE: GNU Free Documentation License Version 1.2 … … 10 10 This hint is about starting the sessionpart of the dbusdaemon. This 11 11 is based on my hint 12 "Execute scripts at begin and end of a KDE-session using KDM and PAM".12 "Execute scripts at begin and end of a KDE-session using KDM". 13 13 14 14 In this hint is described in general how scripts and commands are 15 started at the begin and end of a KDE session using KDM, and for password 16 sensitive commands support from PAM. 17 18 DBUS does not need anything of PAM, so here you'll find how you can start 19 and stop the session dbus daemon with KDM. 15 started at the begin and end of a KDE session using KDM. 16 17 It's very possible to use this construction with oher loginmanagers as well. 18 20 19 21 20 ATTACHMENT: … … 33 32 1.2 Starting the sessionbus part of dbus 34 33 1.3 Stopping the sessionbus part of dbus 35 1.4 Installation of Sudo 1.6.8p 734 1.4 Installation of Sudo 1.6.8p12 36 35 1.5 One user is more than one time logged in 37 36 … … 40 39 --------------------------------------------------------------------------------- 41 40 42 The dbus package is split up in two parts: one systemwide part and one for (each) session/user.43 The systemwide part (a daemon) is started at boottime, with special privileges of a dedicated user. 44 The sessionwide part (also a daemon) has to started when a session for a user begins,45 and stopped when the session ends.46 47 The construction with kdm I'm using here is ideal for this. One script in the startup directory to48 start the sessiondaemon for a user, running with the privileges of that user, and one in the reset49 directory an other script has to stop that daemon.50 51 But is not so simple as that. Some variables (DBUS_SESSION_BUS_ADDRESS and DBUS_SESSION_BUS_PID) have to52 be available in the environment to every application which works with dbus.53 IMHO the setting of these variables should go in the bash-startupscripts. 54 Then whatever script or application you're running, these variables are set 55 to the right value.41 The dbus package is split up in two parts: one systemwide part and one 42 for (each) session/user. The systemwide part (a daemon) is started at boottime, 43 with special privileges of a dedicated user. The sessionwide part (also a daemon) 44 has to started when a session for a user begins, and stopped when the session ends. 45 46 The construction with kdm I'm using here is ideal for this. One script in the 47 startup directory to start the sessiondaemon for a user, running with the privileges 48 of that user, and one in the reset directory an other script has to stop that daemon. 49 50 But is not so simple as that. Some variables (DBUS_SESSION_BUS_ADDRESS and 51 DBUS_SESSION_BUS_PID) have to be available in the environment to every application 52 which works with dbus. IMHO the setting of these variables should go in the 53 bash-startupscripts. Then whatever script or application you're running, these 54 variables are set to the right value. 56 55 57 56 … … 60 59 ---------------------------------- 61 60 62 The sessiondaemon of dbus creates a file which contains the environmentvariables. As stated above this 63 file should be read (sourced) by bash when it starts for this user. 64 65 When bash is started by "login" as an interactive login shell, it reads /etc/profile and ~/.bash_profile. 66 Bash is also started by "kdm", and the files /etc/profile and ~/.bash_profile are sourced. 61 The sessiondaemon of dbus creates a file which contains the environmentvariables. 62 As stated above this file should be read (sourced) by bash when it starts for this user. 63 64 When bash is started by "login" as an interactive login shell, it reads /etc/profile 65 and ~/.bash_profile. Bash is also started by "kdm", and the files /etc/profile 66 and ~/.bash_profile are sourced. 67 67 68 68 My idea is to store the output of the command … … 74 74 $HOME/.dbus-session 75 75 76 This file is "sourced" when bash start. This happens not automatically, but you will have to add the following script to /etc/profile.d : 76 This file is "sourced" when bash start. This happens not automatically, but you 77 will have to add the following script to /etc/profile.d : 77 78 78 79 cat >> dbus-session.sh << "EOF" … … 96 97 (beginning 200510..). 97 98 98 Create a script in the /etc/session.d/kdm/startup directory dbus- kdm.sh:99 Create a script in the /etc/session.d/kdm/startup directory dbus-session-start.sh: 99 100 100 101 cd /etc/session.d/kdm/startup 101 102 102 cat >> dbus- kdm.sh << "EOF"103 cat >> dbus-session-start.sh << "EOF" 103 104 #!/bin/bash 104 105 … … 113 114 114 115 if [ -d $homedir ]; then 115 116 # should there be a check dbus-launch is already running for this user? 117 116 117 # 118 # do a check whether dbus-daemon is already running 119 # dbus-daemon needs to be started by the user (uidnr) logging in 120 # 121 122 if [ -f $homedir/.dbus-session ]; then 123 124 # do a check the dbus-daemon for this user is running with the pid 125 # in the .dbus-session file 126 127 # pid according to the ps command 128 ps_dbus_session_pid=$(ps aux | grep -m 1 -E "^$userid.*dbus-daemon.*session.*" \ 129 | grep -v "grep" | sed 's@[[:space:]][[:space:]]*@ @g' | cut -d " " -f 2) 130 131 # read the pid from the .dbus-session file 132 . $homedir/.dbus-session 133 134 135 # check they are the same 136 if [ -z "$ps_dbus_session_pid" ]; then 137 138 # dbus for this user not running 139 rm $homedir/.dbus-session 140 141 elif [ $DBUS_SESSION_BUS_PID -ne $ps_dbus_session_pid ]; then 142 143 # there is something wrong: stop dbus-daemon for this user 144 # and remove .dbus-session file 145 if [ $(id -u) -eq 0 ]; then 146 sudo -H -u $userid sh -c "kill $ps_dbus_session_pid" 147 148 elif [ $(id -u) -eq $uidnr ]; then 149 kill -SIGTERM $ps_dbus_session_pid; 150 fi 151 152 rm $homedir/.dbus-session 153 154 fi 155 156 fi 157 158 if [ ! -f $homedir/.dbus-session ]; then 159 160 # only start a dbus session if .dbus-session file it not found 161 # in users homedirectory 162 118 163 if [ $(id -u) -eq 0 ]; then 119 164 sudo -u $userid -H /bin/sh -c "dbus-launch --auto-syntax > $homedir/.dbus-session" 120 165 retcode=$? 121 166 chown $uidnr:$gidnr $homedir/.dbus-session 122 chmod u+x $homedir/.dbus-session123 167 elif [ $(id -u) -eq $uidnr ]; then 124 168 dbus-launch --auto-syntax > $homedir/.dbus-session 125 169 retcode=$? 126 chmod u+x $homedir/.dbus-session127 170 fi 171 172 fi 128 173 129 174 fi; … … 135 180 exit $retcode 136 181 EOF 182 183 chmod 755 /etc/session.d/kdm/startup/dbus-session-start.sh 137 184 138 185 This script, executed by KDM at startup will start the dbus session daemon for this user, 139 186 and will create the .dbus-session file in the homedirectory of this user, containing 140 187 all the dbusvariables. 188 It will only do this when dbus is not already running for this user. 141 189 142 190 Now when bash starts at login, it reads (sources) this file. … … 160 208 161 209 162 Creating the dbus .sh script in the reset directory:210 Creating the dbus-session-stop.sh script in the reset directory: 163 211 164 212 165 213 cd /etc/session.d/kdm/reset 166 214 167 cat >> dbus- kdm.sh << "EOF"215 cat >> dbus-session-stop.sh << "EOF" 168 216 #!/bin/bash 169 217 … … 202 250 EOF 203 251 252 chmod 755 /etc/session.d/kdm/reset/dbus-session-stop.sh 253 204 254 This script stops the session part of the dbus-daemon. 205 255 … … 238 288 one sessions at the same time? Is it nessacary to start the sessionpart 239 289 of dbus for every session, or is one instance sufficient? 240 At this moment I don't have the answer for that question. 241 Any has, please let me know. 242 243 I'll go check out the Internet about it. 290 291 This construction does not allow more than one dbus-daemon per user. 292 I think that should be good enough. 293 244 294 245 295 ACKNOWLEDGEMENTS: … … 252 302 * Changed the bash scripts 253 303 * changed from sudo-1.6.8p7 to sudo-1.6.8p12 254 304 [2006-09-09] 305 * add check to see dbus-daemon is already running for this user 306 and the information found in .dbus-session is right
