Hi,
I am working with Sun-Solaris 9 and in our application I need to connect the UPS with Serial port,after that I need to monitor it..but before stating communication,It should lock that port,To check it,first i am trying to make sure the lock directory exists and I am able to find it(/var/lock) but not able to lock the port and getting the error message from there---
LOCKDIR=/var/lock in PosixDevLock.c at 53
LOCKDIR=/var/lock in PosixDevLock.c at 57
Error message in PosixDevLock.c at 58
lckStatus value==>2
I am trying to lock the port using the function lock from other file and getting the value in lckStatus variable.
Quote:
int ChkPortIO (const char* portName)
{
printf(" \n Inside ChkPortIO at 82 ...........");
printf("\n 1..JNI_OK value==>%d",JNI_OK);
struct termio pmode; /* modem device attributes */
int portID; /* modem port file descriptor */
int lckStatus;
lckStatus = lock(portName);
if (lckStatus)
{
printf("\n lckStatus value==>%d",lckStatus);
return(lckStatus);
}
/* Open what is hopefully a real serial port. We use readonly access here
// just in case it is something else like a file.
*/
portID = open(portName, O_RDONLY | O_NDELAY | O_NOCTTY);
printf("\n Just before portID value==>%d",portID);
if (portID < 0)
{
printf("\n Inside PortID error no ==>%d",errno);
ulock(portName);
return (errno);
}
this lock function try to lock the port but during this i am not able to lock the port --
Quote:
int lock(const char *line)
{
#ifdef POSIX_DEV_LOCK
int mypid, rempid, i;
int rc = -1;
char tmpname[MAXPATHLEN], lckname[MAXPATHLEN], prodName[MAXPATHLEN];
char *p;
FILE *f;
/* First of all, make sure the lock directory exists. */
#ifdef AIX
if (mkdir(LOCKDIR, S_IWUSR) != 0)
#else
printf("\n LOCKDIR=%s in PosixDevLock.c at 53",LOCKDIR);
if (mkdir(LOCKDIR, S_IWUSR) != 0)
#else
printf("\n LOCKDIR=%s in PosixDevLock.c at 53",LOCKDIR);
if (mkdir(LOCKDIR) != 0)
#endif
{
printf("\n LOCKDIR=%s in PosixDevLock.c at 57",LOCKDIR);
if (errno != EEXIST)
{
printf("\n Error message in PosixDevLock.c at 58 \n");
return(errno);
}
}
/* Get only the text after the last '/'. */
p = strrchr(line, '/');
if (p == NULL)
{
p = (char*)line;
}
else
{
p++;
printf("\n value of p in 71 => %d",p);
}
/* Create a temporary lock file. */
mypid = getpid();
sprintf(tmpname, "%s%d", LCKTMP, mypid);
printf("\n mypid at 78==>> %d",mypid);
printf("\n tmpname at 79==> %s",tmpname);
f = fopen(tmpname, "w");
if (f == NULL)
{
return(errno);
}
It should not go to the if statement(if (mkdir(LOCKDIR) != 0))but it is and returns the error no.-2 means(no such file or directory )...
Quote:
Inside ChkPortIO at 82 ...........
1..JNI_OK value==>0
LOCKDIR=/var/lock in PosixDevLock.c at 53
LOCKDIR=/var/lock in PosixDevLock.c at 57
Error message in PosixDevLock.c at 58
lckStatus value==>2
Please help me to resolve it...
Thanks in advance