Bug #92224 Use "Environment" to set LD_PRELOAD in systemctl is not working
Submitted: 29 Aug 2018 10:46 Modified: 17 Dec 2019 10:00
Reporter: chen chen Email Updates:
Status: Closed Impact on me:
Category:MySQL Server: Installing Severity:S3 (Non-critical)
Version:8.0.12 OS:Any (7.4)
Assigned to: CPU Architecture:x86

[29 Aug 2018 10:46] chen chen
Here it is.

#### Basic info
[root@node2 ~]# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 7.4 (Maipo)
[root@node2 ~]# uname -a
Linux node2 3.10.0-693.el7.x86_64 #1 SMP Thu Jul 6 19:56:57 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux

[root@node2 ~]# yum install gperftools -y

[root@node2 ~]# rpm -ql gperftools-libs-2.6.1-1.el7.x86_64

[root@node2 ~]# lsof -n | grep tcmalloc

### Set the LD_PRELOAD explicitly.
[root@node2 ~]# export LD_PRELOAD=/usr/lib64/libtcmalloc_minimal.so.4
[root@node2 ~]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service

check whether the tcmalloc come into effect
[root@node2 ~]# lsof -n | grep tcmalloc
lsof      2363         root  mem       REG              253,0    154776     339628 /usr/lib64/libtcmalloc_minimal.so.4.4.5
grep      2364         root  mem       REG              253,0    154776     339628 /usr/lib64/libtcmalloc_minimal.so.4.4.5
lsof      2365         root  mem       REG              253,0    154776     339628 /usr/lib64/libtcmalloc_minimal.so.4.4.5

As we can see,the tcmalloc come into effect.

Now,let's check the effect if we set LD_PRELOAD in systemd configuration file.

### Set LD_PRELOAD in systemd configuration file

Open another console

[root@node2 ~]# echo $LD_PRELOAD

[root@node2 ~]# systemctl edit mysqld

[root@node2 ~]# cat /etc/systemd/system/mysqld.service.d/override.conf

[root@node2 ~]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service

[root@node2 ~]#  lsof -n | grep tcmalloc

there is no output.

i guess the tcmalloc did't come into effect

How to repeat:
As stated above
[31 Aug 2018 11:05] Terje Røsten

Thanks for your report!

You are right, indeed setting LD_PRELOAD=... environment variable don't
take effect. This is due to this scriptlet in the RPM spec file:

 /usr/sbin/setcap cap_sys_nice+ep /usr/sbin/mysqld

this has the side effect that the binary is suid as seen from
systemd, and systemd disable LD_PRELOAD for suid executables.

You can verify this by doing:

$ setcap -r /usr/sbin/mysqld

Note: removing CAP_SYS_NICE capability will disable the Resource Group feature:
[17 Dec 2019 10:00] Terje Røsten

This issue was fixed by this commit: