From patchwork Mon Mar 12 13:17:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alin-Gabriel Serdean X-Patchwork-Id: 884591 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ovn.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 400Ndz1D2wz9sSS for ; Tue, 13 Mar 2018 03:26:15 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 1AB041081; Mon, 12 Mar 2018 16:26:12 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 6DF221071 for ; Mon, 12 Mar 2018 16:26:10 +0000 (UTC) X-Greylist: delayed 02:37:25 by SQLgrey-1.7.6 Received: from mslow1.mail.gandi.net (mslow1.mail.gandi.net [217.70.178.240]) by smtp1.linuxfoundation.org (Postfix) with ESMTP id BC473224 for ; Mon, 12 Mar 2018 16:26:09 +0000 (UTC) Received: from relay3-d.mail.gandi.net (unknown [217.70.178.223]) by mslow1.mail.gandi.net (Postfix) with ESMTP id 7E6682A49C0 for ; Mon, 12 Mar 2018 14:48:47 +0100 (CET) X-Originating-IP: 85.186.139.13 Received: from localhost.localdomain (unknown [85.186.139.13]) (Authenticated sender: aserdean@ovn.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 9B1926A173; Mon, 12 Mar 2018 14:17:51 +0100 (CET) From: Alin Gabriel Serdean To: dev@openvswitch.org Date: Mon, 12 Mar 2018 15:17:42 +0200 Message-Id: <20180312131742.13652-1-aserdean@ovn.org> X-Mailer: git-send-email 2.16.1.windows.1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Alin Gabriel Serdean Subject: [ovs-dev] [PATCH v3] ovsdb-client: Set binary mode when doing backup/restore X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Add some needed consistency on Windows for STD_IN/OUT file descriptors when doing backup and restore. Reported-at:https://mail.openvswitch.org/pipermail/ovs-dev/2018-January/343518.html Suggested-by: Ben Pfaff Co-authored-by: Ben Pfaff Signed-off-by: Ben Pfaff Signed-off-by: Alin Gabriel Serdean Acked-by: Ben Pfaff --- v3: Incorporate comments suggested by Ben. v2: Fix copy paste error. --- ovsdb/ovsdb-client.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ovsdb/ovsdb-client.c b/ovsdb/ovsdb-client.c index 222bd6ca8..2aaec0648 100644 --- a/ovsdb/ovsdb-client.c +++ b/ovsdb/ovsdb-client.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -1475,6 +1476,19 @@ print_and_free_log_record(struct json *record) json_destroy(record); } +static void +set_binary_mode(FILE *stream OVS_UNUSED) { +#ifdef _WIN32 + fflush(stream); + /* On Windows set binary mode on the file descriptor to avoid + * translation (i.e. CRLF line endings). */ + if (_setmode(_fileno(stream), O_BINARY) == -1) { + ovs_fatal(errno, "could not set binary mode on fd %d", + _fileno(stream)); + } +#endif +} + static void do_backup(struct jsonrpc *rpc, const char *database, int argc OVS_UNUSED, char *argv[] OVS_UNUSED) @@ -1483,6 +1497,7 @@ do_backup(struct jsonrpc *rpc, const char *database, ovs_fatal(0, "not writing backup to a terminal; " "please redirect stdout to a file"); } + set_binary_mode(stdout); /* Get schema. */ struct ovsdb_schema *schema = fetch_schema(rpc, database); @@ -1599,6 +1614,7 @@ do_restore(struct jsonrpc *rpc, const char *database, ovs_fatal(0, "not reading backup from a terminal; " "please redirect stdin from a file"); } + set_binary_mode(stdin); struct ovsdb *backup; check_ovsdb_error(ovsdb_file_open("/dev/stdin", true, &backup, NULL));