static int unix_sockaddr_cleanup()

in watchman.c [173:192]


static int unix_sockaddr_cleanup(struct unix_sockaddr_context *ctx, struct watchman_error *error)
{
    int ret = 0;
    if (!ctx->orig_dir) {
        return 0;
    }
    /*
     * If we fail, we have moved the cwd of the whole process, which
     * could confuse calling code.  But we don't want to just die, because
     * libraries shouldn't do that.  So we'll return an error but be
     * sad about it.
     */
    if (chdir(ctx->orig_dir) < 0) {
        watchman_err(error, WATCHMAN_ERR_CWD,
                     "unable to restore original working directory");
        ret = -1;
    }
    free(ctx->orig_dir);
    return ret;
}