summaryrefslogtreecommitdiff
path: root/src/p11tool.c
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2017-04-05 08:50:53 +0200
committerNikos Mavrogiannopoulos <nmav@redhat.com>2017-04-05 09:56:16 +0200
commit9e400c33104e9f2e394e8914e7d6138e623da19e (patch)
tree24c84b6784be40f38f8c4fee6310fea3985d1382 /src/p11tool.c
parentac291206e86f4d39e1820bbb746612c9018383b6 (diff)
downloadgnutls-9e400c33104e9f2e394e8914e7d6138e623da19e.tar.gz
tools: remove outfile when exited on error
Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
Diffstat (limited to 'src/p11tool.c')
-rw-r--r--src/p11tool.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/p11tool.c b/src/p11tool.c
index ff247835cd..e3b24b8353 100644
--- a/src/p11tool.c
+++ b/src/p11tool.c
@@ -51,9 +51,19 @@
static void cmd_parser(int argc, char **argv);
static FILE *outfile;
+static const char *outfile_name = NULL;
int batch = 0;
int ask_pass = 0;
+void app_exit(int val)
+{
+ if (val != 0) {
+ if (outfile_name)
+ remove(outfile_name);
+ }
+ exit(val);
+}
+
static void tls_log_func(int level, const char *str)
{
fprintf(stderr, "|<%d>| %s", level, str);
@@ -150,7 +160,7 @@ static void cmd_parser(int argc, char **argv)
if ((ret = gnutls_global_init()) < 0) {
fprintf(stderr, "global_init: %s\n", gnutls_strerror(ret));
- exit(1);
+ app_exit(1);
}
if (HAVE_OPT(PROVIDER)) {
@@ -165,7 +175,7 @@ static void cmd_parser(int argc, char **argv)
if (ret < 0) {
fprintf(stderr, "pkcs11_add_provider: %s\n",
gnutls_strerror(ret));
- exit(1);
+ app_exit(1);
}
}
} else {
@@ -179,8 +189,9 @@ static void cmd_parser(int argc, char **argv)
outfile = safe_open_rw(OPT_ARG(OUTFILE), 0);
if (outfile == NULL) {
fprintf(stderr, "cannot open %s\n", OPT_ARG(OUTFILE));
- exit(1);
+ app_exit(1);
}
+ outfile_name = OPT_ARG(OUTFILE);
} else
outfile = stdout;