Small problem with my sysV setup of semaphore and I have made the following changes to overcome these. This was only evident on powerup:
Changed the resources rouine to:
Code:
static void getResourceLock(void)
{
union semun {
int val;
struct semid_ds *buf;
ushort *array;
} arg;
syslog(LOG_INFO, "getting mutex");
// Get semaphore
mutexId = semget(mutex, 1, IPC_CREAT|0666);
// Check if got, failed then must still be valid so get it
if (mutexId == 0) {
syslog(LOG_INFO, "Failed mutex create");
// Release the mutex
if (semctl(mutexId, 0, IPC_RMID, arg) != -1) {
mutexId = semget(mutex, 1, IPC_CREAT|0666);
}
}
if (mutexId > 0) {
syslog(LOG_INFO, "exisitng mutex Id %d", mutexId);
// Initialise semaphore to 0
arg.val = 1;
semctl(mutexId, 0, SETVAL, arg);
syslog(LOG_INFO, "mutex up");
}
and changed the -s keyword code to:
Code:
case 's':
argc--;
argv++;
// Grab the mutex, -1 will indicate no server
mutexId = semget(mutex, 1, 0);
printf("got mutex %d\n", mutexId);
if (mutexId > 0) {
// Allocate device
open_serial();
// Get command length
iLen = strlen(*argv)/2;
// Get the HEX command
ulMessage = strtoul(*argv, NULL, 16);
// Byte swap please
swab(&ulMessage, &ulMessage, iLen);
// Push it out and return result
printf("%d\n", writeUART(iLen, (unsigned char*)&ulMessage));
}
// Indicate an error
else
printf("-999\n");
exit(0);
break;