Ktam3874/pitx software guide – Kontron KTAM3874-pITX User Manual

Page 272

Advertising
background image

KTD-S0057-I

Page 268 Linux® Programming Examples (DebianTM)


KTAM3874/pITX Software Guide


int main (void)
{

int fifo_rd, fifo_wr, value;

pid_t

pid;

static char buff_rd [RD_SIZE];

static char buff_wr [WR_SIZE];

/* Fork off the parent process */

if ((pid = fork ()) < 0)

ERROR;

/* If we got a good PID then we can exit the parent process */

if (pid > 0)

exit

(EXIT_SUCCESS);

/* process becomes session leader, group leader and has no controlling shell */

if (setsid () < 0)

ERROR;

signal (SIGHUP, signal_handler);

signal (SIGTERM, signal_handler);

get_mask

(1);

if (mkfifo (root_rd, S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP | S_IWOTH | S_IROTH) < 0)

{

umask (get_mask (0));

ERROR;

}

if (mkfifo (root_wr, S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP | S_IWOTH | S_IROTH) < 0)

{

unlink

(root_rd);

umask (get_mask (0));

ERROR;

}

oldmask = umask (0);

if ((fifo_rd = open (root_rd, O_RDONLY)) < 0 || (fifo_wr = open (root_wr, O_WRONLY)) < 0)

{

unlink

(root_rd);

unlink

(root_wr);

umask (get_mask (0));

ERROR;

}

while (read (fifo_rd, buff_rd, RD_SIZE) > 0)

{

if (!strncasecmp (buff_rd, CMD_WDIO, CMD_SIZE))

{

if (!parse_wdio (buff_rd))

write

(fifo_wr,

ACK_STR,

ACK_SIZE);

else

write

(fifo_wr,

NAK_STR,

NAK_SIZE);

}

Advertising
This manual is related to the following products: