Hello, in the following section of code, there's several return err that may result in an empty file or potentially partially-written file being left on disk, but skipping the systemctl commands, etc:
I don't know golang's templating system well -- will this perform a single atomic write to disk? Or will it perform a series of writes while executing the template?
The usual posix pattern for writing files is to create a temporary file in the correct directory with a randomly-generated name (eg mkstemp(3)), perform the operations, confirm the file is saved via checking the return value of close(2), and then perform a rename(2) operation, since that is one of the few atomic tools available.
Hello, in the following section of code, there's several
return err
that may result in an empty file or potentially partially-written file being left on disk, but skipping the systemctl commands, etc:https://github.com/kardianos/service/blob/a1c091bc7f8b6d1a8d28b47d8cf22068608051ef/service_systemd_linux.go#L142
I don't know golang's templating system well -- will this perform a single atomic write to disk? Or will it perform a series of writes while executing the template?
The usual posix pattern for writing files is to create a temporary file in the correct directory with a randomly-generated name (eg
mkstemp(3)
), perform the operations, confirm the file is saved via checking the return value ofclose(2)
, and then perform arename(2)
operation, since that is one of the few atomic tools available.Thanks