"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Stefan Sperling <stsp@stsp.name>
Subject:
Re: add gotctl(8)
To:
Omar Polo <op@omarpolo.com>
Cc:
gameoftrees@openbsd.org
Date:
Sat, 29 Oct 2022 21:15:58 +0200

Download raw body.

Thread
On Sat, Oct 29, 2022 at 08:56:34PM +0200, Omar Polo wrote:
> On 2022/10/29 20:49:21 +0200, Omar Polo <op@omarpolo.com> wrote:
> > just a minor nitpick while reading the code: we could save a local
> > variable and some copying by just reusing the same variable.
> 
> ops, actually connect_gotd can save the conditional altogether by
> initializing the string in main().  (disclaimer: only build tested
> ;-)

This works as well. ok.

> diff /home/op/w/got
> commit - b6ef252ebaef7fa8a1bce4d12b51f735fb5e3e3f
> path + /home/op/w/got
> blob - 821e75bd339a40b002fc603fcf67ccd42e2a0578
> file + gotctl/gotctl.c
> --- gotctl/gotctl.c
> +++ gotctl/gotctl.c
> @@ -341,20 +341,10 @@ connect_gotd(const char *socket_path)
>  connect_gotd(const char *socket_path)
>  {
>  	const struct got_error *error = NULL;
> -	char unix_socket_path[PATH_MAX];
>  	int gotd_sock = -1;
>  	struct sockaddr_un sun;
>  
> -	if (socket_path) {
> -		if (strlcpy(unix_socket_path, socket_path,
> -		    sizeof(unix_socket_path)) >= sizeof(unix_socket_path)) 
> -			errx(1, "gotd socket path too long");
> -	} else {
> -		strlcpy(unix_socket_path, GOTD_UNIX_SOCKET,
> -		    sizeof(unix_socket_path));
> -	}
> -
> -	error = apply_unveil(unix_socket_path);
> +	error = apply_unveil(socket_path);
>  	if (error)
>  		errx(1, "%s", error->msg);
>  
> @@ -367,11 +357,11 @@ connect_gotd(const char *socket_path)
>  
>  	memset(&sun, 0, sizeof(sun));
>  	sun.sun_family = AF_UNIX;
> -	if (strlcpy(sun.sun_path, unix_socket_path,
> -	    sizeof(sun.sun_path)) >= sizeof(sun.sun_path))
> +	if (strlcpy(sun.sun_path, socket_path, sizeof(sun.sun_path)) >=
> +	    sizeof(sun.sun_path))
>  		errx(1, "gotd socket path too long");
>  	if (connect(gotd_sock, (struct sockaddr *)&sun, sizeof(sun)) == -1)
> -		err(1, "connect: %s", unix_socket_path);
> +		err(1, "connect: %s", socket_path);
>  
>  #ifndef PROFILE
>  	if (pledge("stdio", NULL) == -1)
> @@ -392,7 +382,7 @@ main(int argc, char *argv[])
>  	    { "version", no_argument, NULL, 'V' },
>  	    { NULL, 0, NULL, 0 }
>  	};
> -	const char *socket_path = NULL;
> +	const char *socket_path = GOTD_UNIX_SOCKET;
>  
>  	setlocale(LC_CTYPE, "");
>  
>