HAMMER Util: Fix missing check on fopen result.
authorMatthew Dillon <dillon@apollo.backplane.com>
Wed, 24 Jun 2009 15:51:11 +0000 (08:51 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Wed, 24 Jun 2009 15:51:11 +0000 (08:51 -0700)
Fix a missing check when the fopen() to create a new period file fails.

Reported-by: Antonio Huete Jimenez <tuxillo@quantumachine.net>
sbin/hammer/cmd_cleanup.c

index 95b7d49..0cd1f09 100644 (file)
@@ -467,10 +467,15 @@ save_period(const char *snapshots_path, const char *cmd,
        asprintf(&ocheck_path, "%s/.%s.period", snapshots_path, cmd);
        asprintf(&ncheck_path, "%s/.%s.period.new", snapshots_path, cmd);
        fp = fopen(ncheck_path, "w");
-       fprintf(fp, "0x%08llx\n", (long long)savet);
-       if (fclose(fp) == 0)
-               rename(ncheck_path, ocheck_path);
-       remove(ncheck_path);
+       if (fp) {
+               fprintf(fp, "0x%08llx\n", (long long)savet);
+               if (fclose(fp) == 0)
+                       rename(ncheck_path, ocheck_path);
+               remove(ncheck_path);
+       } else {
+               fprintf(stderr, "hammer: Unable to create period-file %s: %s\n",
+                       ncheck_path, strerror(errno));
+       }
 }
 
 /*