Skip to content

Commit

Permalink
Check for existence of sys/param.h before using Posix constants.
Browse files Browse the repository at this point in the history
Modify tapestat to use the same checks as pidstat.
  • Loading branch information
dnarc committed Oct 19, 2016
1 parent c1d7ec0 commit 79ecfab
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ SYSMACROS = @SYSMACROS@
ifeq ($(SYSMACROS),y)
DFLAGS += -DHAVE_SYS_SYSMACROS_H
endif
SYSPARAM = @SYSPARAM@
ifeq ($(SYSPARAM),y)
DFLAGS += -DHAVE_SYS_PARAM_H
endif
NLS = @NLS@
ifeq ($(NLS),y)
REQUIRE_NLS = -DUSE_NLS -DPACKAGE=\"$(PACKAGE)\" -DLOCALEDIR=\"$(NLS_DIR)\"
Expand Down
21 changes: 21 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ SA_DIR
sa_dir
SA_LIB_DIR
sa_lib_dir
SYSPARAM
SYSMACROS
INITD_DIR
INIT_DIR
Expand Down Expand Up @@ -4019,6 +4020,7 @@ echo .
HAVE_LIBINTL_H=
HAVE_LOCALE_H=
HAVE_SYS_SYSMACROS_H=
HAVE_SYS_PARAM_H=
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5
$as_echo_n "checking for ANSI C header files... " >&6; }
if ${ac_cv_header_stdc+:} false; then :
Expand Down Expand Up @@ -4409,6 +4411,18 @@ fi
done
for ac_header in sys/param.h
do :
ac_fn_c_check_header_mongrel "$LINENO" "sys/param.h" "ac_cv_header_sys_param_h" "$ac_includes_default"
if test "x$ac_cv_header_sys_param_h" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_SYS_PARAM_H 1
_ACEOF
HAVE_SYS_PARAM_H=1
fi
done
for ac_header in sys/stat.h
do :
ac_fn_c_check_header_mongrel "$LINENO" "sys/stat.h" "ac_cv_header_sys_stat_h" "$ac_includes_default"
Expand Down Expand Up @@ -4927,6 +4941,13 @@ else
fi
if test $HAVE_SYS_PARAM_H; then
SYSPARAM="y"
else
SYSPARAM="n"
fi
# Set sadc directory
if test $prefix != "NONE"; then
AuxPrefix=$prefix
Expand Down
9 changes: 9 additions & 0 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ echo .
HAVE_LIBINTL_H=
HAVE_LOCALE_H=
HAVE_SYS_SYSMACROS_H=
HAVE_SYS_PARAM_H=
AC_HEADER_STDC
AC_HEADER_DIRENT
AC_CHECK_HEADERS(ctype.h)
Expand All @@ -70,6 +71,7 @@ AC_CHECK_HEADERS(signal.h)
AC_CHECK_HEADERS(stdio.h)
AC_CHECK_HEADERS(sys/file.h)
AC_CHECK_HEADERS(sys/ioctl.h)
AC_CHECK_HEADERS(sys/param.h, HAVE_SYS_PARAM_H=1)
AC_CHECK_HEADERS(sys/stat.h)
AC_CHECK_HEADERS(sys/sysmacros.h, HAVE_SYS_SYSMACROS_H=1)

Expand Down Expand Up @@ -209,6 +211,13 @@ else
fi
AC_SUBST(SYSMACROS)

if test $HAVE_SYS_PARAM_H; then
SYSPARAM="y"
else
SYSPARAM="n"
fi
AC_SUBST(SYSPARAM)

# Set sadc directory
if test $prefix != "NONE"; then
AuxPrefix=$prefix
Expand Down
18 changes: 14 additions & 4 deletions pidstat.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
* pidstat: Display per-process statistics.
* (C) 2007-2016 by Sebastien Godard (sysstat <at> orange.fr)
*/

#include <sys/param.h>
#undef HZ

#ifndef _PIDSTAT_H
#define _PIDSTAT_H

#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#undef HZ
#endif

#define K_SELF "SELF"

Expand All @@ -18,9 +18,19 @@

#define NR_PID_PREALLOC 100

#ifdef _POSIX_ARG_MAX
#define MAX_COMM_LEN _POSIX_ARG_MAX
#define MAX_CMDLINE_LEN _POSIX_ARG_MAX
#else
#define MAX_COMM_LEN 128
#define MAX_CMDLINE_LEN 128
#endif

#ifdef LOGIN_NAME_MAX
#define MAX_USER_LEN LOGIN_NAME_MAX
#else
#define MAX_USER_LEN 32
#endif

/* Activities */
#define P_A_CPU 0x01
Expand Down
6 changes: 6 additions & 0 deletions tapestat.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/utsname.h>

#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#undef HZ /* sys/param.h defines HZ but needed for MAXPATHLEN */
#endif
#ifndef MAXPATHLEN
#define MAXPATHLEN 256
#endif

#include "version.h"
#include "tapestat.h"
Expand Down

0 comments on commit 79ecfab

Please sign in to comment.