Пример #1
0
int
main(int argc, char **argv)
{
    extern char *__progname;
    int ret, c;

    ret = 0;
    while ((c = getopt(argc, argv, "fFlpPrstT")) != -1) {
        switch (c) {
        case 'f':
            ret |= check_inheritance();
            break;
        case 'F':
            ret |= do_fdpass();
            break;
        case 'l':
            ret |= do_flock();
            break;
        case 'p':
            ret |= do_pipe();
            break;
        case 'P':
            ret |= do_process();
            break;
        case 'r':
            ret |= do_random();
            break;
        case 's':
            ret |= do_signal();
            break;
        case 't':
            ret |= do_tun();
            break;
        case 'T':
            ret |= do_pty();
            break;
        default:
            fprintf(stderr, "Usage: %s -[fPprTt]\n", __progname);
            exit(1);
        }
    }

    return (ret);
}
Пример #2
0
/*===========================================================================*
 *				tty_task				     *
 *===========================================================================*/
int main(int argc, char **argv)
{
/* Main routine of the terminal task. */

  message tty_mess;		/* buffer for all incoming messages */
  int ipc_status;
  int line;
  int r;
  register tty_t *tp;

  env_setargs(argc, argv);

  tty_startup();

  while (TRUE) {
	/* Check for and handle any events on any of the ttys. */
	for (tp = FIRST_TTY; tp < END_TTY; tp++) {
		if (tp->tty_events) handle_events(tp);
	}

	/* Get a request message. */
	r= driver_receive(ANY, &tty_mess, &ipc_status);
	if (r != 0)
		panic("driver_receive failed with: %d", r);

	if (is_ipc_notify(ipc_status)) {
		switch (_ENDPOINT_P(tty_mess.m_source)) {
			case CLOCK:
				/* run watchdogs of expired timers */
				expire_timers(tty_mess.m_notify.timestamp);
				break;
			default:
				/* do nothing */
				break;
		}

		/* done, get new message */
		continue;
	}

	if (!IS_CDEV_RQ(tty_mess.m_type)) {
		chardriver_process(&tty_tab, &tty_mess, ipc_status);
		continue;
	}

	/* Only device requests should get to this point.
	 * All requests have a minor device number.
	 */
	if (OK != chardriver_get_minor(&tty_mess, &line))
		continue;

	if (is_pty(line)) {
		/* Terminals and pseudo terminals belong together. We can only
		 * make a distinction between the two based on minor number and
		 * not on position in the tty_table. Hence this special case.
		 */
		do_pty(&tty_mess, ipc_status);
		continue;
	}

	/* Execute the requested device driver function. */
	chardriver_process(&tty_tab, &tty_mess, ipc_status);
  }

  return 0;
}
Пример #3
0
Файл: tty.c Проект: 54niyu/minix
/*===========================================================================*
 *				tty_task				     *
 *===========================================================================*/
PUBLIC void tty_task()
{
/* Main routine of the terminal task. */

  message tty_mess;		/* buffer for all incoming messages */
  register tty_t *tp;
  unsigned line;

  /* Initialize the terminal lines. */
  for (tp = FIRST_TTY; tp < END_TTY; tp++) tty_init(tp);

  /* Display the Minix startup banner. */
  printf("Minix %s.%s  Copyright 1997 Prentice-Hall, Inc.\n\n",
						OS_RELEASE, OS_VERSION);

#if (CHIP == INTEL)
  /* Real mode, or 16/32-bit protected mode? */
#if _WORD_SIZE == 4
  printf("Executing in 32-bit protected mode\n\n");
#else
  printf("Executing in %s mode\n\n",
	protected_mode ? "16-bit protected" : "real");
#endif
#endif

  while (TRUE) {
	/* Handle any events on any of the ttys. */
	for (tp = FIRST_TTY; tp < END_TTY; tp++) {
		if (tp->tty_events) handle_events(tp);
	}

	receive(ANY, &tty_mess);

	/* A hardware interrupt is an invitation to check for events. */
	if (tty_mess.m_type == HARD_INT) continue;

	/* Check the minor device number. */
	line = tty_mess.TTY_LINE;
	if ((line - CONS_MINOR) < NR_CONS) {
		tp = tty_addr(line - CONS_MINOR);
	} else
	if (line == LOG_MINOR) {
		tp = tty_addr(0);
	} else
	if ((line - RS232_MINOR) < NR_RS_LINES) {
		tp = tty_addr(line - RS232_MINOR + NR_CONS);
	} else
	if ((line - TTYPX_MINOR) < NR_PTYS) {
		tp = tty_addr(line - TTYPX_MINOR + NR_CONS + NR_RS_LINES);
	} else
	if ((line - PTYPX_MINOR) < NR_PTYS) {
		tp = tty_addr(line - PTYPX_MINOR + NR_CONS + NR_RS_LINES);
		do_pty(tp, &tty_mess);
		continue;			/* this is a pty, not a tty */
	} else {
		tp = NULL;
	}

	/* If the device doesn't exist or is not configured return ENXIO. */
	if (tp == NULL || !tty_active(tp)) {
		tty_reply(TASK_REPLY, tty_mess.m_source,
						tty_mess.PROC_NR, ENXIO);
		continue;
	}

	/* Execute the requested function. */
	switch (tty_mess.m_type) {
	    case DEV_READ:	do_read(tp, &tty_mess);		break;
	    case DEV_WRITE:	do_write(tp, &tty_mess);	break;
	    case DEV_IOCTL:	do_ioctl(tp, &tty_mess);	break;
	    case DEV_OPEN:	do_open(tp, &tty_mess);		break;
	    case DEV_CLOSE:	do_close(tp, &tty_mess);	break;
	    case CANCEL:	do_cancel(tp, &tty_mess);	break;
	    default:		tty_reply(TASK_REPLY, tty_mess.m_source,
						tty_mess.PROC_NR, EINVAL);
	}
  }
}