Final Suggestion (Re: suggested bsd-setproctitle.c)

Kevin Steves stevesk at sweden.hp.com
Wed Nov 8 20:51:16 EST 2000


On Tue, 7 Nov 2000, Ben Lindstrom wrote:
: May I suggest the attached patch.  Since It's been compiled against NeXT
: it pretty much ensure that all __progname is setup right (since NeXT
: supports it).
: 
: I would perfer using basename() over strrchar() and NULL check.  Even it
: it required me to snag basename() from the OpenBSD tree. (Which I was
: happy to see compiled without any changes!! =)

I was more concerned with cleaning up ifdef bloat vs. fixing the
hardcoded names, but I agree it makes sense to fix that as well.

I don't see a need to necessarily malloc new space for a copy.
i386/crt0.c does this:

	if ((ap = argv[0]))
		if ((__progname = _strrchr(ap, '/')) == NULL)
			__progname = ap;
		else
			++__progname;

If you look at Kerberos or afs warnerr.c you see:

#ifndef HAVE___PROGNAME
const char *__progname;
#endif

void
set_progname(char *argv0)
{
#ifndef HAVE___PROGNAME
    char *p;
    if(argv0 == NULL)
	return;
    p = strrchr(argv0, '/');
    if(p == NULL)
	p = argv0;
    else
	p++;
    __progname = p;
#endif
}

I'd prefer adding a set_progname() modified to return progname, and
using it vs. importing bsd-basename and mallocing space.

So in main() we'd have:

__progname = set_progname(argv[0]);






More information about the openssh-unix-dev mailing list