Groups > Novell > Novell Libc > Re: Multiple NLM Instances




Multiple NLM Instances

Multiple NLM Instances
Tue, 28 Aug 2007 19:36:14 GMT
How can I find out how many instances of an NLM is presently loaded?  I
added the MULTIPLE flag to my .def (definition) file so it can be loaded
more than once.  When the NLM loads it needs to find out how many
instances of itself are currently loaded.

Thanks,
-Carey

Post Reply
Re: Multiple NLM Instances
Wed, 29 Aug 2007 08:42:03 GMT
carey wrote:
> How can I find out how many instances of an NLM is presently loaded?  I
> added the MULTIPLE flag to my .def (definition) file so it can be loaded
> more than once.  When the NLM loads it needs to find out how many
> instances of itself are currently loaded.

You can find names of all loaded NLMs and compare then to the name of your 
NLM. The program below does this with SSGetNLMLoadedList() and 
SSGetNLMInfo(). You may need to alter OUR_NAME constant in it before 
compiling it:

#include <nit\nwservst.h>
#include <nwerrno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define OUR_NAME "IS1ST.NLM"

union NLMList {
   BYTE buffer[ SS_DEFAULT_BUFFER_SIZE];
   struct GetNLMLoadedListStructure s;
};
union NLMInfo {
   BYTE buffer[ SS_DEFAULT_BUFFER_SIZE];
   struct GetNLMInfoStructure s;
};
int main( void) {
   LONG startNumber = 0;
   union NLMList list;
   size_t number_of_already_loaded_instances = 0;
   LONG ccode;
   if (( ccode = SSGetNLMLoadedList( 0, list.buffer, sizeof( list))) != 
ESUCCESS) {
      printf( "SSGetNLMLoadedList failed, ccode = %u\n", ccode);
      return EXIT_FAILURE;
   }
   do {
      size_t i;
      for ( i = 0; i < list.s.NLMCount; ++i) {
         union NLMInfo info;
         if (( ccode = SSGetNLMInfo(( &( list.s.NLMNumbers))[ i], 
info.buffer, sizeof( info))) != ESUCCESS) {
            printf( "SSGetNLMInfo failed, ccode = %u\n", ccode);
            return EXIT_FAILURE;
         }
         if ( info.s.startOfLStrings == sizeof( OUR_NAME) - 1 &&
            memcmp( &info.s.startOfLStrings + 1, OUR_NAME, sizeof( 
OUR_NAME) - 1) == 0) {
            ++number_of_already_loaded_instances;
         }
      }
      startNumber = ( &( list.s.NLMNumbers))[ list.s.NLMCount - 1] + 1;
   } while ( SSGetNLMLoadedList( startNumber, list.buffer, sizeof( list)) == 
ESUCCESS && list.s.NLMCount != 0);
   printf( "This module has been loaded %u times, press any key to
exit\n", 
number_of_already_loaded_instances);
   getch();
   return EXIT_SUCCESS;
}

Post Reply
Re: Multiple NLM Instances
Wed, 29 Aug 2007 14:20:11 GMT
Dmitry Mityugov wrote:

> carey wrote:
> > How can I find out how many instances of an NLM is presently loaded? 
I
> > added the MULTIPLE flag to my .def (definition) file so it can be
loaded
> > more than once.  When the NLM loads it needs to find out how many
> > instances of itself are currently loaded.

> You can find names of all loaded NLMs and compare then to the name of your

> NLM. The program below does this with SSGetNLMLoadedList() and 
> SSGetNLMInfo(). You may need to alter OUR_NAME constant in it before 
> compiling it:

> #include <nitnwservst.h>
> #include <nwerrno.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>

> #define OUR_NAME "IS1ST.NLM"

> union NLMList {
>    BYTE buffer[ SS_DEFAULT_BUFFER_SIZE];
>    struct GetNLMLoadedListStructure s;
> };
> union NLMInfo {
>    BYTE buffer[ SS_DEFAULT_BUFFER_SIZE];
>    struct GetNLMInfoStructure s;
> };
> int main( void) {
>    LONG startNumber = 0;
>    union NLMList list;
>    size_t number_of_already_loaded_instances = 0;
>    LONG ccode;
>    if (( ccode = SSGetNLMLoadedList( 0, list.buffer, sizeof( list))) != 
> ESUCCESS) {
>       printf( "SSGetNLMLoadedList failed, ccode = %un", ccode);
>       return EXIT_FAILURE;
>    }
>    do {
>       size_t i;
>       for ( i = 0; i < list.s.NLMCount; ++i) {
>          union NLMInfo info;
>          if (( ccode = SSGetNLMInfo(( &( list.s.NLMNumbers))[ i], 
> info.buffer, sizeof( info))) != ESUCCESS) {
>             printf( "SSGetNLMInfo failed, ccode = %un", ccode);
>             return EXIT_FAILURE;
>          }
>          if ( info.s.startOfLStrings == sizeof( OUR_NAME) - 1 &&
>             memcmp( &info.s.startOfLStrings + 1, OUR_NAME, sizeof( 
> OUR_NAME) - 1) == 0) {
>             ++number_of_already_loaded_instances;
>          }
>       }
>       startNumber = ( &( list.s.NLMNumbers))[ list.s.NLMCount - 1] +
1;
>    } while ( SSGetNLMLoadedList( startNumber, list.buffer, sizeof( list))
== 
> ESUCCESS && list.s.NLMCount != 0);
>    printf( "This module has been loaded %u times, press any key to
exitn", 
> number_of_already_loaded_instances);
>    getch();
>    return EXIT_SUCCESS;
> }


Thanks for the reply.  But the SSGetNLMLoadedList() API is CLIB based.  My
NLM is LIBC.  My understanding is that it is not recommended to combine
CLIB and LIBC API's.  Is there a LIBC method that can be employed instead?


Post Reply
Re: Multiple NLM Instances
Wed, 29 Aug 2007 14:37:33 GMT
carey wrote:
...
> Thanks for the reply.  But the SSGetNLMLoadedList() API is CLIB based.  My
> NLM is LIBC.  My understanding is that it is not recommended to combine
> CLIB and LIBC API's.  Is there a LIBC method that can be employed instead?

Oh, this is a LibC forum indeed, sorry.

It seems that you can convert NLM handles to corresponding names with 
uname2(), but I can't figure out how to enumerate NLM handles. If I find 
something, I'll post it here.

With best wishes

Dmitry

Post Reply
Re: Multiple NLM Instances
Wed, 29 Aug 2007 14:52:14 GMT
Dmitry Mityugov wrote:

> carey wrote:
> ....
> > Thanks for the reply.  But the SSGetNLMLoadedList() API is CLIB based.
 My
> > NLM is LIBC.  My understanding is that it is not recommended to
combine
> > CLIB and LIBC API's.  Is there a LIBC method that can be employed
instead?

> Oh, this is a LibC forum indeed, sorry.

> It seems that you can convert NLM handles to corresponding names with 
> uname2(), but I can't figure out how to enumerate NLM handles. If I find 
> something, I'll post it here.

> With best wishes

> Dmitry

I kind of get the feeling that there is no easy way to accomplish my goal.

Post Reply
<< Previous 1 2 Next >>
( Page 1 of 2 )
about | contact