Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Tuesday, 26 November 2013

ioctl decoding

I was interested to know how to decode an ioctl hex string, I worked through the example described in the kernel documentation at /ioctl/ioctl-decoding.txt
Then I tested it out on an ioctl code listed in an error message in a server log, here is my working (this is for an x86_64 server, other architectures may vary)

ioctl code in hex is
cc770002

Which in binary is
11001100011101110000000000000010

First two bits gives us the macro used
11
this according to the document is _IOWR (Read/Write)

The next 14 bits give the size of the arguments
00110001110111
which in decimal is 3191

The next 8 bits are an ascii character, which in my example gives NULL (could well be an issue and why the message appears in the logs for that application)
00000000

The final 8 bits gives the function number, in my example this is
00000010
which in decimal is 2

If I had the sourcecode of the application I could go and look up this function using the character and the function number. In the example above, looks like a bug in the application is generating the wrong character and the ioctl call will fail.

Wednesday, 30 October 2013

The Dark Mod

Having seen the announcement The Dark Mod version 2.0 is completely standalone and was inspired by the Thief series of games which I enjoyed playing (and I am looking forward to the new one that is coming out soon), I decided to give it a try.

There were a few issues to getting it up and running.

Following the instructions I downloaded the updater and set it running, which downloaded all the needed files. However, when I tried to run it, it kept crashing out.
I had hoped this was just due to it being a 32bit binary and I was running it on 64bit. I installed additional 32bit libraries (and their dependencies) that were missing libboost-filesystem, DevIL, mesa-dri-drivers.

This got me a little further, I got a blank screen and could hear music and sound effects. When looking at a copy of the startup messages (passed to tee and dumped to a file), I saw messages relating to not being able to load various font and image files (including ones related to the menu), hence the black screen. I double checked that there were no addition files by re-running the updater, everything was downloaded.
Checking the startup messages and checking the forum, quickly lead me to this page which appeared to have exactly the same symptoms and was suggesting that this was related to S3TC (S3 Texture Compression) support.
There was a suggestion that disabling this in the config might work, however this did not work for me.
Was I missing the 32bit library that contained this support? I was, however as I was testing this on Fedora, Fedora does not ship this particular library as it is patented by S3. I could have gone and downloaded this from a 3rd party repo, but I am not happy at installing lots of extra packages from random locations.
Luckily I came across another solution when using mesa drivers >  version 9 and this is to set the following variable before launching thedarkmod
force_s3tc_enable=true
This worked fine and allowed me to launch the game and start playing through the training mission.


Tuesday, 23 July 2013

libc version

While looking at different ways to find out what version of libc is installed on a system (especially useful on a system that is compiled from source such as LFS), I discovered that you can actually run libc and it will print out useful version info.

For example

# /lib/libc.so.6
GNU C Library (GNU libc) stable release version 2.17, by Roland McGrath et al.
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.7.2.
Compiled on a Linux 3.8.1 system on 2013-07-18.
Available extensions:
    crypt add-on version 2.1 by Michael Glad and others
    GNU Libidn by Simon Josefsson
    Native POSIX Threads Library by Ulrich Drepper et al
    BIND-8.2.3-T5B
libc ABIs: UNIQUE IFUNC
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.


Wednesday, 3 July 2013

sysinfo()

I was reminded in an article about sysinfo() on Linux, also gave me a change to remind myself of some basic C programming principles, e.g. bitwise shifts.

#include <stdio.h>
#include <sys/sysinfo.h>


int main() {
   struct sysinfo info;
   float todivideby = 0.00;
   sysinfo(&info);
   printf("Uptime (s) = %ld\n",info.uptime);
   printf("SI_LOAD_SHIFT = %d\n", SI_LOAD_SHIFT);
   todivideby = 1<<SI_LOAD_SHIFT;
   //printf("divide by: %.2f\n", todivideby);
   printf("Load Averages %.2f,%.2f,%.2f\n",info.loads[0]/todivideby, info.loads[1]/todivideby, info.loads[2]/todivideby);
   printf("Totalram = %ld memory units\n",info.totalram);
   printf("Freeram = %ld memory units\n",info.freeram);
   printf("Memory used = %ld memory units\n", info.totalram - info.freeram);
   printf("Sharedram = %ld memory units\n",info.sharedram);
   printf("bufferram = %ld memory units\n",info.bufferram);
   printf("totalswap = %ld memory units\n",info.totalswap);
   printf("freeswap = %ld memory units\n",info.freeswap);
   printf("totalhigh = %ld memory units\n",info.totalhigh);
   printf("freehigh = %ld memory units\n",info.freehigh);
   printf("Memory unit = %d bytes\n", info.mem_unit);
   printf("Number of procs = %d\n", info.procs);
   return 0;
}