linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: David Howells <dhowells@redhat.com>
Cc: linux-xfs@vger.kernel.org, hch@infradead.org, amir73il@gmail.com,
	david@fromorbit.com, fstests@vger.kernel.org,
	linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH 1/4] xfstests: Add an auxiliary program to create an AF_UNIX socket [ver #3]
Date: Mon, 3 Apr 2017 09:59:06 -0700	[thread overview]
Message-ID: <20170403165906.GF10881@birch.djwong.org> (raw)
In-Reply-To: <149122078093.24821.17192375733082382807.stgit@warthog.procyon.org.uk>

On Mon, Apr 03, 2017 at 12:59:40PM +0100, David Howells wrote:
> Add an auxiliary program to create an AF_UNIX socket at the specified
> location so that tests can do things with it.
> 
> Signed-off-by: David Howells <dhowells@redhat.com>
> ---
> 
>  .gitignore    |    1 +
>  src/Makefile  |    2 +-
>  src/af_unix.c |   66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 68 insertions(+), 1 deletion(-)
>  create mode 100644 src/af_unix.c
> 
> diff --git a/.gitignore b/.gitignore
> index 1ed2a92..8a7c052 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -35,6 +35,7 @@
>  /ltp/iogen
>  
>  # src/ binaries
> +/src/af_unix
>  /src/alloc
>  /src/append_reader
>  /src/append_writer
> diff --git a/src/Makefile b/src/Makefile
> index a7f27f0..716c178 100644
> --- a/src/Makefile
> +++ b/src/Makefile
> @@ -12,7 +12,7 @@ TARGETS = dirstress fill fill2 getpagesize holes lstat64 \
>  	godown resvtest writemod makeextents itrash rename \
>  	multi_open_unlink dmiperf unwritten_sync genhashnames t_holes \
>  	t_mmap_writev t_truncate_cmtime dirhash_collide t_rename_overwrite \
> -	holetest t_truncate_self t_mmap_dio
> +	holetest t_truncate_self t_mmap_dio af_unix
>  
>  LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \
>  	preallo_rw_pattern_writer ftrunc trunc fs_perms testx looptest \
> diff --git a/src/af_unix.c b/src/af_unix.c
> new file mode 100644
> index 0000000..dc2368e
> --- /dev/null
> +++ b/src/af_unix.c
> @@ -0,0 +1,66 @@
> +/* Create an AF_UNIX socket.
> + *
> + * Copyright (C) 2017 Red Hat, Inc. All Rights Reserved.
> + * Written by David Howells (dhowells@redhat.com)
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public Licence
> + * as published by the Free Software Foundation; either version
> + * 2 of the Licence, or (at your option) any later version.
> + */
> +
> +#include <stdarg.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <stdbool.h>
> +#include <string.h>
> +#include <unistd.h>
> +#include <errno.h>
> +#include <fcntl.h>
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +#include <sys/socket.h>
> +#include <sys/un.h>
> +
> +#define offsetof(TYPE, MEMBER)	((size_t)&((TYPE *)0)->MEMBER)
> +
> +int main(int argc, char *argv[])
> +{
> +	struct sockaddr_un sun;
> +	struct stat st;
> +	size_t len, max;
> +	int fd;
> +
> +	if (argc != 2) {
> +		fprintf(stderr, "Format: %s <socketpath>\n", argv[0]);
> +		exit(2);
> +	}
> +
> +	max = sizeof(sun.sun_path);
> +	len = strlen(argv[1]);
> +	if (len >= max) {
> +		fprintf(stderr, "Filename too long (max %zu)\n", max);
> +		exit(2);
> +	}
> +
> +	fd = socket(AF_UNIX, SOCK_DGRAM, 0);
> +	if (fd < 0) {
> +		perror("socket");
> +		exit(1);
> +	}
> +
> +	memset(&sun, 0, sizeof(sun));
> +	sun.sun_family = AF_UNIX;
> +	strcpy(sun.sun_path, argv[1]);
> +	if (bind(fd, (struct sockaddr *)&sun, sizeof(sun)) == -1) {
> +		perror("bind");
> +		exit(1);
> +	}
> +
> +	if (stat(argv[1], &st)) {
> +		fprintf(stderr, "Couldn't stat socket after creation: %m\n");
> +		exit(1);
> +	}

Looks ok,
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>

--D

> +
> +	exit(0);
> +}
> 
> --
> To unsubscribe from this list: send the line "unsubscribe fstests" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

      parent reply	other threads:[~2017-04-03 16:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-03 11:59 [PATCH 1/4] xfstests: Add an auxiliary program to create an AF_UNIX socket [ver #3] David Howells
2017-04-03 11:59 ` [PATCH 2/4] xfstests: Add first statx test " David Howells
2017-04-03 12:00 ` [PATCH 3/4] xfstests: Partially expand the documentation " David Howells
2017-04-03 16:41   ` Darrick J. Wong
2017-04-03 12:00 ` [PATCH 4/4] xfstests: Check the stx_attributes settable by chattr " David Howells
2017-04-03 16:39   ` Darrick J. Wong
2017-04-03 21:05   ` David Howells
2017-04-03 21:17   ` David Howells
2017-04-04  6:28     ` Amir Goldstein
2017-04-03 16:59 ` Darrick J. Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170403165906.GF10881@birch.djwong.org \
    --to=darrick.wong@oracle.com \
    --cc=amir73il@gmail.com \
    --cc=david@fromorbit.com \
    --cc=dhowells@redhat.com \
    --cc=fstests@vger.kernel.org \
    --cc=hch@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).