Friday, October 28, 2011

» Loop mount iso files without being root

There is a rather convenient way to mount ISO files (CD/DVD images) onto a directory on Linux, which goes as follows:
mount -o loop,ro /path/to/image.iso /path/to/mountpoint
(where the mountpoint is a directory).

This method works very well, but has one essential drawback: you must be root in order to do that. So how do I get to do so as a regular user ?

A barely known alternative lies in fuseiso, which uses the FUSE filesystem in user-space layer to accomplish that.

In order to use it, you must install the package fuseiso, which is available with the openSUSE distribution, and from the release repository (e.g. for 11.4) as well as from the filesystems repository and OBS project:
zypper install fuseiso

Once that has been done (as root ;)), you can simply mount ISO files like this, without being root:
fuseiso /path/to/image.iso /path/to/mountpoint

Note that as an additional benefit, fuseiso also supports images in NRG, BIN, MDF and IMG (dd) format, as well as zisofs.

In order to unmount, simply use fusermount -u, e.g. like this:
fusermount -u /path/to/mountpoint

Labels: ,

Sunday, April 17, 2011

» Workaround for Eclipse Helios JVM crashes

You might run into this too: when using Eclipse Helios (3.6.2 here), it sometimes crashes on an alleged double free in the JVM, detected by glibc.
That's actually a feature of glibc that serves to detect bugs and security issues, which kills a process that tries to free a previously allocated memory area that has already been freed.

In this case, however, it is most probably a false positive, but glibc still decides to kill the process.

The workaround is to run Eclipse with the environment variable MALLOC_CHECK_ set to 0. There are several ways to achieve this:

  1. when you run eclipse from a shell, run it like this:
    MALLOC_CHECK_=0 eclipse
  2. if you prefer to just run eclipse or by clicking on an icon, create the following file in your $HOME/bin, e.g. like this (just copy/paste into a shell):
    cat<<EOF >"$HOME/bin/eclipse"
    #!/bin/bash
    export MALLOC_CHECK_=0
    exec /usr/bin/eclipse "$@"
    EOF
    chmod 0755 "$HOME/bin/eclipse"
Note that with the latter option, you obviously need to adapt the fully qualified path to the eclipse script depending on how and where you installed it. If it comes from RPM packages, than /usr/bin/eclipse is fine. If, like me, you downloaded the tarball from eclipse.org and unpacked it somewhere under your home, you must change it accordingly -- e.g. to $HOME/apps/eclipse/eclipse

In any case, you should NOT add export MALLOC_CHECK_=0 to your ~/.profile or ~/.bashrc as that would turn off that glibc check for ALL the applications and processes you would run. And that's a bad idea.

Labels: , , ,

Wednesday, February 17, 2010

» Generate a moderately secure random password

Just to remind myself... ;)
cat /dev/urandom \
| base64 \
| tr -d '[^:alnum:]' \
| cut -c1-10 \
| head -1
The command chain above does the following:
  • dd if=/dev/urandom: read random data from /dev/urandom and write it to STDOUT
  • base64: encode that binary data into Base64 to make it human-readable
  • tr -d '[^:alnum:]': remove all characters that are not alphanumeric (i.e. remove whitespaces, +, ...)
  • cut -c1-10: only keep characters 1 to 10 from each line
  • head -1: only keep the first line
Better randomness may be achieved by doing a cat on /dev/random instead of /dev/urandom, if you have enough entropy (see cat /proc/sys/kernel/random/entropy_avail) Obviously, if you prefer passwords of a different length, e.g. 16, change the cut -c1-10 accordingly: cut -c1-16

Labels: ,

Friday, July 24, 2009

» Find python dependencies

When building Python packages, one recurrent and very tedious task is to analyze what dependencies each upstream project has. As we can't apply ldd as with C/C++, nor something like jdepend as with Java, and because I'm lazy and don't like doing repetitive stuff, I've hacked a little script that uses some heuristics to try to find out by itself what a bunch of python sources require. It does so by grepping the import statements (in various forms) in all .py files under the current directory, and then tries to resolve them to .py files under the Python lib directory (e.g. /usr/lib64/python2.6, although it finds out what that directory is by poking Python itself, no assumptions made there) and map those files onto RPM packages (by simply using rpm -qf). Again, simple and stupid, and the ANSI colouring assumes a dark terminal background ;), but you might want to give it a try and you even might find it useful. The (Perl) script is here: fpydep Sample output (make sure to have your browser on UTF-8 encoding):
 WARN  failed to resolve json
 WARN  failed to resolve simplejson
Resolved:
Requires: python-xml

Locals:
services
surl
surl.services
surl.surl
surl.version
version

Failed to resolve python files for the following imports:
json
simplejson
If anyone is aware of a more thorough approach to doing that, please let me know :)

Labels: , ,

Friday, July 17, 2009

» Educating upstream: C pointers are not int

Once and for all, a pointer (in C) is NOT an int It just happens to be one on 32bit systems, but the only proper type for casting a pointer into a number (for whatever reason, such as pointer arithmetics) is

To have that type, also add an #include on stdint.h where appropriate. It is really annoying when, as a packager, you keep running into C sources that have only been compiled and tested on 32bit systems and where the authors have assumed that they can cast their pointers to int. On x86_64, that generates quite a lot of warnings, on purpose: on 64bit systems, a pointer is an unsigned long. But don't rely on that either, just use intptr_t Arguably, it has been added in C99, and only as optional but hey, if you're in for a big heap of assumptions by doing pointer arithmetics, you could as well assume it's a modern C compiler and libc.

Labels: ,

Wednesday, March 18, 2009

» freshmeat.net 3 project metadata scraping

Freshmeat 3
freshmeat.net provides an invaluable service to the FOSS community by allowing us to keep track of new projects and new releases of existing projects in a single central location (at least for most of them). As such, it is especially useful to packagers. Recently, the site has undergone a complete rewrite of its web interface and in that process, the XML project metadata that was available on the previous version of the site has been removed and will be replaced with a JSON API. I don't really care whether it's JSON or XML though, albeit XML is slightly easier to parse and process (e.g. with XPath), as long as it is machine readable. Over the past few years, I've actually been using those project descriptions (as XML) to fill RPM spec files automatically, instead of having to tediously copy/paste the usual annoying bits (Summary:, %description, URL:, License:, ...). Until a JSON API is available, and out of sheer curiosity, I've written a little PHP command-line script that scrapes the project metadata from the HTML markup on the new freshmeat.net site. It also resolves freshmeat.net redirect URLs to sources and website (by doing a HTTP HEAD) and tries to format the description as paragraphs, using the command-line tool fmt). If you want to have a look on how to do that, or even use the script as-is, here it is: fm3-scrape And just for the record, here is the old script, which is broken now: ffxml

Labels: , , ,

Thursday, August 07, 2008

» Thunderbird/Enigmail: fix quoting

At some point Thunderbird/Enigmail started quoting using "|" instead of the standard ">". Finally bothered to find a way to fix this! When you have the about:config extension, read this thread on the enigmail forum. When not, do it by directly editing Thunderbird's prefs.js:
for f in ~/.thunderbird/*/prefs.js; do echo 'user_pref("mailnews.send_plaintext_flowed", false);' >>"$f"; done

Labels: , , ,

Saturday, July 19, 2008

» Reattaching to ssh-agent

A rather rare situation, hopefully... I happened to clean up /tmp and delete a temporary directory used by ssh-agent, that held the UNIX domain socket that was used to communicate with it. Arguably, that's a pretty stupid thing to do and fixing it is as simple as logging out (of your X session) and in again. But I didn't want to close running applications and hence, hacked a little bash function to re-attach to a running ssh-agent (which means setting the environment variables SSH_AGENT_PID and SSH_AUTH_SOCK appriopriately) after having started another ssh-agent process. As it might be useful to others (or just an interesting sample of bash scripting), here it is:
function reattach-ssh-agent {
   local pid
   local line
   local r=$(ps h -o pid -C ssh-agent | while read pid; do
      sudo lsof -a -w -LPn -p "$pid" -U -Fn \
      | grep '^n/tmp/ssh-.*/agent\..*' | while read line; do
         line=${line#?}
         [ -e "$line" ] && {
            echo "FOUND: pid=$pid sock=$line" >/dev/tty;
            echo "export SSH_AGENT_PID=$pid; export export SSH_AUTH_SOCK=\"$line\"";
         }
      done;
   done)
   [ -n "$r" ] && { eval $r; } \
   || { echo "Failed to find running and operational ssh-agent" >&2; }
}
Note that it must be a function, not a script as the latter would be executed as a sub-process of the current shell and, hence, not be able to modify the environment of the current shell (which is the whole idea about it). So if you need that function here and then, make sure to add it to ~/.bashrc Also note that a major drawback of this function is that it requires executing lsof as root (here using sudo) as the open files of ssh-agent are only visible to root. Another approach would be to implement the above in a separate script that would just output the shell code to execute (export SSH_AGENT_PID ...) and run setuid (using a C wrapper or such) but.. not necessarily easier nor much more secure.

Labels: , ,

Sunday, December 30, 2007

» Disable middle mouse pasting (sort of)

Someone asked on IRC how to disable middle mouse pasting in X. Seems like it's a mystery to almost everyone as it's asked on quite a few forums but always left unanswered. I wouldn't want to miss that feature, personally, but well, here's a trick to disable middle mouse pasting in X:
  1. list your current mouse pointer X mappings using xmodmap -pp (look at the 2nd column)
  2. swap the button 2 with some unused one, typically the highest number
  3. add a line e.g. "pointer = 1 9 3 4 5 6 7 8 2" (if you have 9 buttons, for the sake of an example) to ~/.Xmodmap
Note that it will completely disable the middle key (but you'll still be able to use it to scroll as scrolling up and down is mapped to two other distinct pointers in X (4 and 5, actually)) To automate the process, just copy/paste the following snippet into a shell (and execute it):
xmodmap -pp |perl -ne 'BEGIN{@a=();$h=0} {next unless /^\s*\d+\s+\d+\s*$/; ($v)=/^\s*\d+\s+(\d+)\s*$/; push(@a,$v); if ($v gt $h) {$h=$v}} END{@b=();foreach(@a){ if ($_ eq "2"){push(@b,$h)} elsif($_ eq $h){push(@b,"2")} else{push(@b,$_)} }; print "pointer = ".join(" ",@b)."\n";}' >> ~/.Xmodmap

Labels: ,