1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of elogind.
5 Copyright 2017 Sven Eden
7 elogind is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
12 elogind is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with elogind; If not, see <http://www.gnu.org/licenses/>.
24 #include "alloc-util.h"
27 char *program_invocation_name = NULL;
28 char *program_invocation_short_name = NULL;
31 const char *program_arg_name = NULL;
33 #include "musl_missing.h"
35 static void elogind_free_program_name(void) {
37 if (program_invocation_name && (program_invocation_name != program_arg_name) && strlen(program_invocation_name))
38 program_invocation_name = mfree(program_invocation_name);
39 if (program_invocation_short_name && (program_invocation_short_name != program_arg_name) && strlen(program_invocation_short_name))
40 program_invocation_short_name = mfree(program_invocation_short_name);
43 void elogind_set_program_name(const char* pcall) {
44 assert(pcall && pcall[0]);
46 program_arg_name = pcall;
48 if ( ( program_invocation_name
49 && strcmp(program_invocation_name, program_arg_name))
50 || ( program_invocation_short_name
51 && strcmp(program_invocation_short_name, basename(program_arg_name)) ) )
52 elogind_free_program_name();
54 if (NULL == program_invocation_name)
55 program_invocation_name = strdup(program_arg_name);
56 if (NULL == program_invocation_short_name)
57 program_invocation_short_name = strdup(basename(program_arg_name));
59 atexit(elogind_free_program_name);