Find the answer to your Linux question:
Results 1 to 2 of 2
Hi, i've the following problem : i've written small tool in C which makes measurements on my router (OpenWrt White Russian). It is working as a deamon. If the tool ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2010
    Posts
    2

    Make system call from an automatically started daemon...


    Hi, i've the following problem :

    i've written small tool in C which makes measurements on my router (OpenWrt White Russian).

    It is working as a deamon. If the tool is started manually, everything works fine.
    If it is started per script on startup, the following system call doesn't work :

    Code:
    sprintf(command,"/bin/cat /root/%s%s | /usr/bin/ssh -p2222 user(at)host -i /root/.ssh/id_rsa \"/bin/cat >> result/%s%s\"", apmac, source, apmac, dest);
    
    rc = system (command);
    the returned rc in this case is 256.

    first i thought it is a problems with the user rights for the tool, so i have added +s to it. but that didn't help. as i said, when the daemon is started by hand, the system call works fine.

    any suggestions ?

    thanks !

  2. #2
    Linux User
    Join Date
    Nov 2008
    Location
    Tokyo, Japan
    Posts
    260
    It might be user rights for the "result/apmacdest" file to which you append. Either the directory doesn't exist, or you don't have write permissions. Shouldn't you instead append to a file in "/var/log"?

    It could also be possible that "ssh" requires services that are not yet available at start-up time. Make sure the script that executes your program is in the correct runlevel and executes after all necessary services have started. If your Linux supports a "system services" interface, write a service to execute your program, make this service dependent on ssh client services.

    Also, consider writing debug code like:
    Code:
    fprintf(stderr, "MY_PROGRAM: %s\n", strerror(errno));
    then grep for "MY_PROGRAM" in /var/log/messages

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •