- f = fopen(unit, "wxe");
- if (!f) {
- log_error("Failed to create unit file %s: %m", unit);
- return -errno;
+ /* We might already have a symlink with the same name from a Provides:,
+ * or from backup files like /etc/init.d/foo.bak. Real scripts always win,
+ * so remove an existing link */
+ if (is_symlink(unit)) {
+ log_warning("Overwriting existing symlink %s with real service", unit);
+ (void) unlink(unit);