M-A's

technology blog

Wednesday, 30 June 2010

rdesktop from linux into Windows with a ca-fr keyboard layout

[note to myself]

I am using the French Canadian keyboard layout on Ubuntu Lucid and was having a hard time typing "\". Solution:

  • With "Terminal Server Client" GUI and on the "Local Resources" tab, set the keyboard to "ca-fr".
    • Note it's "ca-fr" and not "fr-ca" or "fr_CA" or whatever wrong values I could come up with..!
  • With rdesktop, it's "rdesktop -k fr-ca <hostip>".
    • Note it's "fr-ca" there and not "ca-fr" or "fr_CA". +1 for consistency. Oh well...
Update
Forget about tsclient and rdesktop, I never fully got them to work correctly. Remmina works much better for me. It is based on FreeRDP that uses sane keyboard input. Simply install its ppa since Ubuntu Lucid's version is too old.

    Monday, 14 June 2010

    automatic git mergetool selection based on X availability

    I usually edit code over ssh, when merging, vimdiff is sufficient to me most of the time but when the merge is too complex, kdiff3 does a better job so I NX into the box and start the merge from there. I got tired of using git mergetool=kdiff3 so I wrote this tool. Note that vimdiff is started in a different configuration that would be done in a normal git config merge.tool = vimdiff; cursor is reset to line 0 and the viewport is modified in a more useful format, plus all the 4 buffers are loaded.
    #!/bin/sh
    # Copyright (c) 2010 Marc-Antoine Ruel
    # Automatically select the right merge tool based on X session availability.

    if [ ! "$(git config --global --get mergetool.autodiff.cmd)" ]; then
      echo Setting git config --global merge.tool = autodiff
      git config --global mergetool.autodiff.cmd "`pwd`/autodiff.sh \$BASE \$LOCAL \$REMOTE \$MERGED"
      git config --global merge.tool autodiff
      echo Done.
      exit
    fi

    if [ -z "$DISPLAY" ]; then
      # Start in diff mode, move the viewport down and move up to first line.
      vimdiff -c "wincmd J" -c "0" $4 $2 $1 $3
    else
      # Inside an X session, redirect stderr.
      kdiff3 --auto --L1 "$4 (Base)" --L2 "$4 (Local)" --L3 "$4 (Remote)" -o $4 $1 $2 $3 2> /dev/null
    fi

    Wednesday, 12 May 2010

    Process ID reuse on Windows

    Process IDs are reused on Windows after uptime has been long enough. Probably for compatibility with old applications, Windows tries to use 15 bits process ids for as long as it can and they eventually grow to 31 bits values if you create enough processes simultaneously.

    I always though process ids weren't reused until it was unreferenced. I was wrong in how it is referenced. I thought that having a process ID as a parent of another live process was enough but I was wrong, it needs to have a handle alive.

    Here's an example screenshot. This kind of behavior can be recreated by having a lot of orphan processes that no process keeps an handle to their parent:


    I found this behavior while recreating a process tree tool. Naively checking the process ids is not sufficient. As you can see, Process Explorer already know about that fact and doesn't simply compare the process IDs. It uses another comparison else to discover the real parenthood. PROCESSENTRY32.th32ParentProcessID doesn't give enough data to discriminate. So the only good way is to use GetProcessTimes() and verify the process creation dates.

    Wednesday, 28 April 2010

    MacOSX survival guide

    Terminal preference;
    1) Tab Startup, new window with settings: Pro
    2) Tab Settings, Pro
      * Text, check everything except antialias text
      * Window, check only Active process name
      * Window, Background color, set alpha to >90%
      * Keyboard, check Use option as meta key
      * Keyboard, add end, page up, page down, home usage without shift modifier
      * Advanced, Delete sends Ctrl-H
    (It's impressive how the terminal app is broken by default on Mac OS X)

    System Preferences;
    1) Keyboard & Mouse
      * Keyboard, check Use all F1, F2, etc. keys as standard function keys
      * Keyboard Shortcuts, Uncheck Desktop (F11) and all the stupid shortcuts.
    2) Trackpad
      * Enable Tap to Click and Dragging and Secondary Tap

    Enable lock icon:
    1) /Applications / Utility/ Keychain Access
    2) Preferences
    3) check Show Status in Menu Bar

    French Canadian keyboard:
    http://matthieu.yiptong.ca/2009/09/09/canadian-french-keyboard-layout-for-mac-os-x/

    Friday, 15 January 2010

    Marketing email FAIL

    You know you put too much junk in your marketing emails when you keep obsolete statements from more than 3 years ago:

    "8. Microsoft requires that a PC have a modern processor and 512MB RAM to be included in the Windows Vista Capable PC program. Since the operating system and drivers are not final, Windows Vista has not been tested on all user configurations. (...)"

    (From a Dell promo email in Canada received today)

    Friday, 9 October 2009

    Windows, just another dumb terminal?

    The more I use ssh + screen, the more I realize Windows is an excellent dumb terminal mainly due to its support of awkward monitor setup support. This is four monitors, 1280, 1920 in portrait, 1920 in portrait, 1920 in landscape.

    Update: Note that Windows' 7 WinKey-Arrow and WinKey-Shift-Arrow shortcut makes it even better as a dumb terminal.

    Monday, 28 September 2009

    Linker

    Do you know what you are linking?
    I'm surprised on how many people are confused about the linking process in general. This discussion will focus on MSVC in particular but this discussion stands for the gnu toolset too. First let's define:
    • A compile unit as a single C++ (.cc) source file generating a single object (.obj) file.
    • A PE is a single output unit from the linker.
    • A symbol is a single named component globally visible, like a global function, class definition, member function, global variable, imported symbol with dllimport or template instance; this list is obviously not exhaustive.
    Compilation units
    When linking, all inputs are linked together to extracts symbols and put them in the output file. This is important for the linker to have compilation units be easy to differentiate one to each other. The reason is that the compilation unit's name (the source file name) is used in the symbol mangling, especially for file static global variable. This is also important since often even if the source files are in various subdirectories, the output objects are in a single intermediary directory. This can cause problems when you have 2 sources files with the same name. For example, libjingle, up to revision 7, has 2 compile units with the same name: constants.cc and constants.cc. If both arrive in the same output dir, you're in trouble. But how come it works in this specific case? Well, when the developer adds the second file in the Visual Studio IDE, the IDE will automatically set the ObjectFile attribute to to add a '1' postfix. See libjingle.vcproj.

    PE and incremental linking
    Every output PE must have a unique name in a solution. This is something we are hitting in the Chromium project since we have chrome.exe and chrome.dll. The issue we face is that both generate chrome.ilk for incremental linking. This cause that incremntal linking fails every time. The workaround is to output one of the binaries in the intermediary output directory and hardlink it back at the right place. Lame but works.

    Every symbol is not on equal footing
    When defining the same symbol multiple times into a PE, the linker will give errors on multiple defined symbols. To alleviate this problem, you can define the symbol as selectany, e.g. a weak symbol. But if the two symbol definitions are not exactly the same, you can get into real trouble since one is selected at random at link time.

    The interesting twist comes with static libraries. If a symbol is defined in one or multiple static libraries and in an object file, the symbol defined in the object file will be used. The best commonly used example is DllMain. When creating a DLL, if it is defined in a .obj file, your definition will be used. If not defined in an object file, the definition provided in the CRT static library will be used.
    So in short, the linker has different priorities when linking its inputs: static libraries are second class citizens to object files.
    So if a symbol defined in a static library is not referenced by a symbol in a object file, it will not be linked in. That's why many people will use the /INCLUDE parameter to force a symbol from a static library to be included. ATL is one doing that with "#pragma comment(linker, "/include:_forceAtlDllManifest")" in atlbase.h.

    Scalability issue
    But linking large static libraries takes time. For the Chromium project, some of our libraries are significantly large, browser.lib and webcore.lib being respectively 320 and 408 megs as revision 27335. One way to help speed up is to use Use Library Dependency Inputs. This permits skipping over the static library linking step. Why? Since static libraries cannot use incremental linking, they are much slower to link in debug than actual PE.

    But all the rules described above change with Use Library Dependency Inputs since the final linker step links only object files and no static libraries. You see it coming, every symbols are now on equal footing. Which mean a lot of fun and helps find a lot of problems.

    I saw unit tests including another compile unit. That results in duplicate symbols. I saw another project having 2 different main() functions. Same failure. I saw an installer including unit tests. Same failure. Why does that work without the ULDI flag? Because of different symbol priority between object file and static library. When a symbol exists in an object file, the symbols defined in static libraries are silently discarded. If all the symbols defined in static libraries are now on higher priority, that breaks on every symbols that are ambiguous.

    That concludes my short explanation.