libsmbclient and forking

Derrell Lipman derrell.lipman at unwireduniverse.com
Wed Mar 4 15:16:40 GMT 2009


2009/3/4 Uri Simchoni <uri_simchoni at hotmail.com>

>
> Is it safe to fork in an application that uses libsmbclient with open
> contexts, assuming they are not using the same connections?
>
>
>
> I mean, suppose after forking I purge the cached servers in the child
> process - smbc_getFunctionPurgeCachedServers(ctx)(ctx)
>
> so that any requests will result in new connections. Still, there may be
> some other shared resources that may not be handled correctly...
>

The safest way to handle it is to simply create a new context in each fork.
In the child process, given some "debug" value and a function "fn" to use
for authorization:

        context = smbc_new_context();
        if (!context) {
                return NULL;
        }

        smbc_setDebug(context, debug);
        smbc_setFunctionAuthData(context, fn);

        if (!smbc_init_context(context)) {
                smbc_free_context(context, False);
                return NULL;
        }

        return context;

You're of course now not using the static context created by smbc_init(),
so, for example, instead of calling
  smbc_opendir(url)

you'll call
  smbc_getFunctionOpendir(context)(context, url);

Derrell


More information about the samba-technical mailing list