Alunduil's Hosting Gentoo Hackery and Other Fun …

22Jan/100

CMake … Java … Pain …

I’ve been work­ing quite fer­vently to get CMake work­ing for a Java project I’ve taken on and have found that it has a cou­ple of issues still. The first issue is an unde­fined CMAKE_Java_LINK_EXECUTABLE vari­able, which because Java doesn’t really do link­ing (JIT takes care of doing some­thing that I haven’t looked into yet) we don’t really need, but CMake expects it to be there. By sim­ply mak­ing it a mv string and set­ting up the class­path option (via INCLUDE_DIRECTORIES direc­tives) cor­rectly, we can com­pile our java project using CMake almost the same way we would expect to make a CXX project.

If any­one knows of the plat­form agnos­tic way to move files in CMake I’d love to know.

Unfor­tu­nately the fol­low­ing changes are required to some CMake 2.8 sys­tem files for this to work:

In /usr/share/cmake/Modules/CMakeJavaInformation.cmake:

IF(NOT ${CMAKE_Java_LINK_EXECUTABLE})
SET(CMAKE_Java_LINK_EXECUTABLE 
    "mv <OBJECTS> <TARGET>")
ENDIF(NOT ${CMAKE_Java_LINK_EXECUTABLE})

In /usr/share/cmake/Modules/CMakeJavaCompiler.cmake.in:

SET(CMAKE_Java_LINK_EXECUTABLE "@CMAKE_Java_LINK_EXECUTABLE@")
Tagged as: , , No Comments
20Jan/100

The Mother System Load

Today I found out that some machines can’t han­dle the load I throw at them. The fol­low­ing was the sta­tus of my web server after apache filled up its mem­ory. A quick (quite slow actu­ally) reboot of apache and every­thing was stabilized.

Ridiculous System Load

11Jan/100

Layman Overlay

My Over­lay

My over­lay has been avail­able via sub­ver­sion for quite some time now, but not in any easy to use for­mat (inte­gra­tion with lay­man).  Get­ting this over­lay to work with yours must have been a pain if you wanted to try some­thing I had been work­ing on.

Mak­ing My Over­lay Available

The first thing I had to do to make my over­lay talk with lay­man let alone get along with lay­man was add an xml def­i­n­i­tion of the over­lay some­where.  I chose the easy to manip­u­late path of http://www.alunduil.com/svn/portage/trunk/portage/alunduil-overlay.xml.

Adding My Over­lay List to Your Layman

To add my overlay(s) to your lay­man list sim­ply add the fol­low­ing path to your over­lays vari­able in /etc/layman/layman.cfg: http://www.alunduil.com/svn/portage/trunk/portage/alunduil-overlay.xml.

18Dec/090

CFLAGS" href="http://www.alunduil.com/2009/12/18/optimizing-gentoo-cflags/" rel="bookmark">Optimizing Gentoo CFLAGS

Start­ing Off

Make sure you’ve at least looked at the fol­low­ing doc­u­ment: [http://www.gentoo.org/doc/en/gcc-optimization.xml](Gentoo Opti­miza­tion Guide).

Check­ing Flags

The only real change we want to make to our sys­tem are sim­ple things we know will not break it. Thus, we only look at mak­ing sure that we have the cor­rect flags for enabling all of the instruc­tion sets that our proces­sor has available.

Check­ing Processor

grep flags /proc/cpuinfo | grep uniq

This pulls out all of the fea­tures of the proces­sor as detected by the ker­nel. Exam­ple out­put is shown (line breaks added for readability):

alunduil@elijah ~ $ grep flags /proc/cpuinfo | uniq
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr 
pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall 
nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow rep_good 
extd_apicid pni cx16 lahf_lm cmp_legacy svm extapic 
cr8_legacy 3dnowprefetch

Check­ing Default Flags

gcc does a great job of deter­min­ing what flags should be set by using the new –march=native flag (which you should have set by this point). Using the fol­low­ing com­mand we can dou­ble check that all of the instruc­tions we want enabled are enabled:

gcc -Q -c -v -march=native --help=target | grep disabled

If any­thing appears in the result­ing list it’s not enabled and should be enabled by adding the appro­pri­ate –m flag. For my cpu this results in: –msse3 –m3dnow.

Putting it Together

By adding the orig­i­nal guide with a check for instruc­tions we allow gcc to uti­lize the instruc­tions that were specif­i­cally cre­ated for uses we may have (mul­ti­me­dia, extended math, etc).

The result­ing CFLAG vari­able that I placed in my make.conf from the above discussion:

CFLAGS="-march=native -O2 -pipe -msse3 -m3dnow"
23Jul/090

Cleaning /etc/portage/package.*

Inro­duc­tion

After a while the files in /etc/portage become clut­tered with the com­mon, “Let’s try this … whoops that didn’t work … let’s try this.” No mat­ter how hard you try to keep this clean you have prob­a­bly for­got­ten some­thing along the way. Installing a test­ing pack­age then remov­ing it because you found a bet­ter one later, etc. Well what’s an easy way to clean these files up and make sure that we min­i­mize their sizes and keep our Gen­too sys­tem crisp (or as crisp as we can by just man­ag­ing these files)? I’ve writ­ten some bash one-liners that assist with this and could eas­ily be adapted into a script that auto­mates a lot of the clean­ing for you.

In all of these scripts change the /etc/portage/package.use to the file you are inter­ested in cleaning.

Check­ing for Mul­ti­ple Occur­rences of an Atom Within a File

for atom in $(gawk '{print $1}' /etc/portage/package.use); do [ "$(grep ${atom} /etc/portage/package.use | wc -l)" -gt "1" ] && echo "${atom}"; done

Check­ing for N Uses of a Use Flag in /etc/portage/package.use

I use this to move fre­quently used use flags to /etc/make.conf if it seems appropriate.

for flag in $(gawk '{print $2}' /etc/portage/package.use); do [ "$(grep "${flag}" /etc/portage/package.use | wc -l)" -gt "2" ] && echo "${flag}"; done

Check­ing for Removed Atoms Within a File

for atom in $(gawk '{print $1}' /etc/portage/package.use); do [ "$(portageq match / ${atom} | wc -l)" -lt "1" ] && echo "${atom}"; done
22Jul/090

“Disabling” KScreenSaver via DBUS" href="http://www.alunduil.com/2009/07/22/disabling-kscreensaver-via-dbus/" rel="bookmark">Disabling” KScreenSaver via DBUS

KDE 4 has some major improve­ments over older ver­sions, but it also seems to have gone back­wards in places. The new libraries prob­a­bly con­tribute to this, and are absolutely the way to go. A nice abil­ity that I’ve been look­ing for in pow­erdevil (the new power man­ager in KDE 4) is how to have the screen­saver “dis­able” when enter­ing pre­sen­ta­tion mode. This is behav­ior that I know I expected, but found to my dis­may part­way through a pre­sen­ta­tion that the screen­saver still kicked in.

After look­ing around for ways to “fix” this prob­lem I finally found some inter­est­ing infor­ma­tion in the form of the DBUS inter­face pro­vided by the screen­saver in KDE. Using qdbusviewer I was able to find an API for the screen­saver that can be invoked at any point and from any­where (assum­ing that you’re part of the ses­sion). Using this new ammu­ni­tion for more Google search­ing I found that I could write a dae­mon in python that would keep the screen­saver from dis­play­ing while it was turned on.

The result of this work can be found in my sub­ver­sion repos­i­tory as stop_kscreensaver.py. This script only has 3 para­me­ters and is very easy to use. When start­ing the dae­mon you sim­ply pass a time between activ­ity sim­u­la­tions (by set­ting this just shorter than the time­out for your screen­saver acti­va­tion it is much more effi­cient) and if desired a dif­fer­ent log level. To stop the dae­mon you sim­ply pass the kill para­me­ter which reads the PID from a stan­dard file and makes sure the dae­mon dies.

The tim­ing para­me­ter for this script is fairly func­tional in that you can pass the time in with var­i­ous units and the con­ver­sion will be taken into account. For exam­ple, one could pass a time of 2h32.1m94.34s. Why any­one would is beyond me, but hey I fig­ured with reg­u­lar expres­sions it might be easy to do. If no units are passed the script assumes that the num­ber passed was in sec­onds. As always if any bugs are found please e-mail me, Alex Brandt with a descrip­tion of the prob­lem (or if you’re ambi­tious a patch file would be appreciated).

Now the impor­tant part. How do we get this to work with pow­erdevil? That’s the eas­i­est part of all with powerdevil’s exe­cute this script when switch­ing to this pro­file fea­ture. We sim­ply save the script some­where, make it exe­cutable (chmod 755), and then set the path (or browse to it) in the pow­erdevil con­fig­u­ra­tion interface.

Once that is in place you can switch to the pro­file you set the dae­mon up to start in and the screen­saver although active will not start up until you switch pro­files again. This let’s you watch that movie you wanted to just like our favorite comic XKCD tells us about.

26Apr/090

Create a Symfony Development Environment

What are We Talk­ing About?

Sym­fony, the hot new frame­work for PHP web appli­ca­tion devel­op­ment, can dras­ti­cally reduce devel­op­ment times on intri­cate appli­ca­tions. By uti­liz­ing a frame­work and the Rapid Appli­ca­tion Devel­op­ment, Agile Devel­op­ment, XP, or what­ever devel­op­ment cycle you might like best, ele­gant code is eas­ier to pro­duce and main­tain. With proper design pat­terns already in use, one sim­ply needs to fill in the appro­pri­ate logic at each level, and let the appli­ca­tion grow into being. For more infor­ma­tion on Sym­fony the fol­low­ing resources are available:

This is all great, but not nearly as use­ful if we can’t develop and test locally. To get a nice devel­op­ment area installed what do we need to do? The fol­low­ing steps out­line how to setup a machine so that you can have a projects direc­tory that will auto­mat­i­cally map to a nice set of URLs with min­i­mal configuration.

What Do We Need?

We need the fol­low­ing installed (Gen­too use flags are in parentheses):

  • apache
  • mysql
  • php (cli ctype reflec­tion spl sim­plexml xml pcre ses­sion apache2 mysql pdo xsl)
  • sym­fony

What’s the Setup?

So how do we turn a direc­tory full of projects into some­thing we can get at by brows­ing to http://localhost/project? Well, we start by sym­link­ing (or just chang­ing) the doc­root to the direc­tory we want to use.

# rm -rf /var/www/localhost/htdocs
# ln -snf <path to projects> /var/www/localhost/htdocs

What we want to do now is change the vhost dec­la­ra­tion for the default vir­tual host in apache. It’s only an addi­tion of a few sim­ple lines (placed after the doc­root declaration):

AliasMatch ^/((?!cgi-bin|icons).+)/sf/(.*) /usr/share/php5/data/symfony/web/sf/$2
AliasMatch ^/((?!sf|cgi-bin|icons).+?)/(.*) /var/www/localhost/htdocs/$1/web/$2

<Directory "/usr/share/php5/data/symfony/web/sf">
  Options Indexes FollowSymLinks               
  Order allow,deny                             
  Allow from all                           
</Directory>

The last thing that needs to be done is make sure the default redi­rect in your sym­fony project’s .htac­cess file redi­rects to //index.php.

Con­clu­sions

That should be all there is to it, but as always your mileage may vary. If you notice sig­nif­i­cant prob­lems or short­com­ings with this how to, please, leave a com­ment denot­ing that. I will update this guide appro­pri­ately as quickly as possible.

Tagged as: , , No Comments
16Apr/080

C++ Programming Students

It’s strange that I’m the only tutor for our Com­puter Sci­ence and Infor­ma­tion Sys­tems depart­ment, but I can live with that. What irks me though, is how these stu­dents come to gain their knowl­edge about programming.

To be fair I will not men­tion names, and not blame any­one. I truly believe this to be a sim­ple mat­ter of mis­com­mu­ni­ca­tion, and eas­ily solved. I also feel that the scope of these classes needs to be mon­i­tored a lit­tle more closely, and what fol­lows is sim­ply what I under­stand the classes should teach in an intro­duc­tory pro­gram­ming class, and my under­stand­ing of what is being taught in our intro­duc­tory pro­gram­ming classes.

The classes in ques­tion are our first intro­duc­tory classes to C++, and then our fol­low up course. These courses together should leave the stu­dent com­fort­able with the basic con­structs and built-ins of C++. It should also make them com­fort­able with classes, and work­ing in an OOP(Object Ori­ented Pro­gram­ming) par­a­digm. The prob­lem crops up in the tran­si­tion between these two classes. It seems (and this I know because of my tutees) that their under­stand­ing of the basics gets mud­dled in the first class, and thus they can­not build upon this knowl­edge in the sec­ond class. I have heard many things about what may be hap­pen­ing wrong in this class to cause such a ter­ri­ble calamity, but let us refo­cus and start by going over what should be cov­ered in the first class in order to suc­ceed in the fol­low­ing class and through­out the whole program.

In an intro­duc­tory pro­gram­ming class it should be impor­tant for stu­dents to become famil­iar with func­tions, con­trol struc­tures, and var­i­ous key­words (not all of them mind you just most of them). Thus they should be com­fort­able look­ing through a piece of code like the fol­low­ing, and have an under­stand­ing of the major­ity of it:

#include <cstdlib>
#include <iostream>

using namespace std;

int factorial(int n)
{
    if (n == 0)
        return 1;
    return n * factorial(n - 1);
}

int main(int argc, char argv[])
{
    if (argc != 2)
    {
        cerr << "You must pass a number to get the factorials!" << endl;
        return EXIT_FAILURE;
    }
    int n = argv[1] + 1;
    while (--n, n > 0)
        cout << "The factorial of " << n << " is " << factorial(n) << "." << endl;
    return EXIT_SUCCESS;
}

They should also be able to under­stand Make­files (rudi­men­tary Make­files not automake or any­thing of its ilk), header files vs. source files, the stages of com­pil­ing and how to deal with dif­fer­ent errors in each (i.e. A link­ing error ver­sus a com­pi­la­tion error), and they should under­stand array mechan­ics (if not exactly what they are then how to use them). They should be able to put all of this together, and make a nice mod­u­lar pro­gram that allows them to expand and reuse code in an intel­li­gent way. Then if there is time (although this gets cov­ered in great detail in the sec­ond class) a quick cov­er­age of structs should ensue. At this point the edu­ca­tion they should have gained from the first class should be enough of the basics that they under­stand the con­structs of the lan­gauge, and can start read­ing sim­ple pro­grams like the one above.

In real­ity, this goal (mind you this is my per­sonal goal and does not reflect the goals of the pro­fes­sors or the depart­ment) was not met, and based on expe­ri­ence with peo­ple I’m tutor­ing who are in the sec­ond class at this time it is quite obvi­ous where their short­com­ings are. Those short­com­ings are out­lined below:

  • Lack of under­stand­ing about the loop­ing con­trol structures
  • Lack of knowl­edge as to how arrays func­tion, and should be used
  • Lack of knowl­edge as to how the com­piler actu­ally takes the source code (pos­si­bly spread over many files), and makes an executable
  • Lack of under­stand­ing as to how to solve sim­ple prob­lems like manip­u­lat­ing all the entries of an array
  • Lack of under­stand­ing as to how to do a sim­ple search, or uti­lize func­tions pro­vided in an API(Advanced Pro­gram­ming Interface).

This list will be updated appro­pri­ately as I gain more knowl­edge on what the stu­dents actu­ally know. Thus this list may have inac­cu­ra­cies and short­com­ings, and may not reflect reality.

The list goes in in much the same fash­ion here after, and this is obvi­ously a prod­uct of the class not ful­fill­ing its pri­mary pur­pose of lay­ing down a foun­da­tion that the stu­dents can build on. To bet­ter achieve this goal it may be nec­es­sary to at the very least rec­om­mend some sup­ple­men­tal texts (see list at the end of this arti­cle for rec­om­mended books for the var­i­ous pro­gram­ming courses).

Now, what I’ve heard reports of in this class is that (1) these con­cepts out­lined above are not get­ting cov­ered in the detail that is required of them in the sub­se­quent classes (which only con­firms what I’ve observed in stu­dents), and (2) there has been a report that a new teach­ing tool “Alice” was used in the intro­duc­tion class.

The first point appears to be just a short­com­ing of the class, and could be ame­lio­rated by sim­ply spend­ing more time and going over more exam­ples of the con­cepts in question.

Also, the stu­dents them­selves need to real­ize that they con­trol their edu­ca­tion, and must par­tic­i­pate for a class to truly be suc­cess­ful for them. When enter­ing a class, stu­dents should think to them­selves what do I want from this class, and how can I have this class help me achieve that goal? By ask­ing ques­tions and look­ing for more mate­r­ial on the spe­cific area of study the stu­dent is inter­ested in they can get a much more ful­fill­ing expe­ri­ence and bet­ter under­stand­ing of the top­ics involved, but may hit a point where they just can’t keep up with the class and need fur­ther assis­tance that isn’t self-guided. Tutors are avail­able from the tutor­ing depart­ment, and should not be shied away from. If you really want to learn the mate­r­ial you have to be will­ing to get help and help your­self towards that goal. That’s only part of the prob­lem, stu­dents who do try are still hav­ing a hard time within the sta­tus quo.

The sec­ond point requires that I do not put forth my per­sonal opin­ion, but does require that I state its pur­pose (from the Alice website):

Alice is an inno­v­a­tive 3D pro­gram­ming envi­ron­ment that makes it easy to cre­ate an ani­ma­tion for telling a story, play­ing an inter­ac­tive game, or a video to share on the web. Alice is a freely avail­able teach­ing tool designed to be a student’s first expo­sure to object-oriented pro­gram­ming. It allows stu­dents to learn fun­da­men­tal pro­gram­ming con­cepts in the con­text of cre­at­ing ani­mated movies and sim­ple video games. In Alice, 3-D objects (e.g., peo­ple, ani­mals, and vehi­cles) pop­u­late a vir­tual world and stu­dents cre­ate a pro­gram to ani­mate the objects.

In Alice’s inter­ac­tive inter­face, stu­dents drag and drop graphic tiles to cre­ate a pro­gram, where the instruc­tions cor­re­spond to stan­dard state­ments in a pro­duc­tion ori­ented pro­gram­ming lan­guage, such as Java, C++, and C#. Alice allows stu­dents to imme­di­ately see how their ani­ma­tion pro­grams run, enabling them to eas­ily under­stand the rela­tion­ship between the pro­gram­ming state­ments and the behav­ior of objects in their ani­ma­tion. By manip­u­lat­ing the objects in their vir­tual world, stu­dents gain expe­ri­ence with all the pro­gram­ming con­structs typ­i­cally taught in an intro­duc­tory pro­gram­ming course.

In con­clu­sion, it is my per­cep­tion that there is a miss­ing com­mu­ni­ca­tion link in the way these classes are han­dled, but it’s not just between the pro­fes­sors of the two classes (they seem to not have a smooth break between the classes), it’s between the stu­dents and the pro­fes­sors that the com­mu­ni­ca­tion has really bro­ken down. The stu­dents must speak up for their edu­ca­tion or they may see it going down a path that does not max­i­mally fur­ther their edu­ca­tion. This is wider spread than just the sim­ple class exam­ple I’ve given here. Almost every­where one looks, it seems that stu­dents are becom­ing more lethar­gic; push­ing to just get through the courses. There is a lack of gen­uine inter­est in the edu­ca­tion being pro­vided, and more of a view that col­lege is now a neces­sity to con­tinue in soci­ety. Unfor­tu­nately, that has begun to be so, but we can still fight for the free­dom of our minds.

Sup­ple­men­tal Books for CSIS Courses: 1. 152 * C++ in Plain Eng­lish by Brian Over­land 2. 252 * C++ in Plain Eng­lish by Brian Over­land 3. 352 * C++ in Plain Eng­lish by Brian Over­land * Beyond the C++ Stan­dard Library: An Intro­duc­tion to Boost by Björn Karls­son * C++ Cod­ing Stan­dards: 101 Rules, Guide­lines, and Best Prac­tices by Herb Sut­ter & Andrei Alexan­drescu * Design Pat­terns: Ele­ments of Reusable Object-Oriented Soft­ware by Erich Gamma, Richard Helm, Ralph John­son, John M. Vlissides

1Oct/070

XBOX 360" href="http://www.alunduil.com/2007/10/01/xbox-360/" rel="bookmark">XBOX 360

I finally broke down and pur­chased an XBOX 360 with Halo 3. It is an incred­i­ble improve­ment over the first sys­tem, and is back­wards com­pat­i­ble. The first intrigu­ing thing about the sys­tem from a net­work­ing per­spec­tive is their idea of “Open”, “Mod­er­ate”, and “Closed” NAT. I didn’t know that this was pos­si­ble, but after a few sniff­ing exper­i­ments later I learned a few things: * XBOX Live uses port 3047 * XBOX Live uses UDP * XBOX Live thinks open NAT means that port and pro­to­col is for­warded to your XBOX through the NAT device.

This leads me to the con­clu­sion that the XBOX Live and Vista ready devices are just engi­neered to pro­vide holes in your net­work. I sup­pose this is fine for most, but what if you want that secu­rity back?

5Jun/070

RAID) Grub Configuration" href="http://www.alunduil.com/2007/06/05/compaq-smart-array-raid-grub-configuration/" rel="bookmark">Compaq Smart Array (RAID) Grub Configuration

Intro­duc­tion

This guide is for Gen­too, but should be generic enough to apply to all Linux dis­tri­b­u­tions and Grub con­fig­u­ra­tions for Com­paq Smart Array RAID controllers.

I’ll assume that the machine is installed, and at the point of either con­fig­ur­ing Grub or installing it.

Install Grub

emerge -av grub

Edit the Grub Con­fig­u­ra­tion (/boot/grub/grub.conf)

Exam­ple (boot par­ti­tion is par­ti­tion 5):

default 0
timeout 30
splashimage=(hd0,4)/boot/grub/splash.xpm.gz

title=linux-2.6.20-gentoo-r8
    root (hd0,4)
    kernel /boot/bzImage-2.6.20-gentoo-r8 root=/dev/ida!c0d0p7

The kicker I noticed in this file for the Com­paq Smart Array Con­trollers is the ! between the first sub­di­rec­tory on the device, and the actual device name.

Edit the Grub Device Map (/boot/grub/device.map)

Exam­ple (Com­paq Smart Arrays might be ida or cciss for the subdirectory):

(fd0) /dev/fd0
(hd0) /dev/ida/c0d0

If you don’t have a floppy remove the fd0 line.

Installing Grub to the MBR

  1. Enter the grub com­mand line interface:

    /sbin/grub --batch --device-map=/boot/grub/device.map --config-file=/boot/grub/grub.conf --no-floppy
    
  2. Then inside the prompt set the device (again boot par­ti­tion is par­ti­tion 5):

    grub> device (hd0) /dev/ida/c0d0
    grub> root (hd0,4)
    grub> setup (hd0)
    grub> quit
    

Fin­ish­ing Grub Install

The Grub instal­la­tion should be com­plete at this point, and the only thing left to do is reboot the machine.