httpd.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. /* snac - A simple, minimalistic ActivityPub instance */
  2. /* copyright (c) 2022 - 2024 grunfink et al. / MIT license */
  3. #include "xs.h"
  4. #include "xs_io.h"
  5. #include "xs_json.h"
  6. #include "xs_socket.h"
  7. #include "xs_httpd.h"
  8. #include "xs_mime.h"
  9. #include "xs_time.h"
  10. #include "xs_openssl.h"
  11. #include "xs_fcgi.h"
  12. #include "xs_html.h"
  13. #include "snac.h"
  14. #include <setjmp.h>
  15. #include <pthread.h>
  16. #include <semaphore.h>
  17. #include <fcntl.h>
  18. #include <stdint.h>
  19. #include <sys/resource.h> // for getrlimit()
  20. #ifdef USE_POLL_FOR_SLEEP
  21. #include <poll.h>
  22. #endif
  23. /** server stat **/
  24. srv_stat s_stat = {0};
  25. srv_stat *p_stat = NULL;
  26. /** job control **/
  27. /* mutex to access the lists of jobs */
  28. static pthread_mutex_t job_mutex;
  29. /* semaphre to trigger job processing */
  30. static sem_t *job_sem;
  31. /* fifo of jobs */
  32. xs_list *job_fifo = NULL;
  33. /* nodeinfo 2.0 template */
  34. const char *nodeinfo_2_0_template = ""
  35. "{\"version\":\"2.0\","
  36. "\"software\":{\"name\":\"snac\",\"version\":\"" VERSION "\"},"
  37. "\"protocols\":[\"activitypub\"],"
  38. "\"services\":{\"outbound\":[],\"inbound\":[]},"
  39. "\"usage\":{\"users\":{\"total\":%d,\"activeMonth\":%d,\"activeHalfyear\":%d},"
  40. "\"localPosts\":%d},"
  41. "\"openRegistrations\":false,\"metadata\":{}}";
  42. xs_str *nodeinfo_2_0(void)
  43. /* builds a nodeinfo json object */
  44. {
  45. int n_utotal = 0;
  46. int n_umonth = 0;
  47. int n_uhyear = 0;
  48. int n_posts = 0;
  49. xs *users = user_list();
  50. xs_list *p = users;
  51. char *v;
  52. double now = (double)time(NULL);
  53. while (xs_list_iter(&p, &v)) {
  54. /* build the full path name to the last usage log */
  55. xs *llfn = xs_fmt("%s/user/%s/lastlog.txt", srv_basedir, v);
  56. double llsecs = now - mtime(llfn);
  57. if (llsecs < 60 * 60 * 24 * 30 * 6) {
  58. n_uhyear++;
  59. if (llsecs < 60 * 60 * 24 * 30)
  60. n_umonth++;
  61. }
  62. n_utotal++;
  63. /* build the file to each user public.idx */
  64. xs *pidxfn = xs_fmt("%s/user/%s/public.idx", srv_basedir, v);
  65. n_posts += index_len(pidxfn);
  66. }
  67. return xs_fmt(nodeinfo_2_0_template, n_utotal, n_umonth, n_uhyear, n_posts);
  68. }
  69. static xs_str *greeting_html(void)
  70. /* processes and returns greeting.html */
  71. {
  72. /* try to open greeting.html */
  73. xs *fn = xs_fmt("%s/greeting.html", srv_basedir);
  74. FILE *f;
  75. xs_str *s = NULL;
  76. if ((f = fopen(fn, "r")) != NULL) {
  77. s = xs_readall(f);
  78. fclose(f);
  79. /* replace %host% */
  80. s = xs_replace_i(s, "%host%", xs_dict_get(srv_config, "host"));
  81. const char *adm_email = xs_dict_get(srv_config, "admin_email");
  82. if (xs_is_null(adm_email) || *adm_email == '\0')
  83. adm_email = "the administrator of this instance";
  84. /* replace %admin_email */
  85. s = xs_replace_i(s, "%admin_email%", adm_email);
  86. /* does it have a %userlist% mark? */
  87. if (xs_str_in(s, "%userlist%") != -1) {
  88. char *host = xs_dict_get(srv_config, "host");
  89. xs *list = user_list();
  90. xs_list *p = list;
  91. xs_str *uid;
  92. xs_html *ul = xs_html_tag("ul",
  93. xs_html_attr("class", "snac-user-list"));
  94. p = list;
  95. while (xs_list_iter(&p, &uid)) {
  96. snac user;
  97. if (user_open(&user, uid)) {
  98. xs_html_add(ul,
  99. xs_html_tag("li",
  100. xs_html_tag("a",
  101. xs_html_attr("href", user.actor),
  102. xs_html_text("@"),
  103. xs_html_text(uid),
  104. xs_html_text("@"),
  105. xs_html_text(host),
  106. xs_html_text(" ("),
  107. xs_html_text(xs_dict_get(user.config, "name")),
  108. xs_html_text(")"))));
  109. user_free(&user);
  110. }
  111. }
  112. xs *s1 = xs_html_render(ul);
  113. s = xs_replace_i(s, "%userlist%", s1);
  114. }
  115. }
  116. return s;
  117. }
  118. int server_get_handler(xs_dict *req, const char *q_path,
  119. char **body, int *b_size, char **ctype)
  120. /* basic server services */
  121. {
  122. int status = 0;
  123. (void)req;
  124. /* is it the server root? */
  125. if (*q_path == '\0') {
  126. xs_dict *q_vars = xs_dict_get(req, "q_vars");
  127. char *t = NULL;
  128. if (xs_type(q_vars) == XSTYPE_DICT && (t = xs_dict_get(q_vars, "t"))) {
  129. int skip = 0;
  130. int show = xs_number_get(xs_dict_get(srv_config, "max_timeline_entries"));
  131. char *v;
  132. if ((v = xs_dict_get(q_vars, "skip")) != NULL)
  133. skip = atoi(v);
  134. if ((v = xs_dict_get(q_vars, "show")) != NULL)
  135. show = atoi(v);
  136. xs *tl = tag_search(t, skip, show + 1);
  137. int more = 0;
  138. if (xs_list_len(tl) >= show + 1) {
  139. /* drop the last one */
  140. tl = xs_list_del(tl, -1);
  141. more = 1;
  142. }
  143. *body = html_timeline(NULL, tl, 0, skip, show, more, t);
  144. }
  145. else
  146. if (xs_type(xs_dict_get(srv_config, "show_instance_timeline")) == XSTYPE_TRUE) {
  147. xs *tl = timeline_instance_list(0, 30);
  148. *body = html_timeline(NULL, tl, 0, 0, 0, 0, NULL);
  149. }
  150. else
  151. *body = greeting_html();
  152. if (*body)
  153. status = 200;
  154. }
  155. else
  156. if (strcmp(q_path, "/susie.png") == 0 || strcmp(q_path, "/favicon.ico") == 0 ) {
  157. status = 200;
  158. *body = xs_base64_dec(default_avatar_base64(), b_size);
  159. *ctype = "image/png";
  160. }
  161. else
  162. if (strcmp(q_path, "/.well-known/nodeinfo") == 0) {
  163. status = 200;
  164. *ctype = "application/json; charset=utf-8";
  165. *body = xs_fmt("{\"links\":["
  166. "{\"rel\":\"http:/" "/nodeinfo.diaspora.software/ns/schema/2.0\","
  167. "\"href\":\"%s/nodeinfo_2_0\"}]}",
  168. srv_baseurl);
  169. }
  170. else
  171. if (strcmp(q_path, "/nodeinfo_2_0") == 0) {
  172. status = 200;
  173. *ctype = "application/json; charset=utf-8";
  174. *body = nodeinfo_2_0();
  175. }
  176. else
  177. if (strcmp(q_path, "/robots.txt") == 0) {
  178. status = 200;
  179. *ctype = "text/plain";
  180. *body = xs_str_new("User-agent: *\n"
  181. "Disallow: /\n");
  182. }
  183. else
  184. if (strcmp(q_path, "/status.txt") == 0) {
  185. status = 200;
  186. *ctype = "text/plain";
  187. *body = xs_str_new("UP\n");
  188. xs *uptime = xs_str_time_diff(time(NULL) - p_stat->srv_start_time);
  189. srv_log(xs_fmt("status: uptime: %s", uptime));
  190. srv_log(xs_fmt("status: job_fifo len: %d", p_stat->job_fifo_size));
  191. }
  192. if (status != 0)
  193. srv_debug(1, xs_fmt("server_get_handler serving '%s' %d", q_path, status));
  194. return status;
  195. }
  196. void httpd_connection(FILE *f)
  197. /* the connection processor */
  198. {
  199. xs *req;
  200. char *method;
  201. int status = 0;
  202. xs_str *body = NULL;
  203. int b_size = 0;
  204. char *ctype = NULL;
  205. xs *headers = xs_dict_new();
  206. xs *q_path = NULL;
  207. xs *payload = NULL;
  208. xs *etag = NULL;
  209. int p_size = 0;
  210. char *p;
  211. int fcgi_id;
  212. if (p_stat->use_fcgi)
  213. req = xs_fcgi_request(f, &payload, &p_size, &fcgi_id);
  214. else
  215. req = xs_httpd_request(f, &payload, &p_size);
  216. if (req == NULL) {
  217. /* probably because a timeout */
  218. fclose(f);
  219. return;
  220. }
  221. if (!(method = xs_dict_get(req, "method")) || !(p = xs_dict_get(req, "path"))) {
  222. /* missing needed headers; discard */
  223. fclose(f);
  224. return;
  225. }
  226. q_path = xs_dup(p);
  227. /* crop the q_path from leading / and the prefix */
  228. if (xs_endswith(q_path, "/"))
  229. q_path = xs_crop_i(q_path, 0, -1);
  230. p = xs_dict_get(srv_config, "prefix");
  231. if (xs_startswith(q_path, p))
  232. q_path = xs_crop_i(q_path, strlen(p), 0);
  233. if (strcmp(method, "GET") == 0 || strcmp(method, "HEAD") == 0) {
  234. /* cascade through */
  235. if (status == 0)
  236. status = server_get_handler(req, q_path, &body, &b_size, &ctype);
  237. if (status == 0)
  238. status = webfinger_get_handler(req, q_path, &body, &b_size, &ctype);
  239. if (status == 0)
  240. status = activitypub_get_handler(req, q_path, &body, &b_size, &ctype);
  241. #ifndef NO_MASTODON_API
  242. if (status == 0)
  243. status = oauth_get_handler(req, q_path, &body, &b_size, &ctype);
  244. if (status == 0)
  245. status = mastoapi_get_handler(req, q_path, &body, &b_size, &ctype);
  246. #endif /* NO_MASTODON_API */
  247. if (status == 0)
  248. status = html_get_handler(req, q_path, &body, &b_size, &ctype, &etag);
  249. }
  250. else
  251. if (strcmp(method, "POST") == 0) {
  252. #ifndef NO_MASTODON_API
  253. if (status == 0)
  254. status = oauth_post_handler(req, q_path,
  255. payload, p_size, &body, &b_size, &ctype);
  256. if (status == 0)
  257. status = mastoapi_post_handler(req, q_path,
  258. payload, p_size, &body, &b_size, &ctype);
  259. #endif
  260. if (status == 0)
  261. status = activitypub_post_handler(req, q_path,
  262. payload, p_size, &body, &b_size, &ctype);
  263. if (status == 0)
  264. status = html_post_handler(req, q_path,
  265. payload, p_size, &body, &b_size, &ctype);
  266. }
  267. else
  268. if (strcmp(method, "PUT") == 0) {
  269. #ifndef NO_MASTODON_API
  270. if (status == 0)
  271. status = mastoapi_put_handler(req, q_path,
  272. payload, p_size, &body, &b_size, &ctype);
  273. #endif
  274. }
  275. else
  276. if (strcmp(method, "OPTIONS") == 0) {
  277. status = 200;
  278. }
  279. /* unattended? it's an error */
  280. if (status == 0) {
  281. srv_archive_error("unattended_method", "unattended method", req, payload);
  282. srv_debug(1, xs_fmt("httpd_connection unattended %s %s", method, q_path));
  283. status = 404;
  284. }
  285. if (status == 403)
  286. body = xs_str_new("<h1>403 Forbidden</h1>");
  287. if (status == 404)
  288. body = xs_str_new("<h1>404 Not Found</h1>");
  289. if (status == 400 && body != NULL)
  290. body = xs_str_new("<h1>400 Bad Request</h1>");
  291. if (status == 303)
  292. headers = xs_dict_append(headers, "location", body);
  293. if (status == 401) {
  294. xs *www_auth = xs_fmt("Basic realm=\"@%s@%s snac login\"",
  295. body, xs_dict_get(srv_config, "host"));
  296. headers = xs_dict_append(headers, "WWW-Authenticate", www_auth);
  297. }
  298. if (ctype == NULL)
  299. ctype = "text/html; charset=utf-8";
  300. headers = xs_dict_append(headers, "content-type", ctype);
  301. headers = xs_dict_append(headers, "x-creator", USER_AGENT);
  302. if (!xs_is_null(etag))
  303. headers = xs_dict_append(headers, "etag", etag);
  304. /* if there are any additional headers, add them */
  305. xs_dict *more_headers = xs_dict_get(srv_config, "http_headers");
  306. if (xs_type(more_headers) == XSTYPE_DICT) {
  307. char *k, *v;
  308. while (xs_dict_iter(&more_headers, &k, &v))
  309. headers = xs_dict_set(headers, k, v);
  310. }
  311. if (b_size == 0 && body != NULL)
  312. b_size = strlen(body);
  313. /* if it was a HEAD, no body will be sent */
  314. if (strcmp(method, "HEAD") == 0)
  315. body = xs_free(body);
  316. headers = xs_dict_append(headers, "access-control-allow-origin", "*");
  317. headers = xs_dict_append(headers, "access-control-allow-headers", "*");
  318. if (p_stat->use_fcgi)
  319. xs_fcgi_response(f, status, headers, body, b_size, fcgi_id);
  320. else
  321. xs_httpd_response(f, status, headers, body, b_size);
  322. fclose(f);
  323. srv_archive("RECV", NULL, req, payload, p_size, status, headers, body, b_size);
  324. /* JSON validation check */
  325. if (!xs_is_null(body) && strcmp(ctype, "application/json") == 0) {
  326. xs *j = xs_json_loads(body);
  327. if (j == NULL) {
  328. srv_log(xs_fmt("bad JSON"));
  329. srv_archive_error("bad_json", "bad JSON", req, body);
  330. }
  331. }
  332. xs_free(body);
  333. }
  334. static jmp_buf on_break;
  335. void term_handler(int s)
  336. {
  337. (void)s;
  338. longjmp(on_break, 1);
  339. }
  340. int job_fifo_ready(void)
  341. /* returns true if the job fifo is ready */
  342. {
  343. return job_fifo != NULL;
  344. }
  345. void job_post(const xs_val *job, int urgent)
  346. /* posts a job for the threads to process it */
  347. {
  348. if (job != NULL) {
  349. /* lock the mutex */
  350. pthread_mutex_lock(&job_mutex);
  351. /* add to the fifo */
  352. if (job_fifo != NULL) {
  353. if (urgent)
  354. job_fifo = xs_list_insert(job_fifo, 0, job);
  355. else
  356. job_fifo = xs_list_append(job_fifo, job);
  357. p_stat->job_fifo_size++;
  358. }
  359. /* unlock the mutex */
  360. pthread_mutex_unlock(&job_mutex);
  361. }
  362. /* ask for someone to attend it */
  363. sem_post(job_sem);
  364. }
  365. void job_wait(xs_val **job)
  366. /* waits for an available job */
  367. {
  368. *job = NULL;
  369. if (sem_wait(job_sem) == 0) {
  370. /* lock the mutex */
  371. pthread_mutex_lock(&job_mutex);
  372. /* dequeue */
  373. if (job_fifo != NULL) {
  374. job_fifo = xs_list_shift(job_fifo, job);
  375. p_stat->job_fifo_size--;
  376. }
  377. /* unlock the mutex */
  378. pthread_mutex_unlock(&job_mutex);
  379. }
  380. }
  381. #ifndef MAX_THREADS
  382. #define MAX_THREADS 256
  383. #endif
  384. static void *job_thread(void *arg)
  385. /* job thread */
  386. {
  387. int pid = (int)(uintptr_t)arg;
  388. srv_debug(1, xs_fmt("job thread %d started", pid));
  389. for (;;) {
  390. xs *job = NULL;
  391. job_wait(&job);
  392. srv_debug(2, xs_fmt("job thread %d wake up", pid));
  393. if (job == NULL)
  394. break;
  395. if (xs_type(job) == XSTYPE_DATA) {
  396. /* it's a socket */
  397. FILE *f = NULL;
  398. xs_data_get(&f, job);
  399. if (f != NULL)
  400. httpd_connection(f);
  401. }
  402. else {
  403. /* it's a q_item */
  404. process_queue_item(job);
  405. }
  406. }
  407. srv_debug(1, xs_fmt("job thread %d stopped", pid));
  408. return NULL;
  409. }
  410. /* background thread sleep control */
  411. static pthread_mutex_t sleep_mutex;
  412. static pthread_cond_t sleep_cond;
  413. static void *background_thread(void *arg)
  414. /* background thread (queue management and other things) */
  415. {
  416. time_t purge_time;
  417. (void)arg;
  418. /* first purge time */
  419. purge_time = time(NULL) + 10 * 60;
  420. srv_log(xs_fmt("background thread started"));
  421. while (p_stat->srv_running) {
  422. time_t t;
  423. int cnt = 0;
  424. {
  425. xs *list = user_list();
  426. char *p, *uid;
  427. /* process queues for all users */
  428. p = list;
  429. while (xs_list_iter(&p, &uid)) {
  430. snac snac;
  431. if (user_open(&snac, uid)) {
  432. cnt += process_user_queue(&snac);
  433. user_free(&snac);
  434. }
  435. }
  436. }
  437. /* global queue */
  438. cnt += process_queue();
  439. /* time to purge? */
  440. if ((t = time(NULL)) > purge_time) {
  441. /* next purge time is tomorrow */
  442. purge_time = t + 24 * 60 * 60;
  443. xs *q_item = xs_dict_new();
  444. q_item = xs_dict_append(q_item, "type", "purge");
  445. job_post(q_item, 0);
  446. }
  447. if (cnt == 0) {
  448. /* sleep 3 seconds */
  449. #ifdef USE_POLL_FOR_SLEEP
  450. poll(NULL, 0, 3 * 1000);
  451. #else
  452. struct timespec ts;
  453. clock_gettime(CLOCK_REALTIME, &ts);
  454. ts.tv_sec += 3;
  455. pthread_mutex_lock(&sleep_mutex);
  456. while (pthread_cond_timedwait(&sleep_cond, &sleep_mutex, &ts) == 0);
  457. pthread_mutex_unlock(&sleep_mutex);
  458. #endif
  459. }
  460. }
  461. srv_log(xs_fmt("background thread stopped"));
  462. return NULL;
  463. }
  464. void httpd(void)
  465. /* starts the server */
  466. {
  467. const char *address;
  468. const char *port;
  469. int rs;
  470. pthread_t threads[MAX_THREADS] = {0};
  471. int n;
  472. xs *sem_name = NULL;
  473. sem_t anon_job_sem;
  474. /* setup the server stat structure */
  475. {
  476. p_stat = &s_stat;
  477. }
  478. p_stat->srv_start_time = time(NULL);
  479. p_stat->use_fcgi = xs_type(xs_dict_get(srv_config, "fastcgi")) == XSTYPE_TRUE;
  480. address = xs_dict_get(srv_config, "address");
  481. port = xs_number_str(xs_dict_get(srv_config, "port"));
  482. if ((rs = xs_socket_server(address, port)) == -1) {
  483. srv_log(xs_fmt("cannot bind socket to %s:%s", address, port));
  484. return;
  485. }
  486. p_stat->srv_running = 1;
  487. signal(SIGPIPE, SIG_IGN);
  488. signal(SIGTERM, term_handler);
  489. signal(SIGINT, term_handler);
  490. srv_log(xs_fmt("httpd%s start %s:%s %s", p_stat->use_fcgi ? " (FastCGI)" : "",
  491. address, port, USER_AGENT));
  492. /* show the number of usable file descriptors */
  493. struct rlimit r;
  494. getrlimit(RLIMIT_NOFILE, &r);
  495. srv_debug(0, xs_fmt("available (rlimit) fds: %d (cur) / %d (max)",
  496. (int) r.rlim_cur, (int) r.rlim_max));
  497. /* initialize the job control engine */
  498. pthread_mutex_init(&job_mutex, NULL);
  499. sem_name = xs_fmt("/job_%d", getpid());
  500. job_sem = sem_open(sem_name, O_CREAT, 0644, 0);
  501. if (job_sem == NULL) {
  502. /* error opening a named semaphore; try with an anonymous one */
  503. if (sem_init(&anon_job_sem, 0, 0) != -1)
  504. job_sem = &anon_job_sem;
  505. }
  506. if (job_sem == NULL) {
  507. srv_log(xs_fmt("fatal error: cannot create semaphore -- cannot continue"));
  508. return;
  509. }
  510. job_fifo = xs_list_new();
  511. /* initialize sleep control */
  512. pthread_mutex_init(&sleep_mutex, NULL);
  513. pthread_cond_init(&sleep_cond, NULL);
  514. p_stat->n_threads = xs_number_get(xs_dict_get(srv_config, "num_threads"));
  515. #ifdef _SC_NPROCESSORS_ONLN
  516. if (p_stat->n_threads == 0) {
  517. /* get number of CPUs on the machine */
  518. p_stat->n_threads = sysconf(_SC_NPROCESSORS_ONLN);
  519. }
  520. #endif
  521. if (p_stat->n_threads < 4)
  522. p_stat->n_threads = 4;
  523. if (p_stat->n_threads > MAX_THREADS)
  524. p_stat->n_threads = MAX_THREADS;
  525. srv_debug(0, xs_fmt("using %d threads", p_stat->n_threads));
  526. /* thread #0 is the background thread */
  527. pthread_create(&threads[0], NULL, background_thread, NULL);
  528. /* the rest of threads are for job processing */
  529. char *ptr = (char *) 0x1;
  530. for (n = 1; n < p_stat->n_threads; n++)
  531. pthread_create(&threads[n], NULL, job_thread, ptr++);
  532. if (setjmp(on_break) == 0) {
  533. for (;;) {
  534. FILE *f = xs_socket_accept(rs);
  535. if (f != NULL) {
  536. xs *job = xs_data_new(&f, sizeof(FILE *));
  537. job_post(job, 1);
  538. }
  539. else
  540. break;
  541. }
  542. }
  543. p_stat->srv_running = 0;
  544. /* send as many empty jobs as working threads */
  545. for (n = 1; n < p_stat->n_threads; n++)
  546. job_post(NULL, 0);
  547. /* wait for all the threads to exit */
  548. for (n = 0; n < p_stat->n_threads; n++)
  549. pthread_join(threads[n], NULL);
  550. pthread_mutex_lock(&job_mutex);
  551. job_fifo = xs_free(job_fifo);
  552. pthread_mutex_unlock(&job_mutex);
  553. sem_close(job_sem);
  554. sem_unlink(sem_name);
  555. xs *uptime = xs_str_time_diff(time(NULL) - p_stat->srv_start_time);
  556. srv_log(xs_fmt("httpd%s stop %s:%s (run time: %s)",
  557. p_stat->use_fcgi ? " (FastCGI)" : "",
  558. address, port, uptime));
  559. }