Re: Changing argv[0] under Linux.

From: Bill Davidsen (
Date: Tue Jan 21 2003 - 09:16:21 EST

On Tue, 14 Jan 2003, DervishD wrote:

> > > libc, but I think that is more on the kernel side, that's why I ask
> > Last time I checked argv[0] was 512 bytes. Many daemons overwrite
> > it with no problem.
> Any header where I can see the length for argv[0] or is this some
> kind of unoficial standard? Just doing strcpy seems dangerous to me
> (you can read 'paranoid'...).

The method used in INN is to make arg 1 some space. So
  nnrpd -s' ' -D ...
You can check that argv[1] is -s, and what its length is, then happily
write over argv[0]. That's portable in practical terms, since most C
implementations just have the variable length args in sequence, while a
few have a fixed length array for args. You're safe in either case.

  if (strncmp(argv[1], "-s", 2) && strlen(argv[1]) > REPLACELEN) {
    sprintf(argv[0], "format", atuff...);

Some systems have setproctitle() but it doesn't appear to be posix.

bill davidsen <>
  CTO, TMR Associates, Inc
Doing interesting things with little computers since 1979.

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to More majordomo info at Please read the FAQ at

This archive was generated by hypermail 2b29 : Thu Jan 23 2003 - 22:00:26 EST