Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we use proper process name instead of linker-36cefa356... #57

Open
ibroheem opened this issue Oct 10, 2020 · 2 comments
Open

Can we use proper process name instead of linker-36cefa356... #57

ibroheem opened this issue Oct 10, 2020 · 2 comments

Comments

@ibroheem
Copy link

When app is run from bin/app, you get linker-36cefa356a7da068c94decf04caef852f344a44e9930131b41826c860ffa0135 in OS process list.
Is there a way to get the name app in process list ?

Thanks.

@sangaline
Copy link
Member

Kind of. We can change arg[0] to whatever we want when invoking the linker, by doing something like:

diff --git a/src/exodus_bundler/templates/launcher.c b/src/exodus_bundler/templates/launcher.c
index 324ceb9..aec8fe0 100644
--- a/src/exodus_bundler/templates/launcher.c
+++ b/src/exodus_bundler/templates/launcher.c
@@ -53,7 +53,7 @@ int main(int argc, char *argv[])  {
         // Construct all of the arguments for the linker.
         char *linker_args[] = { "--library-path", library_path, "--inhibit-rpath", "", "--inhibit-cache" };
         char **combined_args = malloc(sizeof(linker_args) + sizeof(char*) * (argc + 1));
-        combined_args[0] = linker_basename;
+        combined_args[0] = executable;
         memcpy(combined_args + 1, linker_args, sizeof(linker_args));
         // We can't use `--inhinit-rpath` or `--inhibit-cache` with the musl linker.
         int offset = (sizeof(linker_args) / sizeof(char*)) + 1 - ({{full_linker}} ? 0 : 3);
diff --git a/src/exodus_bundler/templates/launcher.sh b/src/exodus_bundler/templates/launcher.sh
index 79311ec..586a41d 100644
--- a/src/exodus_bundler/templates/launcher.sh
+++ b/src/exodus_bundler/templates/launcher.sh
@@ -6,7 +6,7 @@ library_path="{{library_path}}"
 library_path="${current_directory}/${library_path//:/:${current_directory}/}"
 linker="${current_directory}/{{linker_dirname}}/{{linker_basename}}"
 if [ "{{full_linker}}" == "true" ]; then
-    exec "${linker}" --library-path "${library_path}" --inhibit-rpath "" "${executable}" "$@"
+    exec -a {{executable}} "${linker}" --library-path "${library_path}" --inhibit-rpath "" "${executable}" "$@"
 else
-    exec "${linker}" --library-path "${library_path}" "${executable}" "$@"
+    exec -a {{executable}} "${linker}" --library-path "${library_path}" "${executable}" "$@"
 fi

This would change the apparent process name from

/tmp/exodus/bundles/170e6a4a1292a96b07961b262a1904215d042b3c6ca9150a9bc39490c1b9c725/usr/bin/./linker-1942ca1a8b346213b59b23e9d741cd02252a0a22fb9ae4e1d092f044da4e19ec --library-path /tmp/exodus/bundles/170e6a4a1292a96b07961b262a1904215d042b3c6ca9150a9bc39490c1b9c725/usr/bin/../lib/root:/tmp/exodus/bundles/170e6a4a1292a96b07961b262a1904215d042b3c6ca9150a9bc39490c1b9c725/usr/bin/../lib/python2.7:/tmp/exodus/bundles/170e6a4a1292a96b07961b262a1904215d042b3c6ca9150a9bc39490c1b9c725/usr/bin/../../opt/java/lib:/tmp/exodus/bundles/170e6a4a1292a96b07961b262a1904215d042b3c6ca9150a9bc39490c1b9c725/usr/bin/../../opt/java/jre/lib:/tmp/exodus/bundles/170e6a4a1292a96b07961b262a1904215d042b3c6ca9150a9bc39490c1b9c725/usr/bin/../../home/sangaline/projects/exodus/lib:/tmp/exodus/bundles/170e6a4a1292a96b07961b262a1904215d042b3c6ca9150a9bc39490c1b9c725/usr/bin/../../lib64:/tmp/exodus/bundles/170e6a4a1292a96b07961b262a1904215d042b3c6ca9150a9bc39490c1b9c725/usr/bin/../lib64:/tmp/exodus/bundles/170e6a4a1292a96b07961b262a1904215d042b3c6ca9150a9bc39490c1b9c725/usr/bin/../../lib:/tmp/exodus/bundles/170e6a4a1292a96b07961b262a1904215d042b3c6ca9150a9bc39490c1b9c725/usr/bin/../lib:/tmp/exodus/bundles/170e6a4a1292a96b07961b262a1904215d042b3c6ca9150a9bc39490c1b9c725/usr/bin/../../lib32:/tmp/exodus/bundles/170e6a4a1292a96b07961b262a1904215d042b3c6ca9150a9bc39490c1b9c725/usr/bin/../lib32 --inhibit-rpath /tmp/exodus/bundles/170e6a4a1292a96b07961b262a1904215d042b3c6ca9150a9bc39490c1b9c725/usr/bin/./htop-x

to:

./htop --library-path /tmp/exodus/bundles/170e6a4a1292a96b07961b262a1904215d042b3c6ca9150a9bc39490c1b9c725/usr/bin/../lib/root:/tmp/exodus/bundles/170e6a4a1292a96b07961b262a1904215d042b3c6ca9150a9bc39490c1b9c725/usr/bin/../lib/python2.7:/tmp/exodus/bundles/170e6a4a1292a96b07961b262a1904215d042b3c6ca9150a9bc39490c1b9c725/usr/bin/../../opt/java/lib:/tmp/exodus/bundles/170e6a4a1292a96b07961b262a1904215d042b3c6ca9150a9bc39490c1b9c725/usr/bin/../../opt/java/jre/lib:/tmp/exodus/bundles/170e6a4a1292a96b07961b262a1904215d042b3c6ca9150a9bc39490c1b9c725/usr/bin/../../home/sangaline/projects/exodus/lib:/tmp/exodus/bundles/170e6a4a1292a96b07961b262a1904215d042b3c6ca9150a9bc39490c1b9c725/usr/bin/../../lib64:/tmp/exodus/bundles/170e6a4a1292a96b07961b262a1904215d042b3c6ca9150a9bc39490c1b9c725/usr/bin/../lib64:/tmp/exodus/bundles/170e6a4a1292a96b07961b262a1904215d042b3c6ca9150a9bc39490c1b9c725/usr/bin/../../lib:/tmp/exodus/bundles/170e6a4a1292a96b07961b262a1904215d042b3c6ca9150a9bc39490c1b9c725/usr/bin/../lib:/tmp/exodus/bundles/170e6a4a1292a96b07961b262a1904215d042b3c6ca9150a9bc39490c1b9c725/usr/bin/../../lib32:/tmp/exodus/bundles/170e6a4a1292a96b07961b262a1904215d042b3c6ca9150a9bc39490c1b9c725/usr/bin/../lib32 --inhibit-rpath /tmp/exodus/bundles/170e6a4a1292a96b07961b262a1904215d042b3c6ca9150a9bc39490c1b9c725/usr/bin/./htop-x

The reason that I didn't do this initially is because I think it's misleading to show the linker arguments as though they're arguments to the bundled binary when it is, after all, the linker that is being executed and passed these arguments. This also only changes /proc/$pid/cmdline, but not the process name in /proc/$pid/status, so the changes will be reflected with ps -ax but not in ps.

Maybe a comprise would be to set arg[0] to something like htop-linker? I would love a solution that could rewrite things more completely, but I'm not personally aware of one.

@amosbird
Copy link

amosbird commented Jan 8, 2022

We can generate linker hardlinks per executable with the correct name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants