xfuncs, bb_ funcs and "nofork/noexec" plans

Denis Vlasenko vda at ilport.com.ua
Fri Mar 10 09:45:12 UTC 2006


On Friday 10 March 2006 11:18, Denis Vlasenko wrote:
> void bb_lookup_host(struct sockaddr_in *s_in, const char *host)
> {
>         struct hostent *he;
> 
>         memset(s_in, 0, sizeof(struct sockaddr_in));
>         s_in->sin_family = AF_INET;
>         he = xgethostbyname(host);
>         memcpy(&(s_in->sin_addr), he->h_addr_list[0], he->h_length);
> }
> 
> This is a bb_ function, but it calls a xfunc (xgethostbyname) which
> can exit:
> 
> struct hostent *xgethostbyname(const char *name)
> {
>         struct hostent *retval;
> 
>         if ((retval = gethostbyname(name)) == NULL)
>                 bb_herror_msg_and_die("%s", name);
> 
>         return retval;
> }
> 
> How would one know that his program can exit here (taken from ftpgetput.c):
> 
>         server->s_in = &s_in;
>         bb_lookup_host(&s_in, argv[optind]);
>         s_in.sin_port = bb_lookup_port(port, "tcp", 21);
>         if (verbose_flag) {
>                 printf("Connecting to %s[%s]:%d\n",
>                                 argv[optind], inet_ntoa(s_in.sin_addr), ntohs(s_in.sin_port));
>         }
> 
> It's not immediately obvious!
> 
> Will you accept patches which fix such bb_ fuctions? What name would you prefer?
> x_lookup_host? xlookup_host?

Actually, I like more descriptive names like lookup_host_or_die.
We can even have both:

	xlookup_host(&s_in, argv[optind]); //Will die with default error msg

	lookup_host_or_die(&s_in, argv[optind], "\0x3" "Custom error message and exit code");
--
vda



More information about the busybox mailing list