pko.ch

Reflections about reflection

Archive for the ‘troubleshooting’ Category

Taming KbdMgr.exe

Saturday, March 28th, 2009

I have a bootcamp’ed Macbook Pro. As many people, I experienced some lagging sound and graphics from the computer, apparently at random. I googled it a bit, and found DPCs were the cause of it. And the cause DPCs were so slow were some drivers and KbdMgr.exe, a small app that listens to the hardware keys to raise brightness and stuff.

I updated the drivers, and the lag dropped a bit, but not that much. Then I turned to KbdMgr.exe. I read that a quick fix was to set the affinity to the second core and set it to minimum priority. And so I did, and it worked! However, It was just a pain in the butt to do that dance on each boot. I thought of doing some wrapper exe for KbdMgr.exe, but just the thought of downloading Visual Studio and all the SDKs gave me nauseas. And python popped into my mind.

After some 15 minutes of research, I found win32all. And from there, It was just remembering all of the win32 I had forgotten. I eventually churned out some code to scratch my itch.

import win32api
import win32com.client
import win32process
import win32con
import time
import sys, traceback

class ProcessSeekerThrottler(object):

    def __init__(self):
        self.coup_de_grace = self.throttle_and_set_affinity
        self.backoff_interval = 1.0

    def throttle_and_set_affinity(self,pid):
        proc = win32api.OpenProcess(win32con.PROCESS_SET_INFORMATION, 0, pid)

        win32process.SetProcessAffinityMask(proc,0x02)
        win32process.SetPriorityClass(proc,win32process.IDLE_PRIORITY_CLASS)

        win32api.CloseHandle(proc)

    def pids_for(self,process_name):
        self.WMI = win32com.client.GetObject('winmgmts:')
        results = self.WMI.ExecQuery('select * from Win32_Process where Name="%s"'%(process_name,))
        if len(results) < 1:
            raise Exception("Not found: %s"%(process_name,))
        else:
            return [result.Properties_('ProcessId').Value for result in results]

    def hunt_pid_for(self,process_name):
        done = False
        while not done:
            try:
                [self.coup_de_grace(pid) for pid in self.pids_for(process_name)]
                print "Killed!"
                done = True
            except Exception as e:
                print >> sys.stderr, "-"*60
                traceback.print_exc(None,sys.stderr)
                print >> sys.stderr, "Backing off."
                time.sleep(self.backoff_interval)

if __name__ == '__main__':
    try:
        ProcessSeekerThrottler().hunt_pid_for("KbdMgr.exe")
    except Exception as e:
        traceback.print_exc(None,sys.stderr)
        raw_input()

RegExp for capturing strings

Monday, December 15th, 2008

'((?:\\['\n])|[^'\n])*'

Because I keep forgetting.

For those who don’t use SQL too much, just like me.

Tuesday, June 17th, 2008

I’ve been using MySQL more than what I would like to. In these endeavors, I’ve always felt the need for one thing: Negated joins. For example, in a many-to-many, I want to know what categories a post is not linked to.

For those who had similar problems, I present you two solutions:

Thank you so very much!

Restored access to mail.google.com

Sunday, May 11th, 2008

The problem kept reappearing in many other sites. The internet was somewhat fading away for me. I grew really frustrated and tired of it. Must wreak havoc on someone.

So I reseted the router’s configs. Operations returned to normal immediately! Hurray! It was the god damned router! After reconfiguring the router, I hit the same problem. Hmmm.

So, I recapped the changes.
Can’t be changing the network addresses, that would give linksys a support nightmare.
Changing the passwords goes with the same reasoning.
Could it be some DynDNS client collateral damage? Guess not. If I were to implement it, it would only do some HTTP API calls, or some screen scrapping in the worst case.
Could it be WiFi crypto? WPA2 with TKIP+AES… Why not? It’s cpu intensive (compared to the rest of the stuff it’s doing) and very bug prone. Disabled it, operation normal. Bingo! WPA1 with TKIP? Works just fine. So I settled for it.

Linksys, burn in hell.

PS: Yes, I know. It could be worse. I, too, hit some wacky stuff with routers. Reset the guy, config it, test it. No go. Lather, rinse, repeat. Works. Nobody knows why.

Selective access to mail.google.com

Friday, May 9th, 2008

Edit: Problem solved! I reseted the router’s configs and operations returned to normal. After reconfiguring the router, I hit the same problem. Disabled WPA2 and AES encryption and everything came back to normal.

My PowerBook’s pouting. Yesterday, it just stopped talking to mail.google.com. No apparent reason. I’m a sysadmin type of guy, and I have no idea of what’s wrong. If you can, please help me.

Network Setup

Signal comes through cable, into a Thompson cable modem. It feeds network to a Linksys WRT54GX-v2 (tried both stock and latest firmware) router through RJ45. The router is wireless with 4 wired ports. On one wired port, there’s my personal server (named bolinhas). The rest of the computers are hooked through wifi.

Problem

My PowerBook G4, last edition, can’t get to http://mail.google.com/ (it can resolve the name) when using wifi, no ping nor telnet mail.google.com 80. When wired, everything works as expected. Other computers, both wireless and wired, can all access gmail without a problem.

Traceroutes

PB Wifi:


16:34:49|pkoch@Kochs-PowerBook:~$ traceroute google.com
traceroute: Warning: google.com has multiple addresses; using 64.233.167.99
traceroute to google.com (64.233.167.99), 64 hops max, 40 byte packets
1 10.0.0.254 (10.0.0.254) 4.671 ms 1.069 ms 4.073 ms
2 10.40.191.254 (10.40.191.254) 10.521 ms 46.005 ms 14.467 ms
3 a212-113-169-6.netcabo.pt (212.113.169.6) 11.405 ms 9.431 ms 27.149 ms
4 a212-113-176-66.netcabo.pt (212.113.176.66) 60.116 ms * 16.998 ms
5 a212-113-176-73.netcabo.pt (212.113.176.73) 51.171 ms 52.588 ms 15.169 ms
6 lis2-cr1-gi-12-0-0.cprm.net (195.8.0.173) 39.270 ms 16.069 ms 20.486 ms
7 lis2-cr1-po0-0-4-0.cprm.net (195.8.0.69) 87.412 ms 25.483 ms 82.825 ms
8 lon1-cr1-po12-0-0.cprm.net (195.8.0.70) 116.653 ms 90.707 ms 49.987 ms
9 72.14.198.81 (72.14.198.81) 55.468 ms 50.392 ms 49.704 ms
10 209.85.252.76 (209.85.252.76) 84.751 ms 209.85.255.175 (209.85.255.175) 50.112 ms 209.85.252.76 (209.85.252.76) 156.878 ms
11 * * *
12 209.85.248.216 (209.85.248.216) 122.151 ms 193.339 ms 188.357 ms
13 216.239.46.224 (216.239.46.224) 151.448 ms 171.089 ms 209.85.252.165 (209.85.252.165) 152.219 ms
14 66.249.94.133 (66.249.94.133) 130.489 ms 72.14.238.89 (72.14.238.89) 163.851 ms 140.776 ms
15 64.233.175.26 (64.233.175.26) 141.084 ms 72.14.232.70 (72.14.232.70) 164.070 ms 64.233.175.26 (64.233.175.26) 174.238 ms
16 py-in-f99.google.com (64.233.167.99) 155.060 ms 132.278 ms 181.951 ms

16:35:27|pkoch@Kochs-PowerBook:~$ traceroute mail.google.com
traceroute: Warning: mail.google.com has multiple addresses; using 66.249.91.19
traceroute to googlemail.l.google.com (66.249.91.19), 64 hops max, 40 byte packets
1 10.0.0.254 (10.0.0.254) 1.949 ms 0.859 ms 0.863 ms
2 10.40.191.254 (10.40.191.254) 11.955 ms 28.492 ms 26.307 ms
3 a212-113-169-6.netcabo.pt (212.113.169.6) 37.995 ms 8.724 ms 15.758 ms
4 a212-113-176-70.netcabo.pt (212.113.176.70) 29.253 ms 14.119 ms 39.223 ms
5 a212-113-176-69.netcabo.pt (212.113.176.69) 68.348 ms 17.081 ms 14.946 ms
6 lis2-cr1-po0-0-4-0.cprm.net (195.8.0.69) 58.700 ms 31.845 ms 34.821 ms
7 lon1-cr1-po12-0-0.cprm.net (195.8.0.70) 98.358 ms 48.621 ms 49.145 ms
8 72.14.198.81 (72.14.198.81) 78.529 ms 85.890 ms 48.569 ms
9 209.85.252.76 (209.85.252.76) 54.803 ms 209.85.255.175 (209.85.255.175) 47.858 ms 92.640 ms
10 209.85.248.12 (209.85.248.12) 67.195 ms 145.352 ms 158.805 ms
11 * * *
12 * * *
13 * * *
14 * * *
15 * * *
16 * * *
17 * * *
^C

PB Wired:


16:40:12|pkoch@Kochs-PowerBook:~$ traceroute google.com
traceroute: Warning: google.com has multiple addresses; using 72.14.207.99
traceroute to google.com (72.14.207.99), 64 hops max, 40 byte packets
1 10.0.0.254 (10.0.0.254) 1.284 ms 0.807 ms 0.485 ms
2 10.40.191.254 (10.40.191.254) 10.463 ms 39.591 ms 17.745 ms
3 a212-113-169-6.netcabo.pt (212.113.169.6) 10.095 ms 28.736 ms 31.487 ms
4 * a212-113-176-66.netcabo.pt (212.113.176.66) 44.754 ms 40.161 ms
5 a212-113-176-73.netcabo.pt (212.113.176.73) 63.704 ms 29.511 ms 14.514 ms
6 lis2-cr1-gi-12-0-0.cprm.net (195.8.0.173) 62.878 ms 15.575 ms 15.378 ms
7 lis2-cr1-po0-0-4-0.cprm.net (195.8.0.69) 28.805 ms 24.500 ms 16.264 ms
8 lon1-cr1-po12-0-0.cprm.net (195.8.0.70) 78.276 ms 46.210 ms 48.180 ms
9 72.14.198.81 (72.14.198.81) 63.493 ms 77.912 ms 65.728 ms
10 209.85.252.76 (209.85.252.76) 61.763 ms 58.583 ms 75.047 ms
11 64.233.175.213 (64.233.175.213) 149.771 ms 66.249.95.146 (66.249.95.146) 126.585 ms 64.233.175.213 (64.233.175.213) 119.957 ms
12 72.14.233.113 (72.14.233.113) 125.244 ms 72.14.236.219 (72.14.236.219) 125.475 ms 72.14.233.113 (72.14.233.113) 123.091 ms
13 66.249.94.90 (66.249.94.90) 151.902 ms 147.142 ms 72.14.236.181 (72.14.236.181) 145.065 ms
14 72.14.236.130 (72.14.236.130) 143.891 ms 72.14.236.134 (72.14.236.134) 130.771 ms 66.249.94.50 (66.249.94.50) 128.325 ms
15 eh-in-f99.google.com (72.14.207.99) 137.732 ms 133.693 ms 152.883 ms

16:40:26|pkoch@Kochs-PowerBook:~$ traceroute mail.google.com
traceroute: Warning: mail.google.com has multiple addresses; using 66.249.91.83
traceroute to googlemail.l.google.com (66.249.91.83), 64 hops max, 40 byte packets
1 10.0.0.254 (10.0.0.254) 1.236 ms 0.713 ms 0.288 ms
2 10.40.191.254 (10.40.191.254) 58.780 ms 31.526 ms 25.740 ms
3 a212-113-169-14.netcabo.pt (212.113.169.14) 7.916 ms 8.691 ms 38.554 ms
4 a212-113-176-70.netcabo.pt (212.113.176.70) 23.863 ms 14.347 ms 23.672 ms
5 a212-113-176-69.netcabo.pt (212.113.176.69) 25.344 ms 13.558 ms 39.334 ms
6 lis2-cr1-po0-0-4-0.cprm.net (195.8.0.69) 60.957 ms 43.192 ms 44.532 ms
7 lon1-cr1-po12-0-0.cprm.net (195.8.0.70) 77.503 ms 64.577 ms 46.387 ms
8 72.14.198.81 (72.14.198.81) 60.730 ms 46.733 ms 73.012 ms
9 209.85.255.175 (209.85.255.175) 63.231 ms 209.85.252.76 (209.85.252.76) 70.573 ms 209.85.255.175 (209.85.255.175) 67.999 ms
10 66.249.95.106 (66.249.95.106) 79.603 ms 65.092 ms 209.85.248.12 (209.85.248.12) 71.509 ms
11 216.239.43.123 (216.239.43.123) 69.156 ms 72.14.232.149 (72.14.232.149) 61.423 ms 73.370 ms
12 209.85.255.13 (209.85.255.13) 87.062 ms 63.492 ms 209.85.255.23 (209.85.255.23) 85.022 ms
13 66.249.94.146 (66.249.94.146) 71.771 ms 72.14.233.77 (72.14.233.77) 62.291 ms 69.529 ms
14 ik-in-f83.google.com (66.249.91.83) 87.793 ms 60.903 ms 78.256 ms

bolinhas wired:


pkoch@bolinhas:~$ traceroute google.com
traceroute to google.com (64.233.167.99), 30 hops max, 40 byte packets
1 10.0.0.254 (10.0.0.254) 0.275 ms 0.268 ms 0.256 ms
2 10.40.191.254 (10.40.191.254) 18.956 ms 19.166 ms 19.233 ms
3 a212-113-169-6.netcabo.pt (212.113.169.6) 19.391 ms 27.191 ms 27.331 ms
4 a212-113-176-66.netcabo.pt (212.113.176.66) 33.936 ms 34.041 ms 34.148 ms
5 a212-113-176-73.netcabo.pt (212.113.176.73) 33.076 ms 33.178 ms 33.275 ms
6 lis2-cr1-gi-12-0-0.cprm.net (195.8.0.173) 62.214 ms 27.748 ms 27.842 ms
7 lis2-cr1-po0-0-4-0.cprm.net (195.8.0.69) 86.889 ms 36.410 ms 36.503 ms
8 lon1-cr1-po12-0-0.cprm.net (195.8.0.70) 50.871 ms 51.013 ms 51.122 ms
9 72.14.198.81 (72.14.198.81) 51.228 ms 51.343 ms 51.445 ms
10 209.85.252.76 (209.85.252.76) 85.683 ms 209.85.255.175 (209.85.255.175) 51.476 ms 54.875 ms
11 72.14.236.216 (72.14.236.216) 114.197 ms 114.539 ms 64.233.175.213 (64.233.175.213) 111.037 ms
12 * 66.249.94.235 (66.249.94.235) 115.199 ms 209.85.248.216 (209.85.248.216) 115.592 ms
13 * 216.239.46.224 (216.239.46.224) 346.006 ms *
14 72.14.232.53 (72.14.232.53) 149.020 ms 149.131 ms 66.249.94.133 (66.249.94.133) 148.609 ms
15 72.14.232.70 (72.14.232.70) 160.295 ms 64.233.175.26 (64.233.175.26) 158.286 ms 176.353 ms
16 py-in-f99.google.com (64.233.167.99) 160.671 ms 134.829 ms 129.375 ms

pkoch@bolinhas:~$ traceroute mail.google.com
traceroute to mail.google.com (66.249.91.83), 30 hops max, 40 byte packets
1 10.0.0.254 (10.0.0.254) 0.381 ms 0.275 ms 0.322 ms
2 10.40.191.254 (10.40.191.254) 37.660 ms 42.704 ms 42.843 ms
3 a212-113-169-14.netcabo.pt (212.113.169.14) 43.197 ms 43.329 ms 43.439 ms
4 a212-113-176-70.netcabo.pt (212.113.176.70) 49.254 ms 49.361 ms 49.468 ms
5 a212-113-176-69.netcabo.pt (212.113.176.69) 48.350 ms 48.493 ms 48.597 ms
6 lis2-cr1-po0-0-4-0.cprm.net (195.8.0.69) 49.434 ms 29.464 ms 29.583 ms
7 lon1-cr1-po12-0-0.cprm.net (195.8.0.70) 65.448 ms 108.295 ms 108.389 ms
8 72.14.198.81 (72.14.198.81) 107.701 ms 107.843 ms 112.629 ms
9 209.85.255.175 (209.85.255.175) 113.334 ms 113.481 ms 112.945 ms
10 209.85.248.12 (209.85.248.12) 113.550 ms 66.249.95.106 (66.249.95.106) 113.893 ms 209.85.248.12 (209.85.248.12) 113.580 ms
11 72.14.232.149 (72.14.232.149) 126.236 ms 216.239.43.123 (216.239.43.123) 122.004 ms 57.388 ms
12 72.14.233.79 (72.14.233.79) 61.060 ms 209.85.255.23 (209.85.255.23) 67.601 ms 209.85.255.13 (209.85.255.13) 84.405 ms
13 66.249.94.154 (66.249.94.154) 83.248 ms 72.14.233.81 (72.14.233.81) 84.178 ms 66.249.94.154 (66.249.94.154) 72.744 ms
14 ik-in-f83.google.com (66.249.91.83) 60.367 ms 66.249.94.146 (66.249.94.146) 73.045 ms ik-in-f83.google.com (66.249.91.83) 65.326 ms

Moar python on Bluehost

Thursday, May 8th, 2008

It all began with me wanting Mergurial (hg for short) on Bluehost. I find mercurial as good as git but with more polish. I just followed some tutorial to get hg on Bluehost, and it was good.

However, I longed for more. Pylons more. It’s a lot of packages to install, so I really didn’t want to do it by hand. If I resign to do it this time, it will happen on my next coding whim too. I tried to use ez_setup, but it would screw up with my prefix. Tried virtual python from the easy_install guys, no go either. Tried messing with PYTHONPATH, PATH and the like, but it became really ugly really fast.

Bluehost’s python is very old. Has a big beard and all. Bluehost already forces me to use cgi after all, so i get to choose who runs the script. It might as well be my own version of python. And so it was! Grabbed the source, built it with a prefix and, lo and behold, I had a shiny python working. That simple. The night before it was configuration madness. This time, ./configure --PREFIX=$HOME/local && make && make install or some cash equivalent operation. All went good from there.

Lesson learned: In shared hosting, when forced to use cgi, ./configure --PREFIX=$HOME/local goes a long way. Use it!

Building ffmpeg on a Leopard

Friday, March 21st, 2008

This is a tribute to those who want to, on their own, extract the mp3 out of flv files, or other similar operations, but encountered build issues or problems.

I’m an avid listener of MacBreak Weekly and other TWiT network podcasts. However, the bandwidth provider for most of the shows, CacheFly, has grown a little feud with my connections to their port 80. And I still wanted to listen to my regular entertainment. Someone posted an alternate source for the mp3 files. However, they were distributed in a YouTube-ish fashion, flvs containing the mp3. I downloaded the flv file and felt a relieved to know I, with some help from Perian, could again hear my shows. But not on some players (iPod, for example). My next quest then became to extract the mp3 out of the flv. Some googling pointed me to ffmpeg.

From where I stand, ffmpeg is a very complete codec suite. I’m no fan of multimedia, so I’ll leave my understandings there. First step: aquire the source. That was easy. Just svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg and off we go. However, ./configure && make stopped in the middle of the build.


ppc/dsputil_altivec.c: In function 'sad8_altivec':
ppc/dsputil_altivec.c:292: warning: left-hand operand of comma expression has no effect
......
ppc/dsputil_altivec.c:292: warning: left-hand operand of comma expression has no effect
ppc/dsputil_altivec.c:292: error: can't convert between vector values of different size
ppc/dsputil_altivec.c:292: error: can't convert between vector values of different size

Pain. It’s not my code, it’s not simple C and it’s AltiVec specific. I have a last generation PowerBook G4 with Leopard on it. That’s all I can tell. I tried to figure out what was going on, but the code had too many exotic reserved words for my taste (it was the first time I saw AltiVec’s vector as a reserved word in C). Pain.

So, can we sidestep the need to build something AltiVec specific? Yes, we can! Just build it with ./configure --disable-altivec && make. It ran smoothly from there! =)

The next step was to run ffmpeg -i mbw81.flv -acodec copy mbw81.mp3 and it produced the desired mp3 file, just as seen on TV!