Permalink
Browse files

split poorly named daemonize() into killOthers() + savePid()

  • Loading branch information...
1 parent 15ea3c1 commit 8bef835f2cdce5337f29d92123206b854b919b14 @teleshoes committed May 9, 2012
Showing with 6 additions and 4 deletions.
  1. +6 −4 led-controls/led-batt
View
@@ -21,10 +21,12 @@ my $usage = "Usage:
$0 o g 0.1 O 0.1 o G 0.1 g 0.1 O G 0.1
";
-sub daemonize(){
+sub killOthers(){
if(-e $pidfile){
system "kill -9 `cat $pidfile` 2>/dev/null";
}
+}
+sub savePid(){
system "echo $$ > $pidfile";
}
@@ -51,15 +53,15 @@ sub performCmd($){
sub main(@){
die $usage if @_ == 0;
if(@_ == 1 and $_[0] eq '--stop'){
- daemonize();
+ killOthers();
exit;
}
for my $cmd(@_){
die $usage if $cmd !~ /^(o|O|g|G|\d+|\d*\.\d+)$/;
}
-
- daemonize();
+ killOthers();
+ savePid();
while(1){
performCmd $_ foreach @_;
}

0 comments on commit 8bef835

Please sign in to comment.