UNIX commands in C

Ian Collier imc at prg.ox.ac.uk
Sat May 4 21:34:38 AEST 1991


In article <REARL.91May1113957 at nutrimat.gnu.ai.mit.edu>, rearl at gnu.ai.mit.edu (Robert Earl) wrote:
>In article <24527 at well.sf.ca.us> ron at well.sf.ca.us (Ronald Hayden) writes:
>|   #include <stdio.h>
>|
>|   main ()
>|   {
>|    printf("\nTesting the UNIX 'who' command --\n");
>|    system("who");
>|    printf("\nDone.\n");
>|    exit(1);
>|   }

>Since system() [and popen()] does an implicit fork, it's good practice
>to explicitly flush output buffers before you call this routine;

[etc]

Also, that should really be "/bin/who" rather than just "who", unless
you are going to set the path explicitly in the program. Otherwise the
program could break on someone else's machine if they do not have /bin
in their path (unlikely) or if some other random program called "who"
appears before /bin/who in the path. If you do this in an suid program
be absolutely certain to specify the path, or else this creates a
security loophole.

Ian Collier
Ian.Collier at prg.ox.ac.uk | imc at ecs.ox.ac.uk



More information about the Comp.unix.questions mailing list