2 685f4593 2022-07-15 thomas * Copyright (c) 2016 Nicholas Marriott <nicholas.marriott@gmail.com>
4 685f4593 2022-07-15 thomas * Permission to use, copy, modify, and distribute this software for any
5 685f4593 2022-07-15 thomas * purpose with or without fee is hereby granted, provided that the above
6 685f4593 2022-07-15 thomas * copyright notice and this permission notice appear in all copies.
8 685f4593 2022-07-15 thomas * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 685f4593 2022-07-15 thomas * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 685f4593 2022-07-15 thomas * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 685f4593 2022-07-15 thomas * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 685f4593 2022-07-15 thomas * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
13 685f4593 2022-07-15 thomas * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
14 685f4593 2022-07-15 thomas * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 685f4593 2022-07-15 thomas #include <sys/types.h>
19 685f4593 2022-07-15 thomas #include <stdarg.h>
20 685f4593 2022-07-15 thomas #include <string.h>
22 685f4593 2022-07-15 thomas #include "got_compat.h"
24 685f4593 2022-07-15 thomas #if defined(HAVE_PRCTL) && defined(HAVE_PR_SET_NAME)
26 685f4593 2022-07-15 thomas #include <sys/prctl.h>
29 685f4593 2022-07-15 thomas setproctitle(const char *fmt, ...)
31 685f4593 2022-07-15 thomas char title[16], name[16], *cp;
32 685f4593 2022-07-15 thomas va_list ap;
35 685f4593 2022-07-15 thomas va_start(ap, fmt);
36 685f4593 2022-07-15 thomas vsnprintf(title, sizeof title, fmt, ap);
37 685f4593 2022-07-15 thomas va_end(ap);
39 685f4593 2022-07-15 thomas used = snprintf(name, sizeof name, "%s: %s", getprogname(), title);
40 685f4593 2022-07-15 thomas if (used >= (int)sizeof name) {
41 685f4593 2022-07-15 thomas cp = strrchr(name, ' ');
42 685f4593 2022-07-15 thomas if (cp != NULL)
43 685f4593 2022-07-15 thomas *cp = '\0';
45 685f4593 2022-07-15 thomas prctl(PR_SET_NAME, name);
49 685f4593 2022-07-15 thomas setproctitle(__unused const char *fmt, ...)