[PATCH] openggsn[master]: gsn_restart file: wrap umask change tightly around file crea...

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Wed Oct 12 23:03:47 UTC 2016


Hello Jenkins Builder, Holger Freyther,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/1014

to look at the new patch set (#3).

gsn_restart file: wrap umask change tightly around file creation

An fopen("w") error used to omit the umask() call to reinstate the previous
umask. Also an fopen("r") at the top will never create a file and hence does
not need a umask set.

Instead, wrap the umask change and change-back tightly around the single
fopen("w") call.

Change-Id: If7d948e2f2ba47ecebba5614f18235a53b273d14
---
M gtp/gtp.c
1 file changed, 6 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/openggsn refs/changes/14/1014/3

diff --git a/gtp/gtp.c b/gtp/gtp.c
index ccb2611..dcbe777 100644
--- a/gtp/gtp.c
+++ b/gtp/gtp.c
@@ -648,7 +648,6 @@
 	int counter = 0;
 	char *filename;
 
-	i = umask(022);
 	filename = talloc_asprintf(NULL, "%s/%s", gsn->statedir, RESTART_FILE);
 	OSMO_ASSERT(filename);
 
@@ -658,7 +657,6 @@
 			"State information file (%s) not found. Creating new file.\n",
 			filename);
 	} else {
-		umask(i);
 		rc = fscanf(f, "%d", &counter);
 		if (rc != 1) {
 			LOGP(DLGTP, LOGL_ERROR,
@@ -674,14 +672,18 @@
 	gsn->restart_counter = (unsigned char)counter;
 	gsn->restart_counter++;
 
-	if (!(f = fopen(filename, "w"))) {
+	/* Keep the umask closely wrapped around our fopen() call in case the
+	 * log outputs cause file creation. */
+	i = umask(022);
+	f = fopen(filename, "w");
+	umask(i);
+	if (!f) {
 		LOGP(DLGTP, LOGL_ERROR,
 			"fopen(path=%s, mode=%s) failed: Error = %s\n", filename,
 			"w", strerror(errno));
 		goto free_filename;
 	}
 
-	umask(i);
 	fprintf(f, "%d\n", gsn->restart_counter);
 close_file:
 	if (fclose(f))

-- 
To view, visit https://gerrit.osmocom.org/1014
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: If7d948e2f2ba47ecebba5614f18235a53b273d14
Gerrit-PatchSet: 3
Gerrit-Project: openggsn
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Holger Freyther <holger at freyther.de>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list