From 9bad5ce0c912aa28230c9a6aae3a9a73304e4a7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ondruch?= Date: Tue, 14 Apr 2015 08:39:23 +0200 Subject: [PATCH] Fix glibc and MongoDB compatibility. --- uwsgi.spec | 12 +- uwsgi_fix_glibc_compatibility.patch | 11 ++ uwsgi_fix_mongodb.patch | 269 ++++++++++++++++++++++++++++ 3 files changed, 291 insertions(+), 1 deletion(-) create mode 100644 uwsgi_fix_glibc_compatibility.patch create mode 100644 uwsgi_fix_mongodb.patch diff --git a/uwsgi.spec b/uwsgi.spec index 0a99737..f83fcfc 100644 --- a/uwsgi.spec +++ b/uwsgi.spec @@ -60,7 +60,7 @@ Name: uwsgi Version: 2.0.9 -Release: 3%{?dist} +Release: 4%{?dist} Summary: Fast, self-healing, application container server Group: System Environment/Daemons License: GPLv2 with exceptions @@ -77,6 +77,11 @@ Patch0: uwsgi_trick_chroot_rpmbuild.patch Patch1: uwsgi_fix_rpath.patch Patch2: uwsgi_ruby20_compatibility.patch Patch3: uwsgi_fix_lua.patch +# https://github.com/unbit/uwsgi/issues/883 +# https://sourceware.org/bugzilla/show_bug.cgi?id=17523 +Patch4: uwsgi_fix_glibc_compatibility.patch +# https://github.com/unbit/uwsgi/issues/882 +Patch5: uwsgi_fix_mongodb.patch BuildRequires: curl, python2-devel, libxml2-devel, libuuid-devel, jansson-devel BuildRequires: libyaml-devel, perl-devel, ruby-devel, perl-ExtUtils-Embed %if %{with python3} @@ -966,6 +971,8 @@ echo "plugin_dir = %{_libdir}/%{name}" >> buildconf/$(basename %{SOURCE1}) %patch1 -p1 %patch2 -p1 %patch3 -p1 +%patch4 -p1 +%patch5 -p1 %build %if %{with mongodblibs} @@ -1447,6 +1454,9 @@ fi %changelog +* Tue Apr 14 2015 Vít Ondruch - 2.0.9-4 +- Fix glibc and MongoDB compatibility. + * Fri Mar 13 2015 Jorge A Gallegos - 2.0.9-3 - Adding missing dist tag, have no clue at what point this got dropped :( diff --git a/uwsgi_fix_glibc_compatibility.patch b/uwsgi_fix_glibc_compatibility.patch new file mode 100644 index 0000000..c8d27ff --- /dev/null +++ b/uwsgi_fix_glibc_compatibility.patch @@ -0,0 +1,11 @@ +--- a/core/utils.c ++++ b/core/utils.c +@@ -3514,7 +3514,7 @@ + tmpdir = "/tmp"; + } + #ifdef O_TMPFILE +- fd = open(tmpdir, O_TMPFILE | O_RDWR); ++ fd = open(tmpdir, O_TMPFILE | O_RDWR, S_IRUSR | S_IWUSR); + if (fd >= 0) { + return fd; + } diff --git a/uwsgi_fix_mongodb.patch b/uwsgi_fix_mongodb.patch new file mode 100644 index 0000000..8b7b366 --- /dev/null +++ b/uwsgi_fix_mongodb.patch @@ -0,0 +1,269 @@ +From 83752e472c35632174534763dffd312fc120a429 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=9F=D1=80?= + =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B7=D0=B0=D0=BD=D0=BE=D0=B2?= + +Date: Fri, 10 Apr 2015 22:56:59 +0400 +Subject: [PATCH 1/3] Updated GridFS plugin to work with legacy + mongo-cxx-driver version 1.0.0 + +--- + plugins/gridfs/gridfs.cc | 53 +++++++++++++++++++++++++++++++++---------- + plugins/gridfs/uwsgiplugin.py | 7 +++--- + 2 files changed, 45 insertions(+), 15 deletions(-) + +diff --git a/plugins/gridfs/gridfs.cc b/plugins/gridfs/gridfs.cc +index d11451a..81ff0d9 100644 +--- a/plugins/gridfs/gridfs.cc ++++ b/plugins/gridfs/gridfs.cc +@@ -1,3 +1,7 @@ ++#include ++#include ++#include ++ + #include + + #include +@@ -7,6 +11,7 @@ struct uwsgi_gridfs_mountpoint { + char *mountpoint; + uint16_t mountpoint_len; + char *server; ++ char *replica; + char *db; + char *timeout_str; + int timeout; +@@ -21,6 +26,7 @@ struct uwsgi_gridfs_mountpoint { + uint16_t prefix_len; + char *username; + char *password; ++ std::vector servers; + }; + + struct uwsgi_gridfs { +@@ -38,33 +44,44 @@ extern struct uwsgi_server uwsgi; + extern struct uwsgi_plugin gridfs_plugin; + + static void uwsgi_gridfs_do(struct wsgi_request *wsgi_req, struct uwsgi_gridfs_mountpoint *ugm, char *itemname, int need_free) { +- + try { +- mongo::scoped_ptr conn( mongo::ScopedDbConnection::getScopedDbConnection(ugm->server, ugm->timeout) ); ++ std::unique_ptr conn; ++ ++ if (ugm->replica) { ++ conn = std::unique_ptr (new mongo::DBClientReplicaSet(ugm->replica, ugm->servers)); ++ dynamic_cast(conn.get())->connect(); ++ } ++ else { ++ conn = std::unique_ptr (new mongo::DBClientConnection()); ++ dynamic_cast(conn.get())->connect(ugm->server); ++ } ++ + try { + if (ugm->username && ugm->password) { + std::string errmsg; +- if ((*conn).conn().auth(ugm->db, ugm->username, ugm->password, errmsg)) { ++ if (!conn->auth(ugm->db, ugm->username, ugm->password, errmsg)) { + uwsgi_log("[uwsgi-gridfs]: %s\n", errmsg.c_str()); +- (*conn).done(); + uwsgi_403(wsgi_req); + return; + } + } +- mongo::GridFS gridfs((*conn).conn(), ugm->db); +- mongo::GridFile gfile = gridfs.findFile(itemname); ++ mongo::GridFS gridfs((*conn.get()), ugm->db); ++ mongo::GridFile gfile = gridfs.findFileByName(itemname); ++ + if (need_free) { + free(itemname); + itemname = NULL; + } ++ + if (!gfile.exists()) { +- (*conn).done(); + uwsgi_404(wsgi_req); + return; + } ++ + uwsgi_response_prepare_headers(wsgi_req, (char *)"200 OK", 6); + // first get the content_type (if possibile) + std::string filename = gfile.getFilename(); ++ + if (!ugm->no_mime) { + size_t mime_type_len = 0; + char *mime_type = uwsgi_get_mime_type((char *)filename.c_str(), filename.length(), &mime_type_len); +@@ -72,11 +89,13 @@ static void uwsgi_gridfs_do(struct wsgi_request *wsgi_req, struct uwsgi_gridfs_m + uwsgi_response_add_content_type(wsgi_req, mime_type, mime_type_len); + } + } ++ + if (ugm->orig_filename) { + char *filename_header = uwsgi_concat3((char *)"inline; filename=\"", (char *)filename.c_str(), (char *)"\""); + uwsgi_response_add_header(wsgi_req, (char *)"Content-Disposition", 19, filename_header, 19 + filename.length()); + free(filename_header); + } ++ + uwsgi_response_add_content_length(wsgi_req, gfile.getContentLength()); + + char http_last_modified[49]; +@@ -90,7 +109,7 @@ static void uwsgi_gridfs_do(struct wsgi_request *wsgi_req, struct uwsgi_gridfs_m + char *etag = uwsgi_concat3((char *)"\"", (char *)g_md5.c_str(), (char *)"\""); + uwsgi_response_add_header(wsgi_req, (char *)"ETag", 4, etag, 2+g_md5.length()); + free(etag); +- } ++ } + } + + if (ugm->md5) { +@@ -106,22 +125,20 @@ static void uwsgi_gridfs_do(struct wsgi_request *wsgi_req, struct uwsgi_gridfs_m + int i; + for(i=0;i +Date: Fri, 10 Apr 2015 23:07:41 +0400 +Subject: [PATCH 2/3] Fixed server list parsing + +--- + plugins/gridfs/gridfs.cc | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/plugins/gridfs/gridfs.cc b/plugins/gridfs/gridfs.cc +index 81ff0d9..f58d976 100644 +--- a/plugins/gridfs/gridfs.cc ++++ b/plugins/gridfs/gridfs.cc +@@ -211,6 +211,10 @@ static struct uwsgi_gridfs_mountpoint *uwsgi_gridfs_add_mountpoint(char *arg, si + ugm->servers.push_back(mongo::HostAndPort(buffer.substr(0, pos))); + buffer.erase(0, pos + 1); + } ++ ++ if (!ugm->servers.size()) { ++ ugm->servers.push_back(mongo::HostAndPort(ugm->server)); ++ } + } + + return ugm; +-- +2.1.0 + + +From a870dbfb0dc4268cbcecf573765338ec5a52f195 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=9F=D1=80?= + =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B7=D0=B0=D0=BD=D0=BE=D0=B2?= + +Date: Fri, 10 Apr 2015 23:38:38 +0400 +Subject: [PATCH 3/3] Passing timeout argument to MongoDB connection + +--- + plugins/gridfs/gridfs.cc | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/plugins/gridfs/gridfs.cc b/plugins/gridfs/gridfs.cc +index f58d976..5f7c4ba 100644 +--- a/plugins/gridfs/gridfs.cc ++++ b/plugins/gridfs/gridfs.cc +@@ -48,14 +48,14 @@ static void uwsgi_gridfs_do(struct wsgi_request *wsgi_req, struct uwsgi_gridfs_m + std::unique_ptr conn; + + if (ugm->replica) { +- conn = std::unique_ptr (new mongo::DBClientReplicaSet(ugm->replica, ugm->servers)); ++ conn = std::unique_ptr (new mongo::DBClientReplicaSet(ugm->replica, ugm->servers, ugm->timeout)); + dynamic_cast(conn.get())->connect(); + } + else { +- conn = std::unique_ptr (new mongo::DBClientConnection()); ++ conn = std::unique_ptr (new mongo::DBClientConnection(true, 0, ugm->timeout)); + dynamic_cast(conn.get())->connect(ugm->server); + } +- ++ + try { + if (ugm->username && ugm->password) { + std::string errmsg; +-- +2.1.0 +