fix socket permission

This commit is contained in:
iridiumR 2023-08-07 21:51:35 +08:00
parent 64ac9ad155
commit c22f0ce97c
No known key found for this signature in database
GPG key ID: 49735733EB1A32C8
2 changed files with 9 additions and 9 deletions

View file

@ -1,6 +1,6 @@
# Maintainer: 1ridic <i@8f.al> # Maintainer: 1ridic <i@8f.al>
pkgname=uptimes pkgname=uptimes
pkgver=0.1.3 pkgver=0.1.4
pkgrel=2 pkgrel=2
pkgdesc="status of total uptime" pkgdesc="status of total uptime"
arch=('any') arch=('any')
@ -11,7 +11,7 @@ source=(
local://uptimes local://uptimes
local://uptimesd.service local://uptimesd.service
) )
md5sums=('e70411e89528c1d4f55fdbf97c4e4736' md5sums=('17dfb70e8c5d7c21d13fca3f16c07d02'
'7a90889f87792317e70ebdce9dae7023') '7a90889f87792317e70ebdce9dae7023')
package() { package() {

14
uptimes
View file

@ -90,6 +90,11 @@ def pathExists():
def daemon(fork = True): def daemon(fork = True):
global uptime, now, s global uptime, now, s
if os.path.exists(socket_file):
print('Uptimesd already running')
sys.exit(1)
# fork # fork
if fork: if fork:
pid = os.fork() pid = os.fork()
@ -132,15 +137,10 @@ def daemon(fork = True):
import setproctitle import setproctitle
setproctitle.setproctitle('uptimesd') setproctitle.setproctitle('uptimesd')
# create socket file
try:
os.unlink(socket_file)
except OSError:
if os.path.exists(socket_file):
raise
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.bind(socket_file) s.bind(socket_file)
# socket file permission 777
os.chmod(socket_file, 0o777)
s.listen(1) s.listen(1)
# handle signal # handle signal