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

Submitted by Neels Hofmeyr on Sept. 30, 2016, 11:10 p.m.

Details

Message ID 1475277047-3068-3-git-send-email-nhofmeyr@sysmocom.de
State New
Series "OpenGGSN fixes for gsn_restart file path composition"
Headers show

Commit Message

Neels Hofmeyr Sept. 30, 2016, 11:10 p.m.
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(-)

Patch hide | download patch | download mbox

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,