[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: Starting ksysguard from kicker
From:       Waldo Bastian <bastian () kde ! org>
Date:       2002-03-12 20:05:16
[Download RAW message or body]

On Tuesday 12 March 2002 09:25 am, Chris Schlaeger wrote:
> > Anyway I will change it then so that it always detaches from its
> > controlling tty and make sure that it registers with DCOP first before
> > exiting. I'll send a new patch for review later.
>
> Ok, great.

Please review.

Cheers,
Waldo
-- 
bastian@kde.org  |   SuSE Labs KDE Developer  |  bastian@suse.com

["ksysguard.diff" (text/x-diff)]

Index: ksysguard.cc
===================================================================
RCS file: /home/kde/kdebase/ksysguard/gui/ksysguard.cc,v
retrieving revision 1.51
diff -u -p -r1.51 ksysguard.cc
--- ksysguard.cc	2002/03/03 12:34:46	1.51
+++ ksysguard.cc	2002/03/12 20:02:48
@@ -540,23 +540,36 @@ static const KCmdLineOptions options[] =
 int
 main(int argc, char** argv)
 {
-#ifndef NDEBUG
+	// initpipe is used to keep the parent process around till the child
+	// has registered with dcop. 
+	int initpipe[2];
+	pipe(initpipe);
+
 	/* This forking will put ksysguard in it's on session not having a
 	 * controlling terminal attached to it. This prevents ssh from
 	 * using this terminal for password requests. Unfortunately you
 	 * now need a ssh with ssh-askpass support to popup an X dialog to
 	 * enter the password. Currently only the original ssh provides this
 	 * but not open-ssh. */
+	 
 	pid_t pid;
 	if ((pid = fork()) < 0)
 		return (-1);
 	else
 		if (pid != 0)
 		{
+			close(initpipe[1]);
+
+			// wait till init is complete
+			char c;
+			while( read(initpipe[0], &c, 1) < 0);
+
+			// then exit
+			close(initpipe[0]);
 			exit(0);
 		}
+	close(initpipe[0]);
 	setsid();
-#endif
 
 	KAboutData aboutData("ksysguard", I18N_NOOP("KDE System Guard"),
 						 KSYSGUARD_VERSION, Description,
@@ -581,6 +594,7 @@ main(int argc, char** argv)
 	KCmdLineArgs::init(argc, argv, &aboutData);
 	KCmdLineArgs::addCmdLineOptions(options);
 	
+	KApplication::disableAutoDcopRegistration();
 	// initialize KDE application
 	KApplication *a = new KApplication;
 
@@ -601,6 +615,11 @@ main(int argc, char** argv)
 		if (a->dcopClient()->registerAs("ksysguard_taskmanager", false) ==
 			"ksysguard_taskmanager")
 		{
+			// We have registered with DCOP, our parent can exit now.
+			char c = 0;
+			write(initpipe[1], &c, 1);
+			close(initpipe[1]);
+
 			Toplevel = new TopLevel("KSysGuard");
 			Toplevel->beATaskManager();
 			Toplevel->show();
@@ -612,8 +631,13 @@ main(int argc, char** argv)
 	}
 	else
 	{
-		a->dcopClient()->registerAs("ksysguard", false);
+		a->dcopClient()->registerAs("ksysguard");
 		a->dcopClient()->setDefaultObject("KSysGuardIface");
+
+		// We have registered with DCOP, our parent can exit now.
+		char c = 0;
+		write(initpipe[1], &c, 1);
+		close(initpipe[1]);
 
 		Toplevel = new TopLevel("KSysGuard");
 		Q_CHECK_PTR(Toplevel);
Index: ksysguard.desktop
===================================================================
RCS file: /home/kde/kdebase/ksysguard/gui/ksysguard.desktop,v
retrieving revision 1.128
diff -u -p -r1.128 ksysguard.desktop
--- ksysguard.desktop	2002/03/06 09:37:53	1.128
+++ ksysguard.desktop	2002/03/12 20:02:48
@@ -63,4 +63,4 @@ TerminalOptions=
 Terminal=0
 Path=
 X-KDE-StartupNotify=true
-X-DCOP-ServiceType=Multi
+X-DCOP-ServiceType=Unique


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic