Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not try to continue reading shell commands if input source is closed #10105

Merged
merged 1 commit into from
Oct 30, 2018

Conversation

x3ro
Copy link
Contributor

@x3ro x3ro commented Oct 2, 2018

Contribution description

In RIOT native, sending CTRL+D to a shell started using shell_run would resulted in and
endless prompt loop. I've been unable to trigger such a behaviour
on actual hardware using a UART connection, but calling pm_off seemed
like a better alternative than having an #ifdef BOARD_NATIVE.

Testing procedure

  1. From the Tutorials repo, compile and run task01 for native.
  2. Press CTRL-D in your terminal (this sends EOF)

Expected:

The shell exits cleanly.

Actual:

An infinite loop of prompt characters is triggered

Issues/PRs references

Fixes #9946

@x3ro x3ro force-pushed the fix-shell-prompt-infinite-loop branch from 4622f85 to f3e781f Compare October 2, 2018 16:19
@x3ro x3ro added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Platform: native Platform: This PR/issue effects the native platform labels Oct 2, 2018
@PeterKietzmann
Copy link
Member

@mroethke would you like to give this PR a try?

@mroethke
Copy link

mroethke commented Oct 5, 2018

I can confirm that this fixes my issue.

@x3ro
Copy link
Contributor Author

x3ro commented Oct 5, 2018

@PeterKietzmann would you be in for a quick review? ^_^

@PeterKietzmann PeterKietzmann added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines labels Oct 5, 2018
@PeterKietzmann
Copy link
Member

ACK from my side. I've added related labels. Out of my head I don't know if there is any other/better solution to shut down. Actually I never really looked into the shell implementation.

I'd say let's keep this open for 1-2 days and if no one complains, I'm gonna merge then.

Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also fine with this change. In theory any terminal around should catch an EOF (tested with pyterm and serial_aggregator), so this is only relevant for raw native where there is no terminal program around the input. There it works as expected when hitting Ctrl+D

@jia200x
Copy link
Member

jia200x commented Oct 8, 2018

so, can we merge this one? ;)

@jia200x jia200x added this to the Release 2018.10 milestone Oct 8, 2018
@miri64
Copy link
Member

miri64 commented Oct 8, 2018

If someone gives a proper ACK, I guess. Still like to have the opinion of someone more knowledgeable with the inner workings of the shell though. @kaspar030 @OlegHahm?

@kaspar030
Copy link
Contributor

Please no!

Why does the shell turn off the node? That's not good at all, if only for the added dependency.

@kaspar030
Copy link
Contributor

The shell loop should probably exit on reading EOF.

@miri64
Copy link
Member

miri64 commented Oct 8, 2018

The shell loop should probably exit on reading EOF.

Now that you say it, this makes more sense to me indeed.

@x3ro
Copy link
Contributor Author

x3ro commented Oct 8, 2018

@kaspar030 How would you cause this on a real node (i.e. not native)? Note that it is not turned off when a node receives an EOF, but when getchar returns an error value. In such a case, the current behaviour of the shell would be to infinite loop forever.. Also shell_run is noreturn.

@miri64
Copy link
Member

miri64 commented Oct 8, 2018

@kaspar030 How would you cause this on a real node (i.e. not native)?

The problem is not that it can't (or may not) be caused on a real node, the problem is that the current proposal is pulling in a dependency (pm) that wasn't there before, just so that one platform [edit] and not even a platform intended for production use [/edit] may finish correctly when EOF is signaled.

@x3ro
Copy link
Contributor Author

x3ro commented Oct 8, 2018

So should we modify shell_run to return instead? @kaspar030 @miri64

@jcarrano
Copy link
Contributor

jcarrano commented Oct 9, 2018

@miri64

In theory any terminal around should catch an EOF

No, that's an additional functionality. The terminal emulator should pass though EOF. That's why they have escape keys. The extra "magic" added by the terminal script already gave some headaches when trying non-shell code that communicated via UART, so I'd say it is good if EOFs are handled by RIOT in actual hardware too.

@x3ro
Making the shell return has the advantage of being able to easily restart the node (if one chooses to) by sending a CTRL-D.

@tcschmidt
Copy link
Member

@x3ro any movement towards 2018.10 Release?

@x3ro
Copy link
Contributor Author

x3ro commented Oct 19, 2018

Ah I didn't realize this was marked for the release. I'll take another look at it tomorrow.

@x3ro
Copy link
Contributor Author

x3ro commented Oct 20, 2018

@miri64 @kaspar030 @jcarrano Does this look better?

@@ -76,5 +77,6 @@ int main(void)
shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE);
*/

pm_off();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this is change should get its own PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@@ -72,7 +72,7 @@ typedef struct shell_command_t {
*
* @returns This function does not return.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this message needs updating

@jia200x jia200x removed this from the Release 2018.10 milestone Oct 24, 2018
@jia200x jia200x added this to the Release 2019.01 milestone Oct 24, 2018
@jia200x
Copy link
Member

jia200x commented Oct 26, 2018

@x3ro I'm OK with the proposed change in the shell. Could you address @kaspar030 comments?

This bugfix is listed in the Release 2018.10, so would be very nice to have it :)

@jia200x
Copy link
Member

jia200x commented Oct 30, 2018

ping @x3ro

@x3ro
Copy link
Contributor Author

x3ro commented Oct 30, 2018

@jia200x want to give it another look?

@jia200x
Copy link
Member

jia200x commented Oct 30, 2018

@kaspar030 comments were addressed. Re-tested with current master and with this PR, and works as expected.

@jia200x jia200x added the Process: needs backport Integration Process: The PR is required to be backported to a release or feature branch label Oct 30, 2018
Copy link
Member

@jia200x jia200x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested ACK

In RIOT native, sending CTRL+D to a shell started using shell_run would resulted in and
endless prompt loop. I've been unable to trigger such a behaviour
on actual hardware using a UART connection, but calling `pm_off` seemed
like a better alternative than having an `#ifdef BOARD_NATIVE`.

Fixes RIOT-OS#9946
@x3ro x3ro force-pushed the fix-shell-prompt-infinite-loop branch from 7da6d09 to 62cecc9 Compare October 30, 2018 18:07
@x3ro x3ro merged commit 6ed11de into RIOT-OS:master Oct 30, 2018
@cladmi
Copy link
Contributor

cladmi commented Oct 30, 2018

I just saw this one in master, and the commit message is not prepended by the module/file and the commit message does not match the implemented fix.
Maybe it was not ready for merging ?

@cladmi
Copy link
Contributor

cladmi commented Oct 30, 2018

It was also an API change in theory so would have waited for another ack I think.

@jia200x
Copy link
Member

jia200x commented Oct 30, 2018

I just saw this one in master, and the commit message is not prepended by the module/file and the commit > message does not match the implemented fix.
Maybe it was not ready for merging ?

I wrongly ACK'd. Sorry.

@x3ro
Copy link
Contributor Author

x3ro commented Oct 30, 2018

@cladmi Apologies for missing the commit message, I was under the impression that Murdock checks this, so I didn't pay much attention after squashing.

It was also an API change in theory so would have waited for another ack I think.

Nobody had any issues with the API change so far, and the issue has been open for a month. The changes today were purely removing things that reviewers did not feel like it belonged in the PR. From the API change side, it feels fairly well reviewed IMO.

@cladmi
Copy link
Contributor

cladmi commented Oct 31, 2018

@x3ro to prevent forgetting to update messages, I tend to do my fix with git commit --squash HASH with the updated message in the body. This way when squashing with --autosquash I am asked to squash it and I remember to update the first message.

For the API change, the thing is that it should normally have 2 maintainers ACKs, and should not be backported after the feature-freeze. Even more when this is for a native specific native ease of life improvement.
The change is great, but I would not say worth changing the API during the release RC.

@jia200x jia200x removed this from the Release 2019.01 milestone Nov 1, 2018
@jia200x jia200x removed the Process: needs backport Integration Process: The PR is required to be backported to a release or feature branch label Nov 1, 2018
@jia200x jia200x mentioned this pull request Nov 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: native Platform: This PR/issue effects the native platform Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants