kill(-getpid(), SIGKILL);
}
-static char *run_with_timeout(const void *ctx,
- const char *cmd,
- bool *ok,
- unsigned *timeout_ms)
+char *run_with_timeout(const void *ctx, const char *cmd,
+ bool *ok, unsigned *timeout_ms)
{
pid_t pid;
int p[2];
|| open("/dev/null", O_RDONLY) != STDIN_FILENO)
exit(128);
- setpgid(0, 0);
signal(SIGALRM, killme);
itim.it_interval.tv_sec = itim.it_interval.tv_usec = 0;
itim.it_value.tv_sec = *timeout_ms / 1000;
return 0;
}
-char *temp_file(const void *ctx, const char *extension)
+char *temp_dir(const void *ctx)
{
/* For first call, create dir. */
while (!tmpdir) {
}
talloc_set_destructor(tmpdir, unlink_all);
}
+ return tmpdir;
+}
+
+char *temp_file(const void *ctx, const char *extension)
+{
+ return talloc_asprintf(ctx, "%s/%u%s",
+ temp_dir(ctx), count++, extension);
+}
+
+char *maybe_temp_file(const void *ctx, const char *extension, bool keep,
+ const char *srcname)
+{
+ size_t baselen;
+
+ if (!keep)
+ return temp_file(ctx, extension);
- return talloc_asprintf(ctx, "%s/%u%s", tmpdir, count++, extension);
+ baselen = strrchr(srcname, '.') - srcname;
+ return talloc_asprintf(ctx, "%.*s%s", baselen, srcname, extension);
}
bool move_file(const char *oldname, const char *newname)