summaryrefslogtreecommitdiffstats
path: root/.config/bspwm/network_thread.pl
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-08-15 14:31:32 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-08-15 14:31:32 +0200
commitebad0a066f2814abae9563f050a4f5c62e3251f6 (patch)
tree5205d9bc006acf367d274c037e13e1dcd0f1d244 /.config/bspwm/network_thread.pl
parentdiff (diff)
downloaddotfiles-bsd-ebad0a066f2814abae9563f050a4f5c62e3251f6.tar.gz
dotfiles-bsd-ebad0a066f2814abae9563f050a4f5c62e3251f6.tar.bz2
dotfiles-bsd-ebad0a066f2814abae9563f050a4f5c62e3251f6.tar.xz
dotfiles-bsd-ebad0a066f2814abae9563f050a4f5c62e3251f6.tar.zst
dotfiles-bsd-ebad0a066f2814abae9563f050a4f5c62e3251f6.zip
Threaded bspwm
Diffstat (limited to '.config/bspwm/network_thread.pl')
-rwxr-xr-x.config/bspwm/network_thread.pl63
1 files changed, 63 insertions, 0 deletions
diff --git a/.config/bspwm/network_thread.pl b/.config/bspwm/network_thread.pl
new file mode 100755
index 0000000..105d186
--- /dev/null
+++ b/.config/bspwm/network_thread.pl
@@ -0,0 +1,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__