[MDEV-29222] mysqld_safe script breaks with many versions of grep Created: 2022-08-01  Updated: 2022-08-10  Resolved: 2022-08-10

Status: Closed
Project: MariaDB Server
Component/s: Scripts & Clients, Server
Affects Version/s: 10.7.4
Fix Version/s: 10.6.9, 10.7.5, 10.8.4, 10.9.2

Type: Bug Priority: Minor
Reporter: Addison Gourluck Assignee: Vicențiu Ciorbaru
Resolution: Fixed Votes: 0
Labels: beginner-friendly
Environment:

Linux



 Description   

When running the mysqld_safe start command, if the grep command isn't the exact correct version, it will fail with the following error:

grep: mysqld_safe: No such file or directory

This is a problem, as the script should not assume that the grep command that is installed should have all the features.
It is failing with very common versions of grep, like GNU grep v3.7


This was broken in commit 193bfdd831bbbf65e74acd12baf691d4305e3c11.

The offending line of code is in server/scripts/CMakeLists.txt:

  # FIND_PROC and CHECK_PID are used by mysqld_safe
IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
  SET (FIND_PROC
    "ps wwwp $PID | grep -vE mariadbd-safe -vE mysqld_safe | grep -- $MYSQLD > /dev/null")

This could be fixed by changing the middle grep command from

grep -vE mariadbd-safe -vE mysqld_safe

To the new command:

grep -vE "mariadbd-safe|mysqld_safe"



 Comments   
Comment by Daniel Black [ 2022-08-01 ]

Is removing the '-E' grep option sufficient for busybox to be happy?

Comment by Addison Gourluck [ 2022-08-01 ]

I actually just tried this again with a different grep, and it has the same problem.

grep (GNU grep) 3.7 exhibits the same behaviour.

The issue persists whether or not the -E option is there.

I'm beginning to wonder if this isn't just a typo, and thinking perhaps this code doesn't work on any machine?

Perhaps the code was meant to be:

"ps wwwp $PID | grep -vE mariadbd-safe | grep -vE mysqld_safe | grep -- $MYSQLD > /dev/null")

Generated at Thu Feb 08 10:06:50 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.