sysvinit-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sysvinit-devel] [PATCH] automatically spawn agetty on kernel consol


From: Dr. Werner Fink
Subject: Re: [sysvinit-devel] [PATCH] automatically spawn agetty on kernel consoles
Date: Tue, 21 Jun 2011 13:27:37 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

On Thu, May 26, 2011 at 08:23:30AM +0200, Ludwig Nussel wrote:
> The feature is useful for developers and admins that occasionally need
> to boot with e.g. console=ttyS0.
> The built in default can be overridden via inittab for each device. An
> entry like "S0::off:" turns off the getty on ttyS0.
> ---
>  src/init.c |   74 
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 74 insertions(+), 0 deletions(-)

Ludwig?

Please check out the code of src/consoles.c and src/consoles.h
which does a similar job by not only using "/proc/cmdline" but
also "/proc/consoles" or "/sys/class/tty" if available.

Nonetheless a configure option as mentioned by Mike should be also
added.

   Werner

> diff --git a/src/init.c b/src/init.c
> index d379fb2..13deef7 100644
> --- a/src/init.c
> +++ b/src/init.c
> @@ -1243,6 +1243,76 @@ void startup(CHILD *ch)
>       }
>  }
>  
> +#ifdef __linux__
> +static
> +void check_kernel_console()
> +{
> +     FILE* fp;
> +     char buf[4096];
> +     if ((fp = fopen("/proc/cmdline", "r")) == 0) {
> +             return;
> +     }
> +     if (fgets(buf, sizeof(buf), fp)) {
> +             char* p = buf;
> +             while ((p = strstr(p, "console="))) {
> +                     char* e;
> +                     p += strlen("console=");
> +                     for (e = p; *e; ++e) {
> +                             switch (*e) {
> +                                     case '-' ... '9':
> +                                     case 'A' ... 'Z':
> +                                     case '_':
> +                                     case 'a' ... 'z':
> +                                             continue;
> +                             }
> +                             break;
> +                     }
> +                     if (p != e) {
> +                             CHILD* old;
> +                             int dup = 0;
> +                             char id[8] = {0};
> +                             char dev[32] = {0};
> +                             strncpy(dev, p, MIN(sizeof(dev), 
> (unsigned)(e-p)));
> +                             if (!strncmp(dev, "tty", 3))
> +                                     strncpy(id, dev+3, sizeof(id));
> +                             else
> +                                     strncpy(id, dev, sizeof(id));
> +
> +                             for(old = newFamily; old; old = old->next) {
> +                                     if (!strcmp(old->id, id)) {
> +                                             dup = 1;
> +                                     }
> +                             }
> +                             if (!dup) {
> +                                     CHILD* ch = imalloc(sizeof(CHILD));
> +                                     ch->action = RESPAWN;
> +                                     strcpy(ch->id, id);
> +                                     strcpy(ch->rlevel, "2345");
> +                                     sprintf(ch->process, "/sbin/agetty -L 
> -s 115200,38400,9600 %s vt102", dev);
> +                                     ch->next = NULL;
> +                                     for(old = family; old; old = old->next) 
> {
> +                                             if (strcmp(old->id, ch->id) == 
> 0) {
> +                                                     old->new = ch;
> +                                                     break;
> +                                             }
> +                                     }
> +                                     /* add to end */
> +                                     for(old = newFamily; old; old = 
> old->next) {
> +                                             if (!old->next) {
> +                                                     old->next = ch;
> +                                                     break;
> +                                             }
> +                                     }
> +
> +                                     initlog(L_VB, "added agetty on %s with 
> id %s", dev, id);
> +                             }
> +                     }
> +             }
> +     }
> +     fclose(fp);
> +     return;
> +}
> +#endif
>  
>  /*
>   *   Read the inittab file.
> @@ -1455,6 +1525,10 @@ void read_inittab(void)
>     */
>    if (fp) fclose(fp);
>  
> +#ifdef __linux__
> +  check_kernel_console();
> +#endif
> +
>    /*
>     * Loop through the list of children, and see if they need to
>     * be killed. 
> -- 
> 1.7.3.4
> 

-- 
 Dr. Werner Fink -- Software Engineer Consultant
 SuSE LINUX Products GmbH,  Maxfeldstrasse 5,  Nuernberg,  Germany
 GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer,  HRB 21284 (AG Nuernberg)
 phone: +49-911-740-53-0,  fax: +49-911-3206727,  www.opensuse.org
------------------------------------------------------------------
  "Having a smoking section in a restaurant is like having
          a peeing section in a swimming pool." -- Edward Burr



reply via email to

[Prev in Thread] Current Thread [Next in Thread]