From e247c2bbfe0f5b52ef532cacebcc1ea9dc3bbc76 Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Tue, 19 Nov 2013 14:42:37 +0000 Subject: Added C program which creates named Unix sockets --- yarns/sockbind.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 yarns/sockbind.c diff --git a/yarns/sockbind.c b/yarns/sockbind.c new file mode 100644 index 0000000..8bbcfcf --- /dev/null +++ b/yarns/sockbind.c @@ -0,0 +1,42 @@ +#include +#include +#include +#include +#include +#include + +/* + * There is currently no command within Baserock to create named Unix sockets; + * this program is used to compensate for that. + */ + +int main(int argc, char *argv[]) +{ + int sfd; + struct sockaddr_un sock; + + if (argc != 2) { + fprintf(stderr, "Usage: %s PATH\n", argv[0]); + return EXIT_FAILURE; + } + + if (strlen(argv[1]) >= sizeof(sock.sun_path)) { + fprintf(stderr, "%s: file name too long\n", argv[0]); + return EXIT_FAILURE; + } + + + if ((sfd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { + perror("socket"); + return EXIT_FAILURE; + } + + sock.sun_family = AF_UNIX; + strcpy(sock.sun_path, argv[1]); + if (bind(sfd, (struct sockaddr*)&sock, sizeof(sock)) == -1) { + perror("bind"); + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} -- cgit v1.2.1 From c120ad85905a5e73f995cac9a51b7556ed82b52c Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Tue, 19 Nov 2013 14:43:59 +0000 Subject: Add socket creation program to Makefile --- Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index d0b5fb3..746bd9c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -35,5 +35,6 @@ dist-hook: ChangeLog TESTS = yarns/run_yarns.sh -noinst_PROGRAMS = symtime +noinst_PROGRAMS = symtime sockbind symtime_SOURCES = yarns/symtime.c +sockbind_SOURCES = yarns/sockbind.c -- cgit v1.2.1 From 149de8fcb40dc355e0a81ae8e17c4a43b614d8d7 Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Tue, 19 Nov 2013 14:51:20 +0000 Subject: Socket scenarios added --- yarns/create-deploy.yarn | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/yarns/create-deploy.yarn b/yarns/create-deploy.yarn index 02106ad..f63c6ef 100644 --- a/yarns/create-deploy.yarn +++ b/yarns/create-deploy.yarn @@ -303,6 +303,36 @@ are appropriately changed when a patch has been generated and deployed. AND tbdiff-deploy applies the delta 'AB.tbdiff' to 'A_dir' THEN the block devices 'A_dir/foo_blockdev' and 'B_dir/foo_blockdev' have the same device numbers +Changing, adding and removing of sockets +---------------------------------------- + +Sockets can only be moved, linked or removed by the file system, creation is +only performed by the program that acts as the server, tbdiff won't be doing +that so the only sensible operation is removal. + + SCENARIO Removing of a socket works + GIVEN a directory called 'A_dir' + AND a socket called 'minus_socket' in directory 'A_dir' + AND a directory called 'B_dir' + WHEN tbdiff-create creates a binary delta between directories 'A_dir' and 'B_dir', called 'AB.tbdiff' + AND tbdiff-deploy applies the delta 'AB.tbdiff' to 'A_dir' + THEN the socket 'A_dir/minus_socket' no longer exists + + SCENARIO Creation of a socket doesn't work + GIVEN a directory called 'A_dir' + AND a directory called 'B_dir' + AND a socket called 'minus_socket' in directory 'B_dir' + WHEN tbdiff-create attempts to create a binary delta between directories 'A_dir' and 'B_dir', called 'AB.tbdiff' + THEN stderr contains "tbdiff-create cannot create sockets" + + SCENARIO Changing a socket doesn't work + GIVEN a directory called 'A_dir' + AND a socket called 'foo_socket' in directory 'A_dir' + AND a directory called 'B_dir' + AND a socket called 'foo_socket' in directory 'B_dir' + WHEN tbdiff-create attempts to create a binary delta between directories 'A_dir' and 'B_dir', called 'AB.tbdiff' + THEN stderr contains "tbdiff-create cannot create sockets" + IMPLEMENTS ========== @@ -342,8 +372,16 @@ Implementations for the creating and deploying of binary deltas [ -n "$MATCH_5" ] && mkdir -p "$DATADIR/$MATCH_5" mknod "$DATADIR/$MATCH_5/$MATCH_2" "$(echo "$MATCH_1" | head -c 1)" "$MATCH_3" "$MATCH_4" - IMPLEMENTS WHEN tbdiff-create creates a binary delta between directories '([^']+)' and '([^']+)', called '([^']+)' - "$SRCDIR/tbdiff-create/tbdiff-create" "$DATADIR/$MATCH_3" "$DATADIR/$MATCH_1" "$DATADIR/$MATCH_2" + IMPLEMENTS GIVEN a socket called '([^']+)'(?: in directory '([^']+)')? + [ -n "$MATCH_2" ] && mkdir -p "$DATADIR/$MATCH_2" + "$SRCDIR/sockbind" "$DATADIR/$MATCH_2/$MATCH_1" + + IMPLEMENTS WHEN tbdiff-create (attempts to create|creates) a binary delta between directories '([^']+)' and '([^']+)', called '([^']+)' + set "$SRCDIR/tbdiff-create/tbdiff-create" "$DATADIR/$MATCH_4" "$DATADIR/$MATCH_2" "$DATADIR/$MATCH_3" + if [ $MATCH_1 == creates ]; then "$@" + else + set +e; "$@" 2> "$DATADIR/stderr"; set -e + fi IMPLEMENTS WHEN tbdiff-deploy applies the delta '([^']+)' to '([^']+)' cd "$DATADIR/$MATCH_2" @@ -358,7 +396,7 @@ Implementations for the creating and deploying of binary deltas IMPLEMENTS THEN the (?:file|directory|named pipe) '([^']+)' has the permissions '([^']+)' test "$(stat -c %A "$DATADIR/$MATCH_1")" = "$MATCH_2" - IMPLEMENTS THEN the (?:file|directory|named pipe|symbolic link|(?:character|block) device) '([^']+)' no longer exists + IMPLEMENTS THEN the (?:file|directory|named pipe|symbolic link|(?:character|block) device|socket) '([^']+)' no longer exists test ! -e "$DATADIR/$MATCH_1" IMPLEMENTS THEN the (?:files|directories|named pipes|symbolic links) '([^']+)' and '([^']+)' have the same modification time @@ -381,3 +419,6 @@ Implementations for the creating and deploying of binary deltas IMPLEMENTS THEN the (?:block|character) devices '([^']+)' and '([^']+)' have the same device numbers test "$(stat -c '%t %T' "$DATADIR/$MATCH_1")" = "$(stat -c '%t %T' "$DATADIR/$MATCH_2")" + + IMPLEMENTS THEN (\S+) contains "([^"]+)" + grep "$MATCH_2" "$DATADIR/$MATCH_1" -- cgit v1.2.1