openframeworks / openFrameworks

openFrameworks is a community-developed cross platform toolkit for creative coding in C++.
http://openframeworks.cc
Other
9.84k stars 2.56k forks source link

ofSystem() On Raspberry Pi Error #5108

Open toliaferrode opened 8 years ago

toliaferrode commented 8 years ago

Raspberry Pi 2 with Raspbian, openFrameworks arm6

I've got code in my program to shutdown the Pi using "ofSystem("sudo halt")". Some times it works and sometimes it doesn't. When it doesn't work, it returns an error that says ofSystem() wasn't able to open the return file or something. Maybe it says sudo halt doesn't exist? I'm not sure because I can't reproduce it right now, but it's been happening on and off since I started using ofSystem() on the Pi. Thanks.

bakercp commented 8 years ago

Can you share and capture the exact error that you are getting? Also, can you submit a minimal code example to reproduce the issue? e.g. Does:

...

ofApp::setup() 
{
  ofSystem("sudo halt");
}
...

do it?

arturoc commented 8 years ago

Also to run something with sudo you need to pass the password unless you've done so recently which would explaing why it sometimes works. you can configure some commands to not require passwords editing the sudo config using:

sudo visudo

On 27.05.2016 18:47, Christopher Baker wrote:

Can you share and capture the exact error that you are getting? Also, can you submit a minimal code example to reproduce the issue? e.g. Does:

...

ofApp::setup() { ofSystem("sudo halt"); } ...

do it?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/openframeworks/openFrameworks/issues/5108#issuecomment-222196468, or mute the thread https://github.com/notifications/unsubscribe/AAC8cJcKVKaB1-zAZkjrHMNtWh0pnOE7ks5qFyApgaJpZM4IoC_q.

bakercp commented 8 years ago

+1 to @arturoc 's thought in general. Though depending on your Raspberry Pi setup, sudo doesn't generally ask for a password. So that could be part of the confusion ...

toliaferrode commented 8 years ago

Hi, it's true that the Raspberry Pi doesn't ask for a password with sudo.

I got it to error again, here is the line exactly: 'h[error] ofUtils: ofSystem(): error opening return file for command "sudo halt"'

"h" is the key I have mapped to halt the system through openFrameworks.

It seems like the longer the program is running (it's designed to run for a few hours) the greater the chance of the error occurring. But I'm not totally sure about that.

jvcleave commented 8 years ago

Not that it solves the error but I would take sudo out of the app and run the app like this so it is inherited

sudo ./yourapp

toliaferrode commented 8 years ago

Hey jvcleave, thanks for the tip. Changed it in rc.local (that's where I'm starting it from) to sudo and my app path and changed it to ofSystem("halt") in the code. Recompiled it, rebooted the Pi, and right off the bat it errored with: 'h[error] ofUtils: ofSystem(): error opening return file for command "halt"', instead of sudo halt as above. I rebooted for tests twice and it did work, it halted as expected. I'm still thinking it's going to error again, so I'll do more tests.

toliaferrode commented 8 years ago

After a lot of testing I can confirm that it still errors at about the same rate as before.