From c6562fa39bc3b609429fea9064a94cf080922da5 Mon Sep 17 00:00:00 2001 From: default Date: Sun, 15 Dec 2024 22:52:41 +0100 Subject: New function timeline_link_header(). --- httpd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'httpd.c') diff --git a/httpd.c b/httpd.c index 81d2f9e..0eff657 100644 --- a/httpd.c +++ b/httpd.c @@ -279,6 +279,7 @@ void httpd_connection(FILE *f) xs *payload = NULL; xs *etag = NULL; xs *last_modified = NULL; + xs *link = NULL; int p_size = 0; const char *p; int fcgi_id; @@ -326,7 +327,7 @@ void httpd_connection(FILE *f) status = oauth_get_handler(req, q_path, &body, &b_size, &ctype); if (status == 0) - status = mastoapi_get_handler(req, q_path, &body, &b_size, &ctype); + status = mastoapi_get_handler(req, q_path, &body, &b_size, &ctype, &link); #endif /* NO_MASTODON_API */ if (status == 0) @@ -426,6 +427,8 @@ void httpd_connection(FILE *f) headers = xs_dict_append(headers, "etag", etag); if (!xs_is_null(last_modified)) headers = xs_dict_append(headers, "last-modified", last_modified); + if (!xs_is_null(link)) + headers = xs_dict_append(headers, "Link", link); /* if there are any additional headers, add them */ const xs_dict *more_headers = xs_dict_get(srv_config, "http_headers"); -- cgit v1.2.3 From b9e0c6e74205ee43bea54fe91a9151053f107235 Mon Sep 17 00:00:00 2001 From: default Date: Mon, 16 Dec 2024 19:47:27 +0100 Subject: Added pidfile locking. --- httpd.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'httpd.c') diff --git a/httpd.c b/httpd.c index 0eff657..11e4d17 100644 --- a/httpd.c +++ b/httpd.c @@ -778,6 +778,26 @@ void httpd(void) xs *shm_name = NULL; sem_t anon_job_sem; xs *pidfile = xs_fmt("%s/server.pid", srv_basedir); + int pidfd; + + { + /* do some pidfile locking acrobatics */ + if ((pidfd = open(pidfile, O_RDWR | O_CREAT, 0660)) == -1) { + srv_log(xs_fmt("Cannot create pidfile %s -- cannot continue", pidfile)); + return; + } + + if (lockf(pidfd, F_TLOCK, 1) == -1) { + srv_log(xs_fmt("Cannot lock pidfile %s -- server already running?", pidfile)); + close(pidfd); + return; + } + + ftruncate(pidfd, 0); + + xs *s = xs_fmt("%d\n", (int)getpid()); + write(pidfd, s, strlen(s)); + } address = xs_dict_get(srv_config, "address"); @@ -813,17 +833,6 @@ void httpd(void) srv_log(xs_fmt("httpd%s start %s %s", p_state->use_fcgi ? " (FastCGI)" : "", full_address, USER_AGENT)); - { - FILE *f; - - if ((f = fopen(pidfile, "w")) != NULL) { - fprintf(f, "%d\n", getpid()); - fclose(f); - } - else - srv_log(xs_fmt("Cannot create %s: %s", pidfile, strerror(errno))); - } - /* show the number of usable file descriptors */ struct rlimit r; getrlimit(RLIMIT_NOFILE, &r); -- cgit v1.2.3