aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README5
-rw-r--r--src/config.h10
-rw-r--r--src/mds.c51
3 files changed, 63 insertions, 3 deletions
diff --git a/README b/README
index 6c4cd61..0e806e1 100644
--- a/README
+++ b/README
@@ -10,7 +10,10 @@ version of the display server you can start running the
new version without having to restart the display server.
Moreover, it allows you to replace components with your
own versions or add new components, with exception of
-parts that need the special privileges.
+parts that need the special privileges and one special
+component, the program that starts it all, but that file
+will have no mission except restarting the master server
+if it crashes once it has started the master server.
Is this vaporware? Probably I often bored with graphical
projects. Graphics sucks.
diff --git a/src/config.h b/src/config.h
index fc8bf75..551568c 100644
--- a/src/config.h
+++ b/src/config.h
@@ -20,10 +20,18 @@
/**
+ * The name under which this package is installed
+ */
+#ifndef PKGNAME
+#define PKGNAME "mds"
+#endif
+
+
+/**
* The root directory of all runtime data stored by MDS
*/
#ifndef MDS_RUNTIME_ROOT_DIRECTORY
-#define MDS_RUNTIME_ROOT_DIRECTORY "/run/mds"
+#define MDS_RUNTIME_ROOT_DIRECTORY "/run/" PKGNAME
#endif
diff --git a/src/mds.c b/src/mds.c
index eb87415..95cd6da 100644
--- a/src/mds.c
+++ b/src/mds.c
@@ -91,10 +91,59 @@ int main(int argc_, const char** argv_)
fd = open(pathname, O_CREAT | O_EXCL);
if (fd == -1)
{
- /* TODO reuse display index not no longer used */
+ /* Reuse display index not no longer used. */
+ size_t read_len;
+ f = fopen(pathname, "r");
+ if (f == NULL) /* Race, or error? */
+ {
+ perror(*argv);
+ continue;
+ }
+ read_len = read(piddata, 1, sizeof(piddata) / sizeof(char), f);
+ if (ferror(f)) /* Failed to read. */
+ perror(*argv);
+ else if (feof(f) == 0) /* Did not read everything. */
+ fprintf(stderr,
+ "%s: the content of a PID file is longer than expected.\n",
+ *argv);
+ else
+ {
+ pid_t pid = 0;
+ size_t i, n = read_len - 1;
+ for (i = 0; i < n; i++)
+ {
+ char c = piddata[i];
+ if (('0' <= c) && (c <= '9'))
+ pid = pid * 10 + (c & 15);
+ else
+ {
+ fprintf(stderr,
+ "%s: the content of a PID file is invalid.\n",
+ *argv);
+ goto bad;
+ }
+ }
+ if (piddata[n] != '\n')
+ {
+ fprintf(stderr,
+ "%s: the content of a PID file is invalid.\n",
+ *argv);
+ goto bad;
+ }
+ if (kill(pid, 0) < 0) /* Check if the PID is still allocated to any process. */
+ if (errno == ESRCH) /* PID is not used. */
+ {
+ fclose(f);
+ close(fd);
+ break;
+ }
+ }
+ bad:
+ fclose(f);
continue;
}
close(fd);
+ break;
}
if (display == DISPLAY_MAX)
{