summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Brown <ben.brown@codethink.co.uk>2013-12-16 09:36:52 +0000
committerBen Brown <ben.brown@codethink.co.uk>2013-12-16 09:36:52 +0000
commit672e64a86f5d07ff5c5d26495af257336f57deab (patch)
tree9ff1eed3a683ba90e8238c1cc7f1a07b5d61dd48
parent775d05edada9d9fdf2bd9bc4eb62bbeec0961ad4 (diff)
parent149de8fcb40dc355e0a81ae8e17c4a43b614d8d7 (diff)
downloadtbdiff-672e64a86f5d07ff5c5d26495af257336f57deab.tar.gz
Merge branch 'benbrown/S9482/convert-socket-tests'
-rw-r--r--Makefile.am3
-rw-r--r--yarns/create-deploy.yarn47
-rw-r--r--yarns/sockbind.c42
3 files changed, 88 insertions, 4 deletions
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
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"
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 <stdio.h>
+#include <stddef.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+/*
+ * 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;
+}