File: bugfix-106571_odd_process_name.t

package info (click to toggle)
libproc-processtable-perl 0.637-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 672 kB
  • sloc: ansic: 5,765; perl: 568; makefile: 15
file content (48 lines) | stat: -rw-r--r-- 1,324 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use warnings;
use Test::More;
use Data::Dumper;

BEGIN {
  use_ok('Proc::ProcessTable');
}

SKIP: {
  $0 = "PROC_PROCESSTABLE_TEST_CMD";
  sleep(1);

  my ($ps) = grep {/^$$\s+/} map { chomp; s/^\s*//; $_ } `ps xww`;
  skip 'Cannot set process name', 1
    unless ($ps && $ps =~ /PROC_PROCESSTABLE_TEST_CMD/);

  # From Joelle Maslak: Can't set a process name to a blank name on
  # OpenBSD, so this test is not relevant.  From reading perlvar, it
  # appears that this is likely true on other BSDs, so rather than
  # looking for the OpenBSD operating system, we see if the command line
  # starts with "perl:" as it does on OpenBSD (and presumably other
  # BSDs).  See OpenBSD's setproctitle(3) for information on what at
  # least OpenBSD allows:
  #   https://man.openbsd.org/setproctitle.3
  skip 'Likely *BSD system, can\'t blank process name', 1
    unless ($ps =~ /^perl: /);

  $SIG{CHLD} = 'IGNORE';

  my $pid = fork;
  die "cannot fork" unless defined $pid;

  if ($pid == 0) {
    #child
    $0 = '';
    sleep 10000;
  } else {
    #main
    sleep 1;
    my $t           = Proc::ProcessTable->new;
    my $cmnd_quoted = '';
    my ($p) = grep { $_->{pid} == $pid } @{ $t->table };
    is($p->{cmndline}, $cmnd_quoted, "odd process commandline bugfix ($cmnd_quoted)");
    kill 9, $pid;
  }
}
done_testing();