Skip to content

Commit

Permalink
Fix problem when installing systemd hook and link already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
lpereira committed Aug 25, 2021
1 parent 2500c65 commit b6f13fb
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions hibernation-setup-tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -1472,21 +1472,10 @@ static int handle_systemd_suspend_notification(const char *argv0, const char *wh

static void link_hook(const char *src, const char *dest)
{
const char *base = strrchr(src, '/');
char full_path[PATH_MAX];
int r;

if (!base)
return log_fatal("Couldn't determine base name for '%s'", src);
base++; /* Skip / */

r = snprintf(full_path, PATH_MAX, "%s/%s", dest, base);
if (r < 0 || r > PATH_MAX)
return log_fatal("Building path for symbolic link failed");
unlink(full_path);

if (link(src, dest) < 0)
return log_fatal("Couldn't link %s to %s: %s", src, dest, strerror(errno));
if (link(src, dest) < 0) {
if (errno != EEXIST)
return log_fatal("Couldn't link %s to %s: %s", src, dest, strerror(errno));
}

log_info("Notifying systemd of new hooks");
spawn_and_wait("systemctl", 1, "daemon-reload");
Expand Down

0 comments on commit b6f13fb

Please sign in to comment.