Static linked OCS Solaris Client

Client Download

The standard OCS client is available from: http://bfleisch.free.fr/ocs-solaris-client/ (at the moment of writing, the latest version is .11).

Download it and unzip / untar it.

 gunzip -cd $ARCHIVE | tar -xf -

Initial Compile

In order to create the necessary files, run:

./Configure.sh
make

All references to libraries must be met, so prepare to fetch all required packages from http://www.sunfreeware.org/.

Customizations

Solaris’ gcc is quite picky on the C code; so prepare to fix some lazy programmer’s code (no pun intended); all case statements must end with

...
  default:
    break;
...

Another fix I had to do on the original code was (main.c):

4c4
< #include "ocsinv.h"
---
>     if (! ((node = root->children) && (xmlStrcmp(node->name,"OPTION")==0)))
8a9
>         "OPTION");
10d10
< 
13c13
<       fprintf(stdout, "%s: OCS client for Solaris (version %s)\n"
---
>     content = xmlNodeGetContent (node->next);
111c111
<     if (! ((node = root->children) && (xmlStrcmp(node->name,"OPTION")==0)))
---
>     if (! ((node = root->children) && (xmlStrcmp(node->name,"RESPONSE")==0)))
116c116
<         "OPTION");
---
>         "RESPONSE");
120c120
<     content = xmlNodeGetContent (node->next);
---
>     content = xmlNodeGetContent (node);

I am no programmer, hence the !DIRTY! hack ;)

Also in order to prevent the linker from barfing unknown symbol errors, create a file called dlstubs.c

#include <sys/types.h>
#include <dlfcn.h>

/* dl*() stub routines for static compilation.  Prepared from
  /usr/include/dlfcn.h by Hal Pomeranz <hal@deer-run.com> */

void *dlopen(const char *str, int x) {}
void *dlsym(void *ptr, const char *str) {}
int dlclose(void *ptr) {}
char *dlerror() {}
void *dlmopen(Lmid_t a, const char *str, int x) {}
int dladdr(void *ptr1, Dl_info *ptr2) {}
int dldump(const char *str1, const char *str2, int x) {}
int dlinfo(void *ptr1, int x, void *ptr2) {}

void *_dlopen(const char *str, int x) {}
void *_dlsym(void *ptr, const char *str) {}
int _dlclose(void *ptr) {}
char *_dlerror() {}
void *_dlmopen(Lmid_t a, const char *str, int x) {}
int _dladdr(void *ptr1, Dl_info *ptr2) {}
int _dldump(const char *str1, const char *str2, int x) {}
int _dlinfo(void *ptr1, int x, void *ptr2) {}

And compile it with:

gcc -c -O2 -g dlstubs.c

Once this is all done and make can create a binary, it’s time to create a semi static binary...

Client Compilation

The compile line for the static binary:

gcc -Bstatic -Wall -O2 -g -DDEVICEID="\"/opt/ocs-client/device-id\""  -DAGENTNAME="\"Solaris OCS Inventory Client/0.11\"" -z muldefs -lkstat -lpthread -lnsl dlstubs.o main.o ocs.o content.o os.o memory.o drives.o network.o storage.o /usr/local/lib/libxml2.a /usr/local/lib/libiconv.a /usr/local/lib/libcurl.a /usr/local/lib/libz.a  /usr/lib/libm.a /usr/lib/libsocket.a /usr/local/ssl/lib/libssl.a /usr/local/lib/libidn.a /usr/local/lib/libintl.a /usr/local/ssl/lib/libcrypto.a -o ocsinv-solaris-client

This should result in a ‘universal’ solaris binary!

ldd ocsinv-solaris-client 
        libkstat.so.1 =>         /lib/libkstat.so.1
        libpthread.so.1 =>       /lib/libpthread.so.1
        libnsl.so.1 =>   /lib/libnsl.so.1
        libc.so.1 =>     /lib/libc.so.1
        libdl.so.1 =>    /etc/lib/libdl.so.1
        libmp.so.2 =>    /lib/libmp.so.2
        libthread.so.1 =>        /lib/libthread.so.1
        /usr/platform/SUNW,UltraAX-i2/lib/libc_psr.so.1

References

 
documents/static_ocs_solaris_client.txt · Last modified: 2008/06/23 13:40
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki