]> git.samba.org - mat/samba.git/commitdiff
s3:lib: add a utility function "fsp_fnum_dbg" for logging the fnum of an fsp
authorMichael Adam <obnox@samba.org>
Wed, 13 Jun 2012 15:58:54 +0000 (17:58 +0200)
committerStefan Metzmacher <metze@samba.org>
Fri, 15 Jun 2012 01:28:14 +0000 (03:28 +0200)
This is to unify logging of an files_struct.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
source3/include/proto.h
source3/lib/filename_util.c

index d1d71310657f6c244e6b72e2bdedb85fe80686ea..463d9807b87adfb1ff9636bb696994fd2746e970 100644 (file)
@@ -1630,6 +1630,7 @@ NTSTATUS create_synthetic_smb_fname_split(TALLOC_CTX *ctx,
                                          struct smb_filename **smb_fname_out);
 const char *smb_fname_str_dbg(const struct smb_filename *smb_fname);
 const char *fsp_str_dbg(const struct files_struct *fsp);
+const char *fsp_fnum_dbg(const struct files_struct *fsp);
 NTSTATUS copy_smb_filename(TALLOC_CTX *ctx,
                           const struct smb_filename *smb_fname_in,
                           struct smb_filename **smb_fname_out);
index ba628a85c4209428619dde02e3bac19fcc9ad8af..fe43be6dc22492c2af625f3ad3221a54964277cf 100644 (file)
@@ -132,6 +132,34 @@ const char *fsp_str_dbg(const struct files_struct *fsp)
        return smb_fname_str_dbg(fsp->fsp_name);
 }
 
+/**
+ * Create a debug string for the fnum of an fsp.
+ *
+ * This is allocated to talloc_tos() or a string constant
+ * in certain corner cases. The returned string should
+ * hence not be free'd directly but only via the talloc stack.
+ */
+const char *fsp_fnum_dbg(const struct files_struct *fsp)
+{
+       char *str;
+
+       if (fsp == NULL) {
+               return "fnum [fsp is NULL]";
+       }
+
+       if (fsp->fnum == FNUM_FIELD_INVALID) {
+               return "fnum [invalid value]";
+       }
+
+       str = talloc_asprintf(talloc_tos(), "fnum %d", fsp->fnum);
+       if (str == NULL) {
+               DEBUG(1, ("%s: talloc_asprintf failed\n", __FUNCTION__));
+               return "fnum [talloc failed!]";
+       }
+
+       return str;
+}
+
 NTSTATUS copy_smb_filename(TALLOC_CTX *ctx,
                           const struct smb_filename *smb_fname_in,
                           struct smb_filename **smb_fname_out)