different behaviour on fbsd and linux

Erik Trulsson ertr1013 at student.uu.se
Sun Feb 19 03:30:04 PST 2006


On Sun, Feb 19, 2006 at 11:54:38AM +0100, Divacky Roman wrote:
> On Sat, Feb 18, 2006 at 01:43:30PM -0800, John-Mark Gurney wrote:
> > Divacky Roman wrote this message on Sat, Feb 18, 2006 at 18:39 +0100:
> > > On Sat, Feb 18, 2006 at 06:21:52PM +0100, joerg at britannica.bec.de wrote:
> > > > On Sat, Feb 18, 2006 at 06:17:18PM +0100, Divacky Roman wrote:
> > > > >       execl("/bin/ls", NULL);
> > > > 
> > > > This is wrong. You must specify arg0 != NULL (POSIX says so) and you
> > > > must NULL-terminate the *following* list.
> > > > 
> > > > E.g.:
> > > > 	execl("/bin/ls", "/bin/ls", NULL);
> > > > is what you want to do.
> > > 
> > > 
> > > ah.. thnx.. the man page should be updated with "he
> > >      first argument, by convention, should point to the file name associated
> > >           with the file being executed."
> > > 
> > > s/should/must then
> > 
> > Nope.. it need not be the same..  in cases like this:
> > execl("/usr/bin/gzip", "gunzip", NULL);
> > 
> > will give you gunzip behavior because the gzip binary looks at argv[0]
> > and changes it's behavior based upon what it finds..  look at crunchgen
> > for the ability to combine different programs into one binary...
> 
> ok.. but I'd appreciate info that it cannot be NULL ;(

It is in the manpage if you read carefully. execl(8) says:

[...]
     int
     execl(const char *path, const char *arg, ... /*, (char *)0 */);
[...]

     The const char *arg and subsequent ellipses in the execl(), execlp(), and
     execle() functions can be thought of as arg0, arg1, ..., argn.  Together
     they describe a list of one or more pointers to null-terminated strings
     that represent the argument list available to the executed program. The
     first argument, by convention, should point to the file name associated
     with the file being executed.  The list of arguments must be terminated
     by a NULL pointer.
[...]

Note that it says "one or more pointers to null-terminated strings".
NULL is not a pointer to a null-terminated string, which means that you must
have at least one non-NULL pointer before the teminating NULL.







-- 
<Insert your favourite quote here.>
Erik Trulsson
ertr1013 at student.uu.se


More information about the freebsd-hackers mailing list