Monday, November 11, 2013

Why is mysql_library_end() so slow?


Why is mysql_library_end() soooooo sloooooow?

Under certain conditions it seems mysql_library_end() takes about 5 seconds to complete. Under other scenarios it only takes milliseconds. The latter being the expected, in all honesty.

Why, you ask?

I cannot really tell you why because I haven't dug into the source, but in my case the root cause turned out to be missing call(s) to mysql_thread_end() prior to thread exit from every(!) thread that had initialized a MYSQL struct. Fix that, and v\oila, milliseconds execution from mysql_library_end().

Thursday, September 1, 2011

Let's hear it for Recuva!

A friend of mine lost all his family recordings off his Sony HDD camera. Major crisis!

A quick probe resulted in estimates of up to 10K USD to recover the lost video commercially. A quick google search resulted in Recuva being a likely candidate for a fix. Luckily the owner kept his wits, did not take any additional video. 10 minutes later every video sequence was back on disk, and camera back with its (now) very happy owner :D

So, lets hear it for Recuva!

Tuesday, August 16, 2011

Empty SxS <assembly> tag from VS2008

Symptoms
VS2008 sometimes manages to embed empty manifest into the binaries it builds. Normally this will give you some (at first) strange SxS error when you attempt to run your newly built binary.

Investigation
Using mt.exe we can check out the embedded manifest in the binary
mt.exe -inputresource:myapp.exe -out:foo


Output
In the failing case resulting in this short blurp in foo:

<!--?xml version="1.0" encoding="UTF-8" standalone="yes"?-->
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestversion="1.0"></assembly>

Expected output
You would, however, expect the embedded manifest to look something like the following

<!--?xml version="1.0" encoding="UTF-8" standalone="yes"?-->
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestversion="1.0">
<trustinfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedprivileges>
<requestedexecutionlevel level="asInvoker" uiaccess="false"></requestedexecutionlevel>
</requestedprivileges>
</security>
</trustinfo>
<dependency>
<dependentassembly>
<assemblyidentity type="win32" name="Microsoft.VC90.CRT" version="9.0.nnnnn.mmmmm" processorarchitecture="x86" publickeytoken="1fc8b3b9a1e18e3b"></assemblyidentity>
</dependentassembly>
</dependency>
</assembly>

Examination
This seems to happen only when building files on a networked drive (long story short - I need to). Typically this means your build folders will be on the same networked drive too. As a result, so will the myapp.embed.manifest file that we try to embed.

There's various reasons if you read around on the net, but it all relates to
  1. Incremental linking
  2. and a FAT32 optimization in VS2008 gone haywire
  3. with BIND_TO_CURRENT_CRT
  4. when project files are on a networked drive
I haven't investigated if not using BIND_TO_CURRENT_CRT makes a difference or not, but it might.

Options
There's a few options to avoid this, not all of which may be applicable nor desirable

1. Don't do incremental linking
Will only work for smaller projects.

2. Place cmake files on local disk
Might not be desirable, for various reasons. Dependencies to other projects would be one.

3. Manually embed the correct manifest
Having cmake do a POST_BUILD step, where it runs the cmake equivalent of
mt.exe -verbose  -manifest myapp.embed.manifest  -outputresource:myapp.exe


is really the only safe option IMHO.

So help VS2008 along the way and manually embed your manifest, and you hopefully won't be bothered by that SxS error again...

Friday, February 18, 2011

_access() doesn't work!?

HELP!

The _access() CRT call does not work on Windows - at least not in the way you'd expect coming from unix or linux. The underscored function found in the Windows C runtime library appears to be a Windows equivalent of the Posix function access() reading the MSDN docs.

But appearances can be deceiving.

The unix and linux variants will throw EACCES when accessing a directory/folder where you have no read access. The windows _access() does not. Help! In fact, _access() only proves usable for checking existence of a given path, and nothing else.

How, then, do you get a proper access() function on Windows? Turns out CreateFile() will do what we need:
DWORD dwAccess = GENERIC_READ; // or GENERIC_WRITE, or both |'d
hFile = CreateFile(fname,
dwAccess,
FILE_SHARE_READ|FILE_SHARE_WRITE, // attempt to open with shared read/write access
NULL, // no security needed for probe
OPEN_EXISTING, // check existing files and folders only
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, //both needed for directory probe
NULL); // template file not needed for probe

if (hFile == INVALID_HANDLE_VALUE){
// do whatever you need to handle EACCES
}
CloseHandle(hFile);
...
Hope this can save you a few cycles...

Saturday, January 29, 2011

That dreaded cygwin "Device or Resource busy"...

If you've ever attempted to do any serious work on a Windows box configured with cygwin and a sshd, you've probably already come across the dreaded error message as you attempt to remove a file or folder

"Device or Resource busy"

If, not you probably will - sooner or later. You can't rm the files or folders, your compile is stuck as it can't write objs to disk - or whatever else your file access scenario may be.

SysInternals Handle to the rescue!

Handle will merrily show you what process is holding a handle to the specified file or folder. Once the perpetrator is located, taskkill /PID n, makes for the easy solution.

Simple, yet extremely effective trick for the toolbox...

(In all fairness, the latest 1.7.7 cygwin is a lot better than the previous versions :))

Thursday, November 25, 2010

EMC2 on Ubuntu 10.04

A while back I upgraded my HobbyCNC controller laptop to the latest 2.4 release of EMC2 which now also comes with Ubuntu 10.04 on its LiveCD.

I did need a reinstall of the system, but its now smoother than ever. EMC2 on 10.04 is a true joy to work with. Added bonus is the modern operating system with no-hassle wifi for grabbing your NC files off the home wifi network while in the workshop. The LPT pcmcia card I use still works out of the box.

EMC is a definite two thumbs up in my book!

Who needs backup...?

Most Important Files (TM)
Like me, you likely have your Most Important Files (TM) backed up to a USB disk. I mean, just to be on the safe side. All the photos of the kids as they grow up, all those hobby related project files, and just about everything else you want kept safe. And you have that USB disk hooked up to your home network to boot. Neat.

Enter the brand spanking new laptop... Decrapify and dual, or rather multi, boot it. Move the most recent projects to the new SSD equipped iron wonder. I'll do the rest later.

... a year later
Yeah, right you will.

One day the missus goes "Honey, what's that sound?"
What sound? Oh... Err... No proble... Wait... Did I forge... NO!

My ext3 formatted WD 500Gb MyBook, hooked up to the Synology USBStation, had decided to take a walk down amnesia and bad sector lane. The MyBook was now officially a MyBrick. On the early side of MTBF for the MyBrick guts too, if I dare guess.

A quick peek at the WD community site wasn't getting my hopes up. People are obviously experiencing some real pain with the MyBooks in the end. Not surprisingly disks finally give in - and I was truly caught in the middle of such carnage.

Voiding the warranty
My disk spun up and then stopped at random times. Similar problems on the WD community site was tagged as the disk controller possibly overheating. Being November and -15C outside it was worth a try giving the disk a big chill. Disk good as dead already, after all. Voided the warranty, dismantled the disk from the MyBrick and put it in the open window to cool down.

Tried a couple of free Windows ext3 solutions without luck, and Solaris was (sadly) not playing nice either. Last resort would have been a disk-rescue company and 1000 EUR less in the bank.

Enter Ubuntu 10.04. As the disk spun up, it auto-mounted and contained folders magically appeared. For a very brief moment, at least. Then the disk shut itself down again.

Trail and (bad sector) error
But, new hope. Next disk boot I was able to drag a couple of folders across before the disk shut down again. It worked best if I kept the disk tempered at freezing point, 0C, on the window sill. Slightly tilted on its back, while standing on one foot, with ... You get the point. But it would still stop randomly as it encountered a multitude of different disk errors - all visible in the syslog.

Long story short, I had to reboot the disk some 60+ times to rescue the real important stuff. But I did manage to save my Most Important Files (TM). Merging and skipping files in half saved folders got it back piece by piece.

To RAID, or not to RAID
I actually survived my USB disk crash with my most precious files intact. Am I felling lucky - you bet!
Needless to say I now own a RAID capable NAS - and have backup of my NAS too. Still considering if my ISPs online secure vault service is worth its pricetag.

I'm not advocating you do the same to your crashed USB disk though - whatever make or model. Your problem could be something completely different.

Who needs backup...? I do!

Tuesday, April 13, 2010

Annoying OpenSolaris audio bell

Are you also having your ears blasted by that really loud and annoying audio bell in OpenSolaris?
  1. Install gconf-editor using Package Manager
  2. Start gconf-editor
  3. Navigate to apps -> metacity -> general
  4. Uncheck audio bell
That's it - no more annoyance :)

You used to be able to use xset b 00 00 00 to control the keyboard beep, but that does not seem to work any longer. That nice, tiny, old "tick" sound is long gone...

Oh' well ...

Tuesday, November 10, 2009

Rescuing OpenSolaris after installing Windows 7

I recently did a clean install of Windows 7 on my laptop - and lost my OpenSolaris installs on the second partition of the same disk. Having the same problem?

Here's how to make it work again.

Intro
Prior to installing I had two partitons - one with Vista, the other with a bunch of OpenSolaris builds on zfs. W7 will during a clean install repartition its provided space into two partitions - a 100MB boot partition, and the big chunk of "all-the-rest" partition. It will also install its own stuff in the MBR, so any existing grub installs you have will disappear.

Installing Windows 7
Installed W7, connected to wifi, updated - everything in working order there.

Rescuing OpenSolaris
Rescuing the OpenSolaris install(s) requires a series of steps:

1) Make the OpenSolaris partition
active
The easiest way to do this is with a OpenSolaris live-cd. Boot from it, then in a terminal do

pfexec format

This starts format, so be careful. Select the disk containing your missing OpenSolaris install(s). In my case there was only one disk, c4t0d0. Make a note of the disk name, you'll need it later.

Inside format, start fdisk. Select '2' and mark the solaris partition as active. In my case it was the 3rd partition.

Save ('5'), then exit fdisk (quit) and format (quit).

2) Reinstall grub

We also need to reinstall grub in the Master Boot Record (MBR):

pfexec installgrub -m /boot/grub/stage1 /boot/grub/stage2 /dev/rdsk/c4t0d0s0

The last operand is your root slice - your diskname, prefixed by /dev/rdsk/ and suffixed by s0. Answer 'yes' to overwrite the MBR.

If you reboot now, you should see your old grub menu again. Yippee :)
But you'll only be able to boot the partitions in the grub menu that retained their indexes during the W7 install.

3) Update the grub menu

Since W7 added a new partition - normally at the start of your disk, the revived grub menu will still point to the old partition index. These are now wrong. I had to update my grub menu.lst as all OpenSolaris installs were now on partitions with index+1, due to the added W7 boot partition.

bootadm menu-list

will show you where your current grub menu.lst is located. Mine was at /rpool/boot/grub/menu.lst. Edit the grub menu:

pfexec gedit /rpool/boot/grub/menu.lst

Update the necessary findroot() entries to point to their new partition numbers. I had to update all OpenSolaris partitions from the 2nd to the 3rd partition as follows:

findroot(pool_rpool, 1, a)

to

findroot(pool_rpool, 2, a)

While editing, you can also change the default entry and timeout too if you please. When done rerun 'bootadm menu-list' to see that everything is as desired.

4) Reboot ...
and enjoy your old grub menu with all OpenSolaris installs and W7 :)

That's all there really is to it...

Thursday, July 16, 2009

EMC2 on a modern laptop?

My HobbyCNC router has been running fine with an old Pentium brick for hardware, FreeDOS and TurboCNC for a while. However its kinda slow booting the brick, and the TurboCNC user interface is as far from sexy as you get. Given its free its... well... OK.

There are other commercial alternatives that look a lot better, and works under windows if you please. Then there's EMC2 :)

EMC2 is a GPL machine controller, running on linux with a graphical user interface called Axis. More specificly its a real-time patched Ubuntu 8.04 distro, with EMC2.3.1. Yes, there's even a live-CD if you just want to try it out withput committing hardware. Not wanting to put a new brick on the desk for running my HobbyCNC router, as well as having a spare laptop lying around, I figured I'd have a go with the laptop even though the manuals tell you not to.

The main problem with modern laptops is there's no parallel port. But there's oodles of USB ports. First thought, use a USB-to-LPT cable. Sadly EMC2 does not support that (yet at least), it needs a true LPT port. This has to do with the inner workings of EMC2, using hardware in the parallel port as a "reliable" way of making fast enough clock ticks.

But wait, there's a PCMCIA slot here as well. Time to grab a PCMCIA parallel port expansion card. I got my self a NetMos Technology chipset based one, as it's supposed to work with Ubuntu. And it works indeed - even with EMC2. I won't do this as a step by step instructions for now - but outline the process.

First enable the LPT port in the BIOS, even though there's no physical port. The card is then immediately recognized in Ubuntu as seen by the output of lspci -v. This also show my LPT port located at 0x1000, yours may differ. I do not load either the parport_cs, nor parport drivers, as it cause EMC2 to fail at startup.

Next run the EMC2 configuration wizard, selecting my HobbyCNC controller card, with the LPT port at 0x1000, configuring the pins per HobbyCNC instructions, as well as the router and stepper properties.

EMC2 now starts without complaints. Jogging the router work fine, and Axis shows a nice 3D rendering of the work being done. Success :D

Even though I'm still in the testing and adjusting phase with EMC2, its looking very good IMHO. Should the laptop route give me problems later, I'll simply get myself a newer brick instead, because it looks like EMC2 is here to stay on my desktop!

Monday, June 29, 2009

SDCC on OpenSolaris

SDCC?

Yes, SDCC, the free small device c-compiler. I just gave it a try, wanting to do some programming for a MicroChip PIC, and it seems to work fine on OpenSolaris 2009.06. You do however need to compile it yourself, as there seems to be no packages available yet (that I'm aware of). But, do not fear.

Since I'm a complete noob when it comes to PIC programming, I aided myself with Micah Carricks tutorial on c-programming for PICs using SDCC on linux, and some OpenSolaris development knowledge, and was able to get sdcc working on OpenSolaris. So, thanks Micah!
http://www.micahcarrick.com/04-25-2005/pic-c-programming-linux.html

Step 1: Getting the packages
  • Get the SDCC source (currently 2.9.0)
  • Get the gputils source (currently 0.3.17)
  • Install gcc 4.3.x from your favorite location
  • Install g++ 4.3.x from your favorite location
You might also want to get gpsim and gpicd for simulation and In-circuit debugging respectively, too. But I didn't get to those yet.

Step 2: Environment
Set you PATH to point to gcc4/g++ if it doesn't already. In case you used opencsw or similar, do:
export PATH=$PATH:/opt/csw/gcc4/bin

Set your LD_LIBRARY_PATH to point to libstdc++
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/csw/gcc4/lib

Step 3: Build and install gputils
GNU tools normally build right out of the box :)
pfexec make install takes care of installation.

Step 4: Build and install SDCC
You'll need to make a couple of adjustments to all Makefile.in in the sdcc code. OpenSolaris' ar doesn't accept the -S option, but that can be removed safely. Do that for any Makefile.in in your project.

Step 5: ./configure
A simple
./configure
should configure the build for you.

If it doesn't, it's likely because you either didn't fix all Makefile.ins as described above, or configure/gcc/g++ can't find all libs due to an missing or incorrectly set LD_LIBRARY_PATH.

With gputils and gcc available in $PATH, sdcc configured nicely AFAICT.

Step 6: ./make
With gputils and gcc available in $PATH, sdcc also built nicely AFAICT.

Step 7: Testing sdcc
Using the first two, very small, examples in Micah Carricks tutorial, I put sdcc through its paces and it produced the expected output.

Now, out of the box, configure will make your install go to /usr/local/bin, which is kinda non-opensolaris-ishy, but playing around with the options to configure will put it where you (might) want it to go.

That's all there is (was) to it :)

Plotting on OpenSolaris

If you, like me, want to do large-format PDF plots from OpenSolaris with that old, unsupported, driver-nowhere-to-be-found HPGL plotter, then you might fancy having a look at Alfreds Klomps blog on pushing HPGL data to the plotter linux/(open)solaris/osx style

http://www.alfredklomp.com/technology/plotter/

To covert your PDFs to HGPL, go grab ps2edit

http://www.pstoedit.net/

and you'll be pumping PDFs off that old plotter in no time!

Your CTRLs?

"Your controls" is the term a flight instructor use when the student pilot is handed the controls. Being somewhat of a computer geek and flight instructor, the observant reader will hopefully be able to connect the dots on that play of words...

No matter the result of that mental exercise, I hope my blogging will be of help to someone, somewhere.