diff options
Diffstat (limited to 'httpd.c')
| -rw-r--r-- | httpd.c | 13 |
1 files changed, 13 insertions, 0 deletions
| @@ -483,6 +483,7 @@ void httpd(void) | |||
| 483 | int n; | 483 | int n; |
| 484 | time_t start_time = time(NULL); | 484 | time_t start_time = time(NULL); |
| 485 | char sem_name[24]; | 485 | char sem_name[24]; |
| 486 | sem_t anon_job_sem; | ||
| 486 | 487 | ||
| 487 | address = xs_dict_get(srv_config, "address"); | 488 | address = xs_dict_get(srv_config, "address"); |
| 488 | port = xs_number_get(xs_dict_get(srv_config, "port")); | 489 | port = xs_number_get(xs_dict_get(srv_config, "port")); |
| @@ -510,6 +511,18 @@ void httpd(void) | |||
| 510 | pthread_mutex_init(&job_mutex, NULL); | 511 | pthread_mutex_init(&job_mutex, NULL); |
| 511 | sprintf(sem_name, "/job_%d", getpid()); | 512 | sprintf(sem_name, "/job_%d", getpid()); |
| 512 | job_sem = sem_open(sem_name, O_CREAT, 0644, 0); | 513 | job_sem = sem_open(sem_name, O_CREAT, 0644, 0); |
| 514 | |||
| 515 | if (job_sem == NULL) { | ||
| 516 | /* error opening a named semaphore; try with an anonymous one */ | ||
| 517 | if (sem_init(&anon_job_sem, 0, 0) != -1) | ||
| 518 | job_sem = &anon_job_sem; | ||
| 519 | } | ||
| 520 | |||
| 521 | if (job_sem == NULL) { | ||
| 522 | srv_log(xs_fmt("fatal error: cannot create semaphore -- cannot continue")); | ||
| 523 | return; | ||
| 524 | } | ||
| 525 | |||
| 513 | job_fifo = xs_list_new(); | 526 | job_fifo = xs_list_new(); |
| 514 | 527 | ||
| 515 | /* initialize sleep control */ | 528 | /* initialize sleep control */ |