Re: [gtk-list] Need help in GTK-project
- From: Erik Mouw <J A K Mouw its tudelft nl>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Need help in GTK-project
- Date: Mon, 6 Dec 1999 23:51:06 +0100 (MET)
On Sun, 05 Dec 1999 02:47:26 +0100, Bart Vandewoestyne wrote:
> I'm trying to write a GTK-application to drive a stepper motor using the
> parallel port. I do have a little bit of problems with my program. I'm
> quite new at GTK. People who want to take a look at my program and can
> give me some constructive hints about it can find the program on
> http://hello.to/MC303 -> just follow the link to "Stepper Motor" on the
> left of the screen. I would recommend checking out the buggy version...
> I appreciate feedback on my program, program-style, Makefile, and of
> course on the many bugs that my program still contains... I want to
> learn myself good programming style and will need some expert-feedback
> on this. Getting some feedback from the pro's would be a great help to
> learn about GTK programming I think...
>From motor.c:
* To be able to run as user do as root:
* # chown root ~user/place_to_be/motor
* # chmod ug+s ~user/place_to_be/motor
GTK is _not_ considered safe enough to be useful for root or suid root
programs. Make a small helper application that can safely be suid'ed, it
only has to do the ioperm() and outb() plus it needs some way to
communicate with the main program (which does the user interface).
This is just a security issue; the way you implemented it is not wrong,
but crashing a suid root program is a very well known method to gain root
privileges.
About your coding style: not too bad, I've seen worse (imagine yourself
the picture of a herd of Ph.D. students with peculiar coding practices
trying to program in C). I'd suggest using more header files, so
showmessage.c gets a header file showmessage.h. Oh, and please do use the
anti-double-include-header-file trick (this example is for motor.h):
#ifndef MOTOR_MOTOR_H
#define MOTOR_MOTOR_H
/* asm/io.h is not needed here, but in motor.c, so include it there
* same for unistd.h and stdio.h. gtk.h needs to be included here
*/
#include <gtk/gtk.h>
... rest of motor.h ...
#endif
Oh, "int portstatus" doesn't belong in a header file, but in one of the C
files.
Another thing: avoid namespace pollution. Your project is small enough to
be bitten by it, but you actually should prefix all your functions and
variables (so mot_CreateMenuItem() and MOT_LEFT). Been there and learned
it the hard way.
About your Makefile, try my version which uses implicit rules etc. It's
not as sophisticated as a version that fully supports GNU make, but it
will work with most sane make utilities.
# The main things: compiler, linker, flags
CC=gcc
CFLAGS=-Wall -O2 -g `gtk-config --cflags`
LDFLAGS=-g
LIBS=`gtk-config --libs`
# Sources, object files and target
SRCS=main.c motor.c menu.c misc.c about.c showmessage.c
OBJS=main.o motor.o menu.o misc.o about.o showmessage.o
TARGET=motor
# Implicit rules
.c.o:
$(CC) $(CFLAGS) -c $< -o $@
# Some phony targets (i.e. targets without files)
.PHONY: all clean realclean install
all: $(TARGET)
$(TARGET): $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
clean:
rm -f $(OBJS) $(TARGET)
realclean: clean
rm -f *~
install: $(TARGET)
chown root.mc303 $(TARGET)
chmod ug+s $(TARGET)
HTH,
Erik
--
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031, 2600 GA Delft, The Netherlands
Phone: +31-15-2785859 Fax: +31-15-2781843 Email J.A.K.Mouw@its.tudelft.nl
WWW: http://www-ict.its.tudelft.nl/~erik/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]