xpcom/glue/IntentionalCrash.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #include <string>
     6 #include <sstream>
     7 #include <stdlib.h>
     8 #include <stdio.h>
    10 #ifdef XP_WIN
    11 #include <process.h>
    12 #define getpid _getpid
    13 #else
    14 #include <unistd.h>
    15 #endif
    17 #ifndef mozilla_IntentionalCrash_h
    18 #define mozilla_IntentionalCrash_h
    20 namespace mozilla {
    22 inline void
    23 NoteIntentionalCrash(const char* processType)
    24 {
    25   char* f = getenv("XPCOM_MEM_BLOAT_LOG");
    27   if (!f) 
    28     return;
    30   fprintf(stderr, "XPCOM_MEM_BLOAT_LOG: %s\n", f);
    32   std::string bloatLog(f);
    34   bool hasExt = false;
    35   if (bloatLog.size() >= 4 &&
    36       0 == bloatLog.compare(bloatLog.size() - 4, 4, ".log", 4)) {
    37     hasExt = true;
    38     bloatLog.erase(bloatLog.size() - 4, 4);
    39   }
    41   std::ostringstream bloatName;
    42   bloatName << bloatLog << "_" << processType << "_pid" << getpid();
    43   if (hasExt)
    44     bloatName << ".log";
    46   fprintf(stderr, "Writing to log: %s\n", bloatName.str().c_str());
    48   FILE* processfd = fopen(bloatName.str().c_str(), "a");
    49   fprintf(processfd, "==> process %d will purposefully crash\n", getpid());
    50   fclose(processfd);
    51 }
    53 } // namespace mozilla
    55 #endif // mozilla_IntentionalCrash_h

mercurial