diff options
author | Ævar Arnfjörð Bjarmason <avar@cpan.org> | 2010-04-15 17:12:04 +0000 |
---|---|---|
committer | Steffen Mueller <smueller@cpan.org> | 2010-04-15 19:50:48 +0200 |
commit | 7636ea95c57762930accf4358f7c0c2dec086b5e (patch) | |
tree | 32db84fa5f459bc2276fe180194ba66333fdf7c4 /mg.c | |
parent | 17fddc5cffca4f968d3565ff012c0cfb3af40d68 (diff) | |
download | perl-7636ea95c57762930accf4358f7c0c2dec086b5e.tar.gz |
Set the legacy process name with prctl() on assignment to $0 on Linux
Ever since perl 4.000 we've only set the POSIX process name via
argv[0]. Unfortunately on Linux the POSIX name isn't used by utilities
like top(1), ps(1) and killall(1).
Now when we set C<$0 = "hello"> both C<qx[ps h $$]> (POSIX) and
C<qx[ps hc $$]> (legacy) will say "hello", instead of the latter being
"perl" as was previously the case.
See also the March 9 2010 thread "Why doesn't assignment to $0 on
Linux also call prctl()?" on perl5-porters.
Diffstat (limited to 'mg.c')
-rw-r--r-- | mg.c | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -57,6 +57,10 @@ tie. # include <sys/pstat.h> #endif +#ifdef HAS_PRCTL_SET_NAME +# include <sys/prctl.h> +#endif + #if defined(HAS_SIGACTION) && defined(SA_SIGINFO) Signal_t Perl_csighandler(int sig, siginfo_t *, void *); #else @@ -2823,6 +2827,13 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg) PL_origargv[0][PL_origalen-1] = 0; for (i = 1; i < PL_origargc; i++) PL_origargv[i] = 0; +#ifdef HAS_PRCTL_SET_NAME + /* Set the legacy process name in addition to the POSIX name on Linux */ + if (prctl(PR_SET_NAME, (unsigned long)s, 0, 0, 0) != 0) { + /* diag_listed_as: SKIPME */ + Perl_croak(aTHX_ "Can't set $0 with prctl(): %s", Strerror(errno)); + } +#endif } #endif UNLOCK_DOLLARZERO_MUTEX; |