Skip to content

Commit

Permalink
lxclock: cleanup lxclock_name()
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Dec 15, 2020
1 parent 64630ea commit 1b89b88
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions src/lxc/lxclock.c
Expand Up @@ -80,9 +80,9 @@ static void unlock_mutex(pthread_mutex_t *l)

static char *lxclock_name(const char *p, const char *n)
{
__do_free char *dest = NULL, *rundir = NULL;
int ret;
size_t len;
char *dest, *rundir;

/* lockfile will be:
* "/run" + "/lxc/lock/$lxcpath/$lxcname + '\0' if root
Expand All @@ -104,27 +104,18 @@ static char *lxclock_name(const char *p, const char *n)
return NULL;

ret = snprintf(dest, len, "%s/lxc/lock/%s", rundir, p);
if (ret < 0 || (size_t)ret >= len) {
free(dest);
free(rundir);
return NULL;
}
if (ret < 0 || (size_t)ret >= len)
return ret_set_errno(NULL, EIO);

ret = mkdir_p(dest, 0755);
if (ret < 0) {
free(dest);
free(rundir);
if (ret < 0)
return NULL;
}

ret = snprintf(dest, len, "%s/lxc/lock/%s/.%s", rundir, p, n);
free(rundir);
if (ret < 0 || (size_t)ret >= len) {
free(dest);
return NULL;
}
if (ret < 0 || (size_t)ret >= len)
return ret_set_errno(NULL, EIO);

return dest;
return move_ptr(dest);
}

static sem_t *lxc_new_unnamed_sem(void)
Expand Down

0 comments on commit 1b89b88

Please sign in to comment.