General
cancel
Showing results for 
Search instead for 
Did you mean: 

Core file (segmentation fault) strings help

John Love_3
Regular Advisor

Core file (segmentation fault) strings help

I'm trying to figure out what the problem is with a program that I've compiled.
It works on HP-UX and on MPE/IX but I can't get it to run on Linux.
I'll attach the core file (if I can).
Any help would be greatly appreciated.

John
11 REPLIES
Alex Glennie
Honored Contributor

Re: Core file (segmentation fault) strings help

I don't think the core has attached and I'm pretty sure there's a limit on this web site too so I'd suggest it won't be worth trying again.

Qus. What's the program do, written in, O/S's involved ? Source code eg ?

try a "file core" or try using one of the debuggers in /opt/langtools/bin : dde,gdb or wdb ?

You may also find the following URL useful :

http://devresource.hp.com/
John Love_3
Regular Advisor

Re: Core file (segmentation fault) strings help

It's a C program written to simulate airline reservation bookings so we can get a benchmark on the Transactions Per Second.
So basically a benchmark app. It opens TCP sockets, makes a random booking on a random date, random to and from destinations, etc.

So, compiled on Linux to connect to the 3000. He did have a lot of compile errors, but has fixed them so it compiles with no errors.

What is a Segmentation Fault? Is it any clue as to the problem?

Thanks again. I can probably send you the .c file (code) if you think you can help.

John
Eric Ladner
Trusted Contributor

Re: Core file (segmentation fault) strings help

A segmentation fault usually means that the running program attempted to do something with a pointer that was not properly initialized.

This can happen for a lot of reasons.

The easiest way to find out where the seg fault came from is load your core file in gdb and do a backtrace. That will show you where in the call stack the program died (provided the program was compiled with the -g option).

Several of the routine names should be recognizable to you and you should be able to narrow it down to the line of code that dies.
John Love_3
Regular Advisor

Re: Core file (segmentation fault) strings help

Eric,
The problem seems to occur on Socket Receives.
Is there something about sockets that's different on Linux vs. HP-UX?

Thanks,

John
Eric Ladner
Trusted Contributor

Re: Core file (segmentation fault) strings help

Are there any flags on the recv() call? (you are using recv, right?)

I see there are some flags not in common between Linux and HP.

Also, note that the recv will fail if the connect prior to the first recv failed (i.e. trying to recv from a null socket). Error checking might be in order, but that only pushes up your problem to the socket connection itself.
John Love_3
Regular Advisor

Re: Core file (segmentation fault) strings help

Eric,
Have a look at the code see if you see anything.

int connect_socket()
{
int addrlen = 0;

struct sockaddr_in serveraddr;

if ((fSock=socket(AF_INET,SOCK_STREAM,0)) < 0) {
perror("Client Socket call Error(1)");
printf("Client Socket call Error(1)[%d]\n", sys_pin);
return -1;
}

serveraddr.sin_addr.s_addr = inet_addr(SERV_HOST_ADDR);
serveraddr.sin_port = htons(SERV_TCP_PORT);
serveraddr.sin_family = AF_INET;

addrlen=sizeof(struct sockaddr_in);

if (connect(fSock, (struct sockaddr *) &serveraddr, addrlen) < 0) {
perror("Client Connect call Error(2)");
printf("Client Connect call Error(2)[%d]\n", sys_pin);
return -1;
}

return 0;
}


int recv_it(char *spStatInfo,char *spStatSub)
{
char id[3] = " ";
char code[3] = " ";

struct timeval timeout;

int retval = 0;
int data_len = 0;
int total = 0;
int len = 0;
int hsize = 8;
int period = 180;
int iStatus = 0;

fd_set readmask;

FD_ZERO(&readmask);
FD_SET(fSock,&readmask);
timeout.tv_sec = period;
timeout.tv_usec = 0;

retval = select(fSock + 1, (fd_set *) &readmask, NULL, NULL, &timeout);
if (retval < 0) {
iStatus = ERRORSELECT;
printf("Socket select error(1).[%d]\n", sys_pin);
return iStatus;
}
else if (retval == 0) {
iStatus = TIMEDOUT;
printf("Socket TimeOut/Error(1).[%d]\n", sys_pin);
return iStatus;
}
else if (!FD_ISSET(fSock, &readmask)) {
iStatus = ERRORSOCKSELECT;
printf("Socket ErrorSelect(1).[%d]\n", sys_pin);
return iStatus;
}

len = recv(fSock, (char *) &osreturn, hsize, 0);
if (len < hsize) {
iStatus = ERRORRECV;
printf("Socket Receive/Error(1).[%d]\n", sys_pin);
return iStatus;
}

data_len = osreturn.mh.iHeaderLen - hsize;
memset(osreturn.md.data,32,strlen(osreturn.md.data));

while (total < data_len) {
FD_ZERO(&readmask);
FD_SET(fSock, &readmask);
timeout.tv_sec = period;
timeout.tv_usec = 0;
retval = select(fSock + 1, (fd_set *) &readmask, NULL, NULL, &timeout);
if (retval < 0) {
iStatus = ERRORSELECT;
printf("Socket ErrorSelect(2).[%d]\n", sys_pin);
break;
}
else if (retval == 0) {
iStatus = TIMEDOUT;
printf("Socket TimeOut/Error(2).[%d]\n", sys_pin);
break;
}
else if (!FD_ISSET(fSock, &readmask)) {
iStatus = ERRORSOCKSELECT;
printf("Socket ErrorSockSelect(2).[%d]\n", sys_pin);
break;
}

len = recv(fSock, (char *) &osreturn+hsize+total, sizeof(osreturn), 0);
if (len <= 0) {
iStatus = ERRORRECV;
printf("Socket Receive/Error(2).[%d]\n", sys_pin);
break;
}

total += len;
}

if(iStatus != 0) return iStatus;

process_transaction(code);

return iStatus;
}
Eric Ladner
Trusted Contributor

Re: Core file (segmentation fault) strings help

Put a printf right before the recv to make sure that the fSock and &osreturn is non null. The only thing I can see here that could be a problem would be if osreturn is invalid or is defined to be smaller than hsize.
John Love_3
Regular Advisor

Re: Core file (segmentation fault) strings help

Eric,
First of all a HUGE THANKS FOR YOUR HELP.

it looks like 'iHeaderLen' is getting trashed somehow ... ask if they see anything wrong with the way i have my structures..


typedef struct {
char pacRecipient[4];
int iHeaderLen;
char module_id[2];
char trans_code[2];
char more_flag[1];
char statinfo[4];
char subsys[4];
char version[3];
char tell_flag[1];
char filler[3];
} OSMSGHDR;

typedef union { /* send/reveive buffers to orsrvr */
char data[DATA_SIZE];

struct { /* Error */
char statinfo[4];
char subsys[4];
char textlen[4];
char error_text[80];
char last[1];
} error;

struct { /* Login */
char airline_code[4];
char user_name[8];
char term_id[50];
char temp_login_flag[1];
char new_pass_flag[1];
char new_pass[8];
char password[8];
char server_id[8];
char logon_date[8];
char logon_time[4];
char user_group[8];
char group_desc[40];
char res_prop[20];
char res_max_pax[3];
char res1_prop[20];
char last[1];
} login;

/*others .... removed for example */

} OSMSGDATA;

typedef struct {
OSMSGHDR mh;
OSMSGDATA md;
} OSMSGBUFF;

OSMSGBUFF osbuff;
OSMSGBUFF osreturn;
Eric Ladner
Trusted Contributor

Re: Core file (segmentation fault) strings help

Structures look fine.

It may be an application issue of where the incoming data is transfered to the user defined structures.
John Love_3
Regular Advisor

Re: Core file (segmentation fault) strings help

Any other suggestions at all?

Thanks!
John Love_3
Regular Advisor

Re: Core file (segmentation fault) strings help

Well, I compiled with gcc rather than cc and it works better, although there are still some errors, there is no seg. fault or core dump.

Thanks everybody!

John