[M126 Migration] Migrate process title related patches 64/316164/4
authoruzair <uzair.jaleel@samsung.com>
Wed, 11 Dec 2024 06:26:35 +0000 (11:56 +0530)
committerBot Blink <blinkbot@samsung.com>
Wed, 11 Dec 2024 10:21:34 +0000 (10:21 +0000)
1. In Chromium upstream, child process's title has been set by adding all command line switch. But it is not actually useful and causes some
problems. For instance, crash manager cannot create a file because a title is too long and it has illegal characters. So, this patch sets process title by adding only process type and service type.

2. This change corrects the originally migrated patch to store the process path in arg[0] and rest of flags in arg[1] properly.

3. As we use setenv to update certain environment vars in chromium-efl,comparing the memory location of process environment vars with default|environ| would fail. So this change removes the check for efl port.

Reference:https://archive.tizen.org/gerrit/286539

Change-Id: Ia5075e2206ab23c2c6623592d825de81798e6ba5
Signed-off-by: uzair <uzair.jaleel@samsung.com>
base/process/set_process_title_linux.cc

index a3c3d19ee4f7bf0c999b18ddc2c0e4626d2472bb..d298a04f35880c720e1fbd9848a93bd9e0ef8cab 100644 (file)
@@ -74,6 +74,11 @@ static char* g_argv_start = nullptr;
 static char* g_argv_end = nullptr;
 static char* g_envp_end = nullptr;
 
+#if BUILDFLAG(IS_EFL)
+static char** g_main_argv = nullptr;
+static size_t g_main_argv_size = 0;
+#endif
+
 void setproctitle(const char* fmt, ...) {
   va_list ap;
 
@@ -83,7 +88,7 @@ void setproctitle(const char* fmt, ...) {
     return;
 
   // The title can be up to the end of envp.
-  const size_t avail_size =
+  size_t avail_size =
       base::checked_cast<size_t>(g_envp_end - g_argv_start - 1);
 
   // Linux 4.18--5.2 have a bug where we can never set a process title
@@ -105,6 +110,27 @@ void setproctitle(const char* fmt, ...) {
     return cmdline.size() >= 2;
   }();
 
+#if BUILDFLAG(IS_EFL) && !BUILDFLAG(IS_TIZEN_TV)
+  // Put all arguments into argv[1], not argv[0]
+  if (g_main_argv[0])
+    snprintf(g_main_argv[0], strlen(g_orig_argv0) + 1, "%s", g_orig_argv0);
+  if (g_main_argv[1]) {
+    // argv[0] can be replaced by exceeding the original argument length within
+    // the free memory of the page, but argv[1] cannot exceed the the original
+    // length.
+    // Adjusts the available size to the length of the original arguments.
+    avail_size = g_main_argv_size;
+    avail_size -= (strlen(g_main_argv[0]) + 1);
+
+    memset(g_main_argv[1], 0, avail_size);
+    va_start(ap, fmt);
+    vsnprintf(g_main_argv[1], avail_size, fmt, ap);
+    va_end(ap);
+    g_main_argv[2] = nullptr;
+    return;
+  }
+#endif
+
   memset(g_argv_start, 0, avail_size + 1);
 
   size_t size;
@@ -161,8 +187,13 @@ void setproctitle_init(const char** main_argv) {
   char* argv_end = p;
   size_t environ_size = 0;
   for (size_t i = 0; environ[i]; ++i, ++environ_size) {
+#if !BUILDFLAG(IS_EFL)
+    // Chromium-efl uses setenv at few places, setenv updates the address value
+    // of the particular env. variable, so the below check would fail when we
+    // compare it with default glibc's |environ|
     if (p != environ[i])
       return;
+#endif
     p += strlen(p) + 1;
   }
   char* envp_end = p;
@@ -187,4 +218,11 @@ void setproctitle_init(const char** main_argv) {
   g_argv_start = argv_start;
   g_argv_end = argv_end;
   g_envp_end = envp_end;
+#if BUILDFLAG(IS_EFL)
+  g_main_argv = const_cast<char**>(main_argv);
+  if (argv) {
+    for (int i = 0; argv[i]; ++i)
+      g_main_argv_size += strlen(argv[i]) + 1;
+  }
+#endif
 }