Mawk and mysql conflict

Bug #689563 reported by uzsolt
14
This bug affects 3 people
Affects Status Importance Assigned to Milestone
PLD Linux
Fix Released
Medium
Artur Frysiak

Bug Description

[root@pld-laptop ~]# service mysql restart
Error: datadir specified in /var/lib/mysql/mysqld.conf should be
/var/lib/mysql/mysqldb/db MySQL can't be run.

[root@pld-laptop ~]# grep -v "^#" /etc/mysql/clusters.conf

mysqld.conf=/var/lib/mysql

[root@pld-laptop ~]# rpm -qv mysql
mysql-5.1.52-1.i686

[root@pld-laptop ~]# rpm -qv mawk
mawk-1.3.4-0.20100625.1.i686

mawk build on carme, but some time ago there were in th-foo (I don't
know, in which th-*), and --upgrade-dist didn't "downgrade" mawk.

Revision history for this message
Caleb Maclennan (alerque) wrote :

What do you get for `grep datadir /var/lib/mysql/mysqld.conf`?

Revision history for this message
Artur Frysiak (wiget) wrote :

[root@tower ~]# grep datadir /var/lib/mysql/mysqld.conf
datadir = /var/lib/mysql/mysqldb/db
[root@tower ~]# /etc/init.d/mysql restart
Error: datadir specified in /var/lib/mysql/mysqld.conf should be /var/lib/mysql/mysqldb/db
 MySQL can't be run.

[root@tower ~]# rpm -q mysql mawk gawk
mysql-5.1.52-1.x86_64
mawk-1.3.4-0.20100625.1.x86_64
gawk-3.1.8-1.x86_64

Revision history for this message
Caleb Maclennan (alerque) wrote :

Artur: First of all the 1.3.4 package version you have installed is NOT in the th tree, you must have compiled that yourself. It is still marked with a 0.x release number. If you want a working system you should do something like `poldek -n th --upgrade mawk --downgrade` to get the latest stable version in the th tree even though that will be a step down version from your currently installed one.

I have compiled and confirmed the same problem. For others reference here is a relevant line from an strace of the service restart command:

    [pid 22234] execve("/bin/awk", ["awk", "-F=", "\n\t{\n\t\t# undos\n\t\tgsub(/\\r$/, \"\");"..., "/var/lib/mysql/mysqld.conf"], [/* 7 vars */]) =0

Revision history for this message
Caleb Maclennan (alerque) wrote :

Confirmed existence of conflict but mawk version in question is an unstable snapshot so fix is low priority.

Changed in pld-linux:
importance: Undecided → Low
status: New → Confirmed
Revision history for this message
Artur Frysiak (wiget) wrote :

Fixed in 5.1.52-3

Changed in pld-linux:
status: Confirmed → Fix Released
assignee: nobody → Artur Frysiak (wiget)
importance: Low → Medium
Revision history for this message
Elan Ruusamäe (glen666) wrote : Re: packages: mysql/mysql.init, mysql/mysql.spec - allow spaces and tabs after ...

  On 13.12.2010 17:09, wiget wrote:
> Author: wiget Date: Mon Dec 13 15:09:16 2010 GMT
> Module: packages Tag: HEAD
> ---- Log message:
> - allow spaces and tabs after variable name
...
> section == "mysqld" {
> - if ($1 == "datadir") {
> + if ($1 ~ /^datadir[ \t]*$/) {
> printf("MYSQL_DATA_DIR=%s;", $2);
> - } else if ($1 == "user") {
> + } else if ($1 ~ /^user[ \t]*$/) {
> printf("MYSQL_USER=%s;", $2);
> - } else if ($1 == "pid-file") {
> + } else if ($1 ~ /^pid-file[ \t]*$/) {
> printf("MYSQL_PIDFILE=%s;", $2);
> - } else if ($1 == "socket") {
> + } else if ($1 ~ /^socket[ \t]*$/) {
> printf("MYSQL_SOCKET=%s;", $2);
> - } else if ($1 == "port") {
> + } else if ($1 ~ /^port[ \t]*$/) {
> printf("MYSQL_PORT=%s;", $2);
> - } else if ($1 == "bind-address") {
> + } else if ($1 ~ /^bind-address[ \t]*$/) {
> printf("MYSQL_BIND_ADDRESS=%s;", $2);
> - } else if ($1 == "skip-networking") {
> + } else if ($1 ~ /^skip-networking[ \t]*$/) {
> printf("MYSQL_SKIP_NETWORKING=1;");
> - } else if ($1 == "log-error") {
> + } else if ($1 ~ /^log-error[ \t]*$/) {
> printf("MYSQL_LOG_ERROR=%s;", $2);
> }
>
...pff, make temp var "key" there, which has the spaces/tabs stripped,
instead!

--
glen

Revision history for this message
Artur Frysiak (wiget) wrote : Re: packages: mysql/mysql.init, mysql/mysql.spec - allow spaces and tabs after ...

2010/12/13 Elan Ruusamäe <email address hidden>:
>  On 13.12.2010 17:09, wiget wrote:
>>
>> Author: wiget                        Date: Mon Dec 13 15:09:16 2010 GMT
>> Module: packages                      Tag: HEAD
>> ---- Log message:
>> - allow spaces and tabs after variable name
>
> ...
>>
>>        section == "mysqld" {
>> -               if ($1 == "datadir") {
>> +               if ($1 ~ /^datadir[ \t]*$/) {
>>                        printf("MYSQL_DATA_DIR=%s;", $2);
>> -               } else if ($1 == "user") {
>> +               } else if ($1 ~ /^user[ \t]*$/) {
>>                        printf("MYSQL_USER=%s;", $2);
>> -               } else if ($1 == "pid-file") {
>> +               } else if ($1 ~ /^pid-file[ \t]*$/) {
>>                        printf("MYSQL_PIDFILE=%s;", $2);
>> -               } else if ($1 == "socket") {
>> +               } else if ($1 ~ /^socket[ \t]*$/) {
>>                        printf("MYSQL_SOCKET=%s;", $2);
>> -               } else if ($1 == "port") {
>> +               } else if ($1 ~ /^port[ \t]*$/) {
>>                        printf("MYSQL_PORT=%s;", $2);
>> -               } else if ($1 == "bind-address") {
>> +               } else if ($1 ~ /^bind-address[ \t]*$/) {
>>                        printf("MYSQL_BIND_ADDRESS=%s;", $2);
>> -               } else if ($1 == "skip-networking") {
>> +               } else if ($1 ~ /^skip-networking[ \t]*$/) {
>>                        printf("MYSQL_SKIP_NETWORKING=1;");
>> -               } else if ($1 == "log-error") {
>> +               } else if ($1 ~ /^log-error[ \t]*$/) {
>>                        printf("MYSQL_LOG_ERROR=%s;", $2);
>>                }
>>
>
> ...pff, make temp var "key" there, which has the spaces/tabs stripped,
> instead!

glen, you have write access. So, use your rights and write better
code. This "fix" work for me and other (un)happy mysql/mawk users.

--
Artur Frysiak

Revision history for this message
Elan Ruusamäe (glen666) wrote : Re: [Bug 689563] Re: packages: mysql/mysql.init, mysql/mysql.spec - allow spaces and tabs after ...

 On Tue, 14 Dec 2010 00:01:19 +0100, Artur Frysiak wrote:
> 2010/12/13 Elan Ruusamäe <email address hidden>:
>>  On 13.12.2010 17:09, wiget wrote:
>>>
>>> Author: wiget                        Date: Mon Dec 13 15:09:16 2010
>>> GMT
>>> Module: packages                      Tag: HEAD
>>> ---- Log message:
>>> - allow spaces and tabs after variable name
>>
>> ...pff, make temp var "key" there, which has the spaces/tabs
>> stripped,
>> instead!
>
> glen, you have write access. So, use your rights and write better
> code. This "fix" work for me and other (un)happy mysql/mawk users.

 no, fix yourself, i have no testcase, test environ to test if my
 changes fix or break.

 if you refuse to do it sanely, i rather revert your changes, if you
 want to play.

--
 glen

Revision history for this message
Caleb Maclennan (alerque) wrote :

>>> ...pff, make temp var "key" there
>> you have write access.
>  no, fix yourself,

Hey guys don't forget we're on the same team here.

I tried making this change myself, but either my smattering of awk
knowledge is not enough or something else is going on here. I made up
a variable and striped the spaces from it and used that for the tests,
but it gives the same error we started with. Then I realized that the
original variable was already being stripped (see line 199)! The ~
comparison must be doing something other than just stripping spaces as
per the regex.

Anybody know what else is going on there? Here is my attempted patch.

Index: mysql.init
===================================================================
RCS file: /cvsroot/packages/mysql/mysql.init,v
retrieving revision 1.144
diff -u -r1.144 mysql.init
--- mysql.init 13 Dec 2010 15:09:11 -0000 1.144
+++ mysql.init 14 Dec 2010 09:24:43 -0000
@@ -209,22 +209,25 @@
                next;
        }

+ key = $1;
+ gsub(/[ \t]*/, "", $key);
+
        section == "mysqld" {
- if ($1 ~ /^datadir[ \t]*$/) {
+ if ($key == "datadir") {
                        printf("MYSQL_DATA_DIR=%s;", $2);
- } else if ($1 ~ /^user[ \t]*$/) {
+ } else if ($key == "user") {
                        printf("MYSQL_USER=%s;", $2);
- } else if ($1 ~ /^pid-file[ \t]*$/) {
+ } else if ($key == "pid-file") {
                        printf("MYSQL_PIDFILE=%s;", $2);
- } else if ($1 ~ /^socket[ \t]*$/) {
+ } else if ($key == "socket") {
                        printf("MYSQL_SOCKET=%s;", $2);
- } else if ($1 ~ /^port[ \t]*$/) {
+ } else if ($key == "port") {
                        printf("MYSQL_PORT=%s;", $2);
- } else if ($1 ~ /^bind-address[ \t]*$/) {
+ } else if ($key == "bind-address") {
                        printf("MYSQL_BIND_ADDRESS=%s;", $2);
- } else if ($1 ~ /^skip-networking[ \t]*$/) {
+ } else if ($key == "skip-networking") {
                        printf("MYSQL_SKIP_NETWORKING=1;");
- } else if ($1 ~ /^log-error[ \t]*$/) {
+ } else if ($key == "log-error") {
                        printf("MYSQL_LOG_ERROR=%s;", $2);
                }
        }

Revision history for this message
Elan Ruusamäe (glen666) wrote : Re: [Bug 689563] Re: packages: mysql/mysql.init, mysql/mysql.spec - allow spaces and tabs after ...

  On 14.12.2010 12:02, Caleb Maclennan wrote:
> + key = $1;
> + gsub(/[ \t]*/, "", $key);
> +
try:

gsub(/[ \t]*/, "", key);

or rather to use the original code:

gsub(/^[\t ]*|[\t ]*$/, "", key);

my suspection is that the first { } block is not invoked in that buggy mawk

--
glen

Revision history for this message
Elan Ruusamäe (glen666) wrote : Re: [Bug 689563] Re: packages: mysql/mysql.init, mysql/mysql.spec - allow spaces and tabs after ...

  On 14.12.2010 12:02, Caleb Maclennan wrote:
 > + if ($key == "datadir") {
 > printf("MYSQL_DATA_DIR=%s;", $2);
and here too:

if (key == "datadir") {

(as the original code was)

--
glen

Revision history for this message
Caleb Maclennan (alerque) wrote :

Thanks for your suggestions Elan. I tried them over here but unfortunately I still get the same original error. I've played with it a dozen ways now and what awk is doing with this code defies my imagination. Going back to Artur's code works, but any change to that and it throws up. Simply doing something as simple as substituting $1 for a copy of the variable make it die. Not explicitly matching for the end of string makes it die. Taking too big a bite of chocolate while debugging makes it die.

Frankly after failing to make awk behave the whole stupid eval/awk gig inside this init script is starting to look like a crazy hack. Thoughts?

Artur Frysiak (wiget)
Changed in pld-linux:
status: Fix Released → In Progress
Revision history for this message
Artur Frysiak (wiget) wrote :
Revision history for this message
Elan Ruusamäe (glen666) wrote :

yes absolutely, i assume it works and sent new rel to th

Revision history for this message
Artur Frysiak (wiget) wrote :

Caleb and uzsolt , please test 5.1.52-4 and let me know if it works for you.

Changed in pld-linux:
status: In Progress → Fix Committed
Revision history for this message
uzsolt (udvzsolt) wrote :

Works for me with mawk-1.3.4-0.20100625.1.i686.

Revision history for this message
Elan Ruusamäe (glen666) wrote :

adding test script to dest mawk

$ q mawk gawk
mawk-1.3.3-33.x86_64
gawk-3.1.8-1.x86_64

$ gawk -f 689563.awk
ORIGINAL: [pff]
TRIM1: [pff]
TRIM2: [pff]
ORIGINAL: [ leading-space]
TRIM1: [leading-space]
TRIM2: [leading-space]
ORIGINAL: [trailing-space ]
TRIM1: [trailing-space]
TRIM2: [trailing-space]
ORIGINAL: [ leading-tab]
TRIM1: [leading-tab]
TRIM2: [leading-tab]
ORIGINAL: [traling-tab ]
TRIM1: [traling-tab]
TRIM2: [traling-tab]

$ mawk -f 689563.awk
ORIGINAL: [pff]
TRIM1: [pff]
TRIM2: [pff]
ORIGINAL: [ leading-space]
TRIM1: [leading-space]
TRIM2: [leading-space]
ORIGINAL: [trailing-space ]
TRIM1: [trailing-space]
TRIM2: [trailing-space]
ORIGINAL: [ leading-tab]
TRIM1: [leading-tab]
TRIM2: [leading-tab]
ORIGINAL: [traling-tab ]
TRIM1: [traling-tab]
TRIM2: [traling-tab]
$

Revision history for this message
Caleb Maclennan (alerque) wrote :

Good to go here Artur, thanks to all and grr to awk!

Elan Ruusamäe (glen666)
Changed in pld-linux:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.