Esempio n. 1
0
CmsRet prctl_terminateProcessForcefully(SINT32 pid)
{
   return (oal_signalProcess(pid, SIGTERM));
}
Esempio n. 2
0
CmsRet prctl_signalProcess(SINT32 pid, SINT32 sig)
{
   return (oal_signalProcess(pid, sig));
}
Esempio n. 3
0
CmsRet oal_spawnProcess(const SpawnProcessInfo *spawnInfo, SpawnedProcessInfo *procInfo)
{
   char **argv=NULL;
   SINT32 pid, i;
   CmsRet ret=CMSRET_SUCCESS;

   if ((ret = parseArgs(spawnInfo->exe, spawnInfo->args, &argv)) != CMSRET_SUCCESS)
   {
      return ret;
   }

   pid = fork();
   if (pid == 0)
   {
      SINT32 devNullFd=-1, fd;

      /*
       * This is the child.
       */

      /*
       * If user gave us specific instructions on fd re-routing,
       * do it before execv.
       */
      if ((spawnInfo->stdinFd == -1) ||
          (spawnInfo->stdoutFd == -1) ||
          (spawnInfo->stderrFd == -1)) {
         devNullFd = open("/dev/null", O_RDWR);
         if (devNullFd == -1)
         {
            cmsLog_error("open of /dev/null failed");
            exit(-1);
         }
      }

      if (spawnInfo->stdinFd != 0)
      {
         close(0);
         fd = (spawnInfo->stdinFd == -1) ? devNullFd : spawnInfo->stdinFd;
         dup2(fd, 0);
      }

      if (spawnInfo->stdoutFd != 1)
      {
         close(1);
         fd = (spawnInfo->stdoutFd == -1) ? devNullFd : spawnInfo->stdoutFd;
         dup2(fd, 1);
      }

      if (spawnInfo->stderrFd != 2)
      {
         close(2);
         fd = (spawnInfo->stderrFd == -1) ? devNullFd : spawnInfo->stderrFd;
         dup2(fd, 2);
      }

      if (devNullFd != -1)
      {
         close(devNullFd);
      }

      /* if child has a serverFd, dup it to the fixed number */
      if (spawnInfo->serverFd != -1)
      {
         close(CMS_DYNAMIC_LAUNCH_SERVER_FD);         
         dup2(spawnInfo->serverFd, CMS_DYNAMIC_LAUNCH_SERVER_FD);
      }

#if defined(AEI_VDSL_CUSTOMER_NCS)
#ifdef SUPPORT_HTTPD_SSL
      /* httpd second listen fd, dup it if necessary to the fixed number also */
	 if (spawnInfo->eid == EID_HTTPD || spawnInfo->eid == EID_HTTPSD)
	  {
	      if (spawnInfo->serverFd2 != -1)
	      {
	         close(CMS_DYNAMIC_LAUNCH_SERVER_FD2);         
	         dup2(spawnInfo->serverFd2, CMS_DYNAMIC_LAUNCH_SERVER_FD2);
	      }
	  }
#endif
#endif
      /* close all of the child's other fd's */
      for (i=3; i <= spawnInfo->maxFd; i++)
      {
#if defined(AEI_VDSL_CUSTOMER_NCS) && defined(SUPPORT_HTTPD_SSL)
         if (i == CMS_DYNAMIC_LAUNCH_SERVER_FD || i == CMS_DYNAMIC_LAUNCH_SERVER_FD2)
#else
         if (i == CMS_DYNAMIC_LAUNCH_SERVER_FD)
#endif
  //       if ((spawnInfo->serverFd != -1)  &&
    //         (i == CMS_DYNAMIC_LAUNCH_SERVER_FD))
         {
            continue;
         }
         close(i);
      }

      /*
       * Set all signal handlers back to default action,
       * in case the parent had set them to SIG_IGN or something.
       * See kernel/linux/include/asm-mips/signal.h
       */
      signal(SIGHUP, SIG_DFL);
      if (spawnInfo->inheritSigint == FALSE)
      {
         /*
          * Note: there is a bug in pthread library in the 4.4.2 toolchain
          * which breaks SIG_IGN inheritance.  Apps are advised to set
          * SIGINT handler explicitly in the app itself.
          */
         signal(SIGINT, SIG_DFL);
      }
      signal(SIGQUIT, SIG_DFL);
      signal(SIGILL, SIG_DFL);
      signal(SIGTRAP, SIG_DFL);
      signal(SIGABRT, SIG_DFL);  /* same as SIGIOT */
#ifndef DESKTOP_LINUX
      signal(SIGEMT, SIG_DFL);
#endif
      signal(SIGFPE, SIG_DFL);
      signal(SIGBUS, SIG_DFL);
      signal(SIGSEGV, SIG_DFL);
      signal(SIGSYS, SIG_DFL);
      signal(SIGPIPE, SIG_DFL);
      signal(SIGALRM, SIG_DFL);
      signal(SIGTERM, SIG_DFL);
      signal(SIGUSR1, SIG_DFL);
      signal(SIGUSR2, SIG_DFL);
      signal(SIGCHLD, SIG_DFL);  /* same as SIGCLD */
      signal(SIGPWR, SIG_DFL);
      signal(SIGWINCH, SIG_DFL);
      signal(SIGURG, SIG_DFL);
      signal(SIGIO, SIG_DFL);    /* same as SIGPOLL */
      signal(SIGSTOP, SIG_DFL);
      signal(SIGTSTP, SIG_DFL);
      signal(SIGCONT, SIG_DFL);
      signal(SIGTTIN, SIG_DFL);
      signal(SIGTTOU, SIG_DFL);
      signal(SIGVTALRM, SIG_DFL);
      signal(SIGPROF, SIG_DFL);
      signal(SIGXCPU, SIG_DFL);
      signal(SIGXFSZ, SIG_DFL);


      /* overlay child executable over myself */
      execv(spawnInfo->exe, argv);

      /* We should not reach this line.  If we do, exec has failed. */
      exit(-1);
   }

   /* this is the parent */

   freeArgs(argv); /* don't need these anymore */

   memset(procInfo, 0, sizeof(SpawnedProcessInfo));
   procInfo->pid = pid;
   procInfo->status = PSTAT_RUNNING;

   if (spawnInfo->spawnMode == SPAWN_AND_WAIT)
   {
      CollectProcessInfo collectInfo;

      collectInfo.collectMode = COLLECT_PID_TIMEOUT;
      collectInfo.pid = pid;
      collectInfo.timeout = spawnInfo->timeout;

      ret = oal_collectProcess(&collectInfo, procInfo);
      if (ret == CMSRET_TIMED_OUT)
      {
         CmsRet r2;

         cmsLog_debug("pid %d has not exited in %d ms, SIGKILL", spawnInfo->timeout);
         r2 = oal_signalProcess(pid, SIGKILL);
         if (r2 != CMSRET_SUCCESS)
         {
            cmsLog_error("SIGKILL to pid %d failed with ret=%d", pid, r2);
         }

         /* try one more time to collect it */
         collectInfo.collectMode = COLLECT_PID_TIMEOUT;
         collectInfo.pid = pid;
         collectInfo.timeout = COLLECT_WAIT_INTERVAL_MS;
         r2 = oal_collectProcess(&collectInfo, procInfo);
         if (r2 == CMSRET_SUCCESS)
         {
            /* we finally go it, otherwise, leave ret at CMSRET_TIMED_OUT */
            ret = CMSRET_SUCCESS;
         }
      }
      else if (ret != CMSRET_SUCCESS)
      {
         /* some other error with collect */
         cmsLog_error("Could not collect pid %d", pid);
      }
   }

   return ret;
}