Skip to content

Commit

Permalink
[nozzle] cleanup and document nozzle_set_down
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
  • Loading branch information
fabbione committed Nov 28, 2017
1 parent 21b6a6d commit 5169d51
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 11 deletions.
38 changes: 27 additions & 11 deletions libnozzle/libnozzle.c
Expand Up @@ -810,57 +810,73 @@ int nozzle_set_up(nozzle_t nozzle, char **error_preup, char **error_up)

static int _set_down(nozzle_t nozzle, char **error_down, char **error_postdown)
{
int err = 0;
int err = 0, savederrno = 0;

if (!nozzle->up)
if (!nozzle->up) {
goto out_clean;
}

memset(&nozzle->ifr, 0, sizeof(struct ifreq));
strncpy(nozzle->ifname, nozzle->nozzlename, IFNAMSIZ);

err=ioctl(lib_cfg.sockfd, SIOCGIFFLAGS, &nozzle->ifr);
if (err)
err = ioctl(lib_cfg.sockfd, SIOCGIFFLAGS, &nozzle->ifr);
if (err) {
savederrno = errno;
goto out_clean;
}

_exec_updown(nozzle, "down.d", error_down);

nozzle->ifr.ifr_flags &= ~IFF_UP;
err=ioctl(lib_cfg.sockfd, SIOCSIFFLAGS, &nozzle->ifr);

if (err)
err = ioctl(lib_cfg.sockfd, SIOCSIFFLAGS, &nozzle->ifr);
if (err) {
savederrno = errno;
goto out_clean;
}

_exec_updown(nozzle, "post-down.d", error_postdown);

nozzle->up = 0;

out_clean:
errno = savederrno;
return err;
}

int nozzle_set_down(nozzle_t nozzle, char **error_down, char **error_postdown)
{
int err = 0;
int err = 0, savederrno = 0;

pthread_mutex_lock(&lib_mutex);
if (!nozzle) {
errno = EINVAL;
return -1;
}

savederrno = pthread_mutex_lock(&lib_mutex);
if (savederrno) {
errno = savederrno;
return -1;
}

if (!_check(nozzle)) {
errno = EINVAL;
savederrno = EINVAL;
err = -1;
goto out_clean;
}

if ((nozzle->hasupdown) && ((!error_down) || (!error_postdown))) {
errno = EINVAL;
savederrno = EINVAL;
err = -1;
goto out_clean;
}

err = _set_down(nozzle, error_down, error_postdown);
savederrno = errno;

out_clean:
pthread_mutex_unlock(&lib_mutex);

errno = savederrno;
return err;
}

Expand Down
23 changes: 23 additions & 0 deletions libnozzle/libnozzle.h
Expand Up @@ -100,6 +100,29 @@ int nozzle_close(nozzle_t nozzle, char **error_down, char **error_postdown);
*/

int nozzle_set_up(nozzle_t nozzle, char **error_preup, char **error_up);

/**
* nozzle_set_down
* @brief equivalent of ifconfig down, executes down.d post-down.d
*
* nozzle - pointer to the nozzle struct
*
* error_down - pointers to string to record errors from executing down.d
* when configured. The string is malloc'ed, the caller needs to free those
* buffers.
*
* error_postdown - pointers to string to record errors from executing post-down.d
* when configured. The string is malloc'ed, the caller needs to free
* those buffers.
*
* @return
* 0 on success
* -1 on error and error is set.
* error_down / error_postdown are set to NULL if execution of external scripts
* is sucessful
* error_down / error_postdown will contain strings recording the execution error.
*/

int nozzle_set_down(nozzle_t nozzle, char **error_down, char **error_postdown);

nozzle_t nozzle_find(char *dev, size_t dev_size);
Expand Down

0 comments on commit 5169d51

Please sign in to comment.