#include "auth/gensec/gensec.h"
#include "libcli/smb/smb_util.h"
#include "cmdline_private.h"
+#include "lib/util/util_process.h"
#include <samba/version.h>
return NULL;
}
#endif
+ process_save_binary_name(name);
return poptGetContext(name, argc, argv, options, flags);
}
#include "debug.h"
#include "lib/util/signal.h" /* Avoid /usr/include/signal.h */
#include "fault.h"
+#include "util_process.h"
static struct {
bool disabled;
_PUBLIC_ void smb_panic_log(const char *why)
{
+ const char *binary_name = process_get_saved_binary_name();
+ const char *short_title = process_get_short_title();
+ const char *long_title = process_get_long_title();
+
DEBUGSEP(0);
- DEBUG(0,("INTERNAL ERROR: %s in pid %lld (%s)\n",
+ DEBUG(0,("INTERNAL ERROR: %s in %s (%s) (%s) pid %lld (%s)\n",
why,
+ binary_name,
+ short_title,
+ long_title,
(unsigned long long)getpid(),
SAMBA_VERSION_STRING));
DEBUG(0,("If you are running a recent Samba version, and "
/**
Something really nasty happened - panic !
+
+ This function is in this file to allow sharing the last set process
+ title into the logs before the backtrace
**/
_PUBLIC_ void smb_panic(const char *why)
{
#include <sys/prctl.h>
#endif
+/*
+ * These variables are static so that we can print them in access them
+ * with process_get_short_title() and process_get_long_title(). The
+ * purpose of this is to allow smb_panic_log() to print them.
+ */
+static char short_comment[16] = {0,};
+static char long_comment[256] = {0,};
+static char binary_name[256];
+
void process_set_title(const char *short_format, const char *long_format, ...)
{
#if defined(HAVE_PRCTL) && defined(PR_SET_NAME)
if (short_format != NULL) {
- char short_comment[16] = {0,};
va_list ap;
va_start(ap, long_format);
#endif
if (long_format != NULL) {
- char long_comment[256] = {0,};
va_list ap;
va_start(ap, long_format);
}
}
+const char *process_get_short_title(void)
+{
+ return short_comment;
+}
+
+const char *process_get_long_title(void)
+{
+ return long_comment;
+}
+
+/*
+ * This is just for debugging in a panic, so we don't want to do
+ * anything more than return a fixed pointer, so we save a copy to a
+ * static variable.
+ */
+void process_save_binary_name(const char *progname)
+{
+ strlcpy(binary_name, progname, sizeof(binary_name));
+}
+
+/* Samba binaries will set this during popt handling */
+const char *process_get_saved_binary_name(void)
+{
+ return binary_name;
+}
+
+
int prctl_set_comment(const char *comment_format, ...)
{
char comment[16];
void process_set_title(const char *short_format, const char *long_format, ...)
PRINTF_ATTRIBUTE(1,3) PRINTF_ATTRIBUTE(2,3);
+/**
+ * @brief Get the process comment name set from process_set_title()
+ *
+ * @return process comment name
+ */
+const char *process_get_short_title(void);
+
+/**
+ * @brief Get the process longname set from process_set_title()
+ *
+ * @return process longname
+ */
+const char *process_get_long_title(void);
+
+/*
+ * @brief Save the binary name for later printing in smb_panic()
+ *
+ * @param[in] progname The binary name at process startup
+ *
+ * This is just for debugging in a panic, so we don't want to do
+ * anything more than return a fixed pointer, so we save a copy to a
+ * static variable.
+ */
+void process_save_binary_name(const char *progname);
+
+/**
+ * @brief Get the binary name set at startup process_save_binary_name()
+ *
+ * @return binary name set at startup
+ */
+/* Samba binaries will set this during popt handling */
+const char *process_get_saved_binary_name(void);
+
+
#endif
source='''
fault.c
signal.c
+ util_process.c
''',
deps='''
replace
util.c
idtree.c
substitute.c
- util_process.c
util_strlist.c
strv_util.c
bitmap.c