[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Solaris flock/lockf...problems with UCB libs

Posted on 1997-01-20
1
Medium Priority
?
1,713 Views
Last Modified: 2013-12-20
I am porting code from IRIX 5.3 to Solaris 2.4.  The code
compiles and works fine on IRIX, but I have had some problems with flock (and now lockf) on the Solaris system.
The first problem I had was:
(1) I attempted to compile using /usr/ucb/cc the result was:   cc:  language optional software package not installed

In order to avoid this problem I used gcc instead.  I added
"/usr/ucbinclude/" to my include paths, "/usr/ucblib" to my
library paths, and "-lucb -lsocket -lnsl" to my libraries.

(2)I created a simple test program that simply opens a file
and then uses flock() to lock it.  I got everything to
compile, but when I run the executable one of two things
happens:
 (a) If the file I am opening does not exist before program
     execution and is created by the call to open(), i get
     a valid file descriptor, and then pass it to flock.
     flock() returns -1, and sets errno=22 (Invalid
     arguments)--incedentally, i am using LOCK_EX
 (b) If the file exists prior to execution, and is simply
     opened by the call to open, then I get back a valid
     file descriptor, and pass it to flock.  flock() still
     returns -1 and this time sets errno=9 (Bad file number)

(3)So I assumed the problem was with flock(), and attempted
to avoid the UCB libraries all together by switching all
file locking to use lockf().  Now my test program fails on
the call to lockf(), except this time I have errno=11 which
is "Resource temporarily unavailable".

It seems as if open() and flock() are referencing different
file descriptor tables.  I think the problem has to do with
linking, and may be related to the fact that I am using gcc
instead of /usr/ucb/cc.  Other information that may be
relevant is that the file it is attempting to open/lock is
on an NFS mounted drive (although I can't see this having
any effect on the file locking).  If somebody knows the
solution to my problem I would greatly appreciate it.

Thanks,
Barry M. Caceres
barryc@alumni.caltech.edu
0
Comment
Question by:barryc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
ian010997 earned 400 total points
ID: 1292364
You seem to be from cal-tech, but why are you still using /usr/ucb (UC Berkely...spelling??)?

Use POSIX.1 for all your Unix file manipulations if at all possible.  flock(3) is a POSIX.1 function and should be all you will need.

If you do a:

#define _POSIX_SOURCE 1

in your C programs (function libraries) that need POSIX.1, you should be in the clear if your compiler supports POSIX.1 which most do, but I doubt /usr/ucb/cc does.

I have had MAJOR problems using ``ucb'' on Sun machines before.  The best bet I have gone with is using POSIX.1 functions.

There is a VERY good book published on POSIX.1:

The POSIX Programmer's Guied by Donald Lewine published by O'Reilly & Assoc.

You shouldn't have any more problems porting from IRIX to POSIX.1 (since POSIX.1 is mostly SysVR4 which is mostly IRIX) if you use the define I gave you and use the functions in the book above with the standard compiler on a Sun.

What's more, since IRIX and Solaris are both SysVR4, you shouldn't use the ``ucb'' libs, compilers, etc. anyway.  ``ucb'' is BSD Unix not SysVR4.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question