summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2011-10-10 10:12:51 +0100
committerRichard Maw <richard.maw@codethink.co.uk>2011-10-10 10:33:54 +0100
commitc14b45f70cc1cac1cca46af30c0c9c7aa32b459f (patch)
treec4146b06b4943c2e23a941c275a7553cbb245520
parentcdb2882dc33b7bd1ee3fba2190cc17fef324050d (diff)
downloadtbdiff-c14b45f70cc1cac1cca46af30c0c9c7aa32b459f.tar.gz
libtbd_create now fails if target directory has a socket.
tbdiff-create will print a suggested fix Made check_command shell function able to use any type of command for return value checking Fixed minor bugs in TBD_ERROR macro not being used for some errors
-rw-r--r--libtbd_apply.c4
-rw-r--r--libtbd_create.c33
-rw-r--r--tbdiff.h3
-rw-r--r--tbdiff_create.c10
-rw-r--r--tests/test_lib.sh8
5 files changed, 46 insertions, 12 deletions
diff --git a/libtbd_apply.c b/libtbd_apply.c
index a749952..62b1399 100644
--- a/libtbd_apply.c
+++ b/libtbd_apply.c
@@ -413,7 +413,7 @@ tbd_apply_cmd_symlink_create(FILE *stream)
fprintf(stderr, "cmd_symlink_create %s -> %s\n", linkname, linkpath);
if(symlink(linkpath, linkname))
- return TBD_ERROR_UNABLE_TO_CREATE_SYMLINK;
+ return TBD_ERROR(TBD_ERROR_UNABLE_TO_CREATE_SYMLINK);
struct timeval tv[2];
gettimeofday(&tv[0], NULL);
@@ -450,7 +450,7 @@ tbd_apply_cmd_special_create(FILE *stream)
if(mknod(name, mode, (dev_t)dev) != 0) {
free(name);
- return TBD_ERROR_UNABLE_TO_CREATE_SPECIAL_FILE;
+ return TBD_ERROR(TBD_ERROR_UNABLE_TO_CREATE_SPECIAL_FILE);
}
struct utimbuf timebuff = { time(NULL), mtime };
diff --git a/libtbd_create.c b/libtbd_create.c
index 80874a8..e25b3c1 100644
--- a/libtbd_create.c
+++ b/libtbd_create.c
@@ -438,7 +438,7 @@ tbd_create_cmd_symlink_create(FILE *stream,
ssize_t len = readlink(slpath, path, sizeof(path)-1);
free(slpath);
if(len < 0)
- return TBD_ERROR_UNABLE_TO_READ_SYMLINK;
+ return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_SYMLINK);
path[len] = '\0';
if((err = tbd_create_fwrite_cmd(stream, TBD_CMD_SYMLINK_CREATE)) != 0 ||
@@ -470,7 +470,7 @@ tbd_create_cmd_symlink_delta(FILE *stream,
free(spath_b);
if(len_a < 0 || len_b < 0)
- return TBD_ERROR_UNABLE_TO_READ_SYMLINK;
+ return TBD_ERROR(TBD_ERROR_UNABLE_TO_READ_SYMLINK);
path_a[len_a] = path_b[len_b] = '\0';
@@ -526,6 +526,26 @@ tbd_create_cmd_special_delta(FILE *stream,
}
static int
+tbd_create_cmd_socket_create(FILE *stream,
+ tbd_stat_t *nod)
+{
+ (void)stream;
+ (void)nod;
+ return TBD_ERROR(TBD_ERROR_UNABLE_TO_CREATE_SOCKET_FILE);
+}
+
+static int
+tbd_create_cmd_socket_delta(FILE *stream,
+ tbd_stat_t *a,
+ tbd_stat_t *b)
+{
+ (void)stream;
+ (void)a;
+ (void)b;
+ return TBD_ERROR(TBD_ERROR_UNABLE_TO_CREATE_SOCKET_FILE);
+}
+
+static int
tbd_create_dir(FILE *stream,
tbd_stat_t *d)
{
@@ -600,12 +620,13 @@ tbd_create_impl(FILE *stream,
case TBD_STAT_TYPE_CHRDEV:
case TBD_STAT_TYPE_BLKDEV:
case TBD_STAT_TYPE_FIFO:
- case TBD_STAT_TYPE_SOCKET:
fprintf(stderr, "special new %s\n", b->name);
return tbd_create_cmd_special_create(stream, b);
+ case TBD_STAT_TYPE_SOCKET:
+ fprintf(stderr, "socket new %s\n", b->name);
+ return tbd_create_cmd_socket_create(stream, b);
default:
return TBD_ERROR(TBD_ERROR_FEATURE_NOT_IMPLEMENTED);
- break;
}
}
@@ -619,9 +640,11 @@ tbd_create_impl(FILE *stream,
case TBD_STAT_TYPE_CHRDEV:
case TBD_STAT_TYPE_BLKDEV:
case TBD_STAT_TYPE_FIFO:
- case TBD_STAT_TYPE_SOCKET:
fprintf(stderr, "special delta %s\n", a->name);
return tbd_create_cmd_special_delta(stream, a, b);
+ case TBD_STAT_TYPE_SOCKET:
+ fprintf(stderr, "socket delta %s\n", a->name);
+ return tbd_create_cmd_socket_delta(stream, a, b);
case TBD_STAT_TYPE_DIR:
if(!top) {
fprintf(stderr, "dir delta %s\n", a->name);
diff --git a/tbdiff.h b/tbdiff.h
index 3949283..2a4bcf6 100644
--- a/tbdiff.h
+++ b/tbdiff.h
@@ -71,7 +71,8 @@ typedef enum {
TBD_ERROR_UNABLE_TO_READ_SYMLINK = -18,
TBD_ERROR_UNABLE_TO_CREATE_SYMLINK = -19,
TBD_ERROR_UNABLE_TO_READ_SPECIAL_FILE = -20,
- TBD_ERROR_UNABLE_TO_CREATE_SPECIAL_FILE = - 21,
+ TBD_ERROR_UNABLE_TO_CREATE_SPECIAL_FILE = -21,
+ TBD_ERROR_UNABLE_TO_CREATE_SOCKET_FILE = -22,
} tbd_error_e;
#ifdef NDEBUG
diff --git a/tbdiff_create.c b/tbdiff_create.c
index bda42d6..8bc68c7 100644
--- a/tbdiff_create.c
+++ b/tbdiff_create.c
@@ -74,6 +74,16 @@ main(int argc,
fclose(fp);
remove(argv[1]);
fprintf(stderr, "Error: Failed to create tbdiff image (err=%d).\n", err);
+ switch (err) {
+ case TBD_ERROR_UNABLE_TO_CREATE_SOCKET_FILE:
+ fprintf(stderr, "%s directory contains Unix Sockets. "
+ "%s cannot create sockets, please ensure no "
+ "programs are using sockets in directory.\n",
+ argv[3], argv[0]);
+ break;
+ default:
+ break;
+ }
return EXIT_FAILURE;
}
diff --git a/tests/test_lib.sh b/tests/test_lib.sh
index 5112cea..e95759d 100644
--- a/tests/test_lib.sh
+++ b/tests/test_lib.sh
@@ -41,9 +41,9 @@ check_group () {
test $(stat -c %G $1) = $2
}
-#declare -f is faster, but won't work in dash
-is_function () {
- type $1 2>/dev/null | grep 'function'
+# tests whether a command exists
+is_command () {
+ type $1 >/dev/null 2>/dev/null
}
#check_command COMMAND_STRING TEST_COMMAND COMMAND_DESCRIPTION
@@ -53,7 +53,7 @@ check_command () {
COMMAND_DESCRIPTION="$3"
eval $COMMAND_STRING
RETVAL=$?
- if is_function "$TEST_COMMAND"; then #test explicitly checks return
+ if is_command "$TEST_COMMAND"; then #test explicitly checks return
if $TEST_COMMAND $RETVAL; then
if [ "$RETVAL" != "0" ]; then
echo $COMMAND_STRING expected failure in \