1/* $NetBSD: mail_task.c,v 1.3 2022/10/08 16:12:45 christos Exp $ */ 2 3/*++ 4/* NAME 5/* mail_task 3 6/* SUMMARY 7/* set task name for logging purposes 8/* SYNOPSIS 9/* #include <mail_task.h> 10/* 11/* const char *mail_task(argv0) 12/* const char *argv0; 13/* DESCRIPTION 14/* mail_task() enforces consistent naming of mailer processes. 15/* It strips pathname information from the process name, and 16/* prepends the name of the mail system so that logfile entries 17/* are easier to recognize. The mail system name is specified 18/* with the "syslog_name" configuration parameter. 19/* 20/* The result is overwritten with each call. 21/* 22/* A null argv0 argument requests that the current result is 23/* returned, or "unknown" when no current result exists. 24/* LICENSE 25/* .ad 26/* .fi 27/* The Secure Mailer license must be distributed with this software. 28/* AUTHOR(S) 29/* Wietse Venema 30/* IBM T.J. Watson Research 31/* P.O. Box 704 32/* Yorktown Heights, NY 10598, USA 33/* 34/* Wietse Venema 35/* Google, Inc. 36/* 111 8th Avenue 37/* New York, NY 10011, USA 38/*--*/ 39 40/* System library. */ 41 42#include <sys_defs.h> 43#include <string.h> 44 45/* Utility library. */ 46 47#include <vstring.h> 48#include <safe.h> 49 50/* Global library. */ 51 52#include "mail_params.h" 53#include "mail_conf.h" 54#include "mail_task.h" 55 56/* mail_task - clean up and decorate the process name */ 57 58const char *mail_task(const char *argv0) 59{ 60 static VSTRING *canon_name; 61 const char *slash; 62 const char *tag; 63 64 if (argv0 == 0 && canon_name == 0) 65 argv0 = "unknown"; 66 if (argv0) { 67 if (canon_name == 0) 68 canon_name = vstring_alloc(10); 69 if ((slash = strrchr(argv0, '/')) != 0 && slash[1]) 70 argv0 = slash + 1; 71 /* Setenv()-ed from main.cf, or inherited from master. */ 72 if ((tag = safe_getenv(CONF_ENV_LOGTAG)) == 0) 73 /* Check main.cf settings directly, in case set-gid. */ 74 tag = var_syslog_name ? var_syslog_name : 75 mail_conf_eval(DEF_SYSLOG_NAME); 76 vstring_sprintf(canon_name, "%s/%s", tag, argv0); 77 } 78 return (vstring_str(canon_name)); 79} 80