Exemple #1
0
/*
**  Name:	int dpeth_task(void)
**  Function:	Main entry for dp task
*/
PUBLIC int main(int argc, char **argv)
{
  message m;
  int ipc_status;
  int rc;

  /* SEF local startup. */
  env_setargs(argc, argv);
  sef_local_startup();

  while (TRUE) {
	if ((rc = netdriver_receive(ANY, &m, &ipc_status)) != OK){
		panic(RecvErrMsg, rc);
	}

	DEBUG(printf("eth: got message %d, ", m.m_type));

	if (is_ipc_notify(ipc_status)) {
		switch(_ENDPOINT_P(m.m_source)) {
			case CLOCK:
				/* to be defined */
				do_watchdog(&m);
				break;
			case HARDWARE:
				/* Interrupt from device */
				handle_hw_intr();
				break;
			case TTY_PROC_NR:
				/* Function key pressed */
				do_dump(&m);
				break;
			default:	
				/* Invalid message type */
				panic(TypeErrMsg, m.m_type);
				break;
		}
		/* message processed, get another one */
		continue;
	}

	switch (m.m_type) {
	    case DL_WRITEV_S:	/* Write message to device */
		do_vwrite_s(&m);
		break;
	    case DL_READV_S:	/* Read message from device */
		do_vread_s(&m);
		break;
	    case DL_CONF:	/* Initialize device */
		do_init(&m);
		break;
	    case DL_GETSTAT_S:	/* Get device statistics */
		do_getstat_s(&m);
		break;
	    default:		/* Invalid message type */
		panic(TypeErrMsg, m.m_type);
		break;
	}
  }
  return OK;			/* Never reached, but keeps compiler happy */
}
Exemple #2
0
/*===========================================================================*
 *				main					     *
 *===========================================================================*/
int main(int argc, char *argv[])
{
  dpeth_t *dep;
  message m;
  int ipc_status;
  int r;

  /* SEF local startup. */
  env_setargs(argc, argv);
  sef_local_startup();
  
  while (TRUE)
    {
      if ((r= netdriver_receive(ANY, &m, &ipc_status)) != OK)
	panic("netdriver_receive failed: %d", r);

		if(is_ipc_notify(ipc_status)) {
			switch(_ENDPOINT_P(m.m_source)) {
				case CLOCK:
					do_watchdog(&m);
					break;

	case HARDWARE:
	  dep = &de_state;
	  if (dep->de_mode == DEM_ENABLED) {
	    do_interrupt(dep);
	    if (dep->de_flags & (DEF_ACK_SEND | DEF_ACK_RECV))
	    do_reply(dep);
	    sys_irqenable(&dep->de_hook);
	  }
	  break;
	 default:
	 	printf("ignoring notify from %d\n", m.m_source);
	 	break;
			}
			continue;
		}
      
      switch (m.m_type)
	{
	case DL_WRITEV_S:  do_vwrite_s(&m, FALSE); break;
	case DL_READV_S:   do_vread_s(&m, FALSE);  break;	  
	case DL_CONF:      do_conf(&m);            break;  
	case DL_GETSTAT_S: do_get_stat_s(&m);      break;

	default:  
		printf("message 0x%x; %d from %d\n",
			m.m_type, m.m_type-DL_RQ_BASE, m.m_source);
		panic("illegal message: %d", m.m_type);
	}
    }
}
Exemple #3
0
int
spawn_process() {
  /* Spawns the child process.  Returns true if the process terminated
     by itself and should be respawned, false if it was explicitly
     killed (or some other error condition exists), and it should not
     respawn any more. */
  pid_t wresult;
  int status;
  int error_exit;

  child_pid = fork();
  if (child_pid < 0) {
    /* Fork error. */
    perror("fork");
    return 0;
  }

  if (child_pid == 0) {
    /* Child.  Exec the process. */
    fprintf(stderr, "Child pid is %d.\n", getpid());
    exec_process();
    /* Shouldn't get here. */
    exit(1);
  }

  /* Parent. */

  error_exit = 0;

  if (watchdog_url != NULL) {
    /* If we're watchdogging, then go check the URL.  This function
       won't return until the URL fails or the child exits. */
    error_exit = do_watchdog(&status);

  } else {
    /* If we're not watchdogging, then just wait for the child to
       terminate, and diagnose the reason. */
    wresult = waitpid(child_pid, &status, 0);
    if (wresult < 0) {
      perror("waitpid");
      return 0;
    }
  }

  /* Now that we've returned from waitpid, clear the child pid number
     so our signal handler doesn't get too confused. */
  child_pid = 0;

  if (error_exit) {
    /* An HTTP error exit is a reason to respawn. */
    return 1;

  } else if (WIFSIGNALED(status)) {
    int signal = WTERMSIG(status);
    fprintf(stderr, "\nprocess caught signal %d.\n\n", signal);
    /* A signal exit is a reason to respawn unless the signal is TERM
       or KILL. */
    return !stop_on_terminate || (signal != SIGTERM && signal != SIGKILL);

  } else {
    int exit_status = WEXITSTATUS(status);
    fprintf(stderr, "\nprocess exited with status %d.\n\n", WEXITSTATUS(status));
    /* Normal exit is a reason to respawn if the status indicates failure. */
    return !stop_on_terminate || (exit_status != 0);
  }
}