Line data Source code
1 : /* 2 : * Unix SMB/CIFS implementation. 3 : * 4 : * Process utils. 5 : * 6 : * Copyright (c) 2013 Andreas Schneider <asn@samba.org> 7 : * 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. 12 : * 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. 17 : * 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/>. 20 : */ 21 : 22 : #include "util_process.h" 23 : #include "replace.h" 24 : 25 : #ifdef HAVE_SYS_PRCTL_H 26 : #include <sys/prctl.h> 27 : #endif 28 : 29 21318 : void process_set_title(const char *short_format, const char *long_format, ...) 30 : { 31 : #if defined(HAVE_PRCTL) && defined(PR_SET_NAME) 32 21318 : if (short_format != NULL) { 33 21318 : char short_comment[16] = {0,}; 34 : va_list ap; 35 : 36 21318 : va_start(ap, long_format); 37 21318 : vsnprintf(short_comment, sizeof(short_comment), short_format, ap); 38 21318 : va_end(ap); 39 : 40 21318 : prctl(PR_SET_NAME, (unsigned long) short_comment, 0, 0, 0); 41 : } 42 : #endif 43 : 44 21318 : if (long_format != NULL) { 45 21318 : char long_comment[256] = {0,}; 46 : va_list ap; 47 : 48 21318 : va_start(ap, long_format); 49 21318 : vsnprintf(long_comment, sizeof(long_comment), long_format, ap); 50 21318 : va_end(ap); 51 : 52 21318 : setproctitle("%s", long_comment); 53 : } 54 21318 : } 55 : 56 0 : int prctl_set_comment(const char *comment_format, ...) 57 : { 58 : char comment[16]; 59 : va_list ap; 60 : 61 0 : va_start(ap, comment_format); 62 0 : vsnprintf(comment, sizeof(comment), comment_format, ap); 63 0 : va_end(ap); 64 : 65 0 : process_set_title("%s", "%s", comment); 66 0 : return 0; 67 : }