[mw-devel] [Git][arthur/mw][master] 2 commits: Create replay files after setuid

Andrew Price welshbyte at sucs.org
Sun Sep 17 15:56:51 BST 2017


Andrew Price pushed to branch master at Justin Mitchell / mw


Commits:
52df603d by Andrew Price at 2017-09-17T14:41:54+01:00
Create replay files after setuid

- - - - -
731635f8 by Andrew Price at 2017-09-17T14:42:52+01:00
Don't fsync replay file writes

The data isn't important enough to justify the perf hit

- - - - -


4 changed files:

- src/server/mwserv.c
- src/server/replay.c
- src/server/servsock.c
- src/server/servsock.h


Changes:

=====================================
src/server/mwserv.c
=====================================
--- a/src/server/mwserv.c
+++ b/src/server/mwserv.c
@@ -155,8 +155,10 @@ int main(int argc, char **argv)
 	if (err)
 		return err;
 
-	if (init_server() != 0)
+	if (init_server() != 0) {
+		fprintf(stderr, "Server initialisation failed.\n");
 		return 1;
+	}
 
 	mainsock = open_mainsock(cfg_get_int("port"));
 
@@ -182,7 +184,10 @@ int main(int argc, char **argv)
 		}
 	}
 
-	migrate_old_folders();
+	if (init_server_after_setuid() != 0) {
+		fprintf(stderr, "Post-setuid setup failed.\n");
+		return 1;
+	}
 	if (!cfg_get_bool("debug")) {
 		freopen("/dev/null", "w", stdout);
 		freopen("/dev/null", "w", stderr);


=====================================
src/server/replay.c
=====================================
--- a/src/server/replay.c
+++ b/src/server/replay.c
@@ -69,7 +69,6 @@ static int write_message(ipc_message_t *msg, unsigned n)
 	};
 	if (pwritev(fd, iov, 2, 0) != (iov[0].iov_len + iov[1].iov_len))
 		perror(pathname);
-	fsync(fd);
 	close(fd);
 	return 0;
 }


=====================================
src/server/servsock.c
=====================================
--- a/src/server/servsock.c
+++ b/src/server/servsock.c
@@ -647,7 +647,7 @@ static char *has_suffix(char *str, const char *suffix)
 	return NULL;
 }
 
-void migrate_old_folders(void)
+static void migrate_old_folders(void)
 {
 	int dfd;
 	DIR *dirp;
@@ -728,12 +728,18 @@ void migrate_old_folders(void)
 	}
 }
 
-int init_server()
+int init_server(void)
 {
 	INIT_LIST_HEAD(&connection_list);
+	poll_init();
+	return 0;
+}
+
+int init_server_after_setuid(void)
+{
+	migrate_old_folders();
 	if (replay_init() != 0)
 		return 1;
-	poll_init();
 	return 0;
 }
 


=====================================
src/server/servsock.h
=====================================
--- a/src/server/servsock.h
+++ b/src/server/servsock.h
@@ -22,8 +22,8 @@ int msg_attach_to_username(ipc_message_t *msg, const char *username);
 void msg_attach_to_channel(ipc_message_t *msg, int channel, const char * exclude);
 void msg_attach_to_perm(ipc_message_t *msg, perm_t perm);
 void msg_attach(ipc_message_t *msg, ipc_connection_t *conn);
-void migrate_old_folders(void);
 int init_server(void);
+int init_server_after_setuid(void);
 void send_error(ipc_connection_t *conn, ipc_message_t *orig, const char *format, ...);
 void msg_apply_gag(struct user * from, ipc_message_t * msg, const char * field);
 ipc_message_t * msg_wholist(void);



View it on GitLab: https://projects.sucs.org/arthur/mw/compare/2b377cf2da744e471dc642e0b7beaa33aa0da65f...731635f89d908328a5b4383d6d77fec5b3ef23b1

---
View it on GitLab: https://projects.sucs.org/arthur/mw/compare/2b377cf2da744e471dc642e0b7beaa33aa0da65f...731635f89d908328a5b4383d6d77fec5b3ef23b1
You're receiving this email because of your account on projects.sucs.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/mw-devel/attachments/20170917/41501e86/attachment-0001.html>


More information about the mw-devel mailing list