You are not logged in.

#1 2011-04-12 08:13:51

anstmich
Member
Registered: 2009-06-20
Posts: 29

Loading a most stubborn application at startup

Hi all,

I received quite a bit of help on irc, however I have nonetheless been unsuccessful in making this work.  Essentially I have written some software that manages various usb devices as well as a script that runs the application and then logs the output from stdout and stderr.  Running this application from the cli after logging in works great.  Attempting to run the application during boot however does not work (it segfaults).

I have tried many things: writing a bash script and running it from rc.d (via daemons in rc.conf), attempting to run the script directly from rc.local, attempting to run the script using screen from rc.local, performing various modifications to my /etc/inittab such as using this command as described in the wiki x:5:once:/bin/su - -- PREFERRED_USER -l -c 'EXECUTE SCRIPT HERE', etc.

None of these worked.  I figured that, before I quit entirely, I might ask the community to see if anyone else had any ideas.  Any help is greatly appreciated!!!

Offline

#2 2011-04-12 10:52:19

lives2evil
Member
From: GMT+7
Registered: 2010-03-21
Posts: 244

Re: Loading a most stubborn application at startup

If it's a programming related I think you've post at the wrong place.

Well, try running your application manually at console (NO X running), debug it with gdb. And perhaps methods you used could help diagnosis (what libraries you used for instance).


tsujeruplive, tnarongisi... ... ... ... ɥsılƃuǝ sı sıɥʇ

Offline

#3 2011-04-12 13:31:34

anstmich
Member
Registered: 2009-06-20
Posts: 29

Re: Loading a most stubborn application at startup

As I said, running the application from the cli after logging in works without a problem, so I dont see how it could be a bug, although it is possible I guess.  As far libraries go, beyond the standard c libraries, I use libusb (which I am guessing is related to my problem).

Offline

#4 2011-04-12 13:53:15

lives2evil
Member
From: GMT+7
Registered: 2010-03-21
Posts: 244

Re: Loading a most stubborn application at startup

Does your application work when you put it in .xinit?


tsujeruplive, tnarongisi... ... ... ... ɥsılƃuǝ sı sıɥʇ

Offline

#5 2011-04-12 14:39:04

anstmich
Member
Registered: 2009-06-20
Posts: 29

Re: Loading a most stubborn application at startup

lives2evil wrote:

Does your application work when you put it in .xinit?

I dont have X installed on that machine.  Something to note, however, is that the program fails when run in the background (i.e. "/home/user/app &")

Offline

#6 2011-04-12 14:48:39

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,308

Re: Loading a most stubborn application at startup

I agree with lives2evil,

This will get a lot more visibility from the coders over at Programming.  Moving....

I would wager real money you are using dereferencing  null pointer some place.  Maybe some function that fails because the USB in question is not yet set in time for your script?  Set up some logging and pour a bunch of telemetry out to the debug log to see what is happening.

You might want to put the source up on pastebin and provide a link.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#7 2011-04-12 15:19:50

rowdog
Member
From: East Texas
Registered: 2009-08-19
Posts: 118

Re: Loading a most stubborn application at startup

anstmich wrote:

Something to note, however, is that the program fails when run in the background (i.e. "/home/user/app &")

Why? That's probably the first issue to track down. Is this "software" a program that you wrote? What language?

Long running processes are normally written as daemons. Wikipedia has an overview of the usual approach at
http://en.wikipedia.org/wiki/Daemon_%28 … of_daemons

Offline

#8 2011-04-12 16:36:01

anstmich
Member
Registered: 2009-06-20
Posts: 29

Re: Loading a most stubborn application at startup

rowdog wrote:
anstmich wrote:

Something to note, however, is that the program fails when run in the background (i.e. "/home/user/app &")

Why? That's probably the first issue to track down. Is this "software" a program that you wrote? What language?

Long running processes are normally written as daemons. Wikipedia has an overview of the usual approach at
http://en.wikipedia.org/wiki/Daemon_%28 … of_daemons

Yes this is an application that I wrote in C.  I tried daemonizing it and that did not work, which I am guessing somehow relates to the fact that it doesnt like being run as a background prcoess.  Beyond using libusb, the only other "libraries" used are those provided standard with C (i.e. string.h, stdio.h, stdlib.h).  Also, when I did daemonize it, if I called /etc/rc.d/app start it would work just fine, just not during boot, however.  I will do some reading though, thanks! 

I agree with lives2evil,
This will get a lot more visibility from the coders over at Programming.  Moving....
I would wager real money you are using dereferencing  null pointer some place.  Maybe some function that fails because the USB in question is not yet set in time for your script?  Set up some logging and pour a bunch of telemetry out to the debug log to see what is happening.
You might want to put the source up on pastebin and provide a link.

I doubt it is a null pointer (I do quite a bit of error checking for this).  My guess, though, is that you are right about the USB.  There must be something that libusb needs -- an environment variable or something. 

If I try putting in a long delay (30+ seconds) in the python (or bash) script that runs my application, although it pauses successfully, the application called still fails.  Furthermore, if I immediately log in and run the script manually, everything works fine.  This would lead me to believe that there is perhaps a problem detaching the kernel USB driver? Im not sure what else could be different before and after logging in.

Thanks for the help!

Offline

#9 2011-04-12 16:42:17

anstmich
Member
Registered: 2009-06-20
Posts: 29

Re: Loading a most stubborn application at startup

Here is the code that manages all things USB: http://pastebin.com/dUbVM42V

Offline

#10 2011-04-12 17:30:07

anstmich
Member
Registered: 2009-06-20
Posts: 29

Re: Loading a most stubborn application at startup

Ok, so I have a temporary, albeit far from ideal, solution.  Using rungetty + inittab, I had it autologin as root and then setup my .bash_profile to load the python script.  Far from elegant, but it at least works. Sigh

Offline

#11 2011-04-13 01:21:13

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 7,358

Re: Loading a most stubborn application at startup

anstmich wrote:

Ok, so I have a temporary, albeit far from ideal, solution.  Using rungetty + inittab, I had it autologin as root and then setup my .bash_profile to load the python script.  Far from elegant, but it at least works. Sigh

Talk about overkill smile. I don't have any better suggestions though, unfortunately. Hope you trust your code.


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

#12 2011-04-13 11:37:22

lives2evil
Member
From: GMT+7
Registered: 2010-03-21
Posts: 244

Re: Loading a most stubborn application at startup

Well, I was going to suggest some thing similiar. My idea was to run it as normal user (.bashrc), but allow it to run only once (I think a lock file is pretty simple).
Glad you got it working then.


tsujeruplive, tnarongisi... ... ... ... ɥsılƃuǝ sı sıɥʇ

Offline

#13 2011-04-13 21:48:54

tavianator
Member
From: Waterloo, ON, Canada
Registered: 2007-08-21
Posts: 859
Website

Re: Loading a most stubborn application at startup

Use valgrind to track down the bug.  I'd help, but you didn't post all the code (it's missing the main() routine at least).

Offline

#14 2011-04-17 22:45:45

anstmich
Member
Registered: 2009-06-20
Posts: 29

Re: Loading a most stubborn application at startup

I dont have too much time at the moment to do any debugging, however out of curiosity, what kind of bug could prevent an application from being run in the background?  What changes internally when this is done?

Offline

Board footer

Powered by FluxBB