Example #1
0
int get_console_fd(char* tty_name) 
{
  int fd;

  if (tty_name)
    {
      if (-1 == (fd = open_a_console(tty_name)))
	return -1;
      else
	return fd;
    }
  
  fd = open_a_console("/dev/tty");
  if (fd >= 0)
    return fd;
  
  fd = open_a_console("/dev/tty0");
  if (fd >= 0)
    return fd;
  
  fd = open_a_console("/dev/console");
  if (fd >= 0)
    return fd;
  
  for (fd = 0; fd < 3; fd++)
    if (is_a_console(fd))
      return fd;
  
  fprintf(stderr,
	  "Couldnt get a file descriptor referring to the console\n");
  return -1;		/* total failure */
}
Example #2
0
//=========================================
// getfd...
//-----------------------------------------
int getfd(void) {
	int fd;

	fd = open_a_console("/dev/tty");
	if (fd >= 0) {
		return fd;
	}
	fd = open_a_console("/dev/tty0");
	if (fd >= 0) {
		return fd;
	}
	fd = open_a_console("/dev/console");
	if (fd >= 0) {
		return fd;
	}

	for (fd = 0; fd < 3; fd++) {
	if (is_a_console(fd)) {
		return fd;
	}
	}
	fprintf(
		stderr,"could not get a console file descriptor\n"
	);
	exit(1);
}
Example #3
0
File: console.c Project: d3x0r/SACK
int getfd (const char * const nm) {
    int fd;

    if (nm) {
	fd = open_a_console(nm);
	if (fd >= 0)
	    return fd;
    } else {
	fd = open_a_console("/dev/tty");
	if (fd >= 0)
	    return fd;

	fd = open_a_console("/dev/tty0");
	if (fd >= 0)
	    return fd;

	fd = open_a_console("/dev/console");
	if (fd >= 0)
	    return fd;

	for (fd = 0; fd < 3; fd++)
	    if (is_a_console(fd))
		return fd;
    }
    fprintf(stderr,
	    "Couldnt get a file descriptor referring to the console\n");
    exit(1);		/* total failure */
}
int get_console_fd(void)
{
	static const char *const console_names[] = {
		DEV_CONSOLE, CURRENT_VC, CURRENT_TTY
	};

	int fd;

	for (fd = 2; fd >= 0; fd--) {
		int fd4name;
		int choise_fd;
		char arg;

		fd4name = open_a_console(console_names[fd]);
 chk_std:
		choise_fd = (fd4name >= 0 ? fd4name : fd);

		arg = 0;
		if (ioctl(choise_fd, KDGKBTYPE, &arg) == 0)
			return choise_fd;
		if(fd4name >= 0) {
			close(fd4name);
			fd4name = -1;
			goto chk_std;
		}
	}

	bb_error_msg("cannot get file descriptor referring to console");
	return fd;                      /* total failure */
}