Wednesday, July 23, 2014

creating rpms with a specfile from a repository

I was working with my varnish vmod today, attempting to package it into rpm. I found a useful tutorial here: https://fedoraproject.org/wiki/How_to_create_an_RPM_package

I tend to be a bit impatient though and I didn't read everything. I wanted to have my rpmbuild process checkout the code from a repo and then to ./configure && make but I ended up getting this odd error:

error: No "Source:" tag in the spec file

It took a little while to get to the bottom of things, but I eventually discovered by having the following macro in my .spec file 

%setup -q

caused rpmbuild to need a Source: line. Once I took that line out, all was good again. The spec files I built are for libmaxmindb, varnish cache and a varnish module. The code is here:

https://github.com/russellsimpkins/varnish-mmdb-vmod


Friday, July 18, 2014

Working with Grids

While working on a course of Algorithms and data structures I had the need to represent a grid of x/y in an array. After a bit of thought I realized that for any grid of size N, you can represent the grid as an N*N length array. To convert an array element into X/Y coordinates, you do the following:

x = p/N
y = p%n

To get the array position p from an x/y coordinate:

p = N*x+y


Wednesday, June 25, 2014

How to determine which yum package to install

If you have a library that's missing and can't quite figure out what provides the file, you can ask yum:

yum whatprovides '*/libz.so.1"

32 bit compatability

If you don't install rpms a lot, you get a little rusty. If you have a 32 bit program on your 64 bit server (or vice versa) you will know it when you get an error like this:

/lib/ld-linux.so.2: bad ELF interpreter: No such file or directory

If you link to the wrong version. Say you're file is linked to a 64 bit version at compile time and you alter the LD_LIBRARY_PATH (thinking you're going to fix it,) you will resolve the link, but since its not the right version you will get:

wrong ELF class:

To install the 32 bit compatibility, you should install the .i686 version e.g.

yum install -y libz.i686

You can also add the compatibility while you're at it:

 yum groupinstall "Compatibility libraries"

Wednesday, April 30, 2014

How to get a core dump


If your process is segfaulting, and you aren't getting a core dump, you need to make sure the kernel will allow them. First make sure that ulimit allows core files. 


$> ulimit -a 
core file size          (blocks, -c) 0

That says that core files are not allowed. You can set that for the current session by running:

$> ulimit -c unlimited 

Though you may be better off updating editing /etc/security/limits.conf. The next thing to set is fs.suid_dumpable and kernel.core_pattern. see: http://man7.org/linux/man-pages/man5/core.5.html


$> sysctl -w fs.suid_dumpable=2
$> sysctl -w kernel.core_pattern=/tmp/core

When setting the core_pattern, make sure that directory, in this case /tmp, is writable by the user process you want a core dump from. Be careful that your start script is not overriding anything anything. I found that /etc/init.d/functions daemon function set's the -c option and you need to export DAEMON_COREFILE_LIMIT=unlimited in your start script.

Once you have a core file, you can analyze with gdb e.g. 

$> gdb /tmp/core.0231
$> bt


The backtrace may require you to install debug symbols with debug-info. To do that I had to run:

$> yum install yum-utils

Then I could run debuginfo-install e.g. 

$> debuginfo-install httpd-2.2.15-30.el6.centos.x86_64


Saturday, March 1, 2014

How to generate analyze statements for Oracle

Sometimes you get stuck with DBAs that can't be bothered to analyze your tables or indexes. There is an easy way to generate your own analyze statements. This example is assuming you're using sqlplus. Remove <TABLE_OWNER> with you're own table owner.

set pagesize 0
set linesize 255
spool /tmp/analyze-table.sql

select 'analyze table <TABLE_OWNER>.' || object_name || ' compute statistics;' from all_objects where owner like '<TABLE_OWNER>%' and object_type = 'TABLE';
exit

You will now have all the statements you need in /tmp/analyze-table.sql

Thursday, January 23, 2014