Discussion:
system command returns 32512
(too old to reply)
k***@gmail.com
2006-01-19 13:01:37 UTC
Permalink
Hi,

I am executing a C program in AIX 4.3 machine.

The program sends email with the body redirected from a file.
I use mailx command ( sendmail utility ) in AIX.
The code has following lines:

########################
char *str = "mailx -s hi -c ***@abc.com ***@abc.com < test.txt"

rc = system(str);

#########################

I execute this in a loop for many times.
For example, if i execute it for 10 times then 1-2 mails are not sent.
The return from system command for these 2-3 failed mails is 32512

I printed value of rc and it showed that rc=32512.
The mailx command was not invoked.
I saw in some groups, they have mentioned that the return 32512 is
because the exec of the child process failed.

I want to know the reason why the exec of the child process failed.
I have verified that the number of processes is not exceding the system
limit.
Can anyone please tell me the root cause of this return 32512.

Thanks and Regards
Kiran Hiremath
Dan Foster
2006-01-19 13:31:10 UTC
Permalink
Post by k***@gmail.com
I am executing a C program in AIX 4.3 machine.
The program sends email with the body redirected from a file.
I use mailx command ( sendmail utility ) in AIX.
I printed value of rc and it showed that rc=32512.
32512 divided by 256 is 127... so it sounds like EOVERFLOW.

(grep 127 /usr/include/errno.h)

What is the size of file.txt? And the size of the target user's mailbox?

Is there any entry in 'errpt' for the problem?

Is the machine at 4.3.3 and fully patched?

-Dan
k***@gmail.com
2006-01-19 14:01:36 UTC
Permalink
Hi Dan,

I checked the file size and it is just 90 bytes.
And what is the entry 'errpt'. where can i find it.
I could see that when the system caommand failed, the mailx command was
not triggerred.
The target mailbox has a very huge size.
Also please not, some mailx commands which have a bigger file as a body
are executed successfully.

Also please let me know which are the patches which should be
installed.
What does the Error Number EOVERFLOW indicate?

Thanks and Regards
Kiran
Dan Foster
2006-01-19 14:06:47 UTC
Permalink
Post by k***@gmail.com
I checked the file size and it is just 90 bytes.
And what is the entry 'errpt'. where can i find it.
It's a command. For example:

# /usr/sbin/errpt | more

But may not be needed.
Post by k***@gmail.com
The target mailbox has a very huge size.
Ahh! Is the target mailbox at least 2,147,483,648 bytes?

If it is 2 GB or more, mailx will fail.

I would guess maybe because mailx could be written to only handle signed
32-bit numbers for file I/O access, or related to non-big files JFS.

So when the value is too big to fit in the off_t data type, you get the
overflow error (errno number 127).

Solution: reduce target user's mailbox size to less than 2 GB.

-Dan
k***@gmail.com
2006-01-19 14:17:49 UTC
Permalink
Hi Dan,

The target user mailbox size is 50 MB.
The system command forks a child process and then it calls the exec
command.
I think the exec command is failing.
Can it be due to any memory error? For example current process memory
usage.
Do you have any idea on this?

Thanks
Kiran
Dan Foster
2006-01-19 14:32:52 UTC
Permalink
Post by k***@gmail.com
The target user mailbox size is 50 MB.
Ahh. Hmm. Guess that's not a problem, then.
Post by k***@gmail.com
The system command forks a child process and then it calls the exec
command.
I think the exec command is failing.
Can it be due to any memory error? For example current process memory
usage.
# /usr/bin/errpt | grep VMM

That will report if there were any virtual memory-related failures
logged.

-Dan
k***@gmail.com
2006-01-20 07:19:08 UTC
Permalink
Hi Dan,
Actaully my code is as follows:

################################################################

length = strlen(to) + strlen(from) + strlen(replyto) + strlen(cc) +
strlen(subject);
mailcommand = (char*)malloc(length + 128);

strcpy(mailcommand,"mailx -s \'");
strcat(mailcommand,subject);
strcat(mailcommand,"\' ");
strcat(mailcommand,"-c \"");
strcat(mailcommand,cc);
strcat(mailcommand,"\" ");
strcat(mailcommand,"-r \"");
strcat(mailcommand,replyto);
strcat(mailcommand,"\" ");
strcat(mailcommand,"\"");
strcat(mailcommand,to);
strcat(mailcommand,"\"");
strcat(mailcommand," ");

strcat(mailcommand,"< ");
strcat(mailcommand,tmpfilename);
strcat(mailcommand,"\n");

system(mailcommand);

free(mailcommand);

#######################################################
The tmpfilename is the file which contains body.

Do you think there is any memory leak or any such thing here ?

Thanks and Regards
Kiran
Laurenz Albe
2006-01-20 09:25:22 UTC
Permalink
Post by k***@gmail.com
################################################################
length = strlen(to) + strlen(from) + strlen(replyto) + strlen(cc) +
strlen(subject);
mailcommand = (char*)malloc(length + 128);
strcpy(mailcommand,"mailx -s \'");
strcat(mailcommand,subject);
strcat(mailcommand,"\' ");
strcat(mailcommand,"-c \"");
strcat(mailcommand,cc);
strcat(mailcommand,"\" ");
strcat(mailcommand,"-r \"");
strcat(mailcommand,replyto);
strcat(mailcommand,"\" ");
strcat(mailcommand,"\"");
strcat(mailcommand,to);
strcat(mailcommand,"\"");
strcat(mailcommand," ");
strcat(mailcommand,"< ");
strcat(mailcommand,tmpfilename);
strcat(mailcommand,"\n");
system(mailcommand);
free(mailcommand);
#######################################################
The tmpfilename is the file which contains body.
Do you think there is any memory leak or any such thing here ?
I cannot see a memory leak.
The '\n' at the end of the command is superfluous, but I don't think that
is the problem (since you say it occurs only sometimes).

Here's what the manual has to say about system(2) return values:

Return Values

Upon successful completion, the system subroutine returns the exit status
of the shell. The exit status of the shell is returned in the same manner
as a call to the wait or waitpid subroutine, using the structures in the
sys/wait.h file.

If the String parameter is a null pointer and a command processor is
available, the system subroutine returns a nonzero value. If the fork
subroutine fails or if the exit status of the shell cannot be obtained,
the system subroutine returns a value of -1. If the exec l subroutine
fails, the system subroutine returns a value of 127. In all cases, the
errno global variable is set to indicate the error.

What I would do in your place is change the code for debugging purposes:

#include <errno.h>
#include <string.h>
#include <stdio.h>

...

int rc;

...

rc = system(mailcommand);
printf("Executed command \"%s\", got return code %d, errno = %d (%s)\n",
mailcommand, rc, errno, strerror(errno));

Then let it run and examine the output. Share your observations!

Yours,
Laurenz Albe
Jeff Herrick
2006-01-20 15:13:25 UTC
Permalink
Post by k***@gmail.com
Hi Dan,
################################################################
length = strlen(to) + strlen(from) + strlen(replyto) + strlen(cc) +
strlen(subject);
mailcommand = (char*)malloc(length + 128);
You need to include a sizeof() operator in your call to malloc. Your
current code assumes a character is one byte in size when most
likely you're dealing with either 32 bytes or 64 bytes per char i.e.

mailcommand = (char *)malloc(sizeof(char)*length+128)

This may not be your actual problem, but sloppy code like that will
come back and bite you at some point.

Cheers

JH
Laurenz Albe
2006-01-20 16:18:11 UTC
Permalink
Post by Jeff Herrick
Post by k***@gmail.com
length = strlen(to) + strlen(from) + strlen(replyto) + strlen(cc) +
strlen(subject);
mailcommand = (char*)malloc(length + 128);
You need to include a sizeof() operator in your call to malloc. Your
current code assumes a character is one byte in size when most
likely you're dealing with either 32 bytes or 64 bytes per char i.e.
mailcommand = (char *)malloc(sizeof(char)*length+128)
This may not be your actual problem, but sloppy code like that will
come back and bite you at some point.
As far as I know, the ANSI standard requires sizeof(char) to be 1.

Yours,
Laurenz Albe
Jeff Herrick
2006-01-20 19:31:06 UTC
Permalink
Post by Laurenz Albe
As far as I know, the ANSI standard requires sizeof(char) to be 1.
Yours,
Laurenz Albe
You are correct, I hit send too fast and I was confusing bytes with
word size =8-0

Cheers

JH
k***@gmail.com
2006-01-23 08:13:07 UTC
Permalink
Hi,

my code is as follows:

##################################

rc = system(mailcommand);

if ( rc != 0)
printf("Return from system command is RC=%d",rc);

###################################

mailcommand = (char*)malloc(length + 128);

In this command, i add 128 just to have little extra memory for single
quotes , double quotes, mailx options spaces etc.

Do you mean that :
sizeof(char) = 1 in 32 bit system
sizeof(char) = 2 in 64 bit system
How much will this affect my code?

For 20 runs of this code, I have 2-3 emails missing.
I am worried why other emails were recieved and only some emails
failed.

When I reboot the system, an run the code, then all the emails are
recieved successfully.
After 4-5 runs of my code again the missing email problem arises.

Any idea !!!!

Thanks and Regards
Kiran Hiremath
Laurenz Albe
2006-01-23 08:36:32 UTC
Permalink
Post by k***@gmail.com
mailcommand = (char*)malloc(length + 128);
In this command, i add 128 just to have little extra memory for single
quotes , double quotes, mailx options spaces etc.
sizeof(char) = 1 in 32 bit system
sizeof(char) = 2 in 64 bit system
How much will this affect my code?
No, what I wrote and what I meant is:

sizeof(char) is always equal to 1. You can rely on that.
So your code is correct.
Post by k***@gmail.com
For 20 runs of this code, I have 2-3 emails missing.
I am worried why other emails were recieved and only some emails
failed.
In a previous post, I told you how I would debug this.
Did you try it? What is the output?

Yours,
Laurenz Albe
k***@gmail.com
2006-01-23 14:22:44 UTC
Permalink
Hi,

This mail function is a small part of an application which I have
developed.
The application changes password of the user in some domain and sends
email to the email id to inform the changed password.
This mail function is executed for every user. When I execute this for
about 15 users, 12-13 emails are sent and some 2-3 emails are not sent
When I reboot the system, an run the code, then all the emails are
recieved successfully.
After 4-5 runs of my code again the missing email problem arises.
I put some logs and found out that the system command was returning
32512.
The mailx command in the system command was not invoked.
So there is no issue in mailx command. The issue is some memory
problem.
So I just pasted the code, for you to identify the issue.
Do you think, dynamic memory allocation ( malloc ) should be changed by
static memory allocation.?
Example:
char mailcommand[1024] = "";
If I do so, what affect will it do to my code.

I hope you understand the scenario now.

Thanks and Regards
Kiran Hiremath
Jeff Herrick
2006-01-23 15:10:54 UTC
Permalink
Post by k***@gmail.com
Hi,
After 4-5 runs of my code again the missing email problem arises.
I put some logs and found out that the system command was returning
32512.
The mailx command in the system command was not invoked.
So there is no issue in mailx command. The issue is some memory
problem.
Kiran,

32512 decimal = 7F00 hex

7F hex = 127 decimal (after a 1 byte righ-shift..this might not mean
anything...but it is kinda coincidental that system will return 127
if the command fails)

Have you logged each individual command that failed and then attempted
to manually run the command yourself? Is there some timing issue in the
app that is making the temp file inaccessible at the time you issue the
mailx? Are you running out of space writing the temp file?

It doesn't look like a memory problem. Allocating off the stack is
probably not going to make a difference. Looks more like a timing problem
of some sort with respect to your temp file.

Cheers
Jeff Herrick
2006-01-23 16:39:04 UTC
Permalink
Kiran

Further to my last post:

If you compile/run the following small program

#include <stdio.h>
#include <stdlib.h>

int main()
{
int i=0;
i = system("foo");
printf("system returned %d\n",i);
}

you will see it returns 32512 for a bad command...you're obviously
either passing garbage (extra quotes?) to the system() call or
it's a timing issue as mentioned in my last response. This is not
an AIX or memory management issue as far as I am concerned.

Cheers

JH
k***@gmail.com
2006-01-24 13:45:47 UTC
Permalink
Hi,

When I restart the AIX server and test my application, all emails are
recieved successfully.
After 4-5 runs, again email issue arises.
system command returns 32512.

Can it be due to other code in my application?

Thanks and Regards
Kiran Hiremath
Jeff Herrick
2006-01-24 14:32:13 UTC
Permalink
Post by k***@gmail.com
Hi,
When I restart the AIX server and test my application, all emails are
recieved successfully.
After 4-5 runs, again email issue arises.
system command returns 32512.
Can it be due to other code in my application?
Thanks and Regards
Kiran Hiremath
Have you even read the replies?????

You just made it on to my 'ignore' list buddy
k***@gmail.com
2006-02-03 10:46:27 UTC
Permalink
Hi,

I put some debug statements and replaced the system command with fork()
and exec() commands.
I got the errno = 7 ( Arg list too long ).
When I run my code for initial 4-5 times , i don't have this issue.
After 7-8 runs of my application, I get this issue.

There is a macro called ARG_MAX in "/usr/include/sys/limits.h" file.
Will increasing this value solve the problem ?
Is there any other cause.
Any idea, by which I can solve this issue.

Thanks and Regards
Kiran

Laurenz Albe
2006-01-23 15:35:02 UTC
Permalink
Post by k***@gmail.com
This mail function is a small part of an application which I have
developed.
The application changes password of the user in some domain and sends
email to the email id to inform the changed password.
This mail function is executed for every user. When I execute this for
about 15 users, 12-13 emails are sent and some 2-3 emails are not sent
When I reboot the system, an run the code, then all the emails are
recieved successfully.
After 4-5 runs of my code again the missing email problem arises.
I put some logs and found out that the system command was returning
32512.
The mailx command in the system command was not invoked.
So there is no issue in mailx command. The issue is some memory
problem.
So I just pasted the code, for you to identify the issue.
Do you think, dynamic memory allocation ( malloc ) should be changed by
static memory allocation.?
I cannot 'identify the issue', you have to do that yourself.

I have no access to your machine.

Your code LOOKS alright.

In message <***@proxy.dienste.wien.at> I gave you hints how
to use some printfs to shed light on the problem.
Why don't you try it?

Yours,
Laurenz Albe
Jeff Herrick
2006-01-20 17:08:32 UTC
Permalink
Post by k***@gmail.com
Hi Dan,
################################################################
length = strlen(to) + strlen(from) + strlen(replyto) + strlen(cc) +
strlen(subject);
mailcommand = (char*)malloc(length + 128);
strcpy(mailcommand,"mailx -s \'");
strcat(mailcommand,subject);
strcat(mailcommand,"\' ");
strcat(mailcommand,"-c \"");
strcat(mailcommand,cc);
strcat(mailcommand,"\" ");
strcat(mailcommand,"-r \"");
strcat(mailcommand,replyto);
strcat(mailcommand,"\" ");
strcat(mailcommand,"\"");
strcat(mailcommand,to);
strcat(mailcommand,"\"");
strcat(mailcommand," ");
strcat(mailcommand,"< ");
strcat(mailcommand,tmpfilename);
strcat(mailcommand,"\n");
system(mailcommand);
free(mailcommand);
Not sure of leakage but you could eliminate the overhead of 15 strcat()
calls with one call to sprintf() =8-)

Also, you don't add the length of your tempfilename to the command
buffer length....I guess that's what the extra 128 bytes is for?

How do you arrive at the 32512 value if you're not saving the
system() function's return value?

Cheers

JH
Loading...