Mercurial > prosody-hg
comparison plugins/mod_posix.lua @ 2456:260601859c9f
mod_posix: Adjust file open mode depending on whether file exists (take that fopen designers!!!)
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Wed, 13 Jan 2010 00:03:22 +0000 |
| parents | 0b3184f3c9e4 |
| children | 692b3c6c5bd2 |
comparison
equal
deleted
inserted
replaced
| 2455:0b3184f3c9e4 | 2456:260601859c9f |
|---|---|
| 18 end | 18 end |
| 19 | 19 |
| 20 local logger_set = require "util.logger".setwriter; | 20 local logger_set = require "util.logger".setwriter; |
| 21 | 21 |
| 22 local lfs = require "lfs"; | 22 local lfs = require "lfs"; |
| 23 local stat = lfs.attributes; | |
| 23 | 24 |
| 24 local prosody = _G.prosody; | 25 local prosody = _G.prosody; |
| 25 | 26 |
| 26 module.host = "*"; -- we're a global module | 27 module.host = "*"; -- we're a global module |
| 27 | 28 |
| 79 if pidfile_handle then | 80 if pidfile_handle then |
| 80 remove_pidfile(); | 81 remove_pidfile(); |
| 81 end | 82 end |
| 82 pidfile = module:get_option("pidfile"); | 83 pidfile = module:get_option("pidfile"); |
| 83 if pidfile then | 84 if pidfile then |
| 84 pidfile_handle, err = io.open(pidfile, "a+"); | 85 local mode = stat(pidfile) and "r+" or "w+"; |
| 86 pidfile_handle, err = io.open(pidfile, mode); | |
| 85 if not pidfile_handle then | 87 if not pidfile_handle then |
| 86 module:log("error", "Couldn't write pidfile at %s; %s", pidfile, err); | 88 module:log("error", "Couldn't write pidfile at %s; %s", pidfile, err); |
| 87 prosody.shutdown("Couldn't write pidfile"); | 89 prosody.shutdown("Couldn't write pidfile"); |
| 88 else | 90 else |
| 89 if not lfs.lock(pidfile_handle, "w") then -- Exclusive lock | 91 if not lfs.lock(pidfile_handle, "w") then -- Exclusive lock |
