| 139 | } |
| 140 | |
| 141 | static struct subd_req *add_req(const tal_t *ctx, |
| 142 | struct subd *sd, int type, size_t num_fds_in, |
| 143 | void (*replycb)(struct subd *, const u8 *, const int *, |
| 144 | void *), |
| 145 | void *replycb_data TAKES) |
| 146 | { |
| 147 | struct subd_req *sr = tal(sd, struct subd_req); |
| 148 | |
| 149 | sr->type = type; |
| 150 | sr->replycb = replycb; |
| 151 | sr->replycb_data = replycb_data; |
| 152 | if (taken(replycb_data)) |
| 153 | tal_steal(sr, replycb_data); |
| 154 | sr->num_reply_fds = num_fds_in; |
| 155 | |
| 156 | /* We don't allocate sr off ctx, because we still have to handle the |
| 157 | * case where ctx is freed between request and reply. Hence this |
| 158 | * trick. */ |
| 159 | if (ctx) { |
| 160 | sr->disabler = notleak(tal(ctx, char)); |
| 161 | tal_add_destructor2(sr->disabler, disable_cb, sr); |
| 162 | } else |
| 163 | sr->disabler = NULL; |
| 164 | assert(strends(sd->msgname(sr->type + SUBD_REPLY_OFFSET), "_REPLY")); |
| 165 | |
| 166 | /* Keep in FIFO order: we sent in order, so replies will be too. */ |
| 167 | list_add_tail(&sd->reqs, &sr->list); |
| 168 | tal_add_destructor(sr, destroy_subd_req); |
| 169 | |
| 170 | return sr; |
| 171 | } |
| 172 | |
| 173 | /* Caller must free. */ |
| 174 | static struct subd_req *get_req(struct subd *sd, int reply_type) |