text

Project work scheduled

Things get messy at times, and this is definitly the case ––– the list of projects to start/push-forward/finish before I finish my studies is really not that short...

  • Dive into saa716x Linux kernel Driver - if it is not worth the effort sell the TV card.
  • Complete my SDA/Nav Simulation and implement it on STM32F4 Discovery board hanging around.

text

Gtk+ 3.x ProTip™ #1

Roaring uninformative errors appear (and eat your time) if you forget to call gtk_init (&argc, &argv) before doing anything GtkWidget related.

(process:5751): Gtk-CRITICAL **: _gtk_style_cascade_get_for_screen: assertion 'GDK_IS_SCREEN (screen)' failed

(process:5751): Gtk-CRITICAL **: _gtk_style_provider_private_lookup: assertion 'GTK_IS_STYLE_PROVIDER_PRIVATE (provider)' failed

(process:5751): Gtk-CRITICAL **: _gtk_css_lookup_resolve: assertion 'GTK_IS_STYLE_PROVIDER_PRIVATE (provider)' failed

(process:5751): Gtk-CRITICAL **: _gtk_css_rgba_value_get_rgba: assertion 'rgba->class == &GTK_CSS_VALUE_RGBA' failed

(process:5751): Gtk-CRITICAL **: _gtk_style_provider_private_lookup: assertion 'GTK_IS_STYLE_PROVIDER_PRIVATE (provider)' failed

(process:5751): Gtk-CRITICAL **: _gtk_css_lookup_resolve: assertion 'GTK_IS_STYLE_PROVIDER_PRIVATE (provider)' failed

(process:5751): Gtk-CRITICAL **: _gtk_css_rgba_value_get_rgba: assertion 'rgba->class == &GTK_CSS_VALUE_RGBA' failed

(process:5751): Gtk-CRITICAL **: _gtk_css_rgba_value_get_rgba: assertion 'rgba->class == &GTK_CSS_VALUE_RGBA' failed

(process:5751): Gtk-CRITICAL **: _gtk_css_rgba_value_get_rgba: assertion 'rgba->class == &GTK_CSS_VALUE_RGBA' failed

(process:5751): Gtk-CRITICAL **: _gtk_style_provider_private_lookup: assertion 'GTK_IS_STYLE_PROVIDER_PRIVATE (provider)' failed

(process:5751): Gtk-CRITICAL **: _gtk_css_lookup_resolve: assertion 'GTK_IS_STYLE_PROVIDER_PRIVATE (provider)' failed

(process:5751): Gtk-CRITICAL **: _gtk_css_rgba_value_get_rgba: assertion 'rgba->class == &GTK_CSS_VALUE_RGBA' failed

snip

(process:5751): Gtk-CRITICAL **: _gtk_css_lookup_resolve: assertion 'GTK_IS_STYLE_PROVIDER_PRIVATE (provider)' failed

(process:5751): Gtk-CRITICAL **: _gtk_style_provider_private_lookup: assertion 'GTK_IS_STYLE_PROVIDER_PRIVATE (provider)' failed

(process:5751): Gtk-CRITICAL **: _gtk_css_lookup_resolve: assertion 'GTK_IS_STYLE_PROVIDER_PRIVATE (provider)' failed

(process:5751): Gtk-CRITICAL **: _gtk_css_array_value_get_n_values: assertion 'value != NULL' failed
Segmentation fault (core dumped)

For the sake of completeness:

# pkg-config --modversion gtk+-3.0
3.10.7

text

C daemons for Linux

Just recently I had to write a daemon as part of my studentjob for a embedded Linux system – and there are quite a few pitfalls around which could influence your daemons security.

The classy structure of a daemon is:

  1. make the thing exclusive this is usually achieved by either

    1. write pid to file if not exists, chicken out if exists (oldschool)
    2. register to dbus with a application specific name (how it should be done nowadays and in the forseable future)
  2. read config files

  3. drop privileges (and make sure they may not be regained, setgid(),setuid() - always in that order!)

  4. reparent to process 1

    1. use daemon() function if availiable at your platform (part of <unistd.h>)
    2. if not:
      1. close all file descriptors (including stdio, stderr, stdin as well as explicitly opened ones)
      2. fork(), exit() the parent
      3. to run the child in a new session, use setsid()
      4. prevent keeping some directory busy, preventing potential umounts chdir("/")
      5. fix unknown umaks umask(0)
      6. fork(), exit() the parent
  5. rebind 0,1,2 file descriptors to your logfiles, /dev/null or /dev/console as needed
  6. drop privileges

Sources:

http://web.archive.org/web/20120428044610/
http://www.steve.org.uk/Reference/Unix/faq_2.html#SEC16
http://www.netzmafia.de/skripten/unix/linux-daemon-howto.html
http://www.thegeekstuff.com/2012/02/c-daemon-process/
http://swoolley.org/man.cgi/3/daemon

http://etutorials.org/Programming/secure+programming/Chapter+1.+Safe+Initialization/1.3+Dropping+Privileges+in+setuid+Programs/
http://stackoverflow.com/questions/3357737/dropping-root-privileges

text

dvb and mplayer

I currently use a rusty old TV card (only PAL alias DVB-S, no DVB-S2), but it works very well.

lspci reports it as a Conexant based card, everything else is pointless to say, sometimes manufacturers change the chips even within a revision without further notice.

05:01.0 Multimedia video controller: Conexant Systems, Inc.
        CX23880/1/2/3 PCI Video and Audio Decoder (rev 05)
05:01.1 Multimedia controller: Conexant Systems, Inc.     
        CX23880/1/2/3 PCI Video and Audio Decoder [Audio Port] (rev 05)
05:01.2 Multimedia controller: Conexant Systems, Inc. 
        CX23880/1/2/3 PCI Video and Audio Decoder [MPEG Port] (rev 05)
05:01.4 Multimedia controller: Conexant Systems, Inc.
        CX23880/1/2/3 PCI Video and Audio Decoder [IR Port] (rev 05)

For playback with mplayer I recommend

mplayer dvb://"Das Erste" -vo vdpau:deint=4 -cache 2048

which works very well with a NVidia GTX 460, with weaker NVidia cards you may have to lower from deint=4 to something less demanding, see this mplayer manpage extract for details:

 deint=<0-4>
       Select the deinterlacer (default: 0).  All modes > 0 re-
       spect -field-dominance.
             0    no deinterlacing
             1    Show only first field, similar to -vf field.
             2    Bob deinterlacing, similar to -vf tfields=1.
             3    motion adaptive temporal deinterlacing May  lead
                  to  A/V  desync  with slow video hardware and/or
                  high resolution.  This is the default if "D"  is
                  used to enable deinterlacing.
             4    motion   adaptive  temporal  deinterlacing  with
                  edge-guided  spatial  interpolation  Needs  fast
                  video hardware.

excerpt of my ~/.mplayer/channels.conf

Das Erste:11836:h:0:27500:101:102:28106
ZDF:11953:h:0:27500:110:120:28006
Bayerisches FS Nord:11836:h:0:27500:201:202:28110
RTL FS:12187:h:0:27500:163:104:12006
SAT.1 Bayern:12544:h:0:22000:255:256:17507
ProSieben:12544:h:0:22000:511:512:17501
RTL2:12187:h:0:27500:166:128:12020
kabel eins:12544:h:0:22000:767:768:17502
VOX:12187:h:0:27500:167:136:12060
SWR Fernsehen BW:11836:h:0:27500:801:802:28113
ORF1:12692:h:0:22000:160:161:13001
ORF2:12692:h:0:22000:500:501:13002
SIXX:12460:h:0:27500:767:768:776
RTL 1440:12343:h:0:27500:0:105:2052
Bayerisches FS Süd:11836:h:0:27500:201:202:28107
hr-fernsehen:11836:h:0:27500:301:302:28108
EUROSPORT:12402:v:0:27500:1110:1121:8711
ARTE:12402:v:0:27500:1210:1221:8712

text

Schedulers Simplified

In the lecture and exercises scheduling methods were explained breifly and .. well just too complicated to be easily graspable. These are very rough, without task switching costs, without interdependencies of tasks, without limited resources access constraints. Purely introductional

Round Robin

As soon as process has used up its cpu time slice, enqueue self if not finished If new process appears, enqueue

Priority

Priority queue determines next process, new processes are inserted into priority queue and if they get to be the first item, they take over the cpu

Deadline

Use the deadline time value as priority - in other words, the task that has to finish first will be processed first.

text

Birthday Problem

The classy birthy collision problem (matlab/octave)

function [p] = birthday_collision(n)
% calculate the likelyness of n persons
% having at least one (or more) birthday
% collisions (2 birthdays at one day at least)
n = 5;
q = 1;
for j=1:n,
    q = q * (365-n+1)/365;
end;
p = 1 - q;

text

QTimer wants to live in a QThread

QTimer wants to live in a QThread – yes – and it fails at runtime if it is running within a GThread though it contains a QMainLoop - wierd stuff.

My personal suggestion, avoid QtCore where possible, if not possible, use it for everything.