2 * Unix SMB/CIFS implementation.
6 * Copyright (c) 2013 Andreas Schneider <asn@samba.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 #include "util_process.h"
25 #ifdef HAVE_SYS_PRCTL_H
26 #include <sys/prctl.h>
30 * These variables are static so that we can access them
31 * with process_get_short_title() and process_get_long_title(). The
32 * purpose of this is to allow smb_panic_log() to print them.
34 static char short_comment
[16] = {0,};
35 static char long_comment
[256] = {0,};
36 static char binary_name
[256];
38 void process_set_title(const char *short_format
, const char *long_format
, ...)
40 #if defined(HAVE_PRCTL) && defined(PR_SET_NAME)
41 if (short_format
!= NULL
) {
44 va_start(ap
, long_format
);
45 vsnprintf(short_comment
, sizeof(short_comment
), short_format
, ap
);
48 prctl(PR_SET_NAME
, (unsigned long) short_comment
, 0, 0, 0);
52 if (long_format
!= NULL
) {
55 va_start(ap
, long_format
);
56 vsnprintf(long_comment
, sizeof(long_comment
), long_format
, ap
);
59 setproctitle("%s", long_comment
);
63 const char *process_get_short_title(void)
68 const char *process_get_long_title(void)
74 * This is just for debugging in a panic, so we don't want to do
75 * anything more than return a fixed pointer, so we save a copy to a
78 void process_save_binary_name(const char *progname
)
80 strlcpy(binary_name
, progname
, sizeof(binary_name
));
83 /* Samba binaries will set this during popt handling */
84 const char *process_get_saved_binary_name(void)
90 int prctl_set_comment(const char *comment_format
, ...)
95 va_start(ap
, comment_format
);
96 vsnprintf(comment
, sizeof(comment
), comment_format
, ap
);
99 process_set_title("%s", "%s", comment
);