How to add subshell support for ash

Alexander Kriegisch kriegaex at freetz.org
Mon Mar 5 13:27:51 UTC 2012


Update: I have factored out the INPUTRC fix (including two source code
comments for the bash case) into a separate 030-bash_inputrc.patch so as
to separate it from the ash patches and enable you to easily fix the
upstream code issue separately.


Alexander Kriegisch, 05.03.2012 14:25:
> Oswald Buddenhagen, 05.03.2012 09:27:
>> On Sun, Mar 04, 2012 at 03:19:52PM +0100, Alexander Kriegisch wrote:
>>> I know how to do this via shell script, but not cleanly via C, sorry.
>>>
>> you could start by posting the sh code as text or a comment ...
> 
> I do not really know what the point would be to produce something which
> would never be used, but I am thinking about it and might post an update
> later.
> 
>>>   - Plese refer to code comments for how and why I implemented the
>>>     precmd via PS1 with two-fold indirection.
>>>
>> as ash is as close to pure posix as it gets, this pretty much qualifies
>> as a generic solution. one could even remove the paths for the other
>> bourne-compatible shells (except that they are less hacky) ...
> 
> I am providing my code as-is, so as I said, every core MC developer or
> maintainer is welcome to optimise and streamline my patch as well as the
> upstream code base. So if my PS1 precmd trick works for other shells,
> too, feel free to use it there, too. Maybe if I have time available I
> can test that, but my main concern still is ash.
> 
>>> Remark: In order to get ENV into the environment for the init file, I
>>> had to uncomment "g_free (putenv_str)".
>>>
>> that sounds like adding a memory leak. you need to move, not remove the
>> free.  but then, i don't know that code, maybe there is already a second
>> cleanup path.
> 
> I took the chance to just test the INPUTRC case and found out that as I
> suspected, it actually does *not* work because the variable is g_free'd
> before the subshell is called. The effect is that even though I created
> a test file ~/.local/share/mc/inputrc, it was not used by bash and
> INPUTRC was undefined in the subshell.
> 
> So I updated my patch: putenv_str is now created before the first switch
> statement and g_free(putenv_str) is called at the same place as
> g_free(init_file). No matter whether my ash subshell patch is accepted
> into the code base or not, the INPUTRC case needs to be fixed upstream.
> Probably it never worked unless the g_free'd memory area was not
> overwritten yet by the time it was used by the bash subshell. After my
> fix, INPUTRC is available and used by the bash subshell. I have tested
> it on my mipsel target platform.
> 
>>> +                    // A: This leads to a stopped subshell (=frozen mc) if user calls "sh" command
>>>
>> please fix the indentation and avoid c99/c++ comments.
> 
> I must say, I am rather happy that indentation and commenting style is
> your major concern about my code and not anything functional. My updated
> patch does not use c99 style comments anymore. The second patch file
> remains unchanged because I did not add any comments there. As for
> indentation, I did not find anything wrong there. I am using four spaces
> instead of tabs just like you MC developers, even though I find that
> rather strange. The indentation level is in line with the rest of the
> switch-case statement, even though I personally do not indent that way,
> but indentation is largely a matter of taste anyway and I am merely
> trying to adapt to the style I found in your code base.
> 
> 
> 
> 
> _______________________________________________
> mc-devel mailing list
> http://mail.gnome.org/mailman/listinfo/mc-devel
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: 030-bash_inputrc.patch
URL: <http://lists.midnight-commander.org/pipermail/mc-devel/attachments/20120305/9906df6a/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: 040-ash_as_subshell.patch
URL: <http://lists.midnight-commander.org/pipermail/mc-devel/attachments/20120305/9906df6a/attachment-0001.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: 040-ash_as_subshell_additional.patch
URL: <http://lists.midnight-commander.org/pipermail/mc-devel/attachments/20120305/9906df6a/attachment-0002.ksh>


More information about the mc-devel mailing list