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

List:       kde-commits
Subject:    KDE/kdelibs/kinit
From:       Oswald Buddenhagen <ossi () kde ! org>
Date:       2009-04-19 13:01:06
Message-ID: 1240146066.184379.31294.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 956152 by ossi:

much less magical klauncher startup

instead of passing the socket through a fixed fd, pass the actual number
on the command line.
this also rips out the special casing of klauncher from launch(), which
simplifies the code a lot.

 M  +22 -47    kinit.cpp  
 M  +0 -6      klauncher_cmds.h  
 M  +4 -2      klauncher_main.cpp  


--- trunk/KDE/kdelibs/kinit/kinit.cpp #956151:956152
@@ -212,10 +212,10 @@
       d.initpipe[1] = -1;
    }
 
-   if (d.launcher_pid)
+   if (d.launcher[0] != -1)
    {
       close(d.launcher[0]);
-      d.launcher_pid = 0;
+      d.launcher[0] = -1;
    }
    if (d.wrapper != -1)
    {
@@ -423,23 +423,10 @@
                     const char *tty=0, bool avoid_loops = false,
                     const char* startup_id_str = "0" )
 {
-  int starting_klauncher = 0;
   QString lib;
   QByteArray name;
   QByteArray exec;
 
-  if (strcmp(_name, "klauncher") == 0) {
-     /* klauncher is launched in a special way:
-      * It has a communication socket on LAUNCHER_FD
-      */
-     if (0 > socketpair(AF_UNIX, SOCK_STREAM, 0, d.launcher))
-     {
-        perror("kdeinit4: socketpair() failed");
-        exit(255);
-     }
-     starting_klauncher = 1;
-  }
-
     QString libpath;
     QByteArray execpath;
     if (_name[0] != '/') {
@@ -497,19 +484,6 @@
      /** Child **/
      close(d.fd[0]);
      close_fds();
-     if (starting_klauncher)
-     {
-        if (d.fd[1] == LAUNCHER_FD)
-        {
-          d.fd[1] = dup(d.fd[1]); // Evacuate from LAUNCHER_FD
-        }
-        if (d.launcher[1] != LAUNCHER_FD)
-        {
-          dup2( d.launcher[1], LAUNCHER_FD); // Make sure the socket has fd \
                LAUNCHER_FD
-          close( d.launcher[1] );
-        }
-        close( d.launcher[0] );
-     }
 
      // Try to chdir, either to the requested directory or to the user's document \
                path by default.
      // We ignore errors - if you write a desktop file with Exec=foo and \
Path=/doesnotexist, @@ -685,11 +659,6 @@
   default:
      /** Parent **/
      close(d.fd[1]);
-     if (starting_klauncher)
-     {
-        close(d.launcher[1]);
-        d.launcher_pid = d.fork;
-     }
      bool exec = false;
      for(;;)
      {
@@ -747,11 +716,6 @@
        break;
      }
      close(d.fd[0]);
-     if (starting_klauncher && (d.result == 0))
-     {
-        // klauncher launched successfully
-        d.launcher_pid = d.fork;
-     }
   }
 #ifdef Q_WS_X11
   if( !startup_id.none())
@@ -1005,6 +969,23 @@
   return 0;
 }
 
+static void start_klauncher()
+{
+    if (socketpair(AF_UNIX, SOCK_STREAM, 0, d.launcher) < 0) {
+        perror("kdeinit4: socketpair() failed");
+        exit(255);
+    }
+    char args[32];
+    strcpy(args, "--fd=");
+    sprintf(args + 5, "%d", d.launcher[1]);
+    d.launcher_pid = launch( 2, "klauncher", args );
+    close(d.launcher[1]);
+#ifndef NDEBUG
+    fprintf(stderr, "kdeinit4: Launched KLauncher, pid = %ld, result = %d\n",
+                    (long) d.launcher_pid, d.result);
+#endif
+}
+
 static void launcher_died()
 {
    if (!d.launcher_ok)
@@ -1031,10 +1012,7 @@
    close(d.launcher[0]);
    d.launcher[0] = -1;
 
-   pid_t pid = launch( 1, "klauncher", 0 );
-#ifndef NDEBUG
-   fprintf(stderr, "kdeinit4: Relaunching KLauncher, pid = %ld result = %d\n", \
                (long) pid, d.result);
-#endif
+   start_klauncher();
 }
 
 static void handle_launcher_request(int sock = -1)
@@ -1706,11 +1684,8 @@
 #endif
    if (launch_klauncher)
    {
-      pid = launch( 1, "klauncher", 0 );
-#ifndef NDEBUG
-      fprintf(stderr, "kdeinit4: Launched KLauncher, pid = %ld result = %d\n", \
                (long) pid, d.result);
-#endif
-      handle_requests(pid); // Wait for klauncher to be ready
+      start_klauncher();
+      handle_requests(d.launcher_pid); // Wait for klauncher to be ready
    }
 
 #ifdef Q_WS_X11
--- trunk/KDE/kdelibs/kinit/klauncher_cmds.h #956151:956152
@@ -179,12 +179,6 @@
  *    infinite loop by binary->kdeinit_wrapper link in $PATH
  */
 
-#define LAUNCHER_FD	42
-/*
- * File descriptor to use for communication with kdeinit.
- */
-
-
 const char* commandToString(int command);
 
 #endif
--- trunk/KDE/kdelibs/kinit/klauncher_main.cpp #956151:956152
@@ -52,13 +52,15 @@
 {
 #ifndef Q_WS_WIN
    // Started via kdeinit.
-   if (fcntl(LAUNCHER_FD, F_GETFD) == -1)
+   int launcherFd;
+   if (argc != 2 || memcmp(argv[1], "--fd=", 5) || !(launcherFd = atoi(argv[1] + \
5)))  {
       fprintf(stderr, "%s", i18n("klauncher: This program is not supposed to be \
                started manually.\n"
                                  "klauncher: It is started automatically by \
kdeinit4.\n").toLocal8Bit().data());  return 1;
    }
 #endif
+
    KComponentData componentData("klauncher");
 
    // WABA: Make sure not to enable session management.
@@ -103,7 +105,7 @@
    }
 
 #ifndef Q_WS_WIN
-   KLauncher *launcher = new KLauncher(LAUNCHER_FD);
+   KLauncher *launcher = new KLauncher(launcherFd);
 #else
    KLauncher *launcher = new KLauncher();
 #endif


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

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