6 @signal_names = split ' ', $Config{'sig_name'};
7 @signal_numbers{@signal_names} = split ' ', $Config{'sig_num'};
10 $0 = 'dmaster-signal';
11 $daemon_id = shift @ARGV;
12 $signal = shift @ARGV;
14 unless($daemon_id and defined $signal)
16 pod2usage
(-exitval
=>2, -verbose
=>99);
19 $signal_num = $signal_numbers{$signal} // $signal;
20 die "$0: unknown signal: $signal\n" unless $signal_num =~ /^\d+$/;
23 $management_socket_path = ($ENV{'XDG_CACHE_HOME'} || '/var/run').'/dmaster.sock';
24 $management_socket_addr = sockaddr_un
($management_socket_path);
25 socket($management_socket, AF_UNIX
, SOCK_STREAM
, 0) or die "socket: $!\n";
26 connect($management_socket, $management_socket_addr) or die "connect: $management_socket_path: $!\n";
28 while(<$management_socket>)
32 if(/^dmaster\.pid\s+(\d+)$/)
36 elsif(/^daemon\.(.+)\.pidfd\.fileno\s+(\d+)$/ and $1 eq $daemon_id)
44 die "$0: could not find dmaster pid\n";
48 die "$0: could not find daemon's pidfd: $daemon_id\n";
54 $dmaster_pidfd = syscall SYS_pidfd_open
(), int $dmaster_pid, $flags;
55 if($dmaster_pidfd == -1)
57 die "pidfd_open: $!\n";
63 $pidfd = syscall SYS_pidfd_getfd
(), int $dmaster_pidfd, int $target_pidfd, $flags;
66 die "pidfd_getfd: $!\n";
70 print {$management_socket} "\n";
71 close $management_socket;
76 $ret = syscall SYS_pidfd_send_signal
(), int $pidfd, int $signal_num, undef, $flags;
79 die "pidfd_send_signal: $!\n";
92 dmaster-signal - Send a signal to a daemon managed by dmaster
96 dmaster-signal I<DAEMON-ID> I<SIGNAL>
100 dmaster-signal(1) utilizes PIDFD to reliably send signal to the daemon
101 managed by dmaster(1) and specified by I<DAEMON-ID>.
103 I<SIGNAL> is either numeric or symbolic signal name.
107 dmaster(1), pidfd_send_signal(2), signal(7)