From: Eric Bollengier Date: Mon, 9 Mar 2020 09:23:15 +0000 (+0100) Subject: Add little bpipe_test in tools/ X-Git-Tag: Release-11.3.2~1874 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1ff254bc48df625a61cb5615e101778199f3e6df;p=thirdparty%2Fbacula.git Add little bpipe_test in tools/ --- diff --git a/bacula/src/tools/Makefile.in b/bacula/src/tools/Makefile.in index abd66199df..35faddc093 100644 --- a/bacula/src/tools/Makefile.in +++ b/bacula/src/tools/Makefile.in @@ -94,6 +94,11 @@ timelimit: timelimit.o ${CC} ${DEFS} ${DEBUG} -pipe -DHAVE_ERRNO_H -DHAVE_SETITIMER -DHAVE_SIGACTION -c timelimit.c ${CC} -o timelimit timelimit.o +bpipe_test: bpipe_test.o ../lib/libbac$(DEFAULT_ARCHIVE_TYPE) + $(MAKE) -C ../lib alist_test + $(LIBTOOL_LINK) $(CXX) -g $(LDFLAGS) -L. -L../lib -L../findlib -o $@ bpipe_test.o ../lib/unittests.o \ + $(DLIB) -lbac -lm $(LIBS) $(GETTEXT_LIBS) $(OPENSSL_LIBS) + testfind: Makefile ../lib/libbac$(DEFAULT_ARCHIVE_TYPE) ../lib/libbaccfg$(DEFAULT_ARCHIVE_TYPE) \ ../findlib/libbacfind$(DEFAULT_ARCHIVE_TYPE) $(FINDOBJS) $(LIBTOOL_LINK) $(CXX) -g $(LDFLAGS) -o $@ $(FINDOBJS) -L. -L../lib -L../findlib \ diff --git a/bacula/src/tools/bpipe_test.c b/bacula/src/tools/bpipe_test.c new file mode 100644 index 0000000000..2238fbb3a1 --- /dev/null +++ b/bacula/src/tools/bpipe_test.c @@ -0,0 +1,48 @@ +/* + Bacula® - The Network Backup Solution + + Copyright (C) 2000-2020 Bacula Systems SA + All rights reserved. + + The main author of Bacula is Kern Sibbald, with contributions from many + others, a complete list can be found in the file AUTHORS. + + Licensees holding a valid Bacula Systems SA license may use this file + and others of this release in accordance with the proprietary license + agreement provided in the LICENSE file. Redistribution of any part of + this release is not permitted. + + Bacula® is a registered trademark of Kern Sibbald. +*/ + +#include "bacula.h" +#include "../lib/unittests.h" + +int main(int argc, char **argv) +{ + Unittests u("t"); + char buf[512] = {0}; + BPIPE *bp; + FILE *fp; + fp = fopen("toto.sh", "w"); + fprintf(fp, "#!/bin/sh\necho hello\nread a\necho $a\n"); + fclose(fp); + chmod("toto.sh", 0755); + + bp = open_bpipe("./toto.sh", 0, "rw"); + ok(bp != NULL, "open_bpipe"); + + fgets(buf, sizeof(buf), bp->rfd); + ok(strcmp(buf, "hello\n") == 0, "fgets on bpipe"); + printf("%s", buf); + + fprintf(bp->wfd, "titi\n"); + fflush(bp->wfd); + + fgets(buf, sizeof(buf), bp->rfd); + ok(strcmp(buf, "titi\n") == 0, "fgets on bpipe"); + printf("%s", buf); + + ok(close_bpipe(bp) == 0, "closing bpipe"); + return report(); +}