1#	$OpenBSD: Syslogc.pm,v 1.1 2014/09/13 23:38:24 bluhm Exp $
2
3# Copyright (c) 2010-2014 Alexander Bluhm <bluhm@openbsd.org>
4#
5# Permission to use, copy, modify, and distribute this software for any
6# purpose with or without fee is hereby granted, provided that the above
7# copyright notice and this permission notice appear in all copies.
8#
9# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
17use strict;
18use warnings;
19
20package Syslogc;
21use parent 'Proc';
22use Carp;
23
24sub new {
25	my $class = shift;
26	my %args = @_;
27	$args{ktracefile} ||= "syslogc.ktrace";
28	$args{logfile} ||= "syslogc.log";
29	$args{ctlsock} ||= "ctl.sock";
30	$args{up} ||= "execute: ";
31	$args{func} = sub { Carp::confess "$class func may not be called" };
32	my $self = Proc::new($class, %args);
33
34	return $self;
35}
36
37sub child {
38	my $self = shift;
39	my @sudo = $ENV{SUDO} ? $ENV{SUDO} : ();
40
41	my @ktrace = $ENV{KTRACE} || ();
42	@ktrace = "ktrace" if $self->{ktrace} && !@ktrace;
43	push @ktrace, "-i", "-f", $self->{ktracefile} if @ktrace;
44	my @cmd = (@sudo, @ktrace, "syslogc", "-s", $self->{ctlsock});
45	push @cmd, @{$self->{options}} if $self->{options};
46	print STDERR "execute: @cmd\n";
47	exec @cmd;
48	die ref($self), " exec '@cmd' failed: $!";
49}
50
51sub down {
52	my $self = shift;
53	eval { Proc::down($self, @_) };
54	die $@ if $@ && $self->{down} ne "Shutdown";
55	return $self;
56}
57
581;
59