0

The init.d script is installed properly and by me i wrote the script correctly. But i have a very strange situation. The script executes a multi-threaded program written in c++ by me. If i execute the program through terminal (i installed in /usr/sbin/) like: "MyProgram &" everything is ok. But if this program is executed by the init.d script one thread fails. The other threads of the program as the other features of the init.d script specifications works as expected to. I also have to mention that the thread which fails makes a screenshot of the desktop every 30 sec. Obviously the problem has to be from the init.d script. I tried to start the program in that script in the following ways:

$DAEMON &
exec $DAEMON &
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON &
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON & > /dev/null

Where $PIDFILE = /var/run/$NAME.pid ; $DAEMON = /usr/sbin/$NAME; $NAME = MyProgram In all the cases i have the same result: one thread fails. Any ideas?

8
  • What does it mean that "one thread fails"? Are you talking about POSIX threads? Or probably you mean "my process does not start in background"? Oct 17, 2013 at 18:30
  • My c++ program has 5 POSIX threads. So when i start the program through terminal like "MyProgram &" it works perfect, i tested for 24 hours - no crash. But when the program is started from the ini.d script one POSIX thread fails.
    – SASA Aga
    Oct 17, 2013 at 18:37
  • But what do you mean? How can a thread fail? Doesn't it start? Does it crash with an exception? (And if it does, what exception?) Does it hang? (And if it does, why? Deadlock? Infinite loop?) Does a syscall fail? (And if it does, which syscall? With what error number?) Is it killed by a signal? (And if it is, what signal?) Oct 17, 2013 at 19:27
  • You a right the thread itself did not fail, if it would the hole program would also fail. But that thread does not work as expected to, its aim fails. It makes a system call to other utility written by me, also c++ which makes a screenshot. Thats why the thread does not crash, but the utility called crashes. That utility is written with the help of CImg library and it fails at 3rd line: 1. Display *display = XOpenDisplay(NULL); 2. Xprint("Display *display -- created"); 3. Window root = DefaultRootWindow(display);
    – SASA Aga
    Oct 17, 2013 at 19:48
  • Again, what does it mean "it fails"? I guess it gets a SEGFAULT, however you can't ask people here to do the debugging for your :-) I'd really like to help you, however I'm sure you understand I can't guess the problem from three lines of code. You should really find the root cause of the problem and only afterwards ask for help. Oct 17, 2013 at 19:52

1 Answer 1

1

I found the working solution of my problem. Due to X server configuration you can not connect to it in init scripts, though i tried to configure X server to allow incoming connections to a tcp port i had no success to connect. So i launched my program when X starts by adding the display-setup-script=path_to_script in /etc/lightdm/lightdm.conf. The solution i found here: Launch a program when X starts

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .