1
0
mirror of https://github.com/cmur2/dyndnsd.git synced 2024-12-21 14:54:22 +01:00

dyndnsd: handle potential nil cases detected by sorbet

- including review suggestions from @jgraichen
This commit is contained in:
cn 2020-02-28 16:44:27 +01:00
parent 235ff6c2bd
commit 46061a7783
4 changed files with 12 additions and 6 deletions

View File

@ -96,8 +96,14 @@ module Dyndnsd
# drop priviliges as soon as possible
# NOTE: first change group than user
Process::Sys.setgid(Etc.getgrnam(config['group']).gid) if config['group']
Process::Sys.setuid(Etc.getpwnam(config['user']).uid) if config['user']
if config['group']
group = Etc.getgrnam(config['group'])
Process::Sys.setgid(group.gid) if group
end
if config['user']
user = Etc.getpwnam(config['user'])
Process::Sys.setuid(user.uid) if user
end
setup_traps

View File

@ -14,7 +14,7 @@ module Dyndnsd
def load
if File.file?(@db_file)
@db = JSON.parse(File.open(@db_file, 'r', &:read))
@db = JSON.parse(File.read(@db_file, mode: 'r'))
else
@db = {}
end

View File

@ -42,7 +42,7 @@ module Dyndnsd
'error.kind': e.class.to_s,
'error.object': e,
message: e.message,
stack: e.backtrace.join("\n")
stack: e.backtrace&.join("\n") || ''
)
raise
ensure

View File

@ -11,7 +11,7 @@ module Dyndnsd
def update(db)
Helper.span('updater_update') do |span|
span.set_tag('dyndnsd.updater.name', self.class.name.split('::').last)
span.set_tag('dyndnsd.updater.name', self.class.name&.split('::')&.last || 'None')
# write zone file in bind syntax
File.open(@zone_file, 'w') { |f| f.write(@generator.generate(db)) }
@ -21,7 +21,7 @@ module Dyndnsd
end
# detach so children don't become zombies
Process.detach(pid)
Process.detach(pid) if pid
end
end
end