aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libarmep/configuration.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/libarmep/configuration.c b/libarmep/configuration.c
index 67752ca..829ba09 100644
--- a/libarmep/configuration.c
+++ b/libarmep/configuration.c
@@ -134,6 +134,7 @@ int configure(struct aep_context *aep_context, struct aep *aep, const char *dev_
char temp_config[1024];
char linebuf[1024];
int no_copy = 0;
+ int ret = 0;
if (wch) {
strncpy(temp_config, config_filepath, sizeof temp_config - 2);
@@ -177,7 +178,10 @@ int configure(struct aep_context *aep_context, struct aep *aep, const char *dev_
entry_parser = parser;
if (!no_copy && wfd > 0)
- write(wfd, &c, 1);
+ if (write(wfd, &c, 1) < 1) {
+ fprintf(stderr, "Unable to write config file\n");
+ goto bail;
+ }
switch (parser) {
case ACPP_FIRST:
@@ -290,7 +294,10 @@ int configure(struct aep_context *aep_context, struct aep *aep, const char *dev_
if (aep->aep_context->verbose)
fprintf(stderr, "Updating config "
"with \"%s\"\n", linebuf);
- write(wfd, linebuf, strlen(linebuf));
+ if (write(wfd, linebuf, strlen(linebuf)) < 0) {
+ fprintf(stderr, "Unable to write config file\n");
+ goto bail;
+ }
}
ch++;
@@ -361,20 +368,24 @@ int configure(struct aep_context *aep_context, struct aep *aep, const char *dev_
}
c = buf[pos++];
- write(wfd, &c, 1);
+ if (write(wfd, &c, 1) < 0) {
+ fprintf(stderr, "Unable to write config file\n");
+ goto bail;
+ }
}
-
- close(wfd);
}
-
+bail:
close(fd);
if (wfd > 0) {
- unlink(config_filepath);
- rename(temp_config, config_filepath);
+ close(wfd);
+ if (!ret) {
+ unlink(config_filepath);
+ rename(temp_config, config_filepath);
+ }
}
- return 0;
+ return ret;
}