Cleanup in failures a little better.

This commit is contained in:
Ryan C. Gordon 2017-05-30 18:02:48 -04:00
parent 86e71b11eb
commit b892bcfdbc

View file

@ -76,7 +76,7 @@ typedef struct ManifestItem
struct ManifestItem *next; struct ManifestItem *next;
} ManifestItem; } ManifestItem;
static ManifestItem *manifest; static ManifestItem *manifest = NULL;
static void freeManifest(void) static void freeManifest(void)
{ {
@ -92,6 +92,22 @@ static void freeManifest(void)
manifest = NULL; manifest = NULL;
} }
static const char *timestamp(void)
{
time_t t = time(NULL);
char *retval = asctime(localtime(&t));
if (retval) {
char *ptr;
for (ptr = retval; *ptr; ptr++) {
if ((*ptr == '\r') || (*ptr == '\n')) {
*ptr = '\0';
break;
}
}
}
return retval ? retval : "[date unknown]";
}
static FILE *logfile = NULL; static FILE *logfile = NULL;
@ -140,8 +156,10 @@ static void die(const char *why) NEVER_RETURNS;
static void die(const char *why) static void die(const char *why)
{ {
infof("FAILURE: %s", why); infof("FAILURE: %s", why);
curl_global_cleanup();
restoreRollbacks(); restoreRollbacks();
freeManifest(); freeManifest();
infof("Updater ending (in failure), %s", timestamp());
exit(1); exit(1);
} }
@ -628,22 +646,6 @@ static void deleteRollbacks(void)
} }
} }
static const char *timestamp(void)
{
time_t t = time(NULL);
char *retval = asctime(localtime(&t));
if (retval) {
char *ptr;
for (ptr = retval; *ptr; ptr++) {
if ((*ptr == '\r') || (*ptr == '\n')) {
*ptr = '\0';
break;
}
}
}
return retval ? retval : "[date unknown]";
}
static void chdirToBasePath(const char *argv0) static void chdirToBasePath(const char *argv0)
{ {
const char *fname = justFilename(argv0); const char *fname = justFilename(argv0);