summaryrefslogtreecommitdiff
path: root/scripts/system/vyatta_update_syslog.pl
blob: 315e2a9f0c15cd635b94dc94002b0aeefb699e98 (plain)
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
49
50
51
52
53
54
55
56
#!/usr/bin/perl

use strict;
my $SYSLOG_CONF = '/etc/syslog.conf';

my $match1 = shift;
my $match2 = shift;
my $update_line = shift;

if (!defined($match1) || !defined($match2) || !defined($update_line)) {
  exit 1;
}

if (system("touch $SYSLOG_CONF")) {
  exit 2;
}

my $exp1 = "";
my $exp2 = "";
if ($match1 ne "") {
  $exp1 = $match1;
  if ($match2 ne "") {
    $exp2 = $match2;
  }
} elsif ($match2 ne "") {
  $exp1 = $match2;
}

if ($exp2 ne "") {
  if (system("sed -i '/$exp1/{/$exp2/d}' $SYSLOG_CONF")) {
    exit 2;
  }
} elsif ($exp1 ne "") {
  if (system("sed -i '/$exp1/d' $SYSLOG_CONF")) {
    exit 3;
  }
}

open(OUT, ">>$SYSLOG_CONF") or exit 4;
if ($update_line ne "") {
  print OUT "$update_line";
}
close OUT;

sleep 1;
# XXX somehow starting syslogd with 'start-stop-daemon --start...' here fails
# with SEGV (?). just start syslogd directly.
#if (system("/opt/vyatta/sbin/sysklogd.init restart")) {
system("/opt/vyatta/sbin/sysklogd.init stop");
sleep 1;
if (system(". /etc/default/syslogd ; /sbin/syslogd \$SYSLOGD")) {
  exit 5;
}

exit 0;