首页 > 其他分享 >TTY之register_console

TTY之register_console

时间:2023-06-01 10:32:41浏览次数:40  
标签:TTY console bcon register newcon flags drivers CON

extern void register_console(struct console *);
extern int unregister_console(struct console *);
extern struct console *console_drivers;
 
 /*
 * The console driver calls this routine during kernel initialization
 * to register the console printing procedure with printk() and to
 * print any messages that were printed by the kernel before the
 * console driver was initialized.
 *
 * This can happen pretty early during the boot process (because of
 * early_printk) - sometimes before setup_arch() completes - be careful
 * of what kernel features are used - they may not be initialised yet.
 *
 * There are two types of consoles - bootconsoles (early_printk) and
 * "real" consoles (everything which is not a bootconsole) which are
 * handled differently.
 *  - Any number of bootconsoles can be registered at any time.
 *  - As soon as a "real" console is registered, all bootconsoles
 *    will be unregistered automatically.
 *  - Once a "real" console is registered, any attempt to register a
 *    bootconsoles will be rejected
 */
void register_console(struct console *newcon)
{
 int i;
 unsigned long flags;
 struct console *bcon = NULL;
 struct console_cmdline *c;
 
 if (console_drivers)
  for_each_console(bcon)
   if (WARN(bcon == newcon,
     "console '%s%d' already registered\n",
     bcon->name, bcon->index))
    return;
 /*
  * before we register a new CON_BOOT console, make sure we don't
  * already have a valid console
  */
 if (console_drivers && newcon->flags & CON_BOOT) {
  /* find the last or real console */
  for_each_console(bcon) {
   if (!(bcon->flags & CON_BOOT)) {
    pr_info("Too late to register bootconsole %s%d\n",
     newcon->name, newcon->index);
    return;
   }
  }
 }
 if (console_drivers && console_drivers->flags & CON_BOOT)
  bcon = console_drivers;
 if (preferred_console < 0 || bcon || !console_drivers)
  preferred_console = selected_console;
 /*
  * See if we want to use this console driver. If we
  * didn't select a console we take the first one
  * that registers here.
  */
 if (preferred_console < 0) {
  if (newcon->index < 0)
   newcon->index = 0;
  if (newcon->setup == NULL ||
      newcon->setup(newcon, NULL) == 0) {
   newcon->flags |= CON_ENABLED;
   if (newcon->device) {
    newcon->flags |= CON_CONSDEV;
    preferred_console = 0;
   }
  }
 }
 /*
  * See if this console matches one we selected on
  * the command line.
  */
 for (i = 0, c = console_cmdline;
      i < MAX_CMDLINECONSOLES && c->name[0];
      i++, c++) {
  if (!newcon->match ||
      newcon->match(newcon, c->name, c->index, c->options) != 0) {
   /* default matching */
   BUILD_BUG_ON(sizeof(c->name) != sizeof(newcon->name));
   if (strcmp(c->name, newcon->name) != 0)
    continue;
   if (newcon->index >= 0 &&
       newcon->index != c->index)
    continue;
   if (newcon->index < 0)
    newcon->index = c->index;
   if (_braille_register_console(newcon, c))
    return;
   if (newcon->setup &&
       newcon->setup(newcon, c->options) != 0)
    break;
  }
  newcon->flags |= CON_ENABLED;
  if (i == selected_console) {
   newcon->flags |= CON_CONSDEV;
   preferred_console = selected_console;
  }
  break;
 }
 if (!(newcon->flags & CON_ENABLED))
  return;
 /*
  * If we have a bootconsole, and are switching to a real console,
  * don't print everything out again, since when the boot console, and
  * the real console are the same physical device, it's annoying to
  * see the beginning boot messages twice
  */
 if (bcon && ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV))
  newcon->flags &= ~CON_PRINTBUFFER;
 /*
  * Put this console in the list - keep the
  * preferred driver at the head of the list.
  */
 console_lock();
 if ((newcon->flags & CON_CONSDEV) || console_drivers == NULL) {
  newcon->next = console_drivers;
  console_drivers = newcon;
  if (newcon->next)
   newcon->next->flags &= ~CON_CONSDEV;
 } else {
  newcon->next = console_drivers->next;
  console_drivers->next = newcon;
 }
 if (newcon->flags & CON_EXTENDED)
  if (!nr_ext_console_drivers++)
   pr_info("printk: continuation disabled due to ext consoles, expect more fragments in /dev/kmsg\n");
 if (newcon->flags & CON_PRINTBUFFER) {
  /*
   * console_unlock(); will print out the buffered messages
   * for us.
   */
  raw_spin_lock_irqsave(&logbuf_lock, flags);
  console_seq = syslog_seq;
  console_idx = syslog_idx;
  console_prev = syslog_prev;
  raw_spin_unlock_irqrestore(&logbuf_lock, flags);
  /*
   * We're about to replay the log buffer.  Only do this to the
   * just-registered console to avoid excessive message spam to
   * the already-registered consoles.
   */
  exclusive_console = newcon;
 }
 console_unlock();
 console_sysfs_notify();
 /*
  * By unregistering the bootconsoles after we enable the real console
  * we get the "console xxx enabled" message on all the consoles -
  * boot consoles, real consoles, etc - this is to ensure that end
  * users know there might be something in the kernel's log buffer that
  * went to the bootconsole (that they do not see on the real console)
  */
 pr_info("%sconsole [%s%d] enabled\n",
  (newcon->flags & CON_BOOT) ? "boot" : "" ,
  newcon->name, newcon->index);
 if (bcon &&
     ((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV) &&
     !keep_bootcon) {
  /* We need to iterate through all boot consoles, to make
   * sure we print everything out, before we unregister them.
   */
  for_each_console(bcon)
   if (bcon->flags & CON_BOOT)
    unregister_console(bcon);
 }
}

标签:TTY,console,bcon,register,newcon,flags,drivers,CON
From: https://blog.51cto.com/u_11860992/6392726

相关文章

  • 漂亮的输出-----prettytable和colorama的使用
    Python通过prettytable模块将输出内容如表格方式整齐输出,python本身并不内置,需要独立安装该第三方库。1pipinstallPrettyTable1#源码安装2wgethttps://pypi.python.org/packages/source/P/PrettyTable/prettytable-0.7.2.tar.gz3tar-zxvfprettytable-0.7.2.tar.g......
  • 【Netty实战】1~3章学习笔记
    1.Netty总体结构1.1Netty简介​ Netty是一款用于创建高性能网络应用程序的高级框架。它的基于JavaNIO的异步的和事件驱动的实现,保证了高负载下应用程序性能的最大化和可伸缩性。​ 其次,Netty也包含了一组设计模式,将应用程序逻辑从网络层解耦,简化了开发过程,同时也最大限度......
  • ES transport client底层是netty实现,netty本质上是异步方式,但是netty自身可以使用sync
    EStransportclient底层是netty实现,netty本质上是异步方式,但是netty自身可以使用sync或者await(future超时机制)来实现类似同步调用!因此,EStransportclient可以同步调用也可以异步(不过底层的socket必然是异步实现)。发送端例子对于javaclient的数据发送(这里以bulk为例),写过的人都知......
  • 查看nebula版本号 console里show hosts graph
    (root@nebula)[(none)]>showhostsgraph+-------------+------+----------+---------+--------------+---------+|Host|Port|Status|Role|GitInfoSha|Version|+-------------+------+----------+---------+--------------+---------+|&q......
  • 神器vConsole!快速定位移动端问题,加快开发效率
    大家好,我是程序视点的小二哥!今天小二哥碰到一新来的实习生在使用alert调试H5页面,仿佛看到小二哥年少时羞涩的样子...趁这个机会,就给大家分享一个针对手机网页的前端开发者调试面板工具:vConsole简介vConsole是框架无关的,可以在Vue、React或其他任何框架中使用。现在vC......
  • Spectre.Console-实现自己的CLI
    引言最近发现自己喜欢用的Todo软件总是差点意思,毕竟每个人的习惯和工作流不太一样,我就想着自己写一个小的Todo项目,核心的功能是自动记录Todo执行过程中消耗的时间(尤其面向程序员),按照自己的想法实现一套GTD工作流。不想写Winform,WPF也写腻了,就想着学学MAUI、Avalonia......
  • Netty实战(八)
    (引导)一、引导1.1什么是引导引导一个应用程序是指对它进行配置,并使它运行起来的过程。引导可以简单的认为是将分散的了ChannelPipeline、ChannelHandler和EventLoop组合起来,成为一个完成应用程序的模块。1.2Bootstrap类引导类的层次结构包括一个抽象的父类和两个具体......
  • Netty零拷贝
    传统读取IO流的操作读操作1、应用程序发起读数据操作,JVM会发起read()系统调用。2、这时操作系统OS会进行一次上下文切换(把用户空间切换到内核空间)3、通过磁盘控制器把数据copy到内核缓冲区中,这里的就发生了一次DMACopy4、然后内核将数据copy到用户空间的应用缓冲区中,发生了......
  • facebook console.log bug All In One
    facebookconsole.logbugAllInOneconsole.logURLlinkbugerrors❌console.log(`查看https://www.facebook.com/selfxss详细了解。`)//查看https://www.facebook.com/selfxss详细了解。solutionaddwhitespacesbetweenURLandtext✅在链接与文字之间,添......
  • Netty实战(七)
    (EventLoop和线程模型)一、什么是线程模型简单地说,线程模型指定了操作系统、编程语言、框架或者应用程序的上下文中的线程管理的关键方面。在早期的Java语言中,我们使用多线程处理的主要方式无非是按需创建和启动新的Thread来执行并发的任务单元,这种在高负载下表现得很原......