]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
forwarding-zypp-plugin
authorMartin Vidner <mvidner@suse.cz>
Fri, 17 Jan 2020 14:58:23 +0000 (15:58 +0100)
committerMartin Vidner <mvidner@suse.cz>
Tue, 21 Jan 2020 11:33:24 +0000 (12:33 +0100)
a middleware that reparses what its child plugin is replying
and thus enables detecting protocol errors like bsc#1160938

zypp-plugin/.gitignore
zypp-plugin/Makefile.am
zypp-plugin/forwarding_zypp_plugin.cc [new file with mode: 0644]
zypp-plugin/testsuite/Makefile.am
zypp-plugin/testsuite/test-helper.sh

index ff41d306eb0c76df90987ee1a8381ad6af8a8f32..54dbbb3b799761a4cdcf7f4eaef762d58ddce2c4 100644 (file)
@@ -1,5 +1,6 @@
 *.o
 snapper-zypp-plugin
+forwarding-zypp-plugin
 *.test
 *.log
 *.trs
index f03da12dacd76d83ae440af2c97e73d170ce471d..1fb0a296af35d11ce17c8c204f0a1b88eb19d467 100644 (file)
@@ -17,8 +17,16 @@ snapper_zypp_plugin_LDADD = \
     ../dbus/libdbus.la \
     $(JSONC_LIBS)
 
-check_PROGRAMS = regex.test
-TESTS = $(check_PROGRAMS)
+check_PROGRAMS = regex.test forwarding-zypp-plugin
+
+forwarding_zypp_plugin_SOURCES = \
+    forwarding_zypp_plugin.cc \
+    zypp_plugin.cc zypp_plugin.h
+forwarding_zypp_plugin_LDADD = \
+    ../snapper/libsnapper.la \
+    -lpthread
+
+TESTS = regex.test
 regex_test_SOURCES = regex_test.cc \
     solvable_matcher.cc solvable_matcher.h
 regex_test_LDADD = \
diff --git a/zypp-plugin/forwarding_zypp_plugin.cc b/zypp-plugin/forwarding_zypp_plugin.cc
new file mode 100644 (file)
index 0000000..e41f305
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2020 SUSE LLC
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact SUSE LLC.
+ *
+ * To contact SUSE about this file by physical or electronic mail, you may
+ * find current contact information at www.suse.com.
+ */
+
+#include <string>
+using namespace std;
+
+#include <boost/process.hpp>
+namespace bp = boost::process;
+
+#include "zypp_plugin.h"
+
+class ForwardingZyppPlugin : public ZyppPlugin {
+public:
+    ForwardingZyppPlugin(const string& another_plugin);
+
+    virtual int main() override;
+    virtual Message dispatch(const Message&) override;
+private:
+    string child_program;
+    bp::ipstream childs_out; // we read this
+    // bp::ipstream childs_err; // we read this
+    bp::opstream childs_in; // we write this
+};
+
+ForwardingZyppPlugin::ForwardingZyppPlugin(const string& another_plugin)
+    : child_program(another_plugin)
+{
+}
+
+int ForwardingZyppPlugin::main() {
+    bp::child c(child_program,
+               bp::std_out > childs_out,
+               // bp::std_err > childs_err,
+               bp::std_in < childs_in);
+
+    int result = ZyppPlugin::main();
+
+    //    c.wait();
+    return result;
+}
+
+ZyppPlugin::Message ForwardingZyppPlugin::dispatch(const Message& msg) {
+    write_message(childs_in, msg);
+    Message reply = read_message(childs_out);
+    return reply;
+}
+
+int main(int argc, char** argv) {
+    if (argc != 2)
+       throw runtime_error("Usage: forwarding-zypp-plugin ANOTHER_ZYPP_PLUGIN");
+    ForwardingZyppPlugin plugin(argv[1]);
+    return plugin.main();
+}
index ba7523c39522872fb9435bd7086bceb5354dd1c9..549efb77c5bbd063f3584fda21bedd9f7864bc89 100644 (file)
@@ -5,10 +5,6 @@ check_SCRIPTS = 1-happy.test 2-malformed-xml.test 3-invalid-xml.test 4-badjson.t
 noinst_SCRIPTS = mock-snapperd test-helper.sh
 noinst_DATA = zypp-plugin-malformed.conf zypp-plugin-invalid.conf
 
-# Hack: these tests both use mock-snapperd which is not paralellized
-# so serialize them
-4-badjson.log: 1-happy.log
-
 TESTS = $(check_SCRIPTS)
 
 EXTRA_DIST = $(check_SCRIPTS) $(noinst_SCRIPTS) $(noinst_DATA) tap-driver.sh
index 89461f670ce135a6f25f3f37c2b3c06593e7063f..bfec7d2b8763c9e3d1de693635321f85413faa22 100644 (file)
@@ -12,6 +12,7 @@ runit() {
       SNAPPER_ZYPP_PLUGIN_SNAPPER_CONFIG=testsuite \
       SNAPPER_ZYPP_PLUGIN_DBUS_SESSION=1 \
       $STRACE \
+      "$MYDIR"/../forwarding-zypp-plugin \
       "$MYDIR"/../snapper-zypp-plugin
 }