diff mbox series

[4/5] initd: Don't search the environment list if the watchdog, fd is initialized

Message ID 888e39cb-5cce-762e-d52a-0b23459f78e8@meshplusplus.com
State Changes Requested
Headers show
Series [1/5] initd: Add ubus argument to trigger watchdog tickle. | expand

Commit Message

Michael Jones Sept. 29, 2020, 4:22 p.m. UTC
Signed-off-by: Michael Jones <mike@meshplusplus.com>
---
 watchdog.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

John Crispin Sept. 29, 2020, 6:47 p.m. UTC | #1
On 29.09.20 18:22, Michael Jones wrote:
> Signed-off-by: Michael Jones <mike@meshplusplus.com>
> ---
>   watchdog.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/watchdog.c b/watchdog.c
> index 20830c3..ac5b656 100644
> --- a/watchdog.c
> +++ b/watchdog.c
> @@ -49,11 +49,11 @@ static void watchdog_timeout_cb(struct uloop_timeout *t)
>   
>   static int watchdog_open(bool cloexec)
>   {
> -    char *env = getenv("WDTFD");
> -
>       if (wdt_fd >= 0)
>           return wdt_fd;
>   
> +    char *env = getenv("WDTFD");
> +
>       if (env) {
>           DEBUG(2, "Watchdog handover: fd=%s\n", env);
>           wdt_fd = atoi(env);

this breaks c99 compliance

     John
Michael Jones Sept. 29, 2020, 6:55 p.m. UTC | #2
On Tue, Sep 29, 2020 at 1:47 PM John Crispin <john@phrozen.org> wrote:
>
>
> On 29.09.20 18:22, Michael Jones wrote:
> > Signed-off-by: Michael Jones <mike@meshplusplus.com>
> > ---
> >   watchdog.c | 4 ++--
> >   1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/watchdog.c b/watchdog.c
> > index 20830c3..ac5b656 100644
> > --- a/watchdog.c
> > +++ b/watchdog.c
> > @@ -49,11 +49,11 @@ static void watchdog_timeout_cb(struct uloop_timeout *t)
> >
> >   static int watchdog_open(bool cloexec)
> >   {
> > -    char *env = getenv("WDTFD");
> > -
> >       if (wdt_fd >= 0)
> >           return wdt_fd;
> >
> > +    char *env = getenv("WDTFD");
> > +
> >       if (env) {
> >           DEBUG(2, "Watchdog handover: fd=%s\n", env);
> >           wdt_fd = atoi(env);
>
> this breaks c99 compliance
>
>      John
>

Do you mean C89 compliance? This should compile just fine in C99.

C99 was released 20 years ago, and C89 30 years ago. I'm personally
not interested in supporting either.

The patch can be modified, or used as inspiration, by someone who is
concerned about C89/C99 compliance and would like to see the
watchdog_open() function improved in this way.
John Crispin Sept. 29, 2020, 6:59 p.m. UTC | #3
On 29.09.20 20:55, Michael Jones wrote:
> On Tue, Sep 29, 2020 at 1:47 PM John Crispin <john@phrozen.org> wrote:
>>
>> On 29.09.20 18:22, Michael Jones wrote:
>>> Signed-off-by: Michael Jones <mike@meshplusplus.com>
>>> ---
>>>    watchdog.c | 4 ++--
>>>    1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/watchdog.c b/watchdog.c
>>> index 20830c3..ac5b656 100644
>>> --- a/watchdog.c
>>> +++ b/watchdog.c
>>> @@ -49,11 +49,11 @@ static void watchdog_timeout_cb(struct uloop_timeout *t)
>>>
>>>    static int watchdog_open(bool cloexec)
>>>    {
>>> -    char *env = getenv("WDTFD");
>>> -
>>>        if (wdt_fd >= 0)
>>>            return wdt_fd;
>>>
>>> +    char *env = getenv("WDTFD");
>>> +
>>>        if (env) {
>>>            DEBUG(2, "Watchdog handover: fd=%s\n", env);
>>>            wdt_fd = atoi(env);
>> this breaks c99 compliance
>>
>>       John
>>
> Do you mean C89 compliance? This should compile just fine in C99.
>
> C99 was released 20 years ago, and C89 30 years ago. I'm personally
> not interested in supporting either.
>
> The patch can be modified, or used as inspiration, by someone who is
> concerned about C89/C99 compliance and would like to see the
> watchdog_open() function improved in this way.


variable declarations should always be at the start of the function.

     John
Michael Jones Sept. 29, 2020, 7 p.m. UTC | #4
On Tue, Sep 29, 2020 at 1:59 PM John Crispin <john@phrozen.org> wrote:
>
>
> On 29.09.20 20:55, Michael Jones wrote:
> > On Tue, Sep 29, 2020 at 1:47 PM John Crispin <john@phrozen.org> wrote:
> >>
> >> On 29.09.20 18:22, Michael Jones wrote:
> >>> Signed-off-by: Michael Jones <mike@meshplusplus.com>
> >>> ---
> >>>    watchdog.c | 4 ++--
> >>>    1 file changed, 2 insertions(+), 2 deletions(-)
> >>>
> >>> diff --git a/watchdog.c b/watchdog.c
> >>> index 20830c3..ac5b656 100644
> >>> --- a/watchdog.c
> >>> +++ b/watchdog.c
> >>> @@ -49,11 +49,11 @@ static void watchdog_timeout_cb(struct uloop_timeout *t)
> >>>
> >>>    static int watchdog_open(bool cloexec)
> >>>    {
> >>> -    char *env = getenv("WDTFD");
> >>> -
> >>>        if (wdt_fd >= 0)
> >>>            return wdt_fd;
> >>>
> >>> +    char *env = getenv("WDTFD");
> >>> +
> >>>        if (env) {
> >>>            DEBUG(2, "Watchdog handover: fd=%s\n", env);
> >>>            wdt_fd = atoi(env);
> >> this breaks c99 compliance
> >>
> >>       John
> >>
> > Do you mean C89 compliance? This should compile just fine in C99.
> >
> > C99 was released 20 years ago, and C89 30 years ago. I'm personally
> > not interested in supporting either.
> >
> > The patch can be modified, or used as inspiration, by someone who is
> > concerned about C89/C99 compliance and would like to see the
> > watchdog_open() function improved in this way.
>
>
> variable declarations should always be at the start of the function.
>
>      John
>

Sorry, I disagree, and there was no documentation that I could see
anywhere related to this on either the OpenWRT wiki, or the procd
repository.

Take the patches or leave them. I'm not going to make updates.
John Crispin Sept. 29, 2020, 7:06 p.m. UTC | #5
On 29.09.20 21:00, Michael Jones wrote:
> On Tue, Sep 29, 2020 at 1:59 PM John Crispin <john@phrozen.org> wrote:
>>
>> On 29.09.20 20:55, Michael Jones wrote:
>>> On Tue, Sep 29, 2020 at 1:47 PM John Crispin <john@phrozen.org> wrote:
>>>> On 29.09.20 18:22, Michael Jones wrote:
>>>>> Signed-off-by: Michael Jones <mike@meshplusplus.com>
>>>>> ---
>>>>>     watchdog.c | 4 ++--
>>>>>     1 file changed, 2 insertions(+), 2 deletions(-)
>>>>>
>>>>> diff --git a/watchdog.c b/watchdog.c
>>>>> index 20830c3..ac5b656 100644
>>>>> --- a/watchdog.c
>>>>> +++ b/watchdog.c
>>>>> @@ -49,11 +49,11 @@ static void watchdog_timeout_cb(struct uloop_timeout *t)
>>>>>
>>>>>     static int watchdog_open(bool cloexec)
>>>>>     {
>>>>> -    char *env = getenv("WDTFD");
>>>>> -
>>>>>         if (wdt_fd >= 0)
>>>>>             return wdt_fd;
>>>>>
>>>>> +    char *env = getenv("WDTFD");
>>>>> +
>>>>>         if (env) {
>>>>>             DEBUG(2, "Watchdog handover: fd=%s\n", env);
>>>>>             wdt_fd = atoi(env);
>>>> this breaks c99 compliance
>>>>
>>>>        John
>>>>
>>> Do you mean C89 compliance? This should compile just fine in C99.
>>>
>>> C99 was released 20 years ago, and C89 30 years ago. I'm personally
>>> not interested in supporting either.
>>>
>>> The patch can be modified, or used as inspiration, by someone who is
>>> concerned about C89/C99 compliance and would like to see the
>>> watchdog_open() function improved in this way.
>>
>> variable declarations should always be at the start of the function.
>>
>>       John
>>
> Sorry, I disagree, and there was no documentation that I could see
> anywhere related to this on either the OpenWRT wiki, or the procd
> repository.
>
> Take the patches or leave them. I'm not going to make updates.
>
ok !
diff mbox series

Patch

diff --git a/watchdog.c b/watchdog.c
index 20830c3..ac5b656 100644
--- a/watchdog.c
+++ b/watchdog.c
@@ -49,11 +49,11 @@  static void watchdog_timeout_cb(struct uloop_timeout *t)
 
 static int watchdog_open(bool cloexec)
 {
-    char *env = getenv("WDTFD");
-
     if (wdt_fd >= 0)
         return wdt_fd;
 
+    char *env = getenv("WDTFD");
+
     if (env) {
         DEBUG(2, "Watchdog handover: fd=%s\n", env);
         wdt_fd = atoi(env);