summaryrefslogtreecommitdiffstats
path: root/parse.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2017-10-21 13:10:36 -0400
committerTavian Barnes <tavianator@tavianator.com>2017-10-21 13:10:36 -0400
commit4e38f139f92b8b3729f82c37f0904c2b77d3eb58 (patch)
treea10f9de054cbcd2176be7666e56e0ae660bebf84 /parse.c
parent305f75468ead1f68aad3f3b5162f7437ad8dd732 (diff)
downloadbfs-4e38f139f92b8b3729f82c37f0904c2b77d3eb58.tar.xz
Report errors that occur when closing files
Otherwise we miss write errors that occur when flushing the cache.
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c37
1 files changed, 30 insertions, 7 deletions
diff --git a/parse.c b/parse.c
index 46c860c..b4b7ddc 100644
--- a/parse.c
+++ b/parse.c
@@ -80,11 +80,14 @@ struct expr expr_false = {
/**
* Free an expression.
*/
-void free_expr(struct expr *expr) {
+int free_expr(struct expr *expr) {
+ int ret = 0;
+
if (expr && expr != &expr_true && expr != &expr_false) {
if (expr->cfile && expr->cfile->close) {
if (cfclose(expr->cfile) != 0) {
perror("cfclose()");
+ ret = -1;
}
}
@@ -96,10 +99,17 @@ void free_expr(struct expr *expr) {
free_bfs_printf(expr->printf);
free_bfs_exec(expr->execbuf);
- free_expr(expr->lhs);
- free_expr(expr->rhs);
+ if (free_expr(expr->lhs) != 0) {
+ ret = -1;
+ }
+ if (free_expr(expr->rhs) != 0) {
+ ret = -1;
+ }
+
free(expr);
}
+
+ return ret;
}
struct expr *new_expr(eval_fn *eval, size_t argc, char **argv) {
@@ -224,14 +234,25 @@ void dump_expr(CFILE *cfile, const struct expr *expr, bool verbose) {
/**
* Free the parsed command line.
*/
-void free_cmdline(struct cmdline *cmdline) {
+int free_cmdline(struct cmdline *cmdline) {
+ int ret = 0;
+
if (cmdline) {
- free_expr(cmdline->expr);
+ if (free_expr(cmdline->expr) != 0) {
+ ret = -1;
+ }
free_bfs_mtab(cmdline->mtab);
- cfclose(cmdline->cerr);
- cfclose(cmdline->cout);
+ if (cfclose(cmdline->cerr) != 0) {
+ perror("cfclose()");
+ ret = -1;
+ }
+ if (cfclose(cmdline->cout) != 0) {
+ perror("cfclose()");
+ ret = -1;
+ }
+
free_colors(cmdline->colors);
struct root *root = cmdline->roots;
@@ -244,6 +265,8 @@ void free_cmdline(struct cmdline *cmdline) {
free(cmdline->argv);
free(cmdline);
}
+
+ return ret;
}
/**