commit 3bd8345
poesty
·
2023-05-09 15:11:57 +0000 UTC
parent 6bad235
Fixed the issue of semaphore name conflicts.
1 files changed,
+4,
-1
M
httpd.c
M
httpd.c
+4,
-1
1@@ -480,6 +480,7 @@ void httpd(void)
2 pthread_t threads[MAX_THREADS] = {0};
3 int n_threads = 0;
4 int n;
5+ char sem_name[24];
6
7 address = xs_dict_get(srv_config, "address");
8 port = xs_number_get(xs_dict_get(srv_config, "port"));
9@@ -505,7 +506,8 @@ void httpd(void)
10
11 /* initialize the job control engine */
12 pthread_mutex_init(&job_mutex, NULL);
13- job_sem = sem_open("/job", O_CREAT, 0644, 0);
14+ sprintf(sem_name, "/job_%d", getpid());
15+ job_sem = sem_open(sem_name, O_CREAT, 0644, 0);
16 job_fifo = xs_list_new();
17
18 /* initialize sleep control */
19@@ -565,6 +567,7 @@ void httpd(void)
20 pthread_mutex_unlock(&job_mutex);
21
22 sem_close(job_sem);
23+ sem_unlink(sem_name);
24
25 srv_log(xs_fmt("httpd stop %s:%d", address, port));
26 }