Skip to contentSkip to conversation

ELDK glibc fcntl(socketFd, F_SETFL, flags) causes Seg Fault

DISCUSSION Daniel Ng 4 participants 5 messages Feb 1, 2007 – Feb 5, 2007

lore
Share & tools
lore

Daniel Ng

author
#0 lore raw

Hi,

My application Seg Faults when I try to set flags for my socket fd.

First, I get the fd by calling socket():
fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);

Then I try getting the fd flags:
fcntl(fd, F_GETFL, flags)

Then I try setting the flags:
flags |= O_NONBLOCK;
fcntl( fd, F_SETFL, flags );

-I get consistent Seg Faults on the last line above.

-I also checked fd, which is a sensible value.
I can even successfully connect() with it.

-The problem happens regardless of what value 'flags' is set to

My embedded target details-

-powerpc8272
-ELDK v4
-the application uses glibc

Any ideas why I'm getting these Seg Faults?

Cheers,
Daniel

#1 lore raw
Quoted 8 lines · In message <[email protected]> you wrote:

My application Seg Faults when I try to set flags for my socket fd.

First, I get the fd by calling socket():
fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);

Then I try getting the fd flags:
fcntl(fd, F_GETFL, flags)

Provide some working / crashing test code, i. e. a complete C program with declarations etc.

Best regards,

Wolfgang Denk

Signature · 5 lines
Software Engineering:  Embedded and Realtime Systems,  Embedded Linux
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: [email protected]
There's an old story about the person who wished his computer were as
easy to use as his telephone. That wish has come  true,  since  I  no
longer know how to use my telephone.
#3 lore raw
In reply to Daniel Ng
Quoted 7 lines · Daniel Ng

Hi,

My application Seg Faults when I try to set flags for my socket fd.

Then I try getting the fd flags:
fcntl(fd, F_GETFL, flags)

Shouldn't it be &flags ??

Signature · 7 lines
Magnus Hjorth, M.Sc.
Omnisys Instruments AB
Gruvgatan 8
SE-421 30  Västra Frölunda, SWEDEN
Phone: +46 31 734 34 09
Fax: +46 31 734 34 29
http://www.omnisys.se 
#4 lore raw

RE: ELDK glibc fcntl(socketFd,F_SETFL, flags) causes Seg Fault

In reply to Daniel Ng
Quoted 2 lines

Then I try getting the fd flags:
fcntl(fd, F_GETFL, flags)

Don't you really need to do this...

flags = fcntl(fd, F_GETFL, 0)

to get the correct initial state of the flags?

Ed Jubenville

author
#2 lore raw
In reply to Wolfgang Denk

Thanks for your help everyone, I figured it out.

The cause of the problem seems to be unrelated to the F_SETFL- it just happened to seg fault at that point all the time.

Cheers,
Daniel