blob: 105d186c007f867085361915f83697c374bca42d (
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
57
58
59
60
61
62
63
|
#!/usr/local/bin/perl
use strict;
use warnings;
use Capture::Tiny qw(capture);
use WWW::Curl::Easy;
use constant {
PGREP_PATH => '/bin/pgrep',
GIT_PATH => '/usr/local/bin/git',
QTOX_PATH => '/usr/local/bin/qtox'
};
use constant NETWORK_TEST_URL => 'https://www.freebsd.org/';
sub run_if_dead
{
my @argv = @_;
my $bin;
my $pid;
$bin = $argv[0];
$bin =~ s/.+\///g;
my (undef, undef, $retval) = capture {
system(
PGREP_PATH,
$bin
);
};
$retval = ($retval >> 8) & 0xff;
if ($retval != 0) {
$pid = fork();
if (not $pid) {
exec(@argv);
exit;
}
}
return;
}
sub run_network_programs
{
my $curl;
my $response_body;
$curl = WWW::Curl::Easy->new;
$curl->setopt(CURLOPT_URL, NETWORK_TEST_URL);
$curl->setopt(CURLOPT_WRITEDATA, \$response_body);
if ($curl->perform == 0) {
system(GIT_PATH, '-C', '/usr/home/jozan/.elfeed', 'pull', 'origin', 'master');
run_if_dead(QTOX_PATH);
}
return;
}
sub main
{
run_network_programs();
return;
}
main();
__END__
|