utils: remove tal_tmpctx altogether, use global.

In particular, we now only free tmpctx at the end of main().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2018-03-15 16:40:20 +10:30
parent 40fe5b7bac
commit 0a6e3d1e13
45 changed files with 115 additions and 375 deletions

View File

@@ -93,11 +93,9 @@ static const char *daemons[] = {
void test_daemons(const struct lightningd *ld)
{
size_t i;
const tal_t *ctx = tal_tmpctx(ld);
for (i = 0; i < ARRAY_SIZE(daemons); i++) {
int outfd;
const char *dpath = path_join(ctx, ld->daemon_dir, daemons[i]);
const char *dpath = path_join(tmpctx, ld->daemon_dir, daemons[i]);
const char *verstring;
pid_t pid = pipecmd(&outfd, NULL, &outfd,
dpath, "--version", NULL);
@@ -105,21 +103,19 @@ void test_daemons(const struct lightningd *ld)
log_debug(ld->log, "testing %s", dpath);
if (pid == -1)
err(1, "Could not run %s", dpath);
verstring = grab_fd(ctx, outfd);
verstring = grab_fd(tmpctx, outfd);
if (!verstring)
err(1, "Could not get output from %s", dpath);
if (!strstarts(verstring, version())
|| verstring[strlen(version())] != '\n')
errx(1, "%s: bad version '%s'", daemons[i], verstring);
}
tal_free(ctx);
}
/* Check if all daemons exist in specified directory. */
static bool has_all_daemons(const char* daemon_dir)
{
size_t i;
bool missing_daemon = false;
const tal_t *tmpctx = tal_tmpctx(NULL);
for (i = 0; i < ARRAY_SIZE(daemons); ++i) {
if (!path_is_file(path_join(tmpctx, daemon_dir, daemons[i]))) {
@@ -128,13 +124,12 @@ static bool has_all_daemons(const char* daemon_dir)
}
}
tal_free(tmpctx);
return !missing_daemon;
}
static const char *find_my_path(const tal_t *ctx, const char *argv0)
{
char *me, *tmpctx = tal_tmpctx(ctx);
char *me;
if (strchr(argv0, PATH_SEP)) {
const char *path;
@@ -173,7 +168,6 @@ static const char *find_my_path(const tal_t *ctx, const char *argv0)
errx(1, "Cannot find %s in $PATH", argv0);
}
tal_free(tmpctx);
return path_dirname(ctx, take(me));
}
static const char *find_my_pkglibexec_path(const tal_t *ctx,
@@ -260,7 +254,6 @@ static void daemonize_but_keep_dir(struct lightningd *ld)
static void pidfile_create(const struct lightningd *ld)
{
char *pid;
const tal_t *tmpctx = tal_tmpctx(NULL);
/* Create PID file */
pid_fd = open(ld->pidfile, O_WRONLY|O_CREAT, 0640);
@@ -275,8 +268,6 @@ static void pidfile_create(const struct lightningd *ld)
/* Get current PID and write to PID fie */
pid = tal_fmt(tmpctx, "%d\n", getpid());
write_all(pid_fd, pid, strlen(pid));
tal_free(tmpctx);
}
int main(int argc, char *argv[])