ctdb-server: Use find_public_ip_vnn() in a couple of extra places
[samba4-gss.git] / lib / util / util_process.c
bloba10b85cac807722365e196bb55e04b6ac65e3708
1 /*
2 * Unix SMB/CIFS implementation.
4 * Process utils.
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"
23 #include "replace.h"
25 #ifdef HAVE_SYS_PRCTL_H
26 #include <sys/prctl.h>
27 #endif
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) {
42 va_list ap;
44 va_start(ap, long_format);
45 vsnprintf(short_comment, sizeof(short_comment), short_format, ap);
46 va_end(ap);
48 prctl(PR_SET_NAME, (unsigned long) short_comment, 0, 0, 0);
50 #endif
52 if (long_format != NULL) {
53 va_list ap;
55 va_start(ap, long_format);
56 vsnprintf(long_comment, sizeof(long_comment), long_format, ap);
57 va_end(ap);
59 setproctitle("%s", long_comment);
63 const char *process_get_short_title(void)
65 return short_comment;
68 const char *process_get_long_title(void)
70 return long_comment;
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
76 * static variable.
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)
86 return binary_name;
90 int prctl_set_comment(const char *comment_format, ...)
92 char comment[16];
93 va_list ap;
95 va_start(ap, comment_format);
96 vsnprintf(comment, sizeof(comment), comment_format, ap);
97 va_end(ap);
99 process_set_title("%s", "%s", comment);
100 return 0;