Okay, I'm trying to build a daemon (for a Debian machine) that will take the command line arguments it receives (via cron) and pass them to different script files.
The daemon's main()
is
int main(int argc , char *argv[])
{
if(argc != 3)
{
exit(0);
}
daemonize(argv[1], argv[2]);
return 0;
}
And the function daemonize has this set up
int daemonize(const char *cmd1, const char *cmd2) {...}
The troubling part in daemonize is here:
if (strcmp(cmd1,"sample_script") == 0)
{
static char *argv[] = {"/etc/init.d/sample_script", ["%s",cmd2], NULL };
execv("/etc/init.d/sample_script",argv);
exit(127);
}
On the line
static char *argv[] = {"/etc/init.d/sample_script", ("%s",cmd2), NULL };
I am getting this error
initializer element is not constant (near initialization for ‘argv[1]’)
Obviously ("%s",cmd2)
is wrong. Because using "start" works fine.
So, how do I get cmd2
to be correctly put into *argv[]
? Or is it something else I am doing wrong?