Click to See Complete Forum and Search --> : RE: C problem ....pls help!! Thanks


pathfinder
09-14-2001, 01:46 AM
hi,
I have written a CGI script to allow me to input values to outb(v,0x378) to my printer ports to do a simple control of LED by lighting up the respective lights. But after debugging for quite some time, I still can't find the source of my problem. Hope u can help :) thanks


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/io.h>
#include "cgi-util.h"

#define BASEPORT 0x378 /* lp1 */

/* --- MAIN --- */

int main(int argc, char * argv[])
{
int res,v;


/* Initialize the CGI and send out an HTTP header: */

res = cgi_init();

printf("Content-type: text/html\n\n");


/* Was there an error initializing the CGI??? */

if (res != CGIERR_NONE)
{
printf("Error # %d: %s<p>\n", res, cgi_strerror(res));
exit(0);
}


/* Display some text: */

printf("Hello.<p>\n");


/* Grab some fields from an HTML form and display them: */

if (cgi_getentrystr("name") != NULL)
printf("name=%s<p>\n", cgi_getentrystr("name"));

printf("age=%d<p>\n", cgi_getentryint("age"));

if (cgi_getentrystr("sex") != NULL)
printf("sex=%s<p>\n", cgi_getentrystr("sex"));


v = cgi_getentryint("lamp");

printf("lamp=%d is on<p>\n", v);


/* Get access to the ports */
if (ioperm(BASEPORT, 1, 1))
{
perror("ioperm");
exit(1);
}

/* Set the data signals */

outb(v, BASEPORT);

/* We don't need the ports anymore */

if (ioperm(BASEPORT, 1, 0))
{
perror("ioperm");
exit(1);
}


/* Close up the CGI: */

printf("Goodbye!<p>\n");

cgi_quit();

return(0);
}

The Kooman
09-14-2001, 08:07 AM
Originally posted by pathfinder:
<STRONG>hi,
I have written a CGI script to allow me to input values to outb(v,0x378) to my printer ports to do a simple control of LED by lighting up the respective lights. But after debugging for quite some time, I still can't find the source of my problem. Hope u can help :) thanks
</STRONG>

Have you checked on the file permissions? What do the httpd error logs say? I haven't tried to run your program but I'd say you look there first because you canget a lot of info there. Besides, what error do you get (if any)?

pinoy
09-15-2001, 12:37 AM
Are you running this as root? I won't be surprised if you can't get permission to write to it. ioport writes requires root priveleges. You can try using the much discouraged setuid.

pathfinder
09-16-2001, 09:52 PM
hi,

Thanks, it managed to compile, but it can't execute during the cgi stage. I wonder what i can do to make the whole process possible to control the LPT port. This process is run under root id, but it can't too.

Cheers

TheLinuxDuck
09-20-2001, 03:34 PM
If it is a permission issue, you could get around it by writing a second binary that basically acts as the control switch. make sure that the cgi has permission to execute it, then run it with a specific command, on the command line, via a system call, and that should take care of it. That way, the CGI is left doing what it needs to do, which is handling the CGI stuff. (^=