Not able to lock the port


 
Thread Tools Search this Thread
Operating Systems Solaris Not able to lock the port
# 1  
Old 02-10-2009
Not able to lock the port

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

Last edited by smartgupta; 02-10-2009 at 09:19 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash script, find the next closed (not in use) port from some port range.

hi, i would like to create a bash script that check which port in my Linux server are closed (not in use) from a specific range, port range (3000-3010). the print output need to be only 1 port, and it will be nice if the output will be saved as a variable or in same file. my code is: ... (2 Replies)
Discussion started by: yossi
2 Replies

2. Solaris

How to find port number wwn of particular port on dual port HBA,?

please find the below o/p for your reference bash-3.00# fcinfo hba-port HBA Port WWN: 21000024ff295a34 OS Device Name: /dev/cfg/c2 Manufacturer: QLogic Corp. Model: 375-3356-02 Firmware Version: 05.03.02 FCode/BIOS Version: BIOS: 2.02; fcode: 2.01;... (3 Replies)
Discussion started by: sb200
3 Replies

3. Solaris

Cabling and adapters to communicate to service processor serial port from Windows PC with USB port.

Hello, I have an unloaded T5140 machine and want to access the ILOM for the first time and subsequently the network port after that., and then load Solaris 10 the final January 2011 build. The first part is what confuses me -the cabling. I am coming from a Windows machine (w/appropriate... (5 Replies)
Discussion started by: joboy
5 Replies

4. IP Networking

Tcp ip port open but no such process (merged: Release A Port)

i want to kill a tcp connection by killing its pid with netstat -an i got the tcp ip connection on port 5914 but when i type ps -a or ps-e there is not such process running on port 5914 is it possible that because i do not log on with proper user account i can not see that process running? (30 Replies)
Discussion started by: alinamadchian
30 Replies

5. UNIX for Advanced & Expert Users

Testing privileges -lock lockfile /var/lock/subsys/..- Permission denied

Hi all, I have to test some user priviliges. The goal is to be sure that an unauthorized user can't restart some modules (ssh, mysql etc...). I'm trying to automate it with a shell script but in same cases I got the syslog broadcast message. Is there any way to simply get a return code... (3 Replies)
Discussion started by: Dedalus
3 Replies

6. Solaris

How to enable Serial port on ILOM, when Network Port is enabled in parallel

Hi Everyone, In my environment, I have few T5220. On the iLOM Management Card, I have both Network and Serial port are cabled, I don't have any issues while I try to connect using Network Management port, but when I try to connect the serial port for the same server which is actually connected... (3 Replies)
Discussion started by: bobby320
3 Replies

7. Red Hat

Security Question: Lock after invalid login, Session Lock and Required Minimum Password Length

Hello all, If anyone has time, I have a few questions: How do I do the following in Linux. We are using Red Hat and Oracle Enterprise Linux, which is based on Red Hat too. 1. How to lock the account after a few (like 3) invalid password attempts? 2. How do you lock a screen after 30... (1 Reply)
Discussion started by: nstarz
1 Replies

8. UNIX for Dummies Questions & Answers

how to lock keyboard without using lock command

how can I lock my keyboard while I'm away from the computer without using lock command. What other commands gives me the option to lock keyboard device? thanks (7 Replies)
Discussion started by: dianayun
7 Replies

9. Filesystems, Disks and Memory

terminal/port (serial) lock up mystery! SCO 5.0

Sorta new to Unix. great site here. I have SCO server with (5) 16 port Digi-boards and 5 line printers. For 3 years we've had no problems, till now... All of a sudden I get terminals and printers locking up. Killed the PID's for these particular situations. No help. So I disable the tty post... (10 Replies)
Discussion started by: ftn96
10 Replies
Login or Register to Ask a Question