errno_t sssctl_run_command(const char *const argv[])
{
    int ret;
    int wstatus;

    DEBUG(SSSDBG_TRACE_FUNC, "Running '%s'\n", argv[0]);

    ret = fork();
    if (ret == -1) {
        ERROR("Error while executing external command\n");
        return EFAULT;
    }

    if (ret == 0) {
        /* cast is safe - see
        https://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html
        "The statement about argv[] and envp[] being constants ... "
        */
        execvp(argv[0], discard_const_p(char * const, argv));
        ERROR("Error while executing external command\n");
        _exit(1);
    } else {
        if (waitpid(ret, &wstatus, 0) == -1) {
            ERROR("Error while executing external command '%s'\n", argv[0]);
            return EFAULT;
        } else if (WEXITSTATUS(wstatus) != 0) {
            ERROR("Command '%s' failed with [%d]\n",
                  argv[0], WEXITSTATUS(wstatus));
            return EIO;
        }
    }

    return EOK;
}
errno_t sssctl_run_command(const char *const argv[])
{
    int ret;
    int wstatus;

    DEBUG(SSSDBG_TRACE_FUNC, "Running '%s'\n", argv[0]);

    ret = fork();
    if (ret == -1) {
        ERROR("Error while executing external command\n");
        return EFAULT;
    }

    if (ret == 0) {
         
        execvp(argv[0], discard_const_p(char * const, argv));
        ERROR("Error while executing external command\n");
        _exit(1);
    } else {
        if (waitpid(ret, &wstatus, 0) == -1) {
            ERROR("Error while executing external command '%s'\n", argv[0]);
            return EFAULT;
        } else if (WEXITSTATUS(wstatus) != 0) {
            ERROR("Command '%s' failed with [%d]\n",
                  argv[0], WEXITSTATUS(wstatus));
            return EIO;
        }
    }

    return EOK;
}