Wednesday 26 October 2011

Emacs is so Emacs

Today I ran into trouble installing brand new Emacs24(it is still not there, beta or alfa or whatever), I used to have ubuntu this days and ppa is already up at https://launchpad.net/~cassou/+archive/emacs But what is new in Emacs24? Right they finally put ELPA inside Emacs and now bundling it together. The problem is that the default repository (elpa.gnu.org) is somewhat conservative, a bit. Also some packages already bundled with emacs like ruby-mode and this creates more trouble then has benefits.


Now to get some real fun from using Emcas in a Ruby on Rails project you would normally want many other modes and packages like 'rinary' and others but these packages are just not there, not in elpa.gnu.org. To get most of those nice things you have to add some more repositories, here is my ~/.emacs.d/init.el :
(require 'package)
(add-to-list 'package-archives
             '("marmalade" . "http://marmalade-repo.org/packages/") t)
(add-to-list 'package-archives
             '("tromey" . "http://tromey.com/elpa/") t)
(package-initialize) 

Don't forget to M-x package-refresh-contents after you do the init.el. Most packages like rinary reside on marmalade, but current rinary version wants ruby-mode 1.1 and default ruby-mode bundled with Emacs is 1.0 (I guess that is also a version in elpa.gnu.org). And right here we need tromey repo that has new ruby-mode.

Monday 24 October 2011

Just do it!

So I ran into a "cp: cannot overwrite non-directory" problem. It means I've tried to overwrite a symbolic link with a directory with the same name.
Imagine you have a folder structure:
/folder2/
          /test1.txt
/folder1/
          / folder2->../folder2/ /
                                  /test1.txt


And
/folder3/
          /folder2/
                    /test1.txt
       
To try this out:
:/tmp$ mkdir folder2
:/tmp$ touch folder2/test1.txt
:/tmp$ mkdir folder1
:/tmp$ cd folder1
:/tmp/folder1$ ln -s ../folder2 .
:/tmp/folder1$ cd ../
:/tmp$ mkdir folder3
:/tmp$ cd folder3
:/tmp/folder3$ mkdir folder2
:/tmp/folder3$ touch folder2/test1.txt
:/tmp$ cp -rf folder3/folder2 folder1/
cp: cannot overwrite non-directory `folder1/folder2' with directory `folder3/folder2'

I tried googling but my searching skills were bad today and 'man' page wasn't helpful too. It seems basic cp cannot do the trick.
Now, I do know python/ruby/perl/shell/many other fancy words however I need to copy really large number of files, millions. Estimations show that just plain cp would take a few days to complete, what can we expect from all those less then perfect scripts?

But as one guy (don't really remember his name) said: "Those that can, do. Those that can't, complain" so the real solution is in the very soul of open source:
cd /tmp
mkdir coreutils
sudo apt-get build-dep coreutils
apt-get source coreutils
emacs coreutils-8.5/src/copy.c

Now the diff is:
--- coreutils-8.5/src/copy.c 2010-04-20 22:52:04.000000000 +0300
+++ /tmp/new/copy.c 2011-10-24 17:50:49.633017303 +0300
@@ -1412,10 +1412,21 @@
                     }
                   else
                     {
-                      error (0, 0,
-                       _("cannot overwrite non-directory %s with directory %s"),
-                             quote_n (0, dst_name), quote_n (1, src_name));
-                      return false;
+                      if (unlink (dst_name) != 0)
+                        {
+                          error (0, errno, _("cannot remove %s"), quote (dst_name));
+                        }
+                      if (x->verbose)
+                        printf (_("removed %s\n"), quote (dst_name));
+
+                      /* Tell caller that the destination file was unlinked.  */
+                      new_dst = true;
+                    
+
+                      /* error (0, 0, */
+                      /*  _("cannot overwrite non-directory %s with directory %s"), */
+                      /*        quote_n (0, dst_name), quote_n (1, src_name)); */
+                      /* return false; */
                     }
                 }
 

And build it:
./configure --prefix=/home/sam/new-coreutils
make
make install
cd /tmp
~/new-coreutils/bin/cp -rf folder3/folder2 folder1/
 
Now it works as I need here.

Wednesday 5 October 2011

handlersocket problem in Ubuntu Lucid


If you ever happen to see:

mysql> install plugin handlersocket soname 'handlersocket.so';
ERROR 1126 (HY000): Can't open shared library '/usr/lib/mysql/plugin/handlersocket.so' (errno: 2 failed to map segment from shared object: Permission denied)

Just check your /var/log/syslog for messags  like:

operation="file_mmap" pid=12750 parent=12354 profile="/usr/sbin/mysqld" requested_mask="::m" denied_mask="::m" fsuid=105 ouid=0 name="/usr/lib/mysql/plugin/handlersocket.so.0.0.0"

That is a problem with apparmor configuration, the good news - you don't need to stop apparmor to run handlersocket in Ubuntu, you only need to add permissions to your /etc/apparmor.d/abstractions/mysql

Now my config  looks like:
#some comments
   /var/lib/mysql/mysql.sock rw,
   /usr/share/mysql/charsets/ r,
   /usr/share/mysql/charsets/*.xml r,
   /usr/lib/mysql/plugin/handlersocket.so* mr,

You also need to reload apparmor profiles as the first google-link suggests:

sudo invoke-rc.d apparmor reload

And plugin works OK:
mysql> install plugin handlersocket soname 'handlersocket.so';
Query OK, 0 rows affected (0.01 sec)

Tuesday 4 October 2011

mysql dev team against common sense

It looks like guys in Mysql dev team just have no real tasks.  Do you remember  that silly story "ENGINE=innodb" vs "TYPE=innodb"?

 Now the same story with replication settings. If you try adding master-host=<IP>  or any master-* into my.cnf in mysql 5.5 and above you'll get:
 [ERROR] /usr/sbin/mysqld: unknown variable 'master-host=my.masterhost.com'

WTF???

Because now you can only use CHANGE MASTER TO ...