i3status-timers.json-io: make output more gently, suppress errors on unsucessful spawn
This commit is contained in:
@@ -8,7 +8,6 @@ use 5.10.0;
|
|||||||
use utf8;
|
use utf8;
|
||||||
use JSON::XS;
|
use JSON::XS;
|
||||||
use threads;
|
use threads;
|
||||||
#use Data::Dumper;
|
|
||||||
|
|
||||||
binmode STDOUT;
|
binmode STDOUT;
|
||||||
binmode STDERR;
|
binmode STDERR;
|
||||||
@@ -165,10 +164,12 @@ while (1) {
|
|||||||
$jo->[6]->{color} = '#3e78fd';
|
$jo->[6]->{color} = '#3e78fd';
|
||||||
|
|
||||||
@{$je} = (@{$jo}, @{$C});
|
@{$je} = (@{$jo}, @{$C});
|
||||||
|
|
||||||
@{$je} = reverse(@{$je});
|
@{$je} = reverse(@{$je});
|
||||||
|
|
||||||
syswrite STDOUT, encode_json($je) . ",\n";
|
if (my $output = encode_json($je)) {
|
||||||
|
syswrite STDOUT, encode_json($je) . ",\n";
|
||||||
|
}
|
||||||
|
|
||||||
$jf = 0;
|
$jf = 0;
|
||||||
}
|
}
|
||||||
# tick timers
|
# tick timers
|
||||||
@@ -501,24 +502,25 @@ sub caps_find() {
|
|||||||
|
|
||||||
sub spawn (@) {
|
sub spawn (@) {
|
||||||
my @args = @_;
|
my @args = @_;
|
||||||
|
|
||||||
# fork, detach, exec
|
|
||||||
my $pid = fork();
|
my $pid = fork();
|
||||||
|
|
||||||
if ($pid) { # Parent
|
if ($pid) { # Parent
|
||||||
1;
|
return;
|
||||||
} elsif ($pid == 0) { # Child
|
} elsif ($pid == 0) { # Child
|
||||||
|
# we need no io streams here, right?
|
||||||
close STDOUT;
|
close STDOUT;
|
||||||
close STDERR;
|
close STDERR;
|
||||||
close STDIN;
|
close STDIN;
|
||||||
my $prg = shift(@args);
|
my $prg = shift(@args);
|
||||||
|
# weird situation, silently quit here :)
|
||||||
|
exit 0 unless(defined($prg));
|
||||||
|
|
||||||
if (@args > 0) {
|
if (@args > 0) {
|
||||||
exec $prg @args;
|
exec $prg @args;
|
||||||
} else {
|
} else {
|
||||||
exec $prg;
|
exec $prg;
|
||||||
}
|
}
|
||||||
} else { # Unable to fork
|
} else { # Unable to fork()
|
||||||
die "ERROR: Could not fork new process: $!\n";
|
warn "ERROR: Could not fork new process: $!\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user