fgets crashes in coreos machine

14 views
Skip to first unread message

Simran Bindra

unread,
Nov 16, 2018, 1:19:17 AM11/16/18
to CoreOS Dev
I have this C code snippet which runs on a coreOS machine:

-----------------------------------------------------------------------------
char db[512];
snprintf(db, 512, "%s %s", <some command>, <args of the command>);
FILE* pipe = popen(db, "r");

if (!pipe) {
return NULL;
}

char buf[256];
while (fgets(buf, sizeof(buf), pipe) != NULL) {
<DEBUG POINT 1>
<some code utilising buf>
}
<DEBUG POINT 2>

-----------------------------------------------------------------------------

Now the command that is being executed and which is streaming to the Pipe in eventually calling a python code which returns None(Null) with the given argument.
The problem that I'm facing is that fgets is not able to handle the response and the program crashes when it tries to execute fgets() on the Pipe. What I mean is that on reaching while(), my program exits and is not able to reach either DEBUG POINT 1 or 2. I have tried searching for possible solutions but am not able to find anything.
Another interesting thing is when I run the same code on a Amazon Linux Machine, it works fine and I get the desired behaviour.

Can someone please guide me in the right direction.

David Michael

unread,
Nov 16, 2018, 8:04:05 AM11/16/18
to coreo...@googlegroups.com, coreo...@googlegroups.com
On Fri, Nov 16, 2018 at 1:19 AM Simran Bindra <saloni...@gmail.com> wrote:
>
> I have this C code snippet which runs on a coreOS machine:
>
> -----------------------------------------------------------------------------
> char db[512];
> snprintf(db, 512, "%s %s", <some command>, <args of the command>);
> FILE* pipe = popen(db, "r");
>
> if (!pipe) {
> return NULL;
> }
>
> char buf[256];
> while (fgets(buf, sizeof(buf), pipe) != NULL) {
> <DEBUG POINT 1>
> <some code utilising buf>
> }
> <DEBUG POINT 2>
>
> -----------------------------------------------------------------------------
>
> Now the command that is being executed and which is streaming to the Pipe in eventually calling a python code which returns None(Null) with the given argument.

Container Linux does not have Python.

> The problem that I'm facing is that fgets is not able to handle the response and the program crashes when it tries to execute fgets() on the Pipe. What I mean is that on reaching while(), my program exits and is not able to reach either DEBUG POINT 1 or 2. I have tried searching for possible solutions but am not able to find anything.
> Another interesting thing is when I run the same code on a Amazon Linux Machine, it works fine and I get the desired behaviour.

What version are you using? Both popen() and fgets() seem to work
fine for me on current alpha.

Are you able to run it through GDB and get a backtrace of the crash
with the developer container? Does it make a difference when you
statically link the binary with the libc on your build system?

Thanks.

David
Reply all
Reply to author
Forward
0 new messages