[mw-devel] [Git][arthur/mw][master] 2 commits: Improve mw.service

Andrew Price welshbyte at sucs.org
Sat Nov 7 21:12:25 GMT 2015


Andrew Price pushed to branch master at Justin Mitchell / mw


Commits:
285b561f by Andrew Price at 2015-11-07T20:56:03Z
Improve mw.service

- Run as mw:mw
- Make systemd create and cleanup /var/run/mw for us
- Correct the path to mwserv

- - - - -
54027aa0 by Andrew Price at 2015-11-07T21:05:41Z
Migrate folders to directories after setuid

Makes sure we don't create the directories with root ownership.

Also make mwserv's stdout line buffered to work better with logging
systems which capture stdout.

- - - - -


4 changed files:

- mw.service
- src/server/mwserv.c
- src/server/servsock.c
- src/server/servsock.h


Changes:

=====================================
mw.service
=====================================
--- a/mw.service
+++ b/mw.service
@@ -3,9 +3,10 @@ Description=Milliways server
 After=network.target
 
 [Service]
-ExecStartPre=-/bin/mkdir /var/run/mw
-ExecStartPre=/bin/chown -R mw:mw /var/run/mw
-ExecStart=/usr/bin/mwserv --foreground --port 9999
+User=mw
+Group=mw
+RuntimeDirectory=mw
+ExecStart=/usr/lib/mw/mwserv --foreground --port 9999
 
 [Install]
 WantedBy=multi-user.target


=====================================
src/server/mwserv.c
=====================================
--- a/src/server/mwserv.c
+++ b/src/server/mwserv.c
@@ -177,7 +177,11 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (!cfg_get_bool("foreground")) daemon(0, 0);
+	migrate_old_folders();
+	if (cfg_get_bool("foreground"))
+		setlinebuf(stdout);
+	else
+		daemon(0, 0);
 
 	uptime = time(0);
 	watch_mainsock(mainsock);


=====================================
src/server/servsock.c
=====================================
--- a/src/server/servsock.c
+++ b/src/server/servsock.c
@@ -597,7 +597,7 @@ static char *has_suffix(char *str, const char *suffix)
 	return NULL;
 }
 
-static void migrate_old_folders(void)
+void migrate_old_folders(void)
 {
 	int dfd;
 	DIR *dirp;
@@ -682,8 +682,6 @@ static void migrate_old_folders(void)
 
 void init_server()
 {
-	migrate_old_folders();
-
 	INIT_LIST_HEAD(&connection_list);
 	if (pollfd == -1) {
 		pollfd = epoll_create(30);


=====================================
src/server/servsock.h
=====================================
--- a/src/server/servsock.h
+++ b/src/server/servsock.h
@@ -15,6 +15,7 @@ int msg_attach_to_userid(ipc_message_t *msg, uint32_t userposn);
 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(ipc_message_t *msg, ipc_connection_t *conn);
+void migrate_old_folders(void);
 void init_server(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);



View it on GitLab: https://projects.sucs.org/arthur/mw/compare/d881fc863cfee125b72b8c07e89090b7a4dceeb6...54027aa0d6cd0baab2a5bd53d01c77ed4241b85a
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/mw-devel/attachments/20151107/10c1e908/attachment.html>


More information about the mw-devel mailing list