prep for calc version 2.14.1.4

Updated COPYING file to indicate that these files are now
covered under "The Unlicense" (see https://unlicense.org):

	sha1.c
	sha1.h
	cal/dotest.cal
	cal/screen.cal

Updated help/credit to match the above changes to COPYING.

Updated CONTRIB-CODE and calc.man to refer to using GitHub pull requests
for contributing to calc (instead of using Email).

Updated BUGS and calc.man to refer to using GitHub issues
for reporting calc bugs (instead of using Email).

Updated QUESTIONS and calc.man to refer to using GitHub issues
for asking calc questions (instead of using Email).

Fixed Makefile.local command example to refer to overriding the
Makefile variable DEBUG (instead of CDEBUG).

Fixed all make chk ASAN warnings under macOS 13.2.1 when calc is compiled
with the following uncommented lines in Makefile.local:

    DEBUG:= -O0 -g
    CFLAGS+= -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined
    LDFLAGS+= -fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined
    CALC_ENV+= ASAN_OPTIONS=detect_stack_use_after_return=1

Improved how pointers to functions are declared for the builtins
array in func.c to avoid function declarations without a prototype
that is now deprecated in C.

Improved how pointers to functions are declared for the opcodes
array in opcodes.c to avoid function declarations without a prototype

Replaced use of egrep with grep -E in Makefiles.

Fixed cases where variables were set but not used in symbol.c, calc.c,
and the main function in func.c as used by funclist.c.

Added rule name to "DO NOT EDIT -- generated by the Makefile" lines
in constructed files.

Test if <sys/vfs.h> exists and set HAVE_SYS_VFS_H accordingly
in have_sys_vfs.h.  Added HAVE_SYS_VFS_H to allow one to force
this value.

Test if <sys/param.h> exists and set HAVE_SYS_PARAM_H accordingly
in have_sys_param.h.  Added HAVE_SYS_PARAM_H to allow one to force
this value.

Test if <sys/mount.h> exists and set HAVE_SYS_MOUNT_H accordingly
in have_sys_mount.h.  Added HAVE_SYS_MOUNT_H to allow one to force
this value.

Test if the system as the statfs() system call and set HAVE_STATFS
accordingly in have_statfs.h.  Added HAVE_STATFS to allow one
to force this value.

The pseudo_seed() function will also try to call statfs() if
possible and permitted by the HAVE_STATFS value.
This commit is contained in:
Landon Curt Noll
2023-03-06 02:17:40 -08:00
parent 644b348bcb
commit d89ea78104
33 changed files with 1999 additions and 1198 deletions

72
seed.c
View File

@@ -66,24 +66,30 @@
#include <sys/types.h>
#include <sys/stat.h>
#include "have_times.h"
#if defined(HAVE_TIME_H)
#include <time.h>
#endif
#endif /* HAVE_TIME_H */
#if defined(HAVE_SYS_TIME_H)
#include <sys/time.h>
#endif
#endif /* HAVE_SYS_TIME_H */
#if defined(HAVE_SYS_TIMES_H)
#include <sys/times.h>
#endif
#endif /* HAVE_SYS_TIMES_H */
#if !defined(_WIN32) && !defined(_WIN64)
# include <sys/resource.h>
#endif
#if defined(HAVE_STDLIB_H)
# include <stdlib.h>
/* NOTE: RANDOM_CNT should remain 32 to circular shift 31-bit returns */
# define RANDOM_CNT (32) /* random() call repeat and circular shift */
# define INITSTATE_SIZE (256) /* initstate pool size */
#endif
#endif /* HAVE_STDLIB_H */
#include <setjmp.h>
#include "alloc.h"
#include "qmath.h"
@@ -98,15 +104,33 @@
#include "have_uid_t.h"
#include "have_environ.h"
#include "have_arc4random.h"
#if defined(HAVE_USTAT)
# include <ustat.h>
#endif
#endif /* HAVE_USTAT */
#if defined(HAVE_URANDOM)
# include <fcntl.h>
# define DEV_URANDOM "/dev/urandom"
# define DEV_URANDOM_POOL (16)
#endif
#endif /* HAVE_URANDOM */
#include "have_sys_vfs.h"
#if defined(HAVE_SYS_VFS_H)
# include <sys/vfs.h>
#endif /* HAVE_SYS_VFS_H */
#include "have_sys_param.h"
#if defined(HAVE_SYS_PARAM_H)
# include <sys/param.h>
#endif /* HAVE_SYS_PARAM_H */
#include "have_sys_mount.h"
#if defined(HAVE_SYS_MOUNT_H)
# include <sys/mount.h>
#endif /* HAVE_SYS_MOUNT_H */
#include "have_statfs.h"
#include "banned.h" /* include after system header <> includes */
@@ -417,6 +441,25 @@ pseudo_seed(void)
/* usage stat of "/var/log/messages" */
struct ustat ustat_messages;
#endif
#if defined(HAVE_STATFS)
struct statfs statfs_dot; /* filesystem stat of "." */
struct statfs statfs_dotdot; /* filesystem stat of ".." */
struct statfs statfs_tmp; /* filesystem stat of "/tmp" */
struct statfs statfs_root; /* filesystem stat of "/" */
struct statfs statfs_tty; /* filesystem stat of "/dev/tty" */
struct statfs statfs_console; /* filesystem stat of "/dev/console" */
struct statfs statfs_stdin; /* filesystem stat of stdin */
struct statfs statfs_stdout; /* filesystem stat of stdout */
struct statfs statfs_stderr; /* filesystem stat of stderr */
struct statfs statfs_zero; /* filesystem stat of "/dev/zero" */
struct statfs statfs_null; /* filesystem stat of "/dev/null" */
struct statfs statfs_sh; /* filesystem stat of "/bin/sh" */
struct statfs statfs_ls; /* filesystem stat of "/bin/ls" */
/* filesystem stat of "/var/log/system.log" */
struct statfs statfs_system;
/* filesystem stat of "/var/log/messages" */
struct statfs statfs_messages;
#endif
#if defined(HAVE_GETSID)
pid_t getsid; /* session ID */
#endif
@@ -559,6 +602,23 @@ pseudo_seed(void)
(void) ustat(sdata.stat_system.st_dev, &sdata.ustat_system);
(void) ustat(sdata.stat_messages.st_dev, &sdata.ustat_messages);
#endif
#if defined(HAVE_STATFS)
(void) statfs("..", &sdata.statfs_dot);
(void) statfs(".", &sdata.statfs_dotdot);
(void) statfs("/tmp", &sdata.statfs_tmp);
(void) statfs("/", &sdata.statfs_root);
(void) statfs("/dev/tty", &sdata.statfs_tty);
(void) statfs("/dev/console", &sdata.statfs_console);
(void) statfs(".dev/stdin", &sdata.statfs_stdin);
(void) statfs("/dev/stdout", &sdata.statfs_stdout);
(void) statfs("/dev/stderr", &sdata.statfs_stderr);
(void) statfs("/dev/zero", &sdata.statfs_zero);
(void) statfs("/dev/null", &sdata.statfs_null);
(void) statfs("/bin/sh", &sdata.statfs_sh);
(void) statfs("/dev/ls", &sdata.statfs_ls);
(void) statfs("/var/log/system.log", &sdata.statfs_system);
(void) statfs("/var/log/messages", &sdata.statfs_messages);
#endif
#if defined(HAVE_GETSID)
sdata.getsid = getsid((pid_t)0);
#endif