mirror of
git://git.sv.gnu.org/coreutils.git
synced 2026-04-21 11:16:16 +02:00
uptime: simplify following gnulib changes
* build-aux/gen-lists-of-programs.sh (build_if_possible_progs): Remove uptime. (normal_progs): Add uptime. * configure.ac: Remove GNULIB_BOOT_TIME invocation. * m4/boottime.m4: Remove file. * src/uptime.c: Don't include <sys/sysctl.h>, <OS.h>. (print_uptime): Don't call sysctl, get_system_info, as Gnulib's readutmp module now does this.
This commit is contained in:
committed by
Paul Eggert
parent
f2c2643fc5
commit
622eea03cd
@@ -33,7 +33,6 @@ build_if_possible_progs='
|
|||||||
stdbuf
|
stdbuf
|
||||||
stty
|
stty
|
||||||
timeout
|
timeout
|
||||||
uptime
|
|
||||||
users
|
users
|
||||||
who
|
who
|
||||||
'
|
'
|
||||||
@@ -132,6 +131,7 @@ normal_progs='
|
|||||||
unexpand
|
unexpand
|
||||||
uniq
|
uniq
|
||||||
unlink
|
unlink
|
||||||
|
uptime
|
||||||
vdir
|
vdir
|
||||||
wc
|
wc
|
||||||
whoami
|
whoami
|
||||||
|
|||||||
@@ -406,8 +406,6 @@ AC_DEFUN([coreutils_DUMMY_1],
|
|||||||
])
|
])
|
||||||
coreutils_DUMMY_1
|
coreutils_DUMMY_1
|
||||||
|
|
||||||
GNULIB_BOOT_TIME([gl_ADD_PROG([optional_bin_progs], [uptime])])
|
|
||||||
|
|
||||||
AC_SYS_POSIX_TERMIOS()
|
AC_SYS_POSIX_TERMIOS()
|
||||||
gl_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
|
gl_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
|
||||||
|
|
||||||
|
|||||||
@@ -1,65 +0,0 @@
|
|||||||
# boottime.m4 serial 4
|
|
||||||
# Determine whether this system has infrastructure for obtaining the boot time.
|
|
||||||
|
|
||||||
# Copyright (C) 1996-2023 Free Software Foundation, Inc.
|
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
|
|
||||||
# This program 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 General Public License for more details.
|
|
||||||
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
# GNULIB_BOOT_TIME([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
|
|
||||||
* ----------------------------------------------------------
|
|
||||||
AC_DEFUN([GNULIB_BOOT_TIME],
|
|
||||||
[
|
|
||||||
AC_CHECK_FUNCS([sysctl])
|
|
||||||
AC_CHECK_HEADERS_ONCE([sys/param.h])
|
|
||||||
AC_CHECK_HEADERS([sys/sysctl.h], [], [],
|
|
||||||
[AC_INCLUDES_DEFAULT
|
|
||||||
[#if HAVE_SYS_PARAM_H
|
|
||||||
#include <sys/param.h>
|
|
||||||
#endif]])
|
|
||||||
AC_CHECK_HEADERS_ONCE([utmpx.h OS.h])
|
|
||||||
AC_CACHE_CHECK(
|
|
||||||
[whether we can get the system boot time],
|
|
||||||
[gnulib_cv_have_boot_time],
|
|
||||||
[
|
|
||||||
AC_COMPILE_IFELSE(
|
|
||||||
[AC_LANG_PROGRAM(
|
|
||||||
[AC_INCLUDES_DEFAULT
|
|
||||||
#if HAVE_SYSCTL && HAVE_SYS_SYSCTL_H
|
|
||||||
# if HAVE_SYS_PARAM_H
|
|
||||||
# include <sys/param.h> /* needed for OpenBSD 3.0 */
|
|
||||||
# endif
|
|
||||||
# include <sys/sysctl.h>
|
|
||||||
#endif
|
|
||||||
#if HAVE_UTMPX_H
|
|
||||||
# include <utmpx.h>
|
|
||||||
#endif
|
|
||||||
#include <utmp.h>
|
|
||||||
#if HAVE_OS_H
|
|
||||||
# include <OS.h>
|
|
||||||
#endif
|
|
||||||
],
|
|
||||||
[[
|
|
||||||
#if (defined BOOT_TIME \
|
|
||||||
|| (defined CTL_KERN && defined KERN_BOOTTIME) \
|
|
||||||
|| HAVE_OS_H)
|
|
||||||
/* your system *does* have the infrastructure to determine boot time */
|
|
||||||
#else
|
|
||||||
please_tell_us_how_to_determine_boot_time_on_your_system
|
|
||||||
#endif
|
|
||||||
]])],
|
|
||||||
[gnulib_cv_have_boot_time=yes],
|
|
||||||
[gnulib_cv_have_boot_time=no])
|
|
||||||
])
|
|
||||||
AS_IF([test $gnulib_cv_have_boot_time = yes], [$1], [$2])
|
|
||||||
])
|
|
||||||
30
src/uptime.c
30
src/uptime.c
@@ -24,14 +24,6 @@
|
|||||||
|
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
|
|
||||||
#if HAVE_SYSCTL && HAVE_SYS_SYSCTL_H && ! defined __GLIBC__
|
|
||||||
# include <sys/sysctl.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HAVE_OS_H
|
|
||||||
# include <OS.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "long-options.h"
|
#include "long-options.h"
|
||||||
#include "quote.h"
|
#include "quote.h"
|
||||||
#include "readutmp.h"
|
#include "readutmp.h"
|
||||||
@@ -51,28 +43,6 @@ print_uptime (idx_t n, struct gl_utmp const *utmp_buf)
|
|||||||
int status = EXIT_SUCCESS;
|
int status = EXIT_SUCCESS;
|
||||||
time_t boot_time = 0;
|
time_t boot_time = 0;
|
||||||
|
|
||||||
#if HAVE_SYSCTL && ! defined __GLIBC__ \
|
|
||||||
&& defined CTL_KERN && defined KERN_BOOTTIME
|
|
||||||
{
|
|
||||||
/* FreeBSD specific: fetch sysctl "kern.boottime". */
|
|
||||||
static int request[2] = { CTL_KERN, KERN_BOOTTIME };
|
|
||||||
struct timeval result;
|
|
||||||
size_t result_len = sizeof result;
|
|
||||||
|
|
||||||
if (sysctl (request, 2, &result, &result_len, nullptr, 0) >= 0)
|
|
||||||
boot_time = result.tv_sec;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HAVE_OS_H /* BeOS */
|
|
||||||
{
|
|
||||||
system_info si;
|
|
||||||
|
|
||||||
get_system_info (&si);
|
|
||||||
boot_time = si.boot_time / 1000000;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Loop through all the utmp entries we just read and count up the valid
|
/* Loop through all the utmp entries we just read and count up the valid
|
||||||
ones, also in the process possibly gleaning boottime. */
|
ones, also in the process possibly gleaning boottime. */
|
||||||
idx_t entries = 0;
|
idx_t entries = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user