libsmblclient and closing connections?
Jeremy Monin
jeremy at shadowlands.org
Thu Feb 17 22:20:18 GMT 2005
On Thu, 17 Feb 2005, Richard Sharpe wrote:
> Perhaps an smbc_shutdown is needed only for completeness sake.
A first pass is attached. Diff is against 3.0.11.
-Jeremy
Jeremy Monin
Sysadmin and open source developer
-------------- next part --------------
diff -ur samba-3.0.11.orig/source/include/libsmbclient.h samba-3.0.11/source/include/libsmbclient.h
--- samba-3.0.11.orig/source/include/libsmbclient.h Fri Jan 28 12:26:30 2005
+++ samba-3.0.11/source/include/libsmbclient.h Thu Feb 17 17:12:05 2005
@@ -500,7 +500,7 @@
* could not be purged
* - EBADF context == NULL
*
- * @see smbc_new_context()
+ * @see smbc_new_context(), smbc_shutdown()
*
* @note It is advised to clean up all the contexts with shutdown_ctx set to 1
* just before exit()'ing. When shutdown_ctx is 0, this function can be
@@ -545,6 +545,8 @@
*
* Must be called before using any of the smbclient API function
*
+ * @see smbc_shutdown()
+ *
* @param fn The function that will be called to obtaion
* authentication credentials.
*
@@ -592,6 +594,27 @@
extern "C" {
#endif
SMBCCTX * smbc_set_context(SMBCCTX * new_context);
+#ifdef __cplusplus
+}
+#endif
+
+/**@ingroup misc
+ * Shut down the samba client library's connections.
+ * Assumes all files are closed.
+ *
+ * Same return codes as smbc_free_context.
+ *
+ * @return Returns 0 on succes. Returns 1 on failure with errno set:
+ * - EBUSY Server connections are still used, Files are open or cache
+ * could not be purged
+ * - EBADF context == NULL
+ *
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+int smbc_shutdown(void);
#ifdef __cplusplus
}
#endif
diff -ur samba-3.0.11.orig/source/libsmb/libsmb_compat.c samba-3.0.11/source/libsmb/libsmb_compat.c
--- samba-3.0.11.orig/source/libsmb/libsmb_compat.c Wed Dec 15 09:33:14 2004
+++ samba-3.0.11/source/libsmb/libsmb_compat.c Thu Feb 17 17:12:20 2005
@@ -152,6 +152,25 @@
}
+/*
+ * Shut down the samba client library's connections.
+ * Assumes no open files.
+ *
+ * Same return codes as smbc_free_context:
+ * Returns 0 on success. Otherwise returns 1, the SMBCCTX is _not_ freed
+ * and thus you'll be leaking memory if not handled properly.
+ */
+int smbc_shutdown(void)
+{
+ if (smbc_compat_initialized) {
+ return smbc_free_context(statcont, True);
+ }
+ return 0;
+}
+
+
+
+
int smbc_open(const char *furl, int flags, mode_t mode)
{
SMBCFILE * file;
More information about the samba-technical
mailing list