SHARE
TWEET

Untitled

a guest Apr 28th, 2019 13 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  *  Copyright (C) 2019 Haiku, Inc.
  3.  *
  4.  * Redistribution and use in source and binary forms, with or without
  5.  * modification, are permitted provided that the following conditions
  6.  * are met:
  7.  * 1. Redistributions of source code must retain the above copyright
  8.  *    notice, this list of conditions and the following disclaimer.
  9.  * 2. Redistributions in binary form must reproduce the above copyright
  10.  *    notice, this list of conditions and the following disclaimer in the
  11.  *    documentation and/or other materials provided with the distribution.
  12.  *
  13.  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
  14.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  15.  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16.  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
  17.  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  18.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  23.  * THE POSSIBILITY OF SUCH DAMAGE.
  24.  */
  25.  
  26. #include "config.h"
  27. #include "ProcessLauncher.h"
  28.  
  29. #define __STDC_FORMAT_MACROS
  30. #include <unistd.h>
  31. #include <string>
  32. #include <inttypes.h>
  33. #include <stdlib.h>
  34. #include <sys/socket.h>
  35. #include <sys/resource.h>
  36.  
  37. #include <Looper.h>
  38.  
  39.  
  40. using namespace WebCore;
  41.  
  42. namespace WebKit {
  43.  
  44. static const char* processName(ProcessLauncher::ProcessType type)
  45. {
  46.     switch(type)
  47.     {
  48.         case ProcessLauncher::ProcessType::Web:
  49.         //debug later will be taken system based absolute path
  50.         return "/WebKit/webkit/WebKitBuild/Release/bin/WebProcess";
  51.         case ProcessLauncher::ProcessType::Network:
  52.         return "/WebKit/webkit/WebKitBuild/Release/bin/NetworkProcess";
  53.     }
  54. }
  55. long int ProcessLauncher::_looperThread(void* data)
  56. {
  57.     fprintf(stderr,"looper boy\n");
  58. }
  59. void ProcessLauncher::launchProcess()
  60. {
  61.    
  62.     const char* name=processName(m_launchOptions.processType);
  63.     char* procName;
  64.     switch(m_launchOptions.processType)
  65.     {
  66.         case ProcessLauncher::ProcessType::Web:
  67.         procName="WebProcess";
  68.         break;
  69.         case ProcessLauncher::ProcessType::Network:
  70.         procName="NetworkProcess";
  71.         break;
  72.     }
  73.     //process identifier
  74.     uint64_t prID = m_launchOptions.processIdentifier.toUInt64();
  75.     fprintf(stderr,"\nlaunch%d\n",prID);
  76.     char buff[21];
  77.     snprintf(buff,sizeof(buff),"%"PRIu64,prID);
  78.     //
  79.    
  80.     //socket
  81.     int sockets[2];
  82.     if(socketpair(AF_UNIX, SOCK_STREAM, 0, sockets)==-1)
  83.     {
  84.         fprintf(stderr,":(%s\n",strerror(errno));
  85.     }
  86.     //1-> client 0-> server is taken convention
  87.    
  88.     std::string sock = std::to_string(sockets[1]);
  89.     char* sockBuff = new char[sock.length()+1];
  90.     strcpy(sockBuff,sock.c_str());
  91.     //
  92.    
  93.     pid_t pid=fork();
  94.     char* m_args[]={procName,buff,sockBuff,NULL};
  95.     if(pid==0)
  96.     {
  97.         execvp(name,m_args);
  98.     }
  99.     else
  100.     {
  101.         fprintf(stderr,"\nChild:%d\n",pid);
  102.     }
  103.    
  104.     //
  105.     //thread create
  106.     thread_id looperInit;
  107.     looperInit=spawn_thread(&WebKit::ProcessLauncher::_looperThread,"runloopthread",B_NORMAL_PRIORITY,(void *)this);
  108.     if(looperInit>=B_OK)
  109.     resume_thread(looperInit);
  110.     //
  111.    
  112.     RefPtr<ProcessLauncher> protectedLauncher(this);
  113.     RunLoop::main().dispatch([]{
  114.         fprintf(stderr,"\n testing looper\n");
  115.     });
  116.     RunLoop::main().dispatch(WTF::Seconds(20.00),[protectedLauncher,pid,sockets]{
  117.             fprintf(stderr,"Messaged function executing now\n");
  118.             protectedLauncher->didFinishLaunchingProcess(pid,sockets[0]);
  119.         });*/
  120. }
  121.  
  122. void ProcessLauncher::terminateProcess()
  123. {
  124. }
  125.  
  126. void ProcessLauncher::platformInvalidate()
  127. {
  128. }
  129.  
  130. } // namespace WebKit
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top