aboutsummaryrefslogtreecommitdiff
path: root/kike.c
diff options
context:
space:
mode:
Diffstat (limited to 'kike.c')
-rw-r--r--kike.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/kike.c b/kike.c
index b5bda0a..c5c36da 100644
--- a/kike.c
+++ b/kike.c
@@ -31,15 +31,7 @@
static struct config_item g_config_table[] =
{
- // TODO: use XDG_RUNTIME_DIR if relative. The last fallback is:
- //
- // "$XDG_DATA_HOME defines the base directory relative to which user
- // specific data files should be stored. If $XDG_DATA_HOME is either not
- // set or empty, a default equal to $HOME/.local/share should be used."
- //
- // Note that when using XDG_RUNTIME_DIR, it either needs to have access
- // time bumped every 6 hours, or have the sticky bit set.
- { "pid_file", NULL, "Full path for the PID file" },
+ { "pid_file", NULL, "Path or name of the PID file" },
{ "server_name", NULL, "Server name" },
{ "server_info", "My server", "Brief server description" },
{ "motd", NULL, "MOTD filename" },
@@ -3671,14 +3663,12 @@ irc_initialize_server_name (struct server_context *ctx, struct error **e)
}
static bool
-irc_lock_pid_file (struct server_context *ctx, struct error **e)
+lock_pid_file (const char *path, struct error **e)
{
- const char *path = str_map_find (&ctx->config, "pid_file");
- if (!path)
- return true;
-
+ // When using XDG_RUNTIME_DIR, the file needs to either have its
+ // access time bumped every 6 hours, or have the sticky bit set
int fd = open (path, O_RDWR | O_CREAT,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH /* 644 */);
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH /* 644 */ | S_ISVTX /* sticky */);
if (fd < 0)
{
error_set (e, "can't open `%s': %s", path, strerror (errno));
@@ -3695,6 +3685,7 @@ irc_lock_pid_file (struct server_context *ctx, struct error **e)
if (fcntl (fd, F_SETLK, &lock))
{
error_set (e, "can't lock `%s': %s", path, strerror (errno));
+ xclose (fd);
return false;
}
@@ -3706,6 +3697,7 @@ irc_lock_pid_file (struct server_context *ctx, struct error **e)
|| write (fd, pid.str, pid.len) != (ssize_t) pid.len)
{
error_set (e, "can't write to `%s': %s", path, strerror (errno));
+ xclose (fd);
return false;
}
str_free (&pid);
@@ -3715,6 +3707,19 @@ irc_lock_pid_file (struct server_context *ctx, struct error **e)
return true;
}
+static bool
+irc_lock_pid_file (struct server_context *ctx, struct error **e)
+{
+ const char *path = str_map_find (&ctx->config, "pid_file");
+ if (!path)
+ return true;
+
+ char *resolved = resolve_filename (path, resolve_relative_runtime_filename);
+ bool result = lock_pid_file (resolved, e);
+ free (resolved);
+ return result;
+}
+
static int
irc_listen (struct addrinfo *gai_iter)
{