[systemd-devel] [PATCH] bootchart: use _cleanup_close_
Nathaniel Chen
nathaniel.chen at intel.com
Thu Mar 7 11:09:16 PST 2013
use _cleanup_{close_,fclose_} to close streams and file descriptors
---
src/bootchart/bootchart.c | 8 +++-----
src/bootchart/svg.c | 5 +----
2 files changed, 4 insertions(+), 9 deletions(-)
diff --git a/src/bootchart/bootchart.c b/src/bootchart/bootchart.c
index 65f16c5..0ad14dc 100644
--- a/src/bootchart/bootchart.c
+++ b/src/bootchart/bootchart.c
@@ -66,10 +66,10 @@ struct cpu_stat_struct cpustat[MAXCPUS];
int pscount;
int cpus;
double interval;
-FILE *of = NULL;
+FILE _cleanup_fclose_ *of = NULL;
int overrun = 0;
static int exiting = 0;
-int sysfd=-1;
+int _cleanup_close_ sysfd=-1;
/* graph defaults */
bool entropy = false;
@@ -106,7 +106,7 @@ int main(int argc, char *argv[])
char datestr[200];
time_t t = 0;
const char *fn;
- _cleanup_fclose_ FILE *f;
+ _cleanup_fclose_ FILE *f = NULL;
int gind;
int i, r;
char *init = NULL, *output = NULL;
@@ -378,10 +378,8 @@ int main(int argc, char *argv[])
svg_do(build);
fprintf(stderr, "systemd-bootchart wrote %s\n", output_file);
- fclose(of);
closedir(proc);
- close(sysfd);
/* nitpic cleanups */
ps = ps_first;
diff --git a/src/bootchart/svg.c b/src/bootchart/svg.c
index 9fee810..7947671 100644
--- a/src/bootchart/svg.c
+++ b/src/bootchart/svg.c
@@ -150,7 +150,7 @@ static void svg_title(const char *build)
char date[256] = "Unknown";
char cpu[256] = "Unknown";
char *c;
- FILE *f;
+ FILE _cleanup_fclose_ *f = NULL;
time_t t;
int fd;
struct utsname uts;
@@ -161,7 +161,6 @@ static void svg_title(const char *build)
if (f) {
if (!fgets(cmdline, 255, f))
sprintf(cmdline, "Unknown");
- fclose(f);
}
/* extract root fs so we can find disk model name in sysfs */
@@ -176,7 +175,6 @@ static void svg_title(const char *build)
if (f) {
if (!fgets(model, 255, f))
fprintf(stderr, "Error reading disk model for %s\n", rootbdev);
- fclose(f);
}
}
@@ -198,7 +196,6 @@ static void svg_title(const char *build)
break;
}
}
- fclose(f);
}
svg("<text class=\"t1\" x=\"0\" y=\"30\">Bootchart for %s - %s</text>\n",
--
1.8.1.4
More information about the systemd-devel
mailing list