| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file implements BSD-style setproctitle() for Linux. | 5 // This file implements BSD-style setproctitle() for Linux. |
| 6 // It is written such that it can easily be compiled outside Chromium. | 6 // It is written such that it can easily be compiled outside Chromium. |
| 7 // | 7 // |
| 8 // The Linux kernel sets up two locations in memory to pass arguments and | 8 // The Linux kernel sets up two locations in memory to pass arguments and |
| 9 // environment variables to processes. First, there are two char* arrays stored | 9 // environment variables to processes. First, there are two char* arrays stored |
| 10 // one after another: argv and environ. A pointer to argv is passed to main(), | 10 // one after another: argv and environ. A pointer to argv is passed to main(), |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 // of the way to make room for a potentially longer title, and then overwrite | 30 // of the way to make room for a potentially longer title, and then overwrite |
| 31 // the memory pointed to by argv[0] with a single replacement string, making | 31 // the memory pointed to by argv[0] with a single replacement string, making |
| 32 // sure its size does not exceed the available space. | 32 // sure its size does not exceed the available space. |
| 33 // | 33 // |
| 34 // It is perhaps worth noting that patches to add a system call to Linux for | 34 // It is perhaps worth noting that patches to add a system call to Linux for |
| 35 // this, like in BSD, have never made it in: this is the "official" way to do | 35 // this, like in BSD, have never made it in: this is the "official" way to do |
| 36 // this on Linux. Presumably it is not in glibc due to some disagreement over | 36 // this on Linux. Presumably it is not in glibc due to some disagreement over |
| 37 // this position within the glibc project, leaving applications caught in the | 37 // this position within the glibc project, leaving applications caught in the |
| 38 // middle. (Also, only a very few applications need or want this anyway.) | 38 // middle. (Also, only a very few applications need or want this anyway.) |
| 39 | 39 |
| 40 #include "base/setproctitle_linux.h" | 40 #include "chrome/common/set_process_title_linux.h" |
| 41 | 41 |
| 42 #include <stdarg.h> | 42 #include <stdarg.h> |
| 43 #include <stdint.h> | 43 #include <stdint.h> |
| 44 #include <stdio.h> | 44 #include <stdio.h> |
| 45 #include <string.h> | 45 #include <string.h> |
| 46 #include <unistd.h> | 46 #include <unistd.h> |
| 47 | 47 |
| 48 extern char** environ; | 48 extern char** environ; |
| 49 | 49 |
| 50 static char** g_main_argv = NULL; | 50 static char** g_main_argv = NULL; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 void setproctitle_init(char** main_argv) { | 106 void setproctitle_init(char** main_argv) { |
| 107 if (g_main_argv) | 107 if (g_main_argv) |
| 108 return; | 108 return; |
| 109 | 109 |
| 110 uintptr_t page_size = sysconf(_SC_PAGESIZE); | 110 uintptr_t page_size = sysconf(_SC_PAGESIZE); |
| 111 // Check that the argv array is in fact on the same page of memory | 111 // Check that the argv array is in fact on the same page of memory |
| 112 // as the environment array just as an added measure of protection. | 112 // as the environment array just as an added measure of protection. |
| 113 if (((uintptr_t) environ) / page_size == ((uintptr_t) main_argv) / page_size) | 113 if (((uintptr_t) environ) / page_size == ((uintptr_t) main_argv) / page_size) |
| 114 g_main_argv = main_argv; | 114 g_main_argv = main_argv; |
| 115 } | 115 } |
| OLD | NEW |