mirror of
https://github.com/shadow-maint/shadow.git
synced 2026-01-29 15:24:12 +00:00
Accessing this variable directly is a recipe for disaster, because binaries and libraries can have different versions in them due to how libshadow_la linking is performed. Make sure that at least NULL check is always performed by calling the proper getter function. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
48 lines
1.1 KiB
C
48 lines
1.1 KiB
C
// SPDX-FileCopyrightText: 2017, Chris Lamb
|
|
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#ident "$Id$"
|
|
|
|
#include <errno.h>
|
|
#include <limits.h>
|
|
#include <stdio.h>
|
|
|
|
#include "atoi/a2i.h"
|
|
#include "defines.h"
|
|
#include "prototypes.h"
|
|
#include "shadowlog.h"
|
|
#include "string/strerrno.h"
|
|
|
|
|
|
/*
|
|
* gettime() returns the time as the number of seconds since the Epoch
|
|
*
|
|
* Like time(), gettime() returns the time as the number of seconds since the
|
|
* Epoch, 1970-01-01 00:00:00 +0000 (UTC), except that if the SOURCE_DATE_EPOCH
|
|
* environment variable is exported it will use that instead.
|
|
*/
|
|
/*@observer@*/time_t
|
|
gettime(void)
|
|
{
|
|
char *source_date_epoch;
|
|
time_t fallback, epoch;
|
|
|
|
fallback = time (NULL);
|
|
source_date_epoch = shadow_getenv ("SOURCE_DATE_EPOCH");
|
|
|
|
if (!source_date_epoch)
|
|
return fallback;
|
|
|
|
if (a2i(time_t, &epoch, source_date_epoch, NULL, 10, 0, fallback) == -1) {
|
|
fprintf(log_get_logfd(),
|
|
_("Environment variable $SOURCE_DATE_EPOCH: a2i(\"%s\"): %s"),
|
|
source_date_epoch, strerrno());
|
|
return fallback;
|
|
}
|
|
return epoch;
|
|
}
|