Inexplicable system call failure! HELP-Expert Needed 
Author Message
 Inexplicable system call failure! HELP-Expert Needed

Howdy folks,

I'm working on a sun solaris machine here at school working on my big
fourth-year comp-sci project in c, and I've just come across possibly
the most confusing and inexplicable behavior I've ever seen.  I've
managed to narrow down the problem to what appears to be the
following:

I have a call to fscanf, and later a system call is made.  For some
reason the system call is not executed.  HOWEVER, if I comment out the
fscanf call, then the system call is executed COMPLETELY NORMALLY.
WHY?  argh.  My narrowed down program I've written for the purose of
this posting exhibits exactly this behavior:

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

int main(){
  char *s;
  FILE *in = fopen("good.txt", "r");
  fscanf(in, "%s", s);
  system("echo hello");

Quote:
}

That's it, and if I compile this by typing "gcc -o out stuff.c" at the
command line, and then I run the out executable, there will be no
hello echo'd to the terminal, however, if I were to comment out the
fscanf, the hello would be echo'd as would be expected.

Here's some details that might be useful I guess:  I'm using the gcc
v2.95.3 compiler on our Sparc Sun-Solaris 5.6 OS.  My name is Erik,
and I'm at a complete and utter loss.  If you have any suggestions on
other places I might post this cry for help, or on an explanation of
what is going on, or more importantly, how to fix or avert this
problem (other than just not using one of the calls) it would be
greatly appreciated.



Wed, 27 Jul 2005 06:33:54 GMT  
 Inexplicable system call failure! HELP-Expert Needed


Quote:
> Howdy folks,

> I'm working on a sun solaris machine here at school working on my big
> fourth-year comp-sci project in c, and I've just come across possibly
> the most confusing and inexplicable behavior I've ever seen.  I've
> managed to narrow down the problem to what appears to be the
> following:

> I have a call to fscanf, and later a system call is made.  For some
> reason the system call is not executed.  HOWEVER, if I comment out the
> fscanf call, then the system call is executed COMPLETELY NORMALLY.
> WHY?  argh.  My narrowed down program I've written for the purose of
> this posting exhibits exactly this behavior:

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

> int main(){
>   char *s; <---- This points to garbage.
>   FILE *in = fopen("good.txt", "r");
>   fscanf(in, "%s", s); <----- Now you write to that garbage addr.
>   system("echo hello");

    return 0;

Quote:
> }

Suggest you try malloc().


Wed, 27 Jul 2005 06:35:35 GMT  
 Inexplicable system call failure! HELP-Expert Needed

Quote:

> int main(){
>   char *s;
>   FILE *in = fopen("good.txt", "r");
>   fscanf(in, "%s", s);
>   system("echo hello");
> }

(snip)

Besides the problem which Mark pointed out, you should check that fopen
doesn't return NULL.

-Tim Miller



Wed, 27 Jul 2005 07:48:21 GMT  
 Inexplicable system call failure! HELP-Expert Needed

Quote:


> > I'm working on a sun solaris machine here at school working on
> > my big fourth-year comp-sci project in c, and I've just come
> > across possibly the most confusing and inexplicable behavior
> > I've ever seen.  I've managed to narrow down the problem to
> > what appears to be the following:

> > I have a call to fscanf, and later a system call is made.  For
> > some reason the system call is not executed.  HOWEVER, if I
> > comment out the fscanf call, then the system call is executed
> > COMPLETELY NORMALLY. WHY?  argh.  My narrowed down program
> > I've written for the purose of this posting exhibits exactly
> > this behavior:

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

> > int main(){
> >   char *s; <---- This points to garbage.
> >   FILE *in = fopen("good.txt", "r");
> >   fscanf(in, "%s", s); <----- Now you write to that garbage addr.
> >   system("echo hello");

>     return 0;
> > }

> Suggest you try malloc().

Besides Marks comments above, you never test that the fopen
succeeded, and never limit the size of string read in.  All of
which are no-nos.

--

   Available for consulting/temporary embedded and systems.
   <http://cbfalconer.home.att.net>  USE worldnet address!



Wed, 27 Jul 2005 09:19:46 GMT  
 Inexplicable system call failure! HELP-Expert Needed

Quote:
> I'm working on a sun solaris machine here at school working on my big
> fourth-year comp-sci project in c, and I've just come across possibly

4th year? You must be kidding...

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

> int main(){
>   char *s;
>   FILE *in = fopen("good.txt", "r");
>   fscanf(in, "%s", s);
>   system("echo hello");
> }

 Compiling ..\MAIN.C:
 Warning ..\MAIN.C 8: Possible use of 's' before definition
 Warning ..\MAIN.C 10: Function should return a value
 Linking EXE\PROJ.EXE:

... if not, you, or your teacher desserves tar and feathers...

Quote:
> That's it, and if I compile this by typing "gcc -o out stuff.c" at the

Next time add -W -Wall -ansi -pedantic -O3

Quote:
> command line, and then I run the out executable, there will be no
> hello echo'd to the terminal, however, if I were to comment out the
> fscanf, the hello would be echo'd as would be expected.

Please stop invoking undefined behaviours and give peace a chance...

--
-ed- emdel at noos.fr ~]=[o
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
C-library: http://www.dinkumware.com/manuals/reader.aspx
"Give peace a chance!"



Wed, 27 Jul 2005 17:18:54 GMT  
 Inexplicable system call failure! HELP-Expert Needed

Quote:
> 4th year? You must be kidding...

> ... if not, you, or your teacher desserves tar and feathers...

> Please stop invoking undefined behaviours and give peace a chance...

For those of you unaware of what being an ass is, read above.  Classic
"lower others to your level so you feel better about yourself"
behavior.  I'm sorry that I'm not everything you think of yourself to
be and more.  For the record the only thing your comments did was{*filter*}
me off.

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

> > int main(){
> >   char *s;
> >   FILE *in = fopen("good.txt", "r");
> >   fscanf(in, "%s", s);
> >   system("echo hello");
> > }

You know, if you're going to be a complete{*filter*} and tear me apart on
the way I coded and compiled a simplified 5-line program that was
intented to isolate and and identify a problem I was having, then just
don't answer at all.  The world could use a more people who are
actually capable of putting thought into what they choose to
communicate.


Thu, 28 Jul 2005 05:27:50 GMT  
 Inexplicable system call failure! HELP-Expert Needed

Quote:
>> 4th year? You must be kidding...

>> ... if not, you, or your teacher desserves tar and feathers...

>> Please stop invoking undefined behaviours and give peace a chance...
> For those of you unaware of what being an ass is, read above.  Classic
> "lower others to your level so you feel better about yourself"
> behavior.  I'm sorry that I'm not everything you think of yourself to
> be and more.  For the record the only thing your comments did was{*filter*}
> me off.

For those of you unaware of what not tolerating criticism is, read
above. I'm sorry that we're not your personal nannies here, and I'm
also sorry you're not God's gift to C programming.
I've seen far too many newbies who take extreme offense when told
that their C code is of poor quality. But if we didn't tell them that,
how could they ever learn C?

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

>> > int main(){
>> >   char *s;
>> >   FILE *in = fopen("good.txt", "r");
>> >   fscanf(in, "%s", s);
>> >   system("echo hello");
>> > }
> You know, if you're going to be a complete{*filter*} and tear me apart on
> the way I coded and compiled a simplified 5-line program that was
> intented to isolate and and identify a problem I was having, then just
> don't answer at all.  The world could use a more people who are
> actually capable of putting thought into what they choose to
> communicate.

Your code above demonstrates an error so fundamental that it can't
help but attract replies such as Emmanuel's above. If you don't
understand how pointers work, you're really in no position to be
rude to Emmanuel.

--

| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.*-*-*.com/ ~palaste       W++ B OP+                     |
\----------------------------------------- Finland rules! ------------/



Thu, 28 Jul 2005 05:56:24 GMT  
 Inexplicable system call failure! HELP-Expert Needed

Quote:
> > That's it, and if I compile this by typing "gcc -o out stuff.c" at the

> Next time add -W -Wall -ansi -pedantic -O3

Aside from my other comments, I thought you might be interested to
know what man pages for gcc say about pedantic:

-pedantic
  Valid ANSI standard C programs should compile  properly
  with or without this option (though a rare few will re-
  quire '-ansi').  However without this option,  certain
  GNU extensions and traditional C features are supported
  as well.  With this option,  they are rejected.  THERE
  IS  NO  REASON  TO  USE THIS OPTION; it exists only to
  satisfay pedants.

Also, -Wall specifically means enable -W as well as 14 other -W*
flags, hence the all portion, so you need not specify -W and -Wall.

And finally, I was writing example code, not a NASA missile
controllers, so the -03 "Optimize yet more" option is totally overkill
in this application.

So next time add -Wall -ansi and that's it!

Quote:
> Please stop invoking undefined behaviours and give peace a chance...

Please stop using unnecessary compiler flags and give simplicity a
chance...


Thu, 28 Jul 2005 07:41:50 GMT  
 Inexplicable system call failure! HELP-Expert Needed

Quote:

> > > That's it, and if I compile this by typing "gcc -o out stuff.c" at the

> > Next time add -W -Wall -ansi -pedantic -O3

> Aside from my other comments, I thought you might be interested to
> know what man pages for gcc say about pedantic:

I think you might be interested to know what the man page for gcc says
in the section `WARNING':

    This man page is not kept up to date except when volunteers want to
    maintain it. If you find a discrepancy between the man page and the
    software, please check the Info file, which is the authoritative
    documentation.

Quote:
> -pedantic
>   Valid ANSI standard C programs should compile  properly
>   with or without this option (though a rare few will re-
>   quire '-ansi').  However without this option,  certain
>   GNU extensions and traditional C features are supported
>   as well.  With this option,  they are rejected.

So what's the problem? The option disables extensions and deprecated
pre-ISO C features, which is exactly what is wanted and *needed* when
compiling ISO C programs.

Quote:
> Also, -Wall specifically means enable -W as well as 14 other -W*
> flags, hence the all portion, so you need not specify -W and -Wall.

No, `-Wall' does *not* imply `-W'. Read the documentation. By
`documentation', I mean the documentation, not the man page.

Quote:
> And finally, I was writing example code, not a NASA missile controllers,
> so the -03 "Optimize yet more" option is totally overkill in this
> application.

Wrong, at least one of the warnings implied by `-Wall' does not work without
optimization. Read the documentation.

Quote:
> So next time add -Wall -ansi and that's it!

Your refusal to include `-W' and optimization is silly, but your refusal to
include `-pedantic' can only be understood as a threat to *deliberately*
post off-topic here. (After all, you have quoted yourself what `-pedantic'
means, and therefore you know that it's *required* to compile ISO C
programs.)

Martin



Thu, 28 Jul 2005 08:22:06 GMT  
 Inexplicable system call failure! HELP-Expert Needed


Quote:
> -pedantic
>   Valid ANSI standard C programs should compile  properly
>   with or without this option (though a rare few will re-
>   quire '-ansi').  However without this option,  certain
>   GNU extensions and traditional C features are supported
>   as well.  With this option,  they are rejected.  THERE
>   IS  NO  REASON  TO  USE THIS OPTION; it exists only to
>   satisfay pedants.

Note: If you want to be notified about using gcc extensions (that
won't be portable) this will actually come in handy and it is
spelled out fairly clearly above.  The man page author apparently
believes that only "pedants" ever need use of a C compiler other
than gcc.

Quote:
> Also, -Wall specifically means enable -W as well as 14 other -W*
> flags, hence the all portion, so you need not specify -W and -Wall.

Interesting, the online gcc docs I just looked at said "The following
-W... options are NOT implied by gcc -Wall ...".  The first one listed
after that paragraph was -W alone.  A google search for "gcc manual"
should be helpful.

Quote:
> And finally, I was writing example code, not a NASA missile
> controllers, so the -03 "Optimize yet more" option is totally overkill
> in this application.

The optimizer allows the compiler to do better analysis and generate
more intelligent warnings in some cases.  This isn't well documented
in the man pages AFAICT, but it is widely known and discussed in this
group often.

Quote:

> So next time add -Wall -ansi and that's it!

That would not necessarily be the optimal solution.  (no pun intended).


Thu, 28 Jul 2005 08:32:00 GMT  
 Inexplicable system call failure! HELP-Expert Needed

Quote:

>> So next time add -Wall -ansi and that's it!

>Your refusal to include `-W' and optimization is silly, but your refusal to
>include `-pedantic' can only be understood as a threat to *deliberately*
>post off-topic here. (After all, you have quoted yourself what `-pedantic'
>means, and therefore you know that it's *required* to compile ISO C
>programs.)

OT regarding -W, it is deliberately separate from -Wall because it includes
warnings that many consider to be pointless and irritating. Although I
usually have -W on because I'm paranoid enough to want to see every
available warning, I don't think it's *ever* caught a bona fide bug in code
that I've worked with. That's not to say it won't ever do so, but so far, it
hasn't paid off. :)

-- Mat.



Thu, 28 Jul 2005 09:21:18 GMT  
 Inexplicable system call failure! HELP-Expert Needed

Quote:


> >> 4th year? You must be kidding...

> >> ... if not, you, or your teacher desserves tar and feathers...

> > For those of you unaware of what being an ass is, read above.
> > Classic "lower others to your level so you feel better about
> > yourself" behavior.  I'm sorry that I'm not everything you
> > think of yourself to be and more.  For the record the only
> > thing your comments did was{*filter*}me off.

> For those of you unaware of what not tolerating criticism is,
> read above. I'm sorry that we're not your personal nannies here,
> and I'm also sorry you're not God's gift to C programming.
> I've seen far too many newbies who take extreme offense when
> told that their C code is of poor quality. But if we didn't tell
> them that, how could they ever learn C?

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

> >> > int main(){
> >> >   char *s;
> >> >   FILE *in = fopen("good.txt", "r");
> >> >   fscanf(in, "%s", s);
> >> >   system("echo hello");
> >> > }

> > You know, if you're going to be a complete{*filter*} and tear me
> > apart on the way I coded and compiled a simplified 5-line
> > program that was intented to isolate and and identify a
> > problem I was having, then just don't answer at all.  The
> > world could use a more people who are actually capable of
> > putting thought into what they choose to communicate.

> Your code above demonstrates an error so fundamental that it
> can't help but attract replies such as Emmanuel's above. If you
> don't understand how pointers work, you're really in no position
> to be rude to Emmanuel.

Not only is he rude and contentious, he has also started this same
thread on at least two other groups by multi-posting, with not
even the courtesy of cross-posting.  I think he should 'fixx' his
attitude, and do some reading on basic netiquette.  He is well on
the way to early PLONKhood.

--

   Available for consulting/temporary embedded and systems.
   < http://www.*-*-*.com/ >  USE worldnet address!



Thu, 28 Jul 2005 09:57:54 GMT  
 Inexplicable system call failure! HELP-Expert Needed

Quote:



>>> So next time add -Wall -ansi and that's it!

>>Your refusal to include `-W' and optimization is silly, but your refusal to
>>include `-pedantic' can only be understood as a threat to *deliberately*
>>post off-topic here. (After all, you have quoted yourself what `-pedantic'
>>means, and therefore you know that it's *required* to compile ISO C
>>programs.)

> OT regarding -W, it is deliberately separate from -Wall because it includes
> warnings that many consider to be pointless and irritating. Although I
> usually have -W on because I'm paranoid enough to want to see every
> available warning, I don't think it's *ever* caught a bona fide bug in code
> that I've worked with. That's not to say it won't ever do so, but so far, it
> hasn't paid off. :)

One warning in particular shits me to tears about -W, which is the
warning about unused parameters.  It often happens that I have callback
function where several of the extra parameters aren't always required.
So, I don't use -W anymore.

        - Kevin.



Thu, 28 Jul 2005 19:08:40 GMT  
 Inexplicable system call failure! HELP-Expert Needed

Quote:
> One warning in particular shits me to tears about -W, which is the
> warning about unused parameters.  It often happens that I have callback
> function where several of the extra parameters aren't always required.
> So, I don't use -W anymore.

IMO, you are wrong. Unfortunately, the C language doesn't support 'optionnal
parameters', and we must deal with it.

The usual trick is to mute the compiler is to add

   (void) <not used parameter>;

in the function.

int f (int a, char *b)
{
   puts ("f() is under construction");

   (void) a;
   (void) b;

   return 0;

Quote:
}

--
-ed- emdel at noos.fr ~]=[o
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
C-library: http://www.dinkumware.com/manuals/reader.aspx
"Give peace a chance!"


Thu, 28 Jul 2005 19:30:19 GMT  
 Inexplicable system call failure! HELP-Expert Needed

Quote:

>> One warning in particular shits me to tears about -W, which is the
>> warning about unused parameters.  It often happens that I have callback
>> function where several of the extra parameters aren't always required.
>> So, I don't use -W anymore.

>IMO, you are wrong. Unfortunately, the C language doesn't support 'optionnal
>parameters', and we must deal with it.

>The usual trick is to mute the compiler is to add

>   (void) <not used parameter>;

>in the function.

Or you could override -W with -Wno-unused-parameter.

  C:\>type unused.c
  void func(int unused) {}

  C:\>gcc -W -Wall -ansi -pedantic -O unused.c -c
  unused.c: In function `func':
  unused.c:1: warning: unused parameter `unused'

  C:\>gcc -W -Wno-unused-parameter -Wall -ansi -pedantic -O unused.c -c

  C:\>

gcc also provides __attribute__((unused)) to kill the warning for specific
variables, but I prefer the (void)param way because most compilers recognise
the idiom, and on those that don't it's a harmless no-op.

-- Mat.



Thu, 28 Jul 2005 20:26:35 GMT  
 
 [ 25 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Inexplicable System call failure - HELP - expert needed

2. Failure of popen and system calls ......

3. URGENT : Help needed with system()/fork() call

4. system call in Sun OS - need help

5. Help with system calls needed

6. Experts: Help!!! SYSTEM command and grabbing STDOUT

7. HELP:perform system call or call an external program

8. Compile Error=> Need help from expert

9. Needed help from Expert to slove my error

10. Recursive experts -- I need help!

11. RS232 Expert help needed

12. Newbie Need Helps from you C expert !!!

 

 
Powered by phpBB® Forum Software