Date: Wed, 27 Oct 1999 14:05:02 +0800 From: Jarvis Cochrane <jarvis@guru.wow.aust.com> To: freebsd-questions@freebsd.org Subject: Problems with open() and flock() on /dev/ttyd1 Message-ID: <381695ED.764A93B@guru.wow.aust.com>
next in thread | raw e-mail | index | archive | help
Hi, I'm installing the SmartUPS monitoring tools from http://www.exploits.org/~rkroll/smartupstools/ on a 3.0-RELEASE Freebsd machine. The UPS is connected to the computer by one of the special APC 'black' cables. After a bit of mucking about I was able to communicate with the UPS using tip, and was able to retreive state information. However, when I ran the ups program, it would complain that the port was locked by another process. It turns out that the serial port is opened by the following code... > upsfd = open (port, O_RDWR | O_NOCTTY | O_NONBLOCK); > alarm (0); > > if (upsfd < 1) { > printf ("Unable to open (1) %s: %s\n", port, strerror(errno)); > exit (1); > } > > upsport = NULL; > > lockport (upsfd, port); "lockport" is as follows: > void lockport (int upsfd, char *port) > { > int res; > char *portname; > > /* keep gcc quiet */ > res = 0; > portname = NULL; > > #ifdef HAVE_UU_LOCK > if (upsport == NULL) { > for (i = strlen (port); i >= 0; i--) > if (port[i] == '/') { > portname = &port[i+1]; > break; > } > > /* save for later in case we need it at shutdown */ > upsport = strdup (portname); > } > > res = uu_lock(portname); > > if (res != 0) { > printf ("Can't lock %s: %s\n", port, uu_lockerr(res)); > exit (1); > } > #else /* no uu_lock */ > #ifdef HAVE_FLOCK > if (flock(upsfd, LOCK_EX | LOCK_NB) != 0) { > printf ("%s is locked by another process\n", port); > exit (1); > } > #endif /* HAVE_FLOCK */ > #endif /* HAVE_UU_LOCK */ > } The call to flock(upsfd, LOCK_EX etc is failing and the process is reporting that it is locked by another process. I haven't been able to find out anything in the man pages for flock() and open() that helps me understand what's going on! Might there be some interaction between the flags used in the open() statement and the those in flock()? Can any of you sio and c gurus help me? Please? TIA Jarvis -- Jarvis Cochrane, IT Support Office of Student Services | jarvis@guru.wow.aust.com Murdoch University | cochrane@central.murdoch.edu.au Western Australia | [61|0] 8 9360 6128 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?381695ED.764A93B>