javamanager/javacaptain/src.linux/pmc.cpp
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Pmc
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <sys/types.h>
       
    20 #include <signal.h>
       
    21 #include <sys/wait.h>
       
    22 #include <errno.h>
       
    23 #include <string.h>
       
    24 #include <stdlib.h>
       
    25 
       
    26 #include "logger.h"
       
    27 
       
    28 #include "pmc.h"
       
    29 #include "processmanagementeventsinterface.h"
       
    30 #include "coreinterface.h"
       
    31 
       
    32 namespace java
       
    33 {
       
    34 namespace captain
       
    35 {
       
    36 
       
    37 Pmc::Pmc()
       
    38 {
       
    39     JELOG4(EJavaCaptain, EInfo);
       
    40 }
       
    41 
       
    42 Pmc::~Pmc()
       
    43 {
       
    44     JELOG4(EJavaCaptain, EInfo);
       
    45 }
       
    46 
       
    47 bool Pmc::start(CoreInterface* /*aCore*/,
       
    48                 ProcessManagementEventsInterface* /*aProcessManagementEventsDispatcher*/)
       
    49 {
       
    50     JELOG4(EJavaCaptain, EInfo);
       
    51 
       
    52     return true;
       
    53 }
       
    54 
       
    55 bool Pmc::stop()
       
    56 {
       
    57     JELOG4(EJavaCaptain, EInfo);
       
    58 
       
    59     return true;
       
    60 }
       
    61 
       
    62 int Pmc::launch(const cmdLine_t& cmdLine, const int& /*options*/)
       
    63 {
       
    64     JELOG4(EJavaCaptain, EInfo);
       
    65 
       
    66     int status = 0, pid = 0;
       
    67 
       
    68     if (!(pid = fork()))
       
    69     {
       
    70         sigset_t unblock;
       
    71         sigemptyset(&unblock);
       
    72         sigaddset(&unblock, SIGINT);
       
    73         int rc = pthread_sigmask(SIG_UNBLOCK, &unblock, NULL);
       
    74         if (rc)
       
    75         {
       
    76             ELOG1(EJavaCaptain, "pthread_sigmask(UNBLOCK) for a child failed with %d", rc);
       
    77         }
       
    78 
       
    79         char** av = new char*[cmdLine.size() + 1];
       
    80         unsigned int index;
       
    81         for (index = 0; index < cmdLine.size() ; index++)
       
    82         {
       
    83             av[index] = const_cast<char*>(cmdLine[index].c_str());
       
    84             LOG1(EJavaCaptain, EInfo, "Launch command line is: %s", av[index]);
       
    85         }
       
    86         av[index] = NULL;
       
    87 
       
    88         status = execvp(av[0], av);
       
    89 
       
    90         if (status == -1)
       
    91         {
       
    92             LOG1(EJavaCaptain, EError, "execvp() returned %d", status);
       
    93             LOG2(EJavaCaptain, EError, "can't start %s, error message: %s", av[0], strerror(errno));
       
    94         }
       
    95         else
       
    96         {
       
    97             LOG1(EJavaCaptain, EInfo, "execvp() returned %d", status);
       
    98         }
       
    99         delete [] av;
       
   100         exit(status);
       
   101     }
       
   102 
       
   103     return pid;
       
   104 }
       
   105 
       
   106 int Pmc::terminate(const int& pid)
       
   107 {
       
   108     JELOG4(EJavaCaptain, EInfo);
       
   109     LOG1(EJavaCaptain, EInfo, "kill(pid=%d, SIGINT)", pid);
       
   110     ::kill(pid, SIGINT);
       
   111     return 0;
       
   112 }
       
   113 
       
   114 int Pmc::kill(const int& pid)
       
   115 {
       
   116     JELOG4(EJavaCaptain, EInfo);
       
   117     LOG1(EJavaCaptain, EInfo, "kill(pid=%d, SIGKILL)", pid);
       
   118     ::kill(pid, SIGKILL);
       
   119     return 0;
       
   120 }
       
   121 
       
   122 } // namespace captain
       
   123 } // namespace java
       
   124