fix: use os.Executable instead of os.Args[0] to get prog path

This commit is contained in:
go-compile 2024-02-20 13:32:19 +00:00
parent 60177cebf2
commit 2c4ebe71d9
No known key found for this signature in database
GPG key ID: 53F4922E9D5497B8

View file

@ -708,10 +708,13 @@ func secureBinaryUnix() error {
}
// Get current file path
binary := os.Args[0]
binary, err := os.Executable()
if err != nil {
return err
}
// Change owner to root:root
err := os.Chown(binary, 0, 0)
err = os.Chown(binary, 0, 0)
if err != nil {
return err
}
@ -724,6 +727,7 @@ func secureBinaryUnix() error {
}
// Move binary to the PATH in a folder which is read-only to non root users
// If already moved, this is a no-op
if err := os.Rename(binary, "/usr/bin/AdGuardHome"); err != nil {
return err
}