static char *pruntf(boolean log_error, char *format, ...)
{
    va_list ap;
    FILE *IF = NULL;
    int rc = -1;
    int outsize = 1025;
    char cmd[1024] = { 0 };
    size_t bytes = 0;
    char *output = NULL;

    va_start(ap, format);
    vsnprintf(cmd, 1024, format, ap);

    strncat(cmd, " 2>&1", 1024 - 1);
    output = NULL;

    IF = popen(cmd, "r");
    if (!IF) {
        LOGERROR("cannot popen() cmd '%s' for read\n", cmd);
        va_end(ap);
        return (NULL);
    }

    output = EUCA_ALLOC(outsize, sizeof(char));
    if (output) {
        output[0] = '\0';              // make sure we return an empty string if there is no output
    }

    while ((output != NULL) && (bytes = fread(output + (outsize - 1025), 1, 1024, IF)) > 0) {
        output[(outsize - 1025) + bytes] = '\0';
        outsize += 1024;
        output = EUCA_REALLOC(output, outsize, sizeof(char));
    }

    if (output == NULL) {
        LOGERROR("failed to allocate mem for output\n");
        va_end(ap);
        pclose(IF);
        return (NULL);
    }

    rc = pclose(IF);
    if (rc) {
        //! @TODO improve this hacky special case: failure to find or detach non-existing loop device is not a failure
        if (strstr(cmd, "losetup") && strstr(output, ": No such device or address")) {
            rc = 0;
        } else {
            if (log_error) {
                LOGERROR("bad return code from cmd '%s'\n", cmd);
                LOGDEBUG("%s\n", output);
            }
            EUCA_FREE(output);
        }
    }
    va_end(ap);

    return (output);
}
static char *pruntf(boolean log_error, char *format, ...)
{
    va_list ap;
    FILE *IF = NULL;
    int rc = -1;
    int outsize = 1025;
    char cmd[1024] = { 0 };
    size_t bytes = 0;
    char *output = NULL;

    va_start(ap, format);
    vsnprintf(cmd, 1024, format, ap);

    strncat(cmd, " 2>&1", 1024 - 1);
    output = NULL;

    IF = popen(cmd, "r");
    if (!IF) {
        LOGERROR("cannot popen() cmd '%s' for read\n", cmd);
        va_end(ap);
        return (NULL);
    }

    output = EUCA_ALLOC(outsize, sizeof(char));
    if (output) {
        output[0] = '\0';               
    }

    while ((output != NULL) && (bytes = fread(output + (outsize - 1025), 1, 1024, IF)) > 0) {
        output[(outsize - 1025) + bytes] = '\0';
        outsize += 1024;
        output = EUCA_REALLOC(output, outsize, sizeof(char));
    }

    if (output == NULL) {
        LOGERROR("failed to allocate mem for output\n");
        va_end(ap);
        pclose(IF);
        return (NULL);
    }

    rc = pclose(IF);
    if (rc) {
         
        if (strstr(cmd, "losetup") && strstr(output, ": No such device or address")) {
            rc = 0;
        } else {
            if (log_error) {
                LOGERROR("bad return code from cmd '%s'\n", cmd);
                LOGDEBUG("%s\n", output);
            }
            EUCA_FREE(output);
        }
    }
    va_end(ap);

    return (output);
}