From patchwork Thu Apr 6 07:35:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 9666249 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 62D6B60365 for ; Thu, 6 Apr 2017 07:36:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51ECD27F9F for ; Thu, 6 Apr 2017 07:36:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 43EF427317; Thu, 6 Apr 2017 07:36:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E20D927317 for ; Thu, 6 Apr 2017 07:36:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934017AbdDFHgA (ORCPT ); Thu, 6 Apr 2017 03:36:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:18045 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932371AbdDFHf7 (ORCPT ); Thu, 6 Apr 2017 03:35:59 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AFAF181252; Thu, 6 Apr 2017 07:35:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AFAF181252 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dhowells@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com AFAF181252 Received: from warthog.procyon.org.uk (ovpn-120-211.rdu2.redhat.com [10.10.120.211]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82063A4089; Thu, 6 Apr 2017 07:35:57 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 1/4] xfstests: Add an auxiliary program to create an AF_UNIX socket [ver #9] From: David Howells To: linux-xfs@vger.kernel.org Cc: hch@infradead.org, amir73il@gmail.com, david@fromorbit.com, fstests@vger.kernel.org, dhowells@redhat.com, linux-fsdevel@vger.kernel.org Date: Thu, 06 Apr 2017 08:35:56 +0100 Message-ID: <149146415678.12061.13562442148388464862.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 06 Apr 2017 07:35:58 +0000 (UTC) Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Darrick J. Wong --- .gitignore | 1 + src/Makefile | 2 +- src/af_unix.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 src/af_unix.c -- 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 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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 \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); + } + + exit(0); +}