1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-08 21:18:16 +03:00

lib/fault: During smb_panic() print process comment and setprocname() title

The purpose of this is to make it clear which part of the AD DC (in particular)
has faulted without having to deduce it from the stacktrace.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
This commit is contained in:
Andrew Bartlett 2023-07-20 14:10:43 +12:00
parent e401ae44b2
commit 3109899299
5 changed files with 85 additions and 4 deletions

View File

@ -21,6 +21,7 @@
#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>
@ -296,6 +297,7 @@ poptContext samba_popt_get_context(const char * name,
return NULL;
}
#endif
process_save_binary_name(name);
return poptGetContext(name, argc, argv, options, flags);
}

View File

@ -36,6 +36,7 @@
#include "debug.h"
#include "lib/util/signal.h" /* Avoid /usr/include/signal.h */
#include "fault.h"
#include "util_process.h"
static struct {
bool disabled;
@ -170,9 +171,16 @@ static void smb_panic_default(const char *why)
_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 "
@ -189,6 +197,9 @@ _PUBLIC_ void smb_panic_log(const char *why)
/**
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)
{

View File

@ -26,11 +26,19 @@
#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);
@ -42,7 +50,6 @@ void process_set_title(const char *short_format, const char *long_format, ...)
#endif
if (long_format != NULL) {
char long_comment[256] = {0,};
va_list ap;
va_start(ap, long_format);
@ -53,6 +60,33 @@ void process_set_title(const char *short_format, const char *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];

View File

@ -47,4 +47,38 @@ int prctl_set_comment(const char *comment_format, ...) PRINTF_ATTRIBUTE(1,2);
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

View File

@ -79,6 +79,7 @@ bld.SAMBA_SUBSYSTEM('smb-panic',
source='''
fault.c
signal.c
util_process.c
''',
deps='''
replace
@ -97,7 +98,6 @@ bld.SAMBA_SUBSYSTEM('samba-util-core',
util.c
idtree.c
substitute.c
util_process.c
util_strlist.c
strv_util.c
bitmap.c