Operating System - HP-UX
1748150 Members
3433 Online
108758 Solutions
New Discussion юеВ

shared library in use + possible resolution

 
SOLVED
Go to solution
Peter_316
Advisor

shared library in use + possible resolution

I am not used to the fact that a shared library is in use when a program runs, on linux you can rm or mv a shared library, the executable will keep on running happily, on restart of course it will use the new version (since the old is gone ;-) or not start anymore


I found a solution for this if I create an executable and afterward I say
chatr +dbg enable
I can move, replace the shared libs used by the executable while it is running.

questions
-is this the way to go about it and is it possible to tell aCC of ld directly what I want and avoiding the chatr step ??
-is there a danger involved by using chatr +dbg enable and is it really safe to remove a shared lib afterward ? (won't it be referenced ever again ?)


(I believe on linux it works because you can mv or rm the file, but as long as it is in use the inode stays alive, untill the last reference to the file is dropped)
6 REPLIES 6
ranganath ramachandra
Esteemed Contributor

Re: shared library in use + possible resolution

i dont know exactly why this is so but:

a shared library is supposed to be shared in memory by all processes that simultaneously load it. when you do a chatr +dbg enable, the library is mapped private into the memory of each process that loads it.

btw, 'mv -f' should work on the busy text file too.
 
--
ranga
[i work for hpe]

Accept or Kudo

Peter_316
Advisor

Re: shared library in use + possible resolution

mv -f, rm -f doesn't work
mv: libhello.sl: cannot write: Text file busy

remains the question -> is there an option which I can pass to aCC avoiding the chatr step (because an extra step is error prone, and will be forgotten)

and is it absolutely safe (so is _everything_ mapped in memory)

why ?
whe wrote a shared lib used by lots of deamon processes, which every once in while needs to be updated, but we don't want to restart all the deamons, ..

cheers,

Peter
Ermin Borovac
Honored Contributor

Re: shared library in use + possible resolution

You can try using cpset with -o option. This should move object (shared library) that's in use to OLDobject and install a new one instead.

# /usr/bin/cpset -o new_shared_lib directory_to_install_to

This should rename old shared library to OLD. Running daemons should continue using old shared library until they are restarted.

Peter_316
Advisor

Re: shared library in use + possible resolution

well well cpset !

never heard of it, it has one problem though, I can use it only once, because it will rename the lib to OLDlib, and the second time OLDlib is in use by the daemons, and cpset refuses duty.

BUT it rang a bell, and I found a nice solution (wouldn't have thought of it without cpset though !)

/*just demo proof of concept code, bla, bla*/
#include
#include
#include
#include

int main(int argc,char *argv[])
{
if ( link(argv[1],argv[2] ) )
{
printf("error : copy %s -> %s : %s\n",argv[1],argv[2],strerror(errno) ) ;
}
else
{
if ( unlink(argv[1]) )
{
printf("error : remove %s : %s\n",argv[1],strerror(errno) ) ;
}
}
}


aCC move.c -o move

move

and YES, it works, all the time, ... !

any dangers involved guru's ?


cheers, Peter
Ermin Borovac
Honored Contributor
Solution

Re: shared library in use + possible resolution

Your code is similar to what cpset does (as far as I can see with tusc).

Please note that 'mv -f' will also work, but you have to do it as follows.

# mv -f libhello.sl \#libhello.sl
# cp newlibhello.sl libhello.sl

It won't work if you do it as

# mv -f newlibhello.sl libhello.sl
Peter_316
Advisor

Re: shared library in use + possible resolution

Aha, first move it out of the way,...

why didn't I think of that

great answers guys, thanks,

I need what I want,

greetz,

Peter