ifupdown: make the locking errors more useful

This commit is contained in:
Ariadne Conill 2020-07-29 03:13:34 -06:00
parent 0ca8e42ee6
commit c71c01862d

View file

@ -109,14 +109,14 @@ acquire_state_lock(const char *state_path, const char *lifname)
};
if (exec_opts.verbose)
fprintf(stderr, "ifupdown: acquiring lock on %s\n", lockpath);
fprintf(stderr, "%s: acquiring lock on %s\n", argv0, lockpath);
if (fcntl(fd, F_SETLKW, &fl) == -1)
if (fcntl(fd, F_SETLK, &fl) == -1)
{
close(fd);
fprintf(stderr, "locking lockfile: %s\n", strerror(errno));
return -1;
return -2;
}
return fd;
@ -127,6 +127,12 @@ change_interface(struct lif_interface *iface, struct lif_dict *collection, struc
{
int lockfd = acquire_state_lock(exec_opts.state_file, ifname);
if (lockfd == -2)
{
fprintf(stderr, "%s: could not acquire exclusive lock for %s\n", argv0, ifname);
return false;
}
if (exec_opts.verbose)
{
fprintf(stderr, "%s: changing state of interface %s to '%s'\n",