diff mbox

[OpenWrt-Devel] procd: delay inittab workers until the tty exists.

Message ID 54B8825C.4030300@exegin.com
State Rejected
Headers show

Commit Message

Owen Kirby Jan. 16, 2015, 3:15 a.m. UTC
If a process with a tty is specified in inittab, delay the worker process until the tty exists.

This allows starting consoles with terminals that get delayed until after procd is reads inittab,
and it also allows hotplugging USB-to-serial adapters attached long after booting.

Signed-off-by: Owen Kirby <osk@exegin.com>
---
  inittab.c | 14 ++++++++++----
  1 file changed, 10 insertions(+), 4 deletions(-)

Comments

John Crispin Jan. 16, 2015, 6:31 a.m. UTC | #1
nack, using magic delays is a no go

On 16/01/2015 04:15, Owen Kirby wrote:
> If a process with a tty is specified in inittab, delay the worker
> process until the tty exists.
> 
> This allows starting consoles with terminals that get delayed until
> after procd is reads inittab,
> and it also allows hotplugging USB-to-serial adapters attached long
> after booting.
> 
> Signed-off-by: Owen Kirby <osk@exegin.com>
> ---
>  inittab.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/inittab.c b/inittab.c
> index 623103d..73c113f 100644
> --- a/inittab.c
> +++ b/inittab.c
> @@ -99,9 +99,15 @@ static void fork_worker(struct init_action *a)
>      if (!a->proc.pid) {
>          p = setsid();
>  
> -        fd = dev_open(a->id);
> -        if (fd != -1)
> -        {
> +        if (a->id) {
> +            struct timespec tm;
> +            tm.tv_sec = a->respawn / 1000;
> +            tm.tv_nsec = (a->respawn % 1000) * 1000000;
> +
> +            while ((fd = dev_open(a->id)) == -1)
> +                if (nanosleep(&tm, NULL) == -1)
> +                    exit(-1);
> +
>              dup2(fd, STDIN_FILENO);
>              dup2(fd, STDOUT_FILENO);
>              dup2(fd, STDERR_FILENO);
> @@ -157,7 +163,7 @@ static void askfirst(struct init_action *a)
>  {
>      int i;
>  
> -    if (!dev_exist(a->id) || (console && !strcmp(console, a->id))) {
> +    if (console && !strcmp(console, a->id)) {
>          DEBUG(4, "Skipping %s\n", a->id);
>          return;
>      }
Owen Kirby Jan. 16, 2015, 8:19 p.m. UTC | #2
Okay, I'll rewrite it.

However: Is it polling for the existence of the tty device that is 
unacceptable (would a solution using uloop_timeout_set() be okay?), or 
would I need to process hotplug events from the kernel?

Thanks,
Owen

On 15-01-15 10:31 PM, John Crispin wrote:
> nack, using magic delays is a no go
>
> On 16/01/2015 04:15, Owen Kirby wrote:
>> If a process with a tty is specified in inittab, delay the worker
>> process until the tty exists.
>>
>> This allows starting consoles with terminals that get delayed until
>> after procd is reads inittab,
>> and it also allows hotplugging USB-to-serial adapters attached long
>> after booting.
>>
>> Signed-off-by: Owen Kirby <osk@exegin.com>
>> ---
>>   inittab.c | 14 ++++++++++----
>>   1 file changed, 10 insertions(+), 4 deletions(-)
>>
>> diff --git a/inittab.c b/inittab.c
>> index 623103d..73c113f 100644
>> --- a/inittab.c
>> +++ b/inittab.c
>> @@ -99,9 +99,15 @@ static void fork_worker(struct init_action *a)
>>       if (!a->proc.pid) {
>>           p = setsid();
>>   
>> -        fd = dev_open(a->id);
>> -        if (fd != -1)
>> -        {
>> +        if (a->id) {
>> +            struct timespec tm;
>> +            tm.tv_sec = a->respawn / 1000;
>> +            tm.tv_nsec = (a->respawn % 1000) * 1000000;
>> +
>> +            while ((fd = dev_open(a->id)) == -1)
>> +                if (nanosleep(&tm, NULL) == -1)
>> +                    exit(-1);
>> +
>>               dup2(fd, STDIN_FILENO);
>>               dup2(fd, STDOUT_FILENO);
>>               dup2(fd, STDERR_FILENO);
>> @@ -157,7 +163,7 @@ static void askfirst(struct init_action *a)
>>   {
>>       int i;
>>   
>> -    if (!dev_exist(a->id) || (console && !strcmp(console, a->id))) {
>> +    if (console && !strcmp(console, a->id)) {
>>           DEBUG(4, "Skipping %s\n", a->id);
>>           return;
>>       }
John Crispin Jan. 17, 2015, 6:07 a.m. UTC | #3
On 16/01/2015 21:19, Owen Kirby wrote:
> Okay, I'll rewrite it.
> 
> However: Is it polling for the existence of the tty device that is 
> unacceptable (would a solution using uloop_timeout_set() be okay?),
> or would I need to process hotplug events from the kernel?
> 

use hotplug events please



> Thanks, Owen
> 
> On 15-01-15 10:31 PM, John Crispin wrote:
>> nack, using magic delays is a no go
>> 
>> On 16/01/2015 04:15, Owen Kirby wrote:
>>> If a process with a tty is specified in inittab, delay the
>>> worker process until the tty exists.
>>> 
>>> This allows starting consoles with terminals that get delayed
>>> until after procd is reads inittab, and it also allows
>>> hotplugging USB-to-serial adapters attached long after
>>> booting.
>>> 
>>> Signed-off-by: Owen Kirby <osk@exegin.com> --- inittab.c | 14
>>> ++++++++++---- 1 file changed, 10 insertions(+), 4
>>> deletions(-)
>>> 
>>> diff --git a/inittab.c b/inittab.c index 623103d..73c113f
>>> 100644 --- a/inittab.c +++ b/inittab.c @@ -99,9 +99,15 @@
>>> static void fork_worker(struct init_action *a) if
>>> (!a->proc.pid) { p = setsid(); -        fd = dev_open(a->id); -
>>> if (fd != -1) -        { +        if (a->id) { +
>>> struct timespec tm; +            tm.tv_sec = a->respawn /
>>> 1000; +            tm.tv_nsec = (a->respawn % 1000) * 1000000; 
>>> + +            while ((fd = dev_open(a->id)) == -1) +
>>> if (nanosleep(&tm, NULL) == -1) +                    exit(-1); 
>>> + dup2(fd, STDIN_FILENO); dup2(fd, STDOUT_FILENO); dup2(fd,
>>> STDERR_FILENO); @@ -157,7 +163,7 @@ static void askfirst(struct
>>> init_action *a) { int i; -    if (!dev_exist(a->id) || (console
>>> && !strcmp(console, a->id))) { +    if (console &&
>>> !strcmp(console, a->id)) { DEBUG(4, "Skipping %s\n", a->id); 
>>> return; }
> _______________________________________________ openwrt-devel
> mailing list openwrt-devel@lists.openwrt.org 
> https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
>
diff mbox

Patch

diff --git a/inittab.c b/inittab.c
index 623103d..73c113f 100644
--- a/inittab.c
+++ b/inittab.c
@@ -99,9 +99,15 @@  static void fork_worker(struct init_action *a)
  	if (!a->proc.pid) {
  		p = setsid();
  
-		fd = dev_open(a->id);
-		if (fd != -1)
-		{
+		if (a->id) {
+			struct timespec tm;
+			tm.tv_sec = a->respawn / 1000;
+			tm.tv_nsec = (a->respawn % 1000) * 1000000;
+
+			while ((fd = dev_open(a->id)) == -1)
+				if (nanosleep(&tm, NULL) == -1)
+					exit(-1);
+
  			dup2(fd, STDIN_FILENO);
  			dup2(fd, STDOUT_FILENO);
  			dup2(fd, STDERR_FILENO);
@@ -157,7 +163,7 @@  static void askfirst(struct init_action *a)
  {
  	int i;
  
-	if (!dev_exist(a->id) || (console && !strcmp(console, a->id))) {
+	if (console && !strcmp(console, a->id)) {
  		DEBUG(4, "Skipping %s\n", a->id);
  		return;
  	}