Skip to content

Commit 27e6fd9

Browse files
committed
MDEV-9095 - [PATCH] systemd capability for --memlock
Adjust systemd files to enable CAP_IPC_LOCK to allow rootless mlockall (triggered by memlock option). This is amended version of a patch originally submitted by Daniel Black.
1 parent 87e6873 commit 27e6fd9

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

sql/mysqld.cc

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5404,25 +5404,33 @@ static int init_server_components()
54045404
(void) mi_log(1);
54055405

54065406
#if defined(HAVE_MLOCKALL) && defined(MCL_CURRENT) && !defined(EMBEDDED_LIBRARY)
5407-
if (locked_in_memory && !getuid())
5407+
if (locked_in_memory)
54085408
{
5409-
if (setreuid((uid_t)-1, 0) == -1)
5410-
{ // this should never happen
5411-
sql_perror("setreuid");
5412-
unireg_abort(1);
5409+
int error;
5410+
if (user_info)
5411+
{
5412+
DBUG_ASSERT(!getuid());
5413+
if (setreuid((uid_t) -1, 0) == -1)
5414+
{
5415+
sql_perror("setreuid");
5416+
unireg_abort(1);
5417+
}
5418+
error= mlockall(MCL_CURRENT);
5419+
set_user(mysqld_user, user_info);
54135420
}
5414-
if (mlockall(MCL_CURRENT))
5421+
else
5422+
error= mlockall(MCL_CURRENT);
5423+
5424+
if (error)
54155425
{
54165426
if (global_system_variables.log_warnings)
54175427
sql_print_warning("Failed to lock memory. Errno: %d\n",errno);
54185428
locked_in_memory= 0;
54195429
}
5420-
if (user_info)
5421-
set_user(mysqld_user, user_info);
54225430
}
5423-
else
5431+
#else
5432+
locked_in_memory= 0;
54245433
#endif
5425-
locked_in_memory=0;
54265434

54275435
ft_init_stopwords();
54285436

support-files/mariadb.service.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ PrivateNetwork=false
4242
User=mysql
4343
Group=mysql
4444

45+
# To allow memlock to be used as non-root user if set in configuration
46+
CapabilityBoundingSet=CAP_IPC_LOCK
47+
4548
# Execute pre and post scripts as root, otherwise it does it as User=
4649
PermissionsStartOnly=true
4750

support-files/mariadb@.service.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ PrivateNetwork=false
4949
User=mysql
5050
Group=mysql
5151

52+
# To allow memlock to be used as non-root user if set in configuration
53+
CapabilityBoundingSet=CAP_IPC_LOCK
54+
5255
# Execute pre and post scripts as root, otherwise it does it as User=
5356
PermissionsStartOnly=true
5457

0 commit comments

Comments
 (0)