Calling Perl Script

D

David Meier

Hi all,

I am not a very skilled C programmer yet and I need the help of the
list bad. OK, here is the problem:

I have written a SIEVE module coded in C for the cyrus imapd mail
server. This module starts a Perl Script upon new mail arrival. The
Perl script then does a HTTP request to an SMS gateway with the
provided arguments. OK, both programs have no compilation errors or
so. When I call the Perl script with appropriate arguments the SMS
notification works perfect. But when the script is called from the C
program, the HTTP request succeeds, however no data is sent. I can see
from the SMS gateway log file that a request is created but destroyed
right after. This is the C code of the file notify_sms.c:

#include <config.h>
#include "notify_sms.h"
#include <syslog.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>

char* notify_sms(const char *class __attribute__((unused)),
const char *priority __attribute__((unused)),
const char *user,
const char *mailbox __attribute__((unused)),
int nopt, char **options,
const char *message)
{
char opt_str[1024] = "";
char *sep = "";
char *argv[5];
int i, pid;

pid = fork();

if (pid == -1) {
syslog(LOG_NOTICE, "Unable to fork SMS Notification!");
return strdup("ERROR, SMS notification failed...");
}
if (pid == 0) {
if (nopt) {
strcpy(opt_str, "(");
for (i = 0; i < nopt; i++, sep = ", ") {
snprintf(opt_str+strlen(opt_str), sizeof(opt_str) - 2,
"%s%s",
sep, options);
}
strcat(opt_str, ")");
}

argv[0] = "sms_send";
argv[1] = (char *)user;
argv[2] = opt_str;
argv[3] = (char *)message;
argv[4] = NULL;

syslog(LOG_NOTICE, "Sending SMS Notificationion...");
execv("/usr/local/bin/sms_send", argv);
return strdup("OK, SMS notification successful...");
}
return strdup("Nothing done...");
}


If I include a log statement after execv() I don't get anything in the
syslog. Therefore it seems to me, that some process terminates before
the HTTP request finishes. Unfortunately I don't know much about
forking, child processes etc. Does anyone has any input to this?
Thanks very much!

Dave
 
A

Artie Gold

David said:
Hi all,

I am not a very skilled C programmer yet and I need the help of the
list bad. OK, here is the problem:

I have written a SIEVE module coded in C for the cyrus imapd mail
server. This module starts a Perl Script upon new mail arrival. The
Perl script then does a HTTP request to an SMS gateway with the
provided arguments. OK, both programs have no compilation errors or
so. When I call the Perl script with appropriate arguments the SMS
notification works perfect. But when the script is called from the C
program, the HTTP request succeeds, however no data is sent. I can see
from the SMS gateway log file that a request is created but destroyed
right after. This is the C code of the file notify_sms.c:

#include <config.h>
#include "notify_sms.h"
#include <syslog.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>

char* notify_sms(const char *class __attribute__((unused)),
const char *priority __attribute__((unused)),
const char *user,
const char *mailbox __attribute__((unused)),
int nopt, char **options,
const char *message)
{
char opt_str[1024] = "";
char *sep = "";
char *argv[5];
int i, pid;

pid = fork();

if (pid == -1) {
syslog(LOG_NOTICE, "Unable to fork SMS Notification!");
return strdup("ERROR, SMS notification failed...");
}
if (pid == 0) {
if (nopt) {
strcpy(opt_str, "(");
for (i = 0; i < nopt; i++, sep = ", ") {
snprintf(opt_str+strlen(opt_str), sizeof(opt_str) - 2,
"%s%s",
sep, options);
}
strcat(opt_str, ")");
}

argv[0] = "sms_send";
argv[1] = (char *)user;
argv[2] = opt_str;
argv[3] = (char *)message;
argv[4] = NULL;

syslog(LOG_NOTICE, "Sending SMS Notificationion...");
execv("/usr/local/bin/sms_send", argv);
return strdup("OK, SMS notification successful...");
}
return strdup("Nothing done...");
}


If I include a log statement after execv() I don't get anything in the
syslog. Therefore it seems to me, that some process terminates before
the HTTP request finishes. Unfortunately I don't know much about
forking, child processes etc. Does anyone has any input to this?
Thanks very much!

Dave


Dave:

Unfortunately, you don't have a standard C question at all (the sole
topic of this newsgroup), but rather one concerning POSIX calls.

The right place is:


where I'm sure you'll get the help you need.

Cheers,
--ag
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,264
Latest member
FletcherDa

Latest Threads

Top