diff options
-rw-r--r-- | src/mds.c | 16 | ||||
-rwxr-xr-x | test | 18 | ||||
-rwxr-xr-x | test.d/dumb-client | 59 | ||||
-rwxr-xr-x | test.d/mdsinitrc | 19 |
4 files changed, 108 insertions, 4 deletions
@@ -204,6 +204,11 @@ int main(int argc_, char** argv_) } fflush(f); fclose(f); + if (chmod(pathname, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) < 0) + { + perror(*argv); + eprintf("while setting permissions for PID file: %s", pathname); + } /* Create data storage directory. */ if (create_directory_root(MDS_STORAGE_ROOT_DIRECTORY)) @@ -223,11 +228,10 @@ int main(int argc_, char** argv_) strcpy(address.sun_path, pathname); unlink(pathname); fd = socket(AF_UNIX, SOCK_STREAM, 0); - if ((fchmod(fd, S_IRWXU) < 0) || - (fchown(fd, getuid(), NOBODY_GROUP_GID) < 0)) + if (fchmod(fd, S_IRWXU) < 0) { perror(*argv); - eprint("while making anonymous socket private to the real user."); + eprint("while making anonymous socket private to its owner."); goto fail; } if (bind(fd, (struct sockaddr*)(&address), sizeof(address)) < 0) @@ -236,6 +240,12 @@ int main(int argc_, char** argv_) eprintf("while binding socket to file: %s", pathname); goto fail; } + if (chown(pathname, getuid(), NOBODY_GROUP_GID) < 0) + { + perror(*argv); + eprint("while making socket private to the real user."); + goto fail; + } /* Start listening on socket. */ if (listen(fd, SOMAXCONN) < 0) @@ -1,4 +1,22 @@ #!/bin/sh + +# mds — A micro-display server +# Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + + set -e cd "$(dirname "$0")" diff --git a/test.d/dumb-client b/test.d/dumb-client new file mode 100755 index 0000000..4868813 --- /dev/null +++ b/test.d/dumb-client @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 +# -*- python -*- + +# mds — A micro-display server +# Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +import os +import sys +import socket +import threading + + +display = os.environ['MDS_DISPLAY'] if 'MDS_DISPLAY' in os.environ else None +if (display is None) or (':' not in display): + print('MDS_DISPLAY has not set.') + sys.exit(1) +if not display.startswith(':'): + print('Remote mds sessions are not supported.') + sys.exit(1) + +socket_path = '/run/mds/%s.socket' % display.split(':')[-1] +socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) +socket.connect(socket_path) + +def read_loop(): + data = socket.recv(1); + if not data: + return + sys.stdout.buffer.write(b'\033[34m'); + sys.stdout.buffer.write(data); + sys.stdout.buffer.write(b'\033[00m'); + sys.stdout.buffer.flush(); + +thread = threading.Thread(target = read_loop) +thread.setDaemon(True) +thread.start() + +while True: + try: + data = input().encode('utf-8') + except: + break + socket.send(data); + +socket.close() + diff --git a/test.d/mdsinitrc b/test.d/mdsinitrc index ca28224..c27cdc0 100755 --- a/test.d/mdsinitrc +++ b/test.d/mdsinitrc @@ -1,8 +1,25 @@ #!/bin/bash -echo "Successfully spawned mdsinitrc. " +# mds — A micro-display server +# Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +echo "Successfully spawned mdsinitrc. " +cd test.d export XDG_CONFIG_HOME="${OLD_XDG_CONFIG_HOME}" unset OLD_XDG_CONFIG_HOME if [ -z "${XDG_CONFIG_HOME}" ]; then |