tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

SetProcessTitle.cpp (1178B)


      1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #include "mozilla/ipc/SetProcessTitle.h"
      7 
      8 #include "nsString.h"
      9 
     10 #ifdef XP_LINUX
     11 
     12 #  include "base/set_process_title_linux.h"
     13 #  define HAVE_SETPROCTITLE
     14 #  define HAVE_SETPROCTITLE_INIT
     15 
     16 #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
     17    defined(__DragonFly__)
     18 
     19 #  include <sys/types.h>
     20 #  include <unistd.h>
     21 #  define HAVE_SETPROCTITLE
     22 
     23 #endif
     24 
     25 namespace mozilla {
     26 
     27 void SetProcessTitle(const std::vector<std::string>& aNewArgv) {
     28 #ifdef HAVE_SETPROCTITLE
     29  nsAutoCStringN<1024> buf;
     30 
     31  bool firstArg = true;
     32  for (const std::string& arg : aNewArgv) {
     33    if (firstArg) {
     34      firstArg = false;
     35    } else {
     36      buf.Append(' ');
     37    }
     38    buf.Append(arg.c_str());
     39  }
     40 
     41  setproctitle("-%s", buf.get());
     42 #endif
     43 }
     44 
     45 void SetProcessTitleInit(char** aOrigArgv) {
     46 #ifdef HAVE_SETPROCTITLE_INIT
     47  setproctitle_init(aOrigArgv);
     48 #endif
     49 }
     50 
     51 }  // namespace mozilla