Returns config file name if not writable */
| 622 | |
| 623 | /* Returns config file name if not writable */ |
| 624 | static const char *config_not_writable(const tal_t *ctx, |
| 625 | struct command *cmd, |
| 626 | const struct configvar *oldcv) |
| 627 | { |
| 628 | struct lightningd *ld = cmd->ld; |
| 629 | const char *fname; |
| 630 | |
| 631 | /* If it exists before, we will need to replace that file (rename) */ |
| 632 | if (oldcv && oldcv->file) { |
| 633 | /* We will rename */ |
| 634 | if (!dir_writable(oldcv->file)) |
| 635 | return oldcv->file; |
| 636 | } |
| 637 | |
| 638 | /* If we don't have a setconfig file we'll have to create it, and |
| 639 | * amend the config file. */ |
| 640 | if (!ld->setconfig_file) { |
| 641 | fname = base_conf_file(tmpctx, ld, NULL); |
| 642 | if (!dir_writable(fname)) |
| 643 | return tal_steal(ctx, fname); |
| 644 | } else { |
| 645 | /* We will try to append config.setconfig */ |
| 646 | if (!file_writable(ld->setconfig_file)) |
| 647 | return tal_strdup(ctx, ld->setconfig_file); |
| 648 | } |
| 649 | return NULL; |
| 650 | } |
| 651 | |
| 652 | static struct command_result *json_setconfig(struct command *cmd, |
| 653 | const char *buffer, |
no test coverage detected