/usr/sbin/laptop_mode: line 1143: return: can only `return' from a function or sourced script

Bug #815201 reported by Eric Belanger
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Laptop Mode Tools
Fix Committed
Undecided
Unassigned

Bug Description

When running "/usr/sbin/laptop_mode auto" (version 1.58), I get the following message:
/usr/sbin/laptop_mode: line 1143: return: can only `return' from a function or sourced script

It looks like the 'return 0;' at the end is causing some problem.

Revision history for this message
Ritesh Raj Sarraf (rrs) wrote : Re: [Bug 815201] [NEW] /usr/sbin/laptop_mode: line 1143: return: can only `return' from a function or sourced script

On 07/24/2011 02:03 AM, Eric Belanger wrote:
> When running "/usr/sbin/laptop_mode auto" (version 1.58), I get the following message:
> /usr/sbin/laptop_mode: line 1143: return: can only `return' from a function or sourced script
>
> It looks like the 'return 0;' at the end is causing some problem.
That is weird. I did test. And I did still do not see this problem on my
setup.

    12:35:53 rrs@champaran:~/devel/Laptop-Mode-Tools/LMT-Debian$ sudo
    /usr/sbin/laptop_mode auto
    [sudo] password for rrs:
    12:36:01 rrs@champaran:~/devel/Laptop-Mode-Tools/LMT-Debian$ Laptop
    mode
    enabled,
    not active [unchanged]

Can you investigate a little more?

--
Ritesh Raj Sarraf | http://people.debian.org/~rrs
Debian - The Universal Operating System

Revision history for this message
Eric Belanger (eric-wz) wrote :

Maybe it depends on the shell.

I noticed that /usr/sbin/laptop_mode uses /bin/sh. On my distribution (Arch Linux), this is a symlink to bash (version 4.2.010). What shell are you using to run sh scripts? Is it bash or is it another shell like dash? dash doesn't return error when doing "return 0" in the shell so maybe that's what you are using.

Revision history for this message
Ritesh Raj Sarraf (rrs) wrote : Re: [Bug 815201] Re: /usr/sbin/laptop_mode: line 1143: return: can only `return' from a function or sourced script

On 07/24/2011 01:52 PM, Eric Belanger wrote:
> Maybe it depends on the shell.
>
> I noticed that /usr/sbin/laptop_mode uses /bin/sh. On my distribution
> (Arch Linux), this is a symlink to bash (version 4.2.010). What shell
> are you using to run sh scripts? Is it bash or is it another shell like
> dash? dash doesn't return error when doing "return 0" in the shell so
> maybe that's what you are using.
Yes, the system default on Debian is dash.

Also, to be POSIX shell compliant, we ensure that we do not have any
bash specific constructs.

--
Ritesh Raj Sarraf
RESEARCHUT - http://www.researchut.com
"Necessity is the mother of invention."

Revision history for this message
Eric Belanger (eric-wz) wrote :

Wouldn't it be possible to put the return 0 in a dummy function to keep bash happy?

Revision history for this message
Ritesh Raj Sarraf (rrs) wrote :

On 07/27/2011 12:08 AM, Eric Belanger wrote:
> Wouldn't it be possible to put the return 0 in a dummy function to keep
> bash happy?
I still will have to call the function to make init scripts clean. Does
keeping it in a function and calling the function help ?

--
Ritesh Raj Sarraf
RESEARCHUT - http://www.researchut.com
"Necessity is the mother of invention."

Revision history for this message
Eric Belanger (eric-wz) wrote :

That would work but I'm not sure if the shell will interpret the return value as being for the script rather than for the function itself. How about replacing 'return 0' by 'exit 0' ? That seems to be better suited for the situation as we are exiting the script at that point. And it is accepted by bash.

Revision history for this message
Ritesh Raj Sarraf (rrs) wrote :

On 07/28/2011 02:57 AM, Eric Belanger wrote:
> That would work but I'm not sure if the shell will interpret the return
> value as being for the script rather than for the function itself. How
> about replacing 'return 0' by 'exit 0' ? That seems to be better suited
> for the situation as we are exiting the script at that point. And it is
> accepted by bash.
Great. Thanks. I'll test it out

--
Ritesh Raj Sarraf
RESEARCHUT - http://www.researchut.com
"Necessity is the mother of invention."

Revision history for this message
Ritesh Raj Sarraf (rrs) wrote :

On 07/28/2011 04:10 AM, Ritesh Raj Sarraf wrote:
> On 07/28/2011 02:57 AM, Eric Belanger wrote:
>> > That would work but I'm not sure if the shell will interpret the return
>> > value as being for the script rather than for the function itself. How
>> > about replacing 'return 0' by 'exit 0' ? That seems to be better suited
>> > for the situation as we are exiting the script at that point. And it is
>> > accepted by bash.
> Great. Thanks. I'll test it out
I think I'll go with exit 0. Line #1089 in 1.58 laptop-mode script
already did exit 0 gracefully. We already log/print error message if
any, so we don't worry about the final exit code. It just got ignored
now because of the polling fix I did. I need to add locking for the
polling code also.

For now, please use exit 0 and report back if it causes any other problems.

--
Ritesh Raj Sarraf | http://people.debian.org/~rrs
Debian - The Universal Operating System

Revision history for this message
Ritesh Raj Sarraf (rrs) wrote : Re: Bug#636251: [Bug 815201] Re: /usr/sbin/laptop_mode: line 1143: return: can only `return' from a function or sourced script

On 08/02/2011 02:21 PM, Cristian Ionescu-Idbohrn wrote:
> EXIT STATUS
> The following exit values shall be returned:
> ...
> Otherwise, the shell shall return the exit status of
> the last command it invoked or attempted to invoke
> (see also the exit utility in Special Built-In
> Utilities).
That is the reason we did a graceful exit. There are many helper
utilities lmt calls. On top of that, with multiple events, now there'll
be multiple invocations. If we carry the prev command's exit status, the
initscript will mostly report a failure.

--
Ritesh Raj Sarraf
RESEARCHUT - http://www.researchut.com
"Necessity is the mother of invention."

Ritesh Raj Sarraf (rrs)
Changed in laptop-mode-tools:
status: New → Fix Committed
Ritesh Raj Sarraf (rrs)
Changed in laptop-mode-tools:
status: Fix Committed → Fix Released
status: Fix Released → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.