| 6 |
* Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com> |
* Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com> |
| 7 |
*/ |
*/ |
| 8 |
|
|
| 9 |
|
#ifdef HAVE_CONFIG_H |
| 10 |
|
#include "config.h" |
| 11 |
|
#endif |
| 12 |
|
|
| 13 |
#include "log.h" |
#include "log.h" |
| 14 |
#include "section_list.h" |
#include "section_list.h" |
| 15 |
#include "trie_dict.h" |
#include "trie_dict.h" |
| 25 |
#include <sys/sem.h> |
#include <sys/sem.h> |
| 26 |
#include <sys/shm.h> |
#include <sys/shm.h> |
| 27 |
|
|
| 28 |
#ifdef _SEM_SEMUN_UNDEFINED |
#if defined(_SEM_SEMUN_UNDEFINED) || defined(__MSYS__) || defined(__MINGW32__) |
| 29 |
union semun |
union semun |
| 30 |
{ |
{ |
| 31 |
int val; /* Value for SETVAL */ |
int val; /* Value for SETVAL */ |
| 34 |
struct seminfo *__buf; /* Buffer for IPC_INFO |
struct seminfo *__buf; /* Buffer for IPC_INFO |
| 35 |
(Linux-specific) */ |
(Linux-specific) */ |
| 36 |
}; |
}; |
| 37 |
#endif // #ifdef _SEM_SEMUN_UNDEFINED |
#endif // #if defined(_SEM_SEMUN_UNDEFINED) |
| 38 |
|
|
| 39 |
enum _section_list_constant_t |
enum _section_list_constant_t |
| 40 |
{ |
{ |
| 1063 |
} |
} |
| 1064 |
|
|
| 1065 |
page_count = p_section->page_count - 1 + |
page_count = p_section->page_count - 1 + |
| 1066 |
(p_section->last_page_visible_article_count + p_section->ontop_article_count) / BBS_article_limit_per_page + |
(p_section->last_page_visible_article_count + p_section->ontop_article_count + BBS_article_limit_per_page - 1) / |
| 1067 |
((p_section->last_page_visible_article_count + p_section->ontop_article_count) % BBS_article_limit_per_page ? 1 : 0); |
BBS_article_limit_per_page; |
| 1068 |
|
|
| 1069 |
if (page_count < 0) |
if (page_count < 0) |
| 1070 |
{ |
{ |
| 1609 |
{ |
{ |
| 1610 |
int index; |
int index; |
| 1611 |
struct sembuf sops[4]; |
struct sembuf sops[4]; |
| 1612 |
|
#if !defined(__MSYS__) && !defined(__MINGW32__) |
| 1613 |
struct timespec timeout; |
struct timespec timeout; |
| 1614 |
|
#endif |
| 1615 |
int ret; |
int ret; |
| 1616 |
|
|
| 1617 |
index = get_section_index(p_section); |
index = get_section_index(p_section); |
| 1642 |
sops[3].sem_flg = SEM_UNDO; // undo on terminate |
sops[3].sem_flg = SEM_UNDO; // undo on terminate |
| 1643 |
} |
} |
| 1644 |
|
|
| 1645 |
|
#if defined(__MSYS__) || defined(__MINGW32__) |
| 1646 |
|
ret = semop(p_section_list_pool->semid, sops, (index == BBS_max_section ? 2 : 4)); |
| 1647 |
|
#else |
| 1648 |
timeout.tv_sec = wait_sec; |
timeout.tv_sec = wait_sec; |
| 1649 |
timeout.tv_nsec = 0; |
timeout.tv_nsec = 0; |
| 1650 |
|
|
| 1651 |
ret = semtimedop(p_section_list_pool->semid, sops, (index == BBS_max_section ? 2 : 4), &timeout); |
ret = semtimedop(p_section_list_pool->semid, sops, (index == BBS_max_section ? 2 : 4), &timeout); |
| 1652 |
|
#endif |
| 1653 |
if (ret == -1 && errno != EAGAIN && errno != EINTR) |
if (ret == -1 && errno != EAGAIN && errno != EINTR) |
| 1654 |
{ |
{ |
| 1655 |
log_error("semtimedop(index = %d, lock read) error %d\n", index, errno); |
log_error("semop(index = %d, lock read) error %d\n", index, errno); |
| 1656 |
} |
} |
| 1657 |
|
|
| 1658 |
return ret; |
return ret; |
| 1662 |
{ |
{ |
| 1663 |
int index; |
int index; |
| 1664 |
struct sembuf sops[3]; |
struct sembuf sops[3]; |
| 1665 |
|
#if !defined(__MSYS__) && !defined(__MINGW32__) |
| 1666 |
struct timespec timeout; |
struct timespec timeout; |
| 1667 |
|
#endif |
| 1668 |
int ret; |
int ret; |
| 1669 |
|
|
| 1670 |
index = get_section_index(p_section); |
index = get_section_index(p_section); |
| 1685 |
sops[2].sem_op = 0; // wait until unlocked |
sops[2].sem_op = 0; // wait until unlocked |
| 1686 |
sops[2].sem_flg = 0; |
sops[2].sem_flg = 0; |
| 1687 |
|
|
| 1688 |
|
#if defined(__MSYS__) || defined(__MINGW32__) |
| 1689 |
|
ret = semop(p_section_list_pool->semid, sops, 3); |
| 1690 |
|
#else |
| 1691 |
timeout.tv_sec = wait_sec; |
timeout.tv_sec = wait_sec; |
| 1692 |
timeout.tv_nsec = 0; |
timeout.tv_nsec = 0; |
| 1693 |
|
|
| 1694 |
ret = semtimedop(p_section_list_pool->semid, sops, 3, &timeout); |
ret = semtimedop(p_section_list_pool->semid, sops, 3, &timeout); |
| 1695 |
|
#endif |
| 1696 |
if (ret == -1 && errno != EAGAIN && errno != EINTR) |
if (ret == -1 && errno != EAGAIN && errno != EINTR) |
| 1697 |
{ |
{ |
| 1698 |
log_error("semtimedop(index = %d, lock write) error %d\n", index, errno); |
log_error("semop(index = %d, lock write) error %d\n", index, errno); |
| 1699 |
} |
} |
| 1700 |
|
|
| 1701 |
return ret; |
return ret; |