⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 manager.c

📁 Minix3.11的源码。[MINIX 3是一个为高可靠性应用而设计的自由且简洁的类UNIX系统。]
💻 C
📖 第 1 页 / 共 2 页
字号:
		   * a binary exponetial backoff.		   */                  if (rp->r_restarts > 0) {		      rp->r_backoff = 1 << MIN(rp->r_restarts,(BACKOFF_BITS-1));		      rp->r_backoff = MIN(rp->r_backoff,MAX_BACKOFF); 		  }		  else {		      start_service(rp);		/* direct restart */		  }              }	      break;	  }      }  }}/*===========================================================================* *				do_period				     * *===========================================================================*/PUBLIC void do_period(m_ptr)message *m_ptr;{  register struct rproc *rp;  clock_t now = m_ptr->NOTIFY_TIMESTAMP;  int s;  /* Search system services table. Only check slots that are in use. */  for (rp=BEG_RPROC_ADDR; rp<END_RPROC_ADDR; rp++) {      if (rp->r_flags & RS_IN_USE) {          /* If the service is to be revived (because it repeatedly exited, 	   * and was not directly restarted), the binary backoff field is  	   * greater than zero. 	   */	  if (rp->r_backoff > 0) {              rp->r_backoff -= 1;	      if (rp->r_backoff == 0) {		  start_service(rp);	      }	  }	  /* If the service was signaled with a SIGTERM and fails to respond,	   * kill the system service with a SIGKILL signal.	   */	  else if (rp->r_stop_tm > 0 && now - rp->r_stop_tm > 2*RS_DELTA_T	   && rp->r_pid > 0) {              kill(rp->r_pid, SIGKILL);		/* terminate */	  }		  /* There seems to be no special conditions. If the service has a 	   * period assigned check its status. 	   */	  else if (rp->r_period > 0) {	      /* Check if an answer to a status request is still pending. If 	       * the driver didn't respond within time, kill it to simulate 	       * a crash. The failure will be detected and the service will 	       * be restarted automatically.	       */              if (rp->r_alive_tm < rp->r_check_tm) { 	          if (now - rp->r_alive_tm > 2*rp->r_period &&		      rp->r_pid > 0) { #if VERBOSE                      printf("RS: service %d reported late\n", rp->r_proc_nr); #endif                      kill(rp->r_pid, SIGKILL);		/* simulate crash */		  }	      }	      /* No answer pending. Check if a period expired since the last	       * check and, if so request the system service's status.	       */	      else if (now - rp->r_check_tm > rp->r_period) {#if VERBOSE                  printf("RS: status request sent to %d\n", rp->r_proc_nr); #endif		  notify(rp->r_proc_nr);		/* request status */		  rp->r_check_tm = now;			/* mark time */              }          }      }  }  /* Reschedule a synchronous alarm for the next period. */  if (OK != (s=sys_setalarm(RS_DELTA_T, 0)))      panic("RS", "couldn't set alarm", s);}/*===========================================================================* *				start_service				     * *===========================================================================*/PRIVATE int start_service(rp)struct rproc *rp;{/* Try to execute the given system service. Fork a new process. The child * process will be inhibited from running by the NO_PRIV flag. Only let the * child run once its privileges have been set by the parent. */  int child_proc_nr;				/* child process slot */  pid_t child_pid;				/* child's process id */  char *file_only;  int s;  message m;  /* Now fork and branch for parent and child process (and check for error). */  child_pid = fork();  switch(child_pid) {					/* see fork(2) */  case -1:						/* fork failed */      report("RS", "warning, fork() failed", errno);	/* shouldn't happen */      return(errno);					/* return error */  case 0:						/* child process */      /* Try to execute the binary that has an absolute path. If this fails,        * e.g., because the root file system cannot be read, try to strip of       * the path, and see if the command is in RS' current working dir.       */      execve(rp->r_argv[0], rp->r_argv, NULL);		/* POSIX execute */      file_only = strrchr(rp->r_argv[0], '/') + 1;      execve(file_only, rp->r_argv, NULL);		/* POSIX execute */      printf("RS: exec failed for %s: %d\n", rp->r_argv[0], errno);      exit(EXEC_FAILED);				/* terminate child */  default:						/* parent process */      child_proc_nr = getnprocnr(child_pid);		/* get child slot */       break;						/* continue below */  }  /* Only the parent process (the RS server) gets to this point. The child   * is still inhibited from running because it's privilege structure is   * not yet set. First try to set the device driver mapping at the FS.   */  if (rp->r_dev_nr > 0) {				/* set driver map */      if ((s=mapdriver(child_proc_nr, rp->r_dev_nr, rp->r_dev_style)) < 0) {          report("RS", "couldn't map driver", errno);	  if(child_pid > 0) kill(child_pid, SIGKILL);	/* kill driver */	  else report("RS", "didn't kill pid", child_pid);          rp->r_flags |= RS_EXITING;			/* expect exit */	  return(s);					/* return error */      }  }  /* The device driver mapping has been set, or the service was not a driver.   * Now, set the privilege structure for the child process to let is run.   * This should succeed: we tested number in use above.   */  m.PR_PROC_NR = child_proc_nr;  if ((s = _taskcall(SYSTEM, SYS_PRIVCTL, &m)) < 0) { 	/* set privileges */      report("RS","call to SYSTEM failed", s);		/* to let child run */      if(child_pid > 0) kill(child_pid, SIGKILL);	/* kill driver */      else report("RS", "didn't kill pid", child_pid);      rp->r_flags |= RS_EXITING;			/* expect exit */      return(s);					/* return error */  }#if VERBOSE      printf("RS: started '%s', major %d, pid %d, proc_nr %d\n",           rp->r_cmd, rp->r_dev_nr, child_pid, child_proc_nr);#endif  /* The system service now has been successfully started. Update the rest   * of the system process table that is maintain by the RS server. The only    * thing that can go wrong now, is that execution fails at the child. If    * that's the case, the child will exit.    */  rp->r_flags = RS_IN_USE;			/* mark slot in use */  rp->r_restarts += 1;				/* raise nr of restarts */  rp->r_proc_nr = child_proc_nr;		/* set child details */  rp->r_pid = child_pid;  rp->r_check_tm = 0;				/* not check yet */  getuptime(&rp->r_alive_tm); 			/* currently alive */  rp->r_stop_tm = 0;				/* not exiting yet */  rproc_ptr[child_proc_nr] = rp;		/* mapping for fast access */  return(OK);}/*===========================================================================* *				stop_service				     * *===========================================================================*/PRIVATE int stop_service(rp,how)struct rproc *rp;int how;{  /* Try to stop the system service. First send a SIGTERM signal to ask the   * system service to terminate. If the service didn't install a signal    * handler, it will be killed. If it did and ignores the signal, we'll   * find out because we record the time here and send a SIGKILL.   */#if VERBOSE  printf("RS tries to stop %s (pid %d)\n", rp->r_cmd, rp->r_pid);#endif  rp->r_flags |= how;				/* what to on exit? */  if(rp->r_pid > 0) kill(rp->r_pid, SIGTERM);	/* first try friendly */  else report("RS", "didn't kill pid", rp->r_pid);  getuptime(&rp->r_stop_tm); 			/* record current time */}/*===========================================================================* *				do_getsysinfo				     * *===========================================================================*/PUBLIC int do_getsysinfo(m_ptr)message *m_ptr;{  vir_bytes src_addr, dst_addr;  int dst_proc;  size_t len;  int s;  switch(m_ptr->m1_i1) {  case SI_PROC_TAB:  	src_addr = (vir_bytes) rproc;  	len = sizeof(struct rproc) * NR_SYS_PROCS;  	break;   default:  	return(EINVAL);  }  dst_proc = m_ptr->m_source;  dst_addr = (vir_bytes) m_ptr->m1_p1;  if (OK != (s=sys_datacopy(SELF, src_addr, dst_proc, dst_addr, len)))  	return(s);  return(OK);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -