SurlyJake Blog

QT Segfault When Accessing Ui Objects

| Comments

I’m starting with QT for a hobby project. My design called for a public method inside of my QMainWindow main window. the method will update the text in the display. When calling anything using the ‘’ui->’‘ pointer, the app would segfault. The QT Creator debugger showed the ui pointer as ’‘. That was a clue. To confirm, I wanted to see gdb’s output.

To enable debug symbols for GDB, I had to edit the ‘.pro’ file and add the line ‘’#CONFIG += debug’‘. After the edit is made, change directories to the project folder, run qmake, make clean, and make. Once the build is completed, ‘gdb ./terminal’ (terminal is the name of my program).

$ gdb ./terminal
(gdb) run
Starting program: /home/jacob/program/./terminal 
Program received signal SIGSEGV, Segmentation fault.
0x0804f8f3 in MainWindow::updateStatus (this=0x2c74c085, status=0xbfffee4c) at mainwindow.cpp:233
233     qDebug() << ui->valueLabelLocusStatus->text();
(gdb) print ui
Cannot access memory at address 0x2c74c09d

After the segfault, I tried to get it to print the value of the ‘ui’ pointer, it said ‘’cannot access memorry at address…’‘. That confirmed it, Something is wrong with the ui pointer.

The problem was threading. Because my application was in a thread other than that of the main window, access to it’s widgets isn’t allowed. To resolve the issue, I followed the QT documentation at http://qt-project.org/doc/qt-5.0/qtcore/signalsandslots.html . I changed the public method on the mainwindow class into a QT slot. I made my class extend QObject and added a signal to my class instead of calling the method directly. Once the signal is connected to the slot, QT handled the threading issue.

Easily Test Packages From Arch Linux Testing Repositories

| Comments

Sometimes, when a new kernel or application that I use a lot comes out, I want to quickly download and test it on my system. It is simple enough to edit /etc/pacman.conf and enable the testing repositories, then update your system. Problem is, enabling the testing and/or community-testing repos at their default position will update all packages which have versions in testing.

If you put the [testing] and [community-testing] repos after [core] and [community] accordingly. This will tell pacman to prefer the stable versions of packages. Running pacman -Syu will result in the same set of packages as before.

Once pacman is configured with the testing repositories enabled as described above, you can selectively run versions of applications that are in testing with all of their testing dependencies without messing about. If you want to install a package from the testing repository, you simply prefix it with the repository’s name. Here is an example:

Linus releases a new kernel and you have read that it fixes some bug that has been plaguing you for months. It’s in [testing], but you just can’t wait. You can:

  1. Go to the Arch packages site and manually download the .pkg.xz files of the kernel and all it’s dependencies, then install them with pacman -U.

  2. Enable the [testing] repo and run an update. This might give you a lot more than you bargained for.

  3. If you configured pacman as I described above, you can simply run pacman -Syu testing/linux

If you have already installed a package which requires an older package than the one you are instaling, pacman will prompt you with the problem like this

error: failed to prepare transaction (could not satisfy dependencies) :: nvidia: requires linux

You can usually sove this by installing a newer version of that dependency. The solution in this case is to also install the nvidia package from testing:

pacman -Syu testing/linux testing/nvidia

Now It should go through.

Disclaimer: Obviously running something from testing is done at your own risk. Be sure to read up on the repositories you enable here: https://wiki.archlinux.org/index.php/Official_Repositories

New ArchLinux Mirror

| Comments

I love Arch linux and have been using it for a few months now. When I started, many of the mirrors I used were slow or would go offline and/or out of date. When I saw an offer for a VPS which should allow me to host a mirror of the archlinux package archives, I snatched it up. If you run arch, you can point pacman at my server by adding this line in /etc/pacman.d/mirrorlist:

Server = http://archlinux.surlyjake.com/archlinux/$repo/os/$arch

I threw together a quick page showing some general stats for the server which you can view at http://archlinux.surlyjake.com/.The server has been added as an official Arch Linux mirror, but is not in the pacman-mirrorlist package (I’m not sure what the process for that is).

Review After One Year of QuickWeb VPS Hosting

| Comments

One year ago, I purchased a VPS from QuickWeb. I found the deal at my one of my favorite sites for cheap hosting: www.lowendbox.com. The deal was:

  • OpenVZ VPS
  • 256MB RAM/386 Burst
  • 10G disk space
  • 250GB bandwidth/ Month on 1 IP
  • $35.88/ 1 Year

I ordered without much of a problem and my Debian server was provisioned within a few minutes. I was a happy camper. $2.99/month is a great deal for root access to a server, even one with such meager specs. I’ve had a decent year of hosting with QuickWeb, but I decided to take my business elsewhere when my plan came up for renewal. To help explain why,  I want to share the three support tickets I had to open with them. This will give you the clearest idea of what you get for the money. I Would have included the full text of these exchanges, but they insert a privacy notice in the signature of their support emails, so i’m worried that I may have agreed to something in their TOS.

  1. The server that QuickWeb provisioned for me was fully loaded. For me, that wasn’t such a good thing. The server already had web, DNS, and mail server software installed and running (apache, named, and postfix IIRC).  I wasn’t comfortable with that because I prefer to start from scratch, planned on using nginx and didn’t need to run a DNS and public mail server. I opened a ticket asking if i could get a server provisioned that only includes the base Debian install. The response from QuickWeb was that they don’t have a minimal template ‘yet’, but that I could uninstall packages that i don’t need using apt-get. Thanks.

  2. In July of last year, there was a service interruption. This site was down.  Not just me, I checked stuff like connecting from a few other servers that I have access too and, of course, http://www.downforeveryoneorjustme.com/. I opened a ticket. An hour and a half later, a response told me that I had sent the ticket to sales instead of the helpdesk and next time, to use the helpdesk for faster response. Another hour and a half later, they replied and told me that the VPS was actually up the whole time, but there was a brief network interruption in their management network, so I wan’t able to connect to check the status of my VPS. I had to reiterrate that whether or not the server was UP, It was unreachable over the network for an hour and a half.  The last reply from them came 8 hours in. They asked me to do stuff like turn off IPtables and give them a traceroute. I gave them a ticket without a lot of information, somehow sent it into their sales queue, but it took them 8 hours to get me a semi-intelligent response.  They never acknowleged a problem with public connectivity to my server.

  3. The isue that sealed the deal for me happened this December when QuickWeb changed the IP of my server. Despite their claims to have notified me, I never got an email from them. I used a gmail account to handle all their communication with me.  Yes, even checked the spam folder. No notice. I submitted a ticket for this one too and all they did was tell me that they sent me emails about it while I told them that they didn’t.

The server this site is runing on now is a KVM VPS from bitcable. So far the support there is night and day compared with QuickWeb.  Preetam helped me set up the virtIO drivers on FreeBSD. More on that later.

Create a Custom Application Launcher in GNOME3

| Comments

On Arch, the system-wide shortcuts are stored in /usr/share/applications. Each one is a .desktop file with a few parameters. user-specific icons are stored in ~/.local/share/applications. I downloaded eclipse and extracted it in my home directory, so I’ll use eclipse as the example application.

  1. Create the .desktop file

     nano ~/.local/share/applications/Eclipse.desktop
    

    Paste this in:

     [Desktop Entry] 
     Encoding=UTF-8 
     Version=1.0 
     Type=Application 
     NoDisplay=false 
     Exec=/path/to/eclipse/eclipse 
     Name=Eclipse Comment=Launcher for Eclipse
    

    Each line is pretty self-explanatory. Edit to suit your needs. As soon as you save the file, you will be able to see your new shortcut in the list.

  2. (Optional) Give the shortcut a nice-looking icon: You probably noticed that your icon is an ugly diamond. To pretty it up, you simply have to add one more line to the desktop file.

     Icon=/path/to/eclipse/eclipse.svg
    

    Your application may have included a png icon, but to make it really look nice, you should grab an SVG file of the logo from somewhere. Arch has a very simple packaging process which lets you examine all of the package building elements through their webpage at http://www.archlinux.org/packages/. I was able to grab the SVG which the package uses like this:

     wget -O eclipse.svg http://projects.archlinux.org/svntogit/packages.git/plain/trunk/eclipse.svg\?h\=packages/eclipse
    

Wordpress HTTPS Secure Login

| Comments

Back when I started with Wordpress, I had to create server rewrites to force my browser to use HTTPS. That changed back in 2008, but this is the first i’ve heard of it.

Wordpress 2.6 (released in July, 2008) and newer include the tools do do this out of the box! Using this documentation, you can get rid of some old .htaccess or nginx rewrite rules: http://codex.wordpress.org/Administration_Over_SSL.  All you have to do is add the declaration in wp-config.php:

define('FORCE_SSL_ADMIN', true);

This forces logins and administrative sessions to use SSL.

Now, you can remove the old nginx rewrites. They aren’t needed anymore:

rewrite ^/wp-login.php(.*) https://www.surlyjake.com/wp-login.php$1 permanent;
rewrite ^/wp-admin(.*) https://www.surlyjake.com/wp-admin$1 permanent;

WordPress Redirection Plugin

| Comments

This blog is undergoing some changes.There is some content (like the zabbix pages) that I can no longer maintain since I no longer use them in my day-job. To keep everything working seamlessly, I wanted to create some 302 (permanently moved) redirectors for the content that I was taking down. In the past, I used a plugin called “smart 404” to intelligently redirect visitors to a good page instead of the dummy standard 404 page. Unfortunately, It looks like smart 404 is having some trouble in newer WordPress versions and wouldn’t create a smart suggestions on my 404 page.

Enter Redirection. Redirection gives you a menu in the admin interface which allows you to easily create and maintain 301 and 302 redirections (among other features). Here is a screenshot of what it looks like once activated:

From the screenshot, you can see that I was able to create a simple 301 redirect from a page on my WordPress instance to an external website where the content will live from now on.  The second rule allowed me to match the URL using a regular expression and redirect it to another page on my site. This is a great piece of software.

One issue I ran into when testing the plugin was that edits I made did not seem to be taking effect. This turned out to simply be my browser caching the 301 response. I recommend that you either manually clear the cache or download the web developer toolbar and disable cache.  I should also note that my server runs nginx and not the Apache web server. I simply deleted the redirection ‘module’ for Apache which attempts to create .htaccess rules to perform the redirections. Without the Apache module, WordPress handles the redirections.

Redirection Plugin documentation: http://urbangiraffe.com/plugins/redirection/

Prevent Samba From Creating Home Directory for Machine Accounts.

| Comments

Since this setup automatically creates a home directory for a user as soon as they access the machine (via samba, ssh, console), I noticed some directories being created for computer accounts.  To prevent this,  I have added a line that only “Domain Users” are allowed to authenticate.  To add this:

wbinfo -n "Domain Users"

It will spit out the SID for the Domain Users group. Something like this:

S-1-5-21-((some number))-((some number))-((some number)) Domain Group (2)

Take that number and change the Pam_winbind.so line in /etc/pam.d/common-session to look like this:

session sufficient pam_winbind.so require_membership_of=S-1-5-21-((some number))-((some number))-((some number)

Create a Single Standalone .exe From a Python Program

| Comments

I have been working on a small windows command line tool that I wanted to distribute it as a single executable file on windows. I tried cx_freeze and py2exe. Both of these tools worked well, but I couldn’t find an easy way to compress make the whole program into a .exe file. py2exe and cx_freeze both create working programs, but there are always some dependent .zip archive or .dll’s somewhere that need to be distributed with it. Pyinstaller, I found, actually compresses everything into a single .exe. This makes a pretty big executable (my small command line utility created a 5MB .exe file), but it’s simple and it works.

To use pyinstaller:

  1. grab pyinstaller 1.5rc (1.4 doesn’t work with python 2.7). extract the zip file anywhere.

  2. change directories to the pyinstaller folder you just created.

  3. Before you create your first executable, you will have to run this once.

    python configure.py
    
  4. Now, pyinstall needs to scan through your program and create what they call a spec file.

    python makespec.py --onefile path\to\program\program.py
    
  5. Now, run this command to generate the executable.

    python build.py program\program.spec
    

Once the command has finished, the standalone executable will be available in the program\dist folder inside of pyinstaller. Instructions for how to do this for a linux executable on ubuntu linux can be found here: http://excid3.com/blog/2009/12/pyinstaller-a-simple-tutorial/. You can find more info on pyinstaller at their website: http://www.pyinstaller.org/.

Install Open-VM-tools on Debian 6 Squeeze

| Comments

Installing Open Virtual Machine Tools is a nice alternative to managing and installing the vmware tools package that comes with Vmware’s hypervisor products.  It allows you to use APT to manage all the dependencies and updates. Module assistant will recompile the kernel modules for you automatically when you update kernels too.

I have verified that this configuration works under ESXi 4.1.0, 260247 and a new Squeeze install. All of the essential functions like being able to see guest OS information on the Vsphere summary page and performing “Shut Down Guest” and “Restart Guest” all work as expected. If your experiences vary, please leave a comment

This should all be performed by the root user (otherwise prepend ‘sudo’ to the commands if you must use sudo). _ The first thing you need to do is add the ‘contrib’ archive to your apt sources config:

nano /etc/apt/sources.list

Add the ‘contrib’ to the end of these source lines. I use the debian.uchicago.edu repository, so mine look like this on a new install:

deb http://debian.uchicago.edu/debian/ squeeze main contrib
deb-src http://debian.uchicago.edu/debian/ squeeze main contrib

After you save changes to the file, simply update your package list and perform the install:

apt-get update
apt-get install open-vm-tools open-vm-source

You might see an error that looks like this:

Loading open-vm-tools modules: vmhgfsFATAL: Module vmhgfs not found.
 vmmemctlFATAL: Module vmmemctl not found.
 vmsyncFATAL: Module vmsync not found.

Don’t worry, this is because we have not installed the kernel modules for some of the more advanced VMware functions like the vmhgfs file system, Memory Balloon (vmmemctl) Driver, and vmsync, which helps freeze the VM while taking snapshots. To install these kernel modules, we’re going to use module-assistant. It will compile the modules for your kernel:

module-assistant auto-install open-vm -i

The ‘-i’ puts module assistant into non-interactive mode. It wont ask you to confirm any additional package installs necesarry to set up the build environment. If you’re running a server without a Graphical environment, you’re finished. If you want features such as automatically adjusting the VM’s monitor resolution or allowing your mouse to seamlessly move between your host system and the VM, you need to install one more package:

apt-get install open-vm-toolbox

Now you won’t need to use CTRL+ALT to switch back and forth.