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