diff options
-rw-r--r-- | TODO | 1 | ||||
-rw-r--r-- | src/libmdsserver/config.h | 9 | ||||
-rw-r--r-- | src/mds.c | 34 |
3 files changed, 29 insertions, 15 deletions
@@ -44,6 +44,5 @@ Make it possible to forbid unauthorised servers for listening, needed for secure A facility is needed to lookup available compose sequences to any character, it would be useful in character map programs so one can easier learn the compose sequences for character that one uses often -`mds` should call `setpgid(0, 0)` and export `getpgrp()` to MDS_PGROUP Servers should be stored in LIBEXECDIR. diff --git a/src/libmdsserver/config.h b/src/libmdsserver/config.h index dbd7655..b4a0087 100644 --- a/src/libmdsserver/config.h +++ b/src/libmdsserver/config.h @@ -191,6 +191,15 @@ /** + * The name of the environment variable that + * indicates the display server's process group + */ +#ifndef PGROUP_ENV +#define PGROUP_ENV "MDS_PGROUP" +#endif + + +/** * The minimum time that most have elapsed * for respawning to be allowed */ @@ -101,11 +101,11 @@ int main(int argc_, char** argv_) /* Set up to ignore SIGUPDATE, used in mds for re-exec, but we cannot re-exec. */ if (xsigaction(SIGUPDATE, SIG_IGN) < 0) - perror(*argv); + xperror(*argv); /* Set up to ignore SIGDANGER. */ if (xsigaction(SIGDANGER, SIG_IGN) < 0) - perror(*argv); + xperror(*argv); /* Create directory for socket files, PID files and such. */ if (create_directory_root(MDS_RUNTIME_ROOT_DIRECTORY)) @@ -124,7 +124,7 @@ int main(int argc_, char** argv_) f = fopen(pathname, "r"); if (f == NULL) /* Race, or error? */ { - perror(*argv); + xperror(*argv); continue; } r = is_pid_file_reusable(f); @@ -146,13 +146,13 @@ int main(int argc_, char** argv_) { fclose(f); if (unlink(pathname) < 0) - perror(*argv); + xperror(*argv); return 1; } fflush(f); fclose(f); if (chmod(pathname, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) < 0) - perror(*argv); + xperror(*argv); /* Create data storage directory. */ xsnprintf(pathname, "%s/%u.data", MDS_STORAGE_ROOT_DIRECTORY, display); @@ -166,6 +166,12 @@ int main(int argc_, char** argv_) ":%u", display); fail_if (setenv(DISPLAY_ENV, pathname, 1) < 0); + /* Create a new process group and export MDS_PGROUP */ + fail_if (setpgid(0, 0) < 0); + xsnprintf(pathname, /* Excuse the reuse without renaming. */ + "%ji", (intmax_t)getpgrp()); + fail_if (setenv(PGROUP_ENV, pathname, 1) < 0); + /* Create display socket. */ xsnprintf(pathname, "%s/%u.socket", MDS_RUNTIME_ROOT_DIRECTORY, display); address.sun_family = AF_UNIX; @@ -204,7 +210,7 @@ int main(int argc_, char** argv_) return rc; pfail: - perror(*argv); + xperror(*argv); rc = 1; goto done; } @@ -223,7 +229,7 @@ int is_pid_file_reusable(FILE* f) read_len = fread(piddata, 1, sizeof(piddata) / sizeof(char), f); if (ferror(f)) /* Failed to read. */ - perror(*argv); + xperror(*argv); else if (feof(f) == 0) /* Did not read everything. */ eprint("the content of a PID file is larger than expected."); else @@ -337,7 +343,7 @@ int spawn_and_respawn_server(int fd) /* Get the current time. (Start of child process.) */ if ((time_error = (monotone(&time_start) < 0))) - perror(*argv); + xperror(*argv); /* Wait for master server to die. */ if (uninterruptable_waitpid(pid, &status, 0) == (pid_t)-1) @@ -359,7 +365,7 @@ int spawn_and_respawn_server(int fd) /* Do not respawn if we could not read the time. */ if (time_error) { - perror(*argv); + xperror(*argv); eprintf("`%s' died abnormally, not respawning because we could not read the time.", master_server); goto fail; } @@ -396,7 +402,7 @@ int spawn_and_respawn_server(int fd) return rc; pfail: - perror(*argv); + xperror(*argv); goto fail; } @@ -436,7 +442,7 @@ int create_directory_root(const char* pathname) return 0; pfail: - perror(*argv); + xperror(*argv); return 1; } @@ -468,7 +474,7 @@ int create_directory_user(const char* pathname) { if (errno != EEXIST) /* Unlikely race condition. */ { - perror(*argv); + xperror(*argv); return 1; } } @@ -476,7 +482,7 @@ int create_directory_user(const char* pathname) /* Set ownership. */ if (chown(pathname, getuid(), NOBODY_GROUP_GID) < 0) { - perror(*argv); + xperror(*argv); return 1; } } @@ -530,7 +536,7 @@ int unlink_recursive(const char* pathname) pfail: - perror(*argv); + xperror(*argv); rc = -1; goto done; } |