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