Skip to content

Commit e81535f

Browse files
committed
Check in 1.8.2.1
1 parent 9ae28c3 commit e81535f

File tree

12 files changed

+83
-51
lines changed

12 files changed

+83
-51
lines changed

LSQUICCOMMIT

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6ed1d09f503c2fc25c3a2b204224ecdad36e077c
1+
d3582f34f0b8dcdb64b3d6b0a25d351bc96f8cdf

dist/lsns/bin/common.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
this = sys.modules[__name__]
1414
this.logged = None
1515
this.serverRoot = '/usr/local/lsws'
16+
this.min_uid = 0
1617

1718
def init_logging():
1819
logging.basicConfig(format="%(asctime)s.%(msecs)03d" + " [%(levelname)s] %(message)s",
@@ -80,14 +81,17 @@ def get_def_min_uid():
8081
return 1000
8182

8283
def get_min_uid():
84+
if this.min_uid != 0:
85+
return this.min_uid
8386
fullfile = get_conf_file('lsns.conf')
8487
try:
8588
f = open(fullfile, 'r')
8689
except Exception as err:
8790
if this.logged is None:
8891
logging.info('Error opening %s: %s, continuing with default min uid %d' % (fullfile, err, get_def_min_uid()))
8992
this.logged = True
90-
return get_def_min_uid()
93+
this.min_uid = get_def_min_uid()
94+
return this.min_uid
9195
try:
9296
uidstr = f.readline()
9397
except Exception as err:
@@ -96,8 +100,9 @@ def get_min_uid():
96100
this.logged = True
97101
uidstr = str(get_def_min_uid())
98102
f.close()
99-
logging.debug('Using min uid: %d' % int(uidstr))
100-
return int(uidstr)
103+
this.min_uid = int(uidstr)
104+
logging.debug('Using min uid: %d' % this.min_uid)
105+
return this.min_uid
101106

102107
def container_file():
103108
return server_root() + "/lsns/conf/lscntr.txt"

dist/lsns/bin/lscgctl

+5-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def list_user(user, dict):
144144
subdict['cpu'] = get_systemctl_cpu(systemctl_results)
145145
subdict['io'] = get_systemctl_dev_num(systemctl_results, 'IOReadBandwidthMax')
146146
subdict['iops'] = get_systemctl_dev_num(systemctl_results, 'IOReadIOPSMax')
147-
subdict['mem'] = get_systemctl_num(systemctl_results, "MemoryHigh")
147+
subdict['mem'] = get_systemctl_num(systemctl_results, "MemoryMax")
148148
subdict['tasks'] = get_systemctl_num(systemctl_results, 'TasksMax')
149149
logging.debug("uid[" + str(user.pw_uid) + ']: ' + str(subdict))
150150
dict[user.pw_uid] = subdict
@@ -194,7 +194,7 @@ def set_no_device_parm(args, option, properties):
194194
val = common.int_num_values(args.cpu)
195195
format_set = '%s=%d%%'
196196
elif option == common.OPTION_MEM:
197-
title = 'MemoryHigh'
197+
title = 'MemoryMax'
198198
val = common.int_num_values(args.mem)
199199
format_set = '%s=%d'
200200
else:
@@ -205,6 +205,9 @@ def set_no_device_parm(args, option, properties):
205205
properties.append('%s=' % title)
206206
else:
207207
properties.append(format_set % (title, val))
208+
if option == common.OPTION_MEM:
209+
properties.append('MemoryHigh=')
210+
208211

209212
def reset_user(args, user, reload):
210213
args.cpu = '-1'

dist/lsns/bin/lsnsctl

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def command_unmount(args, user):
195195
print(result.stdout.decode('utf-8'))
196196
print(result.stderr.decode('utf-8'))
197197
if args.command == 'unmount-all':
198-
common.restart_external(None, True)
198+
common.restart_external([], True)
199199
else:
200200
common.restart_external([user], False)
201201

dist/lsns/bin/lspkgctl

+9-6
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,16 @@ def plesk_home_dict():
129129
def read_pleskplans():
130130
home_dict = plesk_home_dict()
131131
plans = {}
132+
# Thanks to Stas Karpinsky of vangus.co.il for correcting the SQL!
132133
plan_lines = run_program(['plesk', 'db', \
133-
"SELECT sys_users.login, sys_users.home, " + \
134-
"Templates.name from sys_users join " +
135-
"PlansSubscriptions on " +
136-
"PlansSubscriptions.subscription_id = sys_users.id " +
137-
"join Templates on " +
138-
"PlansSubscriptions.plan_id = Templates.id"])
134+
"select sys_users.login, sys_users.home, " + \
135+
"Templates.name from sys_users " + \
136+
"join hosting on sys_users.id = hosting.sys_user_id " + \
137+
"join domains on hosting.dom_id = domains.id " + \
138+
"join Subscriptions on domains.id = Subscriptions.object_id " + \
139+
"and Subscriptions.object_type = 'domain' " + \
140+
"join PlansSubscriptions on Subscriptions.id = PlansSubscriptions.subscription_id " + \
141+
"join Templates on PlansSubscriptions.plan_id = Templates.id"])
139142
for line in plan_lines.splitlines():
140143
if line.startswith('+-') or line.startswith('| login'):
141144
continue

src/h2/h2stream.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ int H2Stream::onPeerShutdown()
7878
if (((H2Connection *)m_pH2Conn)->assignStreamHandler(this) == LS_FAIL)
7979
return LS_FAIL;
8080
}
81-
if (getHandler()->detectContentLenMismatch(m_bufRcvd.size()))
81+
if (getHandler()
82+
&& getHandler()->detectContentLenMismatch(m_bufRcvd.size()))
8283
return LS_FAIL;
8384
return LS_OK;
8485
}

src/main/lshttpdmain.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
/***
9191
* Do not change the below format, it will be set correctly while packing the code
9292
*/
93-
#define BUILDTIME "built: Sat Oct 26 04:05:54 UTC 2024"
93+
#define BUILDTIME "built: Wed Dec 18 03:28:57 UTC 2024"
9494

9595
static const char s_pVersionFull[] = "LiteSpeed/" PACKAGE_VERSION
9696
" Open (" LS_MODULE_VERSION_INFO_ONELINE ") BUILD (" BUILDTIME ")";

src/shm/lsshm.cpp

+42-27
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,15 @@ void LsShm::setFatalErrorHandler( void (*cb)() )
205205

206206
void LsShm::tryRecoverBadOffset(LsShmOffset_t offset)
207207
{
208-
if (x_pShmMap->x_stat.m_iFileSize > offset)
208+
LsShmSize_t curMaxSize = getMapFileSize();
209+
if (curMaxSize > offset)
209210
{
210211
remap();
211212
return;
212213
}
213214
deleteFile();
214215
if (s_fatalErrorCb)
215216
(*s_fatalErrorCb)();
216-
LsShmSize_t curMaxSize = x_pShmMap->x_stat.m_iFileSize;
217217
if ( offset < curMaxSize)
218218
{
219219
assert(offset < curMaxSize);
@@ -231,7 +231,8 @@ void LsShm::tryRecoverCorruption()
231231

232232
int LsShm::isOffsetValid(LsShmOffset_t offset)
233233
{
234-
return (offset <= x_pShmMap->x_stat.m_iFileSize);
234+
LsShmSize_t curMaxSize = getMapFileSize();
235+
return (offset <= curMaxSize);
235236
}
236237

237238

@@ -527,8 +528,8 @@ LsShmStatus_t LsShm::newShmMap(LsShmSize_t size, uint64_t id)
527528
return LSSHM_ERROR;
528529
x_pShmMap->x_id = id;
529530
x_pShmMap->x_globalHashOff = 0;
530-
x_pShmMap->x_stat.m_iFileSize = size; // x_iMaxSize
531-
x_pShmMap->x_stat.m_iUsedSize = LSSHM_SHM_UNITSIZE; // x_iCurSize
531+
ls_atomic_set(&x_pShmMap->x_stat.m_iFileSize, size); // x_iMaxSize
532+
ls_atomic_set(&x_pShmMap->x_stat.m_iUsedSize, LSSHM_SHM_UNITSIZE); // x_iCurSize
532533

533534
if (((x_pShmMap->x_iLockOffset = allocLock()) == 0)
534535
|| (m_pShmLock = offset2pLock(x_pShmMap->x_iLockOffset)) == NULL
@@ -664,21 +665,23 @@ LsShmStatus_t LsShm::initShm(const char *mapName, LsShmXSize_t size,
664665
m_pFileName, pShmMap->x_id, m_locks.getId());
665666
return LSSHM_BADVERSION;
666667
}
667-
668-
if (pShmMap->x_stat.m_iFileSize != mystat.st_size)
668+
LsShmXSize_t fileSize = ls_atomic_value(&pShmMap->x_stat.m_iFileSize);
669+
if (fileSize != mystat.st_size)
669670
{
670671
SHM_WARN("SHM file [%s] size: %lld, does not match x_stat.m_iFileSize: %ld, correct it",
671-
m_pFileName, mystat.st_size, (long)pShmMap->x_stat.m_iFileSize);
672-
pShmMap->x_stat.m_iFileSize = mystat.st_size;
672+
m_pFileName, mystat.st_size, (long)fileSize);
673+
ls_atomic_set(&pShmMap->x_stat.m_iFileSize, mystat.st_size);
674+
fileSize = mystat.st_size;
673675
}
674676

675677
// expand the file if needed... won't shrink
676-
if (size > pShmMap->x_stat.m_iFileSize)
678+
if (size > fileSize)
677679
{
678-
if (expandFile((LsShmOffset_t)pShmMap->x_stat.m_iFileSize,
679-
(LsShmXSize_t)(size - pShmMap->x_stat.m_iFileSize)) != LSSHM_OK)
680+
if (expandFile((LsShmOffset_t)fileSize,
681+
(LsShmXSize_t)(size - fileSize)) != LSSHM_OK)
680682
return LSSHM_ERROR;
681-
pShmMap->x_stat.m_iFileSize = size;
683+
fstat(m_iFd, &mystat);
684+
ls_atomic_set(&pShmMap->x_stat.m_iFileSize, mystat.st_size);
682685
}
683686
else
684687
size = mystat.st_size;
@@ -712,14 +715,21 @@ LsShmStatus_t LsShm::initShm(const char *mapName, LsShmXSize_t size,
712715
// will not shrink at the current moment
713716
LsShmStatus_t LsShm::expand(LsShmXSize_t incrSize)
714717
{
715-
LsShmXSize_t xsize = x_pShmMap->x_stat.m_iFileSize;
716-
718+
LsShmXSize_t xsize = getMapFileSize();
719+
struct stat st;
717720
if (expandFile((LsShmOffset_t)xsize, incrSize) != LSSHM_OK)
718721
return LSSHM_ERROR;
719722

720723
//unmap();
721724
xsize += incrSize;
722-
x_pShmMap->x_stat.m_iFileSize = xsize;
725+
fstat(m_iFd, &st);
726+
if (st.st_size != xsize)
727+
{
728+
SHM_WARN("LsShm::expand() [%s], after exapnd, expected size: %d, actual size: %lld",
729+
m_pFileName, xsize, st.st_size);
730+
xsize = st.st_size;
731+
}
732+
ls_atomic_set(&x_pShmMap->x_stat.m_iFileSize, xsize);
723733

724734
if (mapAddrMap(xsize) != LSSHM_OK)
725735
{
@@ -759,12 +769,14 @@ LsShmStatus_t LsShm::remap()
759769
struct stat mystat;
760770
if (fstat(m_iFd, &mystat) < 0)
761771
return LSSHM_BADMAPFILE;
762-
if (mystat.st_size != x_pShmMap->x_stat.m_iFileSize)
772+
773+
LsShmXSize_t xsize = getMapFileSize();
774+
if (mystat.st_size != xsize)
763775
{
764776
setErrMsg(LSSHM_SYSERROR, "%s: real file size: %lu, SHM stats file size: %lu.",
765777
m_pFileName, (unsigned long)mystat.st_size,
766-
(unsigned long)x_pShmMap->x_stat.m_iFileSize);
767-
if ( x_pShmMap->x_stat.m_iFileSize - mystat.st_size > 100 * 1024 * 1024)
778+
(unsigned long)xsize);
779+
if ( xsize - mystat.st_size > 100 * 1024 * 1024)
768780
{
769781
#ifndef NDEBUG
770782
LsShmMap mapCopy = *x_pShmMap;
@@ -775,10 +787,10 @@ LsShmStatus_t LsShm::remap()
775787

776788
assert(mapCopy.x_stat.m_iFileSize > 0 && !"bad file size.");
777789
}
790+
xsize = mystat.st_size;
778791
}
779-
LsShmXSize_t size = x_pShmMap->x_stat.m_iFileSize;
780792
//unmap();
781-
return mapAddrMap(size);
793+
return mapAddrMap(xsize);
782794
}
783795

784796

@@ -809,36 +821,39 @@ LsShmOffset_t LsShm::allocPage(LsShmSize_t pagesize)
809821
LsShmXSize_t needSize = 0;
810822
LsShmXSize_t targetSize = 0;
811823
// Allocate from heap space
824+
LsShmXSize_t used_size = getUsedSize();
812825
availSize = avail();
813826
LsShmSize_t availAddrSize = m_addrMap.getAvailAddrSpace(
814-
x_pShmMap->x_stat.m_iUsedSize, pagesize);
827+
used_size, pagesize);
815828
if (pagesize > availSize || pagesize > availAddrSize)
816829
{
817830
// min 16 unit at a time
818831

819832
LS_DBG("[SHM] [PID:%d] To alloc page: %d bytes at offset: %ld, availAddr: %d\n",
820-
getpid(), pagesize, (long)x_pShmMap->x_stat.m_iUsedSize, availAddrSize);
833+
getpid(), pagesize, (long)used_size, availAddrSize);
821834
if (pagesize > availAddrSize)
822835
needSize = availAddrSize;
823836
if (pagesize + needSize > availSize)
824837
needSize += (pagesize + needSize - availSize);
825838

826839
if (needSize > 0)
827840
{
828-
targetSize = x_pShmMap->x_stat.m_iFileSize + needSize;
841+
LsShmXSize_t xsize = getMapFileSize();
842+
targetSize = xsize + needSize;
829843
targetSize = (targetSize + (16 * LSSHM_SHM_UNITSIZE - 1)) &
830844
~(16 * LSSHM_SHM_UNITSIZE - 1);
831845

832-
if (expand(targetSize - x_pShmMap->x_stat.m_iFileSize) != LSSHM_OK)
846+
if (expand(targetSize - xsize) != LSSHM_OK)
833847
{
834848
offset = 0;
835849
goto out;
836850
}
837851
}
852+
used_size = getUsedSize();
853+
availAddrSize = m_addrMap.getAvailAddrSpace(used_size, pagesize);
838854
if (pagesize > availAddrSize)
839855
{
840-
m_pGPool->addLeftOverPages(x_pShmMap->x_stat.m_iUsedSize,
841-
availAddrSize);
856+
m_pGPool->addLeftOverPages(used_size, availAddrSize);
842857
used(availAddrSize);
843858
}
844859
}

src/shm/lsshm.h

+11-6
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,11 @@ class LsShm : public ls_shm_s
139139
}
140140

141141
LsShmXSize_t shmMaxSize() const { return m_iMaxShmSize; }
142-
LsShmXSize_t maxSize() const { return x_pStats->m_iFileSize; }
142+
LsShmXSize_t getMapFileSize() const
143+
{ return ls_atomic_value(&x_pStats->m_iFileSize); }
144+
LsShmXSize_t getUsedSize() const
145+
{ return ls_atomic_value(&x_pStats->m_iUsedSize); }
146+
143147
LsShmXSize_t oldMaxSize() const { return m_iMaxSizeO; }
144148
const char *fileName() const { return m_pFileName; }
145149
const char *mapName() const { return obj.m_pName; }
@@ -185,8 +189,9 @@ class LsShm : public ls_shm_s
185189
}
186190

187191
LsShmXSize_t avail() const
188-
{ return (x_pStats->m_iFileSize > x_pStats->m_iUsedSize)
189-
? x_pStats->m_iFileSize - x_pStats->m_iUsedSize : 0; }
192+
{ LsShmXSize_t file_size = getMapFileSize();
193+
LsShmXSize_t used = getUsedSize();
194+
return (file_size > used) ? file_size - used : 0; }
190195

191196
LsShmStatus_t status() const { return m_status; }
192197

@@ -215,7 +220,7 @@ class LsShm : public ls_shm_s
215220

216221
ls_attr_inline LsShmStatus_t chkRemap()
217222
{
218-
return (x_pStats->m_iFileSize == m_iMaxSizeO) ? LSSHM_OK : remap();
223+
return (getMapFileSize() == m_iMaxSizeO) ? LSSHM_OK : remap();
219224
}
220225

221226
LsShmStatus_t remap();
@@ -279,8 +284,8 @@ class LsShm : public ls_shm_s
279284

280285
void used(LsShmSize_t size)
281286
{
282-
assert(x_pStats->m_iFileSize >= x_pStats->m_iUsedSize + size);
283-
x_pStats->m_iUsedSize += size;
287+
assert(getMapFileSize() >= getUsedSize() + size);
288+
ls_atomic_add(&x_pStats->m_iUsedSize, size);
284289
}
285290

286291
LsShmStatus_t mapAddrMap(LsShmXSize_t size);

src/shm/lsshmpool.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ bool LsShmPool::isFreeBlockBelow(
12461246
LsShmOffset_t offset, LsShmSize_t size, int joinFlag)
12471247
{
12481248
LsShmOffset_t belowOffset = offset + size;
1249-
if (belowOffset >= m_pShm->maxSize())
1249+
if (belowOffset >= m_pShm->getMapFileSize())
12501250
return false;
12511251

12521252
LShmFreeTop *ap = (LShmFreeTop *)offset2ptr(belowOffset);

src/shm/lsshmpool.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class LsShmPool : public ls_shmpool_s
141141
{ m_iAutoLock = 0; }
142142

143143
ls_attr_inline LsShmSize_t getShmMapMaxSize() const
144-
{ return m_pShm->maxSize(); }
144+
{ return m_pShm->getMapFileSize(); }
145145

146146
LsShmOffset_t getPoolMapStatOffset() const;
147147

0 commit comments

Comments
 (0)