Bug 1364727 - Prevent libcurl from printing received data to stdout; r=Dexter
authorGabriele Svelto <gsvelto@mozilla.com>
Wed, 17 May 2017 13:34:12 +0200
changeset 360171 38efc433e5dd777d472287b3ff9899b9f6a768ac
parent 360170 748bee7648bcdba8623eaf75408fc8ab6a566d4e
child 360172 34cfc890b2e5d3e75559f1fc82540c5bf243c5d6
push id31871
push userryanvm@gmail.com
push dateTue, 23 May 2017 22:02:07 +0000
treeherdermozilla-central@545ffce30eac [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersDexter
bugs1364727
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1364727 - Prevent libcurl from printing received data to stdout; r=Dexter By default libcurl prints all the data it receives to stdout. By providing a dummy write function that drops incoming data and setting it via CURLOPT_WRITEFUNCTION we can quiet the pingsender operation entirely. MozReview-Commit-ID: BsgaUWxtLn9
toolkit/components/telemetry/pingsender/pingsender_unix_common.cpp
--- a/toolkit/components/telemetry/pingsender/pingsender_unix_common.cpp
+++ b/toolkit/components/telemetry/pingsender/pingsender_unix_common.cpp
@@ -7,20 +7,24 @@
 #include <cstring>
 #include <string>
 
 #include <dlfcn.h>
 #include <unistd.h>
 
 #include "third_party/curl/curl.h"
 
+#include "mozilla/Unused.h"
+
 namespace PingSender {
 
 using std::string;
 
+using mozilla::Unused;
+
 /**
  * A simple wrapper around libcurl "easy" functions. Provides RAII opening
  * and initialization of the curl library
  */
 class CurlWrapper
 {
 public:
   CurlWrapper();
@@ -130,21 +134,33 @@ CurlWrapper::Init()
   if (!mCurl) {
     PINGSENDER_LOG("ERROR: Could not initialize libcurl\n");
     return false;
   }
 
   return true;
 }
 
+static size_t
+DummyWriteCallback(char *ptr, size_t size, size_t nmemb, void *userdata)
+{
+  Unused << ptr;
+  Unused << size;
+  Unused << nmemb;
+  Unused << userdata;
+
+  return size * nmemb;
+}
+
 bool
 CurlWrapper::Post(const string& url, const string& payload)
 {
   easy_setopt(mCurl, CURLOPT_URL, url.c_str());
   easy_setopt(mCurl, CURLOPT_USERAGENT, kUserAgent);
+  easy_setopt(mCurl, CURLOPT_WRITEFUNCTION, DummyWriteCallback);
 
   // Build the date header.
   std::string dateHeader = GenerateDateHeader();
 
   // Set the custom headers.
   curl_slist* headerChunk = nullptr;
   headerChunk = slist_append(headerChunk, kCustomVersionHeader);
   headerChunk = slist_append(headerChunk, kContentEncodingHeader);