diff options
| author | 2024-12-23 13:42:45 +0100 | |
|---|---|---|
| committer | 2024-12-23 13:42:45 +0100 | |
| commit | a7ca4007f2a55a8becab1e4595d2696dd6e7bfd1 (patch) | |
| tree | 3128196bd7eb298be5a37edac5922009ec5fcac1 /httpd.c | |
| parent | Merge tag '2.66' (diff) | |
| parent | Version 2.67 RELEASED. (diff) | |
| download | snac2-a7ca4007f2a55a8becab1e4595d2696dd6e7bfd1.tar.gz snac2-a7ca4007f2a55a8becab1e4595d2696dd6e7bfd1.tar.xz snac2-a7ca4007f2a55a8becab1e4595d2696dd6e7bfd1.zip | |
Merge tag '2.67'
Version 2.67 RELEASED.
Diffstat (limited to 'httpd.c')
| -rw-r--r-- | httpd.c | 36 |
1 files changed, 24 insertions, 12 deletions
| @@ -279,6 +279,7 @@ void httpd_connection(FILE *f) | |||
| 279 | xs *payload = NULL; | 279 | xs *payload = NULL; |
| 280 | xs *etag = NULL; | 280 | xs *etag = NULL; |
| 281 | xs *last_modified = NULL; | 281 | xs *last_modified = NULL; |
| 282 | xs *link = NULL; | ||
| 282 | int p_size = 0; | 283 | int p_size = 0; |
| 283 | const char *p; | 284 | const char *p; |
| 284 | int fcgi_id; | 285 | int fcgi_id; |
| @@ -326,7 +327,7 @@ void httpd_connection(FILE *f) | |||
| 326 | status = oauth_get_handler(req, q_path, &body, &b_size, &ctype); | 327 | status = oauth_get_handler(req, q_path, &body, &b_size, &ctype); |
| 327 | 328 | ||
| 328 | if (status == 0) | 329 | if (status == 0) |
| 329 | status = mastoapi_get_handler(req, q_path, &body, &b_size, &ctype); | 330 | status = mastoapi_get_handler(req, q_path, &body, &b_size, &ctype, &link); |
| 330 | #endif /* NO_MASTODON_API */ | 331 | #endif /* NO_MASTODON_API */ |
| 331 | 332 | ||
| 332 | if (status == 0) | 333 | if (status == 0) |
| @@ -426,6 +427,8 @@ void httpd_connection(FILE *f) | |||
| 426 | headers = xs_dict_append(headers, "etag", etag); | 427 | headers = xs_dict_append(headers, "etag", etag); |
| 427 | if (!xs_is_null(last_modified)) | 428 | if (!xs_is_null(last_modified)) |
| 428 | headers = xs_dict_append(headers, "last-modified", last_modified); | 429 | headers = xs_dict_append(headers, "last-modified", last_modified); |
| 430 | if (!xs_is_null(link)) | ||
| 431 | headers = xs_dict_append(headers, "Link", link); | ||
| 429 | 432 | ||
| 430 | /* if there are any additional headers, add them */ | 433 | /* if there are any additional headers, add them */ |
| 431 | const xs_dict *more_headers = xs_dict_get(srv_config, "http_headers"); | 434 | const xs_dict *more_headers = xs_dict_get(srv_config, "http_headers"); |
| @@ -775,6 +778,26 @@ void httpd(void) | |||
| 775 | xs *shm_name = NULL; | 778 | xs *shm_name = NULL; |
| 776 | sem_t anon_job_sem; | 779 | sem_t anon_job_sem; |
| 777 | xs *pidfile = xs_fmt("%s/server.pid", srv_basedir); | 780 | xs *pidfile = xs_fmt("%s/server.pid", srv_basedir); |
| 781 | int pidfd; | ||
| 782 | |||
| 783 | { | ||
| 784 | /* do some pidfile locking acrobatics */ | ||
| 785 | if ((pidfd = open(pidfile, O_RDWR | O_CREAT, 0660)) == -1) { | ||
| 786 | srv_log(xs_fmt("Cannot create pidfile %s -- cannot continue", pidfile)); | ||
| 787 | return; | ||
| 788 | } | ||
| 789 | |||
| 790 | if (lockf(pidfd, F_TLOCK, 1) == -1) { | ||
| 791 | srv_log(xs_fmt("Cannot lock pidfile %s -- server already running?", pidfile)); | ||
| 792 | close(pidfd); | ||
| 793 | return; | ||
| 794 | } | ||
| 795 | |||
| 796 | ftruncate(pidfd, 0); | ||
| 797 | |||
| 798 | xs *s = xs_fmt("%d\n", (int)getpid()); | ||
| 799 | write(pidfd, s, strlen(s)); | ||
| 800 | } | ||
| 778 | 801 | ||
| 779 | address = xs_dict_get(srv_config, "address"); | 802 | address = xs_dict_get(srv_config, "address"); |
| 780 | 803 | ||
| @@ -810,17 +833,6 @@ void httpd(void) | |||
| 810 | srv_log(xs_fmt("httpd%s start %s %s", p_state->use_fcgi ? " (FastCGI)" : "", | 833 | srv_log(xs_fmt("httpd%s start %s %s", p_state->use_fcgi ? " (FastCGI)" : "", |
| 811 | full_address, USER_AGENT)); | 834 | full_address, USER_AGENT)); |
| 812 | 835 | ||
| 813 | { | ||
| 814 | FILE *f; | ||
| 815 | |||
| 816 | if ((f = fopen(pidfile, "w")) != NULL) { | ||
| 817 | fprintf(f, "%d\n", getpid()); | ||
| 818 | fclose(f); | ||
| 819 | } | ||
| 820 | else | ||
| 821 | srv_log(xs_fmt("Cannot create %s: %s", pidfile, strerror(errno))); | ||
| 822 | } | ||
| 823 | |||
| 824 | /* show the number of usable file descriptors */ | 836 | /* show the number of usable file descriptors */ |
| 825 | struct rlimit r; | 837 | struct rlimit r; |
| 826 | getrlimit(RLIMIT_NOFILE, &r); | 838 | getrlimit(RLIMIT_NOFILE, &r); |