ndomod fails on HP-UX (with patch)

Masse.Olivier at hydro.qc.ca Masse.Olivier at hydro.qc.ca
Fri Jun 13 21:16:28 CEST 2008


I was having a hard time making ndomod.o load on HP-UX (I know, I know). Here is a patch for ndomod.c.

It turns out that a library must be execuable to be dlopen'ed, or else mmap fails with an EACCES. ndomod.o is executable, but not the temporary file it's copied to. There's no option to mkstemp to make an executable, temporary file. So I chmod it to make it executable before running dlopen.

Furthermore, on HP-UX, it seems that you can't unlink() a library which is in use, you get ETXTBSY. So the clever unlink trick, which works on Linux, fails. The best thing I found was to chmod 000 the file to prevent anyone from accidentally writing to it, and cleaning up the temporary directory from the nagios startup script. It could probably be cleaned up when unloading the module but I didn't bother. If anybody has a better idea or implementation of this, I'll be glad to compile it and try it out.

Note: I'm a sysadmin, not a developper. So that basically makes me a stupid developper. These workarounds worked for me but don't bash me if they're not done right. Do whatever you want with it. 

Thanks


*** nebmods.c   Sat Feb 23 16:12:11 2008
--- nebmods.c.hpux      Fri Jun 13 15:00:05 2008
***************
*** 204,209 ****
--- 204,218 ----
                logit(NSLOG_RUNTIME_ERROR,FALSE,"Error: Could not safely copy module '%s'.  The module will not be loaded: %s\n",mod->filename,strerror(errno));
                return ERROR;
                }
+ #ifdef _HPUX_SOURCE
+       /* HP-UX's mmap(), called from dlopen, requires the shared library to be executable, else if fails with EACCESS */
+       /* A workaround is making it executable first hand. */
+       if (chmod(output_file,S_IRUSR|S_IWUSR|S_IXUSR) == -1)
+       {
+               logit(NSLOG_RUNTIME_ERROR,FALSE,"Error: Could not safely make copy of module '%s' executable: %s\n",mod->filename,strerror(errno));
+               return ERROR;
+       }
+ #endif
        /* open module file for reading and copy it */
        if((source_fd=open(mod->filename,O_RDONLY,0644))>0){
                while((bytes_read=read(source_fd,buffer,sizeof(buffer)))>0)
***************
*** 240,245 ****
--- 249,263 ----
        /* this will prevent other processes from overwriting the file (using the same inode), which would cause Nagios to crash */
        /* the kernel will keep the deleted file in memory until we unload it */
        /* NOTE: This *should* be portable to most Unices, but I've only tested it on Linux */
+ #ifdef _HPUX_SOURCE
+       /* On HP-UX, we can't unlink a shared library which is in use. The best we can do is chmod 000 it, */
+       /* hoping that no bonehead will ever try overwriting the contents. The temporary directory must be */
+       /* purged from the nagios startup script, which is a major drawback */
+       if (chmod(output_file,0) == -1) {
+               logit(NSLOG_RUNTIME_ERROR,FALSE,"Error: Could not safely make copy of module '%s' unmodifiable: %s\n",mod->filename,strerror(errno));
+               return ERROR;
+               }
+ #else
        if(unlink(output_file)==-1){
                logit(NSLOG_RUNTIME_ERROR,FALSE,"Error: Could not delete temporary file '%s' used for module '%s'.  The module will be unloaded: %s\n",output_file,mod->filename,strerror(errno));
                neb_unload_module(mod,NEBMODULE_FORCE_UNLOAD,NEBMODULE_ERROR_API_VERSION);
***************
*** 246,251 ****
--- 264,270 ----

                return ERROR;
                }
+ #endif

        /* find module API version */
  #ifdef USE_LTDL

 
--
Olivier Massé
Concepteur exploitation et support
Projets d'automatisation et informatique, Hydro-Québec Distribution
(450)441-7200 ext. 7053 Masse.Olivier at hydro.qc.ca

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php




More information about the Developers mailing list