lockfiles
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -43,6 +44,12 @@ func main() {
|
||||
}
|
||||
}()
|
||||
|
||||
myLock := "/net/corpora/nlnieuws/AT5/lock"
|
||||
mkLock(myLock)
|
||||
defer func() {
|
||||
_ = os.Remove(myLock)
|
||||
}()
|
||||
|
||||
req, err := http.NewRequest("GET", "https://rss.at5.nl/rss", nil)
|
||||
p(err)
|
||||
req.Header.Set("User-Agent", agent)
|
||||
@@ -101,3 +108,16 @@ func main() {
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
func mkLock(filename string) {
|
||||
pid := os.Getpid()
|
||||
link := fmt.Sprintf("%s.%d", filepath.Base(filename), pid)
|
||||
p(os.Symlink(link, filename))
|
||||
|
||||
name, err := os.Readlink(filename)
|
||||
p(err)
|
||||
|
||||
if name != link {
|
||||
p(fmt.Errorf("wrong lock name %q, should be %q", name, link))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user