Listing 3. demo_disconnect Function

static void demo_disconnect(vfs_handle_struct *handle)
{
    int res = 0, *thread_res = NULL;
    struct demo_struct *ctx;
    struct cmd_struct *cmd;

    /* Let the next module do any cleanup it needs to */
    SMB_VFS_NEXT_DISCONNECT(handle);

    SMB_VFS_HANDLE_GET_DATA(handle,
                            ctx,
                            struct demo_struct,
                            goto ctx_error);

    /*
     * Tell the background thread to exit
     */
    cmd = create_cmd(ctx, LOG_EXIT, NULL);
    if (!cmd || !send_cmd(cmd)) {
            return;  /* Not much more to do here ... kill the thread? */
    }

    res = pthread_join(ctx->log_thread, (void **)&thread_res);
    if (res || *thread_res) {
            DEBUG(10, ("Error cleaning up thread: res: %s, "
                       "thread_res: %s\n",
                       strerror(errno), strerror(*thread_res)));
            return;
    }

    /*
     * This is not absolutely needed since that structure used
     * the handle as a talloc context ...
     */
    talloc_free(ctx);

    return;
ctx_error:
    DEBUG(10, ("Error getting context for connection!\n"));
    return;
}