This page describes how labels are generated and displayed on top of webcam images on the UCC web site.
How it works
There are two programs at work here.
A zsh script make-labels.zsh by [TRS] that queries each relevant machine to discover who is logged in and generates labels for each.
A cgi script label.c by [RVS] that takes existing webcam images and draws the labels generated previously on top of them.
make-labels.zsh
TODO: describe make-labels.zsh
label.c
This program reads a configuration file to determine which labels it should check for and where to display them, then constructs a composite image from the webcam and labels generated earlier by make-labels.zsh. The source is available here. The binaries of this file reside in /home/other/webcam/public-html/cgi-bin/.
label.c determines which webcam to read from based on the name of its executable, so for each webcam there is a hard link in this directory eg webcam1.cgi and uvc1.cgi. After determining its name, the whole program is protected from concurrent execution by a named semaphore /dev/shm/sem.$WEBCAM where $WEBCAM is the webcam name.
label.c determines which labels to draw and where to draw them based on information in a configuration file named $WEBCAM.autolabel in /home/other/webcam/, eg webcam1.autolabel. The format of this file is machine-name x y, each line describes a machine and where to draw the label. For example, webcam1 currently has the following in webcam1.autolabel:
combtail 145 104 cephalopod 173 85 cichlid 33 153 canevas 75 130 chanopsis 108 110 humpback 297 159 sidderrog 295 193 persephone 293 221 curdane 290 267
Most of the time, label.c does not generate a new image and simply retransmits the previously generated image. Any of the following conditions will cause it to generate a new image.
- There is no previously generated image or it was unlinked.
- The previously generated image has an older time-stamp than the configuration file.
The previously generated image has an older time-stamp than /home/other/webcam/public-html/cgi-bin/machines/, the directory that contains labels generated by make-labels.zsh.
If an update is necessary, label.c invokes imagemagick programs convert or composite for each label it finds and builds up a composite image stored in /home/other/webcam/cgi-bin/out/ which it finally transmits.
Potential problems and how to fix them
Nobody is logged to a Windows machine but the label is still being drawn
musundo might still think that a user is logged in to that machine, it will go away eventually. To confirm this run
smbstat -b
on musundo, if the user is listed as being logged in then just wait a little while or kill the session and the label will soon disappear.
Alternatively this may be the problem described below.
The wrong user or no user is being drawn for a Linux machine
make-labels.zsh only checks for users logged in to tty7 on Linux machines, if a user has a console session or an X11 session on another tty then make-labels.zsh will not generate a label for that user. Try running
finger @some-linux-machine
to confirm this is the case.
Labels are not being updated
If musundo is on and the network is not broken, this probably indicates a problem with make-labels.zsh. Try running
/home/other/webcam/make-labels.zsh
on musundo and see if any errors indicate the cause of the problem.
Labels are in the wrong place
Modify $WEBCAM.autolabel according to the section label.c above to correct the position of the label.
CGI script times out or produces empty output
This usually means that the semaphore protecting the generation of an image from concurrent requests did not receive a sem_post when it should have. You can fix this by unlinking the named semaphore which will cause it to be recreated next time the CGI script is invoked. On mussel, named semaphores reside in /dev/shm/. The CGI script creates a semaphore with the name of the webcam it is consuming images from, so webcam.cgi's semaphore will be /dev/shm/sem.webcam.
Eg: If webcam1.cgi is timing out, then on mussel run
rm /dev/shm/sem.webcam1
Adding a machine
To add a machine you must:
- Get make-labels.zsh to generate labels for your machine.
- If you are adding a Windows machine on UCCDOMAIN then make-labels.zsh requires no modification.
A linux console machine must be added to the loop near # Linux console machines
A linux thin terminal connecting to meersau must be added to the loop near # Linux thin terminals
An Open-Solaris machine must be added to the loop near # Opensolaris machines
- Contact [TRS] if you want labels generated for a Mac OSX machine.
- Tell the CGI script where to draw the labels.
Modify one or more of the $WEBCAM.autolabel files in /home/other/webcam/ and add your machine to the list as described above in the label.c section.
Adding a webcam
Assuming you have followed the naming conventions of previous webcams, adding another webcam is simply a matter of adding a hard-link in /home/other/webcam/public-html/cgi-bin/ and a configuration file in /home/other/webcam/, and then directing the webcam page towards the CGI script. Eg, to add a webcam called pretty-cool-webcam, run
cd /home/other/webcam/public-html/cgi-bin/ ln webcam.cgi pretty-cool-webcam.cgi vim ../../pretty-cool-webcam.autolabel # Add entries here as described in the label.c section above
Potential Improvements
- Don't fork for each label, use imagemagick's API to produce the images, or some other API.
- Change make-labels.zsh to only produce text files describing the log-in state of each machine and generate the labels in the CGI script.
- Display more information alongside users who are logged in such as which groups they are in (door, coke etc).
- This is currently done in a limited fashion for wheel members who's labels are generated with a larger font size.
- Perhaps don't generate images on demand but rather at regular intervals.
- Perhaps scrap generating a composite image entirely and simply display the labels on top of the image on the webcam site.