Sample Header Ad - 728x90

Systemctl daemon only works when verbose is enabled

0 votes
0 answers
335 views
I have a daemon in init.d which except for the name and description has exactly the same structure as the standard ubuntu [skeleton file](https://gist.github.com/mrowe/8b617a8b12a6248d48b8) . When I try to run said daemon using
sudo /etc/init.d/mydaemon start
I get an error that starting the daemon failed with the message
Control process exited, code=exited, status=1/FAILURE
which isn't very helpful as code 1 doesn't really mean anything as far as I can tell. While debugging this, at one point I decided to change the verbose variable at /lib/init/vars.sh from no to yes, just to provoke some output and upon doing that, the daemon runs flawlessly. Yet when I change verbose back to no, I get the same errors as previously. Have any of you ever encountered somehthing like this and now what may be causing it? Also, the daemon code is in c++ and is the following (although i don't think it's neccesarily relevant for this):
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

#define DAEMON_NAME "mydaemon"

void process(){

    syslog (LOG_NOTICE, "Writing to log from Daemon");
}

int main(int argc, char *argv[]) {

    //Set our Logging Mask and open the Log
    setlogmask(LOG_UPTO(LOG_NOTICE));
    openlog(DAEMON_NAME, LOG_CONS | LOG_NDELAY | LOG_PERROR | LOG_PID, LOG_USER);

    pid_t pid, sid;

   //Fork the Parent Process
    pid = fork();

    if (pid  0) { exit(EXIT_SUCCESS); }

    //Change File Mask
    umask(0);

    //Create a new Signature Id for our child
    sid = setsid();
    if (sid =0; x--)
    {
        close (x);
    }

    //----------------
    //Main Process
    //----------------
    while(true){
        process();    //Run our Process
        sleep(30); //Sleep for 30 seconds
        break;    
    }

    //Close the log
    closelog ();
    return 0;
}
Asked by user404496
Apr 15, 2020, 11:31 AM