commit efec8a6
default
·
2023-05-25 15:20:21 +0000 UTC
parent 18c842d
If sem_open() fails, try again with sem_init().
1 files changed,
+13,
-0
M
httpd.c
M
httpd.c
+13,
-0
1@@ -483,6 +483,7 @@ void httpd(void)
2 int n;
3 time_t start_time = time(NULL);
4 char sem_name[24];
5+ sem_t anon_job_sem;
6
7 address = xs_dict_get(srv_config, "address");
8 port = xs_number_get(xs_dict_get(srv_config, "port"));
9@@ -510,6 +511,18 @@ void httpd(void)
10 pthread_mutex_init(&job_mutex, NULL);
11 sprintf(sem_name, "/job_%d", getpid());
12 job_sem = sem_open(sem_name, O_CREAT, 0644, 0);
13+
14+ if (job_sem == NULL) {
15+ /* error opening a named semaphore; try with an anonymous one */
16+ if (sem_init(&anon_job_sem, 0, 0) != -1)
17+ job_sem = &anon_job_sem;
18+ }
19+
20+ if (job_sem == NULL) {
21+ srv_log(xs_fmt("fatal error: cannot create semaphore -- cannot continue"));
22+ return;
23+ }
24+
25 job_fifo = xs_list_new();
26
27 /* initialize sleep control */