+static int gc_close(struct grab_client *gc, int err)
+{
+ btr_remove_node(&gc->btrn);
+ PARA_INFO_LOG("closing gc: %s\n", para_strerror(-err));
+ list_move(&gc->node, &inactive_grab_client_list);
+ if (err == -E_GC_WRITE || (gc->flags & GF_ONE_SHOT)) {
+ /*
+ * We must not free the gc structure here as it contains ->task
+ * which is still used because this function is called from
+ * post_select().
+ */
+ close(gc->fd);
+ gc->fd = -1;
+ free(gc->parent);
+ free(gc->name);
+ return 1;
+ }
+ return 0;
+}
+
+static int gc_post_select(__a_unused struct sched *s, struct task *t)
+{
+ struct grab_client *gc = container_of(t, struct grab_client, task);
+ struct btr_node *btrn = gc->btrn;
+ int ret;
+ size_t sz;
+ char *buf;
+
+ ret = btr_node_status(btrn, 0, BTR_NT_LEAF);
+ if (ret == 0)
+ return 0;
+ if (ret < 0)
+ goto err;
+ sz = btr_next_buffer(btrn, &buf);
+ assert(sz != 0);
+ ret = gc_write(gc, buf, sz);
+ if (ret < 0)
+ goto err;
+ if (ret > 0)
+ btr_consume(btrn, ret);
+ return 0;
+err:
+ gc_close(gc, ret);
+ return ret;
+}
+
+static int gc_check_args(int argc, char **argv, struct grab_client *gc)