With LITE_FOPT_RSYNC_LINKS, rsync() leaves symlinks in the destination.
If the source later has a regular file or a directory by the same name,
the next run follows the old link and writes to whatever it points at,
which can be outside the destination tree.
Remove such a link before copying.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
Fixing LITE_FOPT_COPYFILE_SYM in copyfile() also changed rsync(), which
has always passed that flag. Every caller would start getting links in
the destination where they used to get a copy of the file.
Keep following links by default and add LITE_FOPT_RSYNC_LINKS for
callers that want them recreated.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
Inspect source links without following them when COPYFILE_SYM is requested, before rejecting directories. This makes the documented option recreate link text instead of copying the referent, including dangling and directory links. Preserve requested link timestamps and report link-creation errors without overwriting the destination. Cover direct calls, destination directories, normal dereferencing and the existing rsync file caller.
Copy the bytes returned by fread instead of treating each input chunk as a NUL-terminated string. Preserve the public stream positions and report read and write failures rather than returning success after a partial copy. Add binary boundary, current-position, native pipe error and full-device regression coverage.
copyfile() passes the source mode to open(2), which applies the umask,
so a 0644 file copied with umask 0027 ends up 0640.
Apply the source mode with fchmod() after creating the destination.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
mkpath(dir, 0755) with umask 0027 silently creates a 0750 directory,
since mkdir(2) applies the umask to the requested mode. Callers pass
an explicit mode and expect exactly that.
Apply the mode with chmod() after each successful mkdir().
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
Avoid leaking memory when realloc() fails by using a temporary pointer
and only updating the original on success. Also remove redundant NULL
check before free().
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
For some builds using Buildroot, the system default _PATH_VARRUN did not
include a trailing slas '/', which cause the pidfile() function to fail.
Example:
pidfile("arg") => "/var/runarg.pid"
Since the __pidfile_path can be overridden we add a check if that prefix
path ends with '/', if not we add one in the path composition.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
The runbg() function is a delayed execvp() that has double-forked to the
background (to not create zombies). It is useful for running commands
in the background for APIs that need to return a reply, e.g. a NETCONF
RPC to reboot the system.
Compared to the original in Infix, this version double forks to reparent
itself to PID 1 (init), closes all open files, including stdio.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>