[PATCH 2/2] gsn_restart file: set umask back to original after write failure

Neels Hofmeyr nhofmeyr at sysmocom.de
Fri Sep 30 23:10:47 UTC 2016


An fopen("w") error used to omit the umask() call to reinstate the previous
umask. Move the final umask() call to the bottom so that it is called in all
code paths.
---
 gtp/gtp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gtp/gtp.c b/gtp/gtp.c
index 161a6f0..a46a76f 100644
--- a/gtp/gtp.c
+++ b/gtp/gtp.c
@@ -681,7 +681,6 @@ static void log_restart(struct gsn_t *gsn)
 		goto free_filename;
 	}
 
-	umask(i);
 	fprintf(f, "%d\n", gsn->restart_counter);
 close_file:
 	if (fclose(f))
@@ -689,6 +688,7 @@ close_file:
 			"fclose failed: Error = %s\n", strerror(errno));
 free_filename:
 	talloc_free(filename);
+	umask(i);
 }
 
 int gtp_new(struct gsn_t **gsn, char *statedir, struct in_addr *listen,
-- 
2.1.4



More information about the osmocom-net-gprs mailing list