diff options
author | Ron Yorston <rmy@pobox.com> | 2021-01-14 13:28:49 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2021-01-14 13:28:49 +0000 |
commit | 89963b524d211e1aec12b72b3725be05ee95c8cf (patch) | |
tree | 48590aef62b7ee7686b7898256f29def8d9c50b9 /libbb/xfuncs_printf.c | |
parent | 9aa5a829070392c2ac6494d0c4e674c0c2bc7dab (diff) | |
parent | 2b7c1aa92c68524559a2067609d09309d5c09adc (diff) | |
download | busybox-w32-89963b524d211e1aec12b72b3725be05ee95c8cf.tar.gz busybox-w32-89963b524d211e1aec12b72b3725be05ee95c8cf.tar.bz2 busybox-w32-89963b524d211e1aec12b72b3725be05ee95c8cf.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'libbb/xfuncs_printf.c')
-rw-r--r-- | libbb/xfuncs_printf.c | 71 |
1 files changed, 61 insertions, 10 deletions
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c index 6fdc0f6a4..4bd19d471 100644 --- a/libbb/xfuncs_printf.c +++ b/libbb/xfuncs_printf.c | |||
@@ -111,6 +111,29 @@ void* FAST_FUNC xmemdup(const void *s, int n) | |||
111 | return memcpy(xmalloc(n), s, n); | 111 | return memcpy(xmalloc(n), s, n); |
112 | } | 112 | } |
113 | 113 | ||
114 | #if !ENABLE_PLATFORM_MINGW32 | ||
115 | void* FAST_FUNC mmap_read(int fd, size_t size) | ||
116 | { | ||
117 | return mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); | ||
118 | } | ||
119 | |||
120 | void* FAST_FUNC mmap_anon(size_t size) | ||
121 | { | ||
122 | return mmap(NULL, size, | ||
123 | PROT_READ | PROT_WRITE, | ||
124 | MAP_PRIVATE | MAP_ANONYMOUS, | ||
125 | /* ignored: */ -1, 0); | ||
126 | } | ||
127 | |||
128 | void* FAST_FUNC xmmap_anon(size_t size) | ||
129 | { | ||
130 | void *p = mmap_anon(size); | ||
131 | if (p == MAP_FAILED) | ||
132 | bb_die_memory_exhausted(); | ||
133 | return p; | ||
134 | } | ||
135 | #endif | ||
136 | |||
114 | // Die if we can't open a file and return a FILE* to it. | 137 | // Die if we can't open a file and return a FILE* to it. |
115 | // Notice we haven't got xfread(), This is for use with fscanf() and friends. | 138 | // Notice we haven't got xfread(), This is for use with fscanf() and friends. |
116 | FILE* FAST_FUNC xfopen(const char *path, const char *mode) | 139 | FILE* FAST_FUNC xfopen(const char *path, const char *mode) |
@@ -502,22 +525,22 @@ void FAST_FUNC xfstat(int fd, struct stat *stat_buf, const char *errmsg) | |||
502 | bb_simple_perror_msg_and_die(errmsg); | 525 | bb_simple_perror_msg_and_die(errmsg); |
503 | } | 526 | } |
504 | 527 | ||
505 | #if !ENABLE_PLATFORM_MINGW32 | 528 | #if ENABLE_SELINUX |
506 | // selinux_or_die() - die if SELinux is disabled. | 529 | // selinux_or_die() - die if SELinux is disabled. |
507 | void FAST_FUNC selinux_or_die(void) | 530 | void FAST_FUNC selinux_or_die(void) |
508 | { | 531 | { |
509 | #if ENABLE_SELINUX | ||
510 | int rc = is_selinux_enabled(); | 532 | int rc = is_selinux_enabled(); |
511 | if (rc == 0) { | 533 | if (rc == 0) { |
512 | bb_simple_error_msg_and_die("SELinux is disabled"); | 534 | bb_simple_error_msg_and_die("SELinux is disabled"); |
513 | } else if (rc < 0) { | 535 | } else if (rc < 0) { |
514 | bb_simple_error_msg_and_die("is_selinux_enabled() failed"); | 536 | bb_simple_error_msg_and_die("is_selinux_enabled() failed"); |
515 | } | 537 | } |
538 | } | ||
516 | #else | 539 | #else |
517 | bb_simple_error_msg_and_die("SELinux support is disabled"); | 540 | /* not defined, other code must have no calls to it */ |
518 | #endif | 541 | #endif |
519 | } | ||
520 | 542 | ||
543 | #if !ENABLE_PLATFORM_MINGW32 | ||
521 | int FAST_FUNC ioctl_or_perror_and_die(int fd, unsigned request, void *argp, const char *fmt,...) | 544 | int FAST_FUNC ioctl_or_perror_and_die(int fd, unsigned request, void *argp, const char *fmt,...) |
522 | { | 545 | { |
523 | int ret; | 546 | int ret; |
@@ -634,14 +657,11 @@ void FAST_FUNC generate_uuid(uint8_t *buf) | |||
634 | pid_t pid; | 657 | pid_t pid; |
635 | int i; | 658 | int i; |
636 | 659 | ||
637 | i = open("/dev/urandom", O_RDONLY); | 660 | open_read_close("/dev/urandom", buf, 16); |
638 | if (i >= 0) { | ||
639 | read(i, buf, 16); | ||
640 | close(i); | ||
641 | } | ||
642 | /* Paranoia. /dev/urandom may be missing. | 661 | /* Paranoia. /dev/urandom may be missing. |
643 | * rand() is guaranteed to generate at least [0, 2^15) range, | 662 | * rand() is guaranteed to generate at least [0, 2^15) range, |
644 | * but lowest bits in some libc are not so "random". */ | 663 | * but lowest bits in some libc are not so "random". |
664 | */ | ||
645 | srand(monotonic_us()); /* pulls in printf */ | 665 | srand(monotonic_us()); /* pulls in printf */ |
646 | pid = getpid(); | 666 | pid = getpid(); |
647 | while (1) { | 667 | while (1) { |
@@ -686,3 +706,34 @@ void FAST_FUNC xvfork_parent_waits_and_exits(void) | |||
686 | /* Child continues */ | 706 | /* Child continues */ |
687 | } | 707 | } |
688 | #endif /* !ENABLE_PLATFORM_MINGW32 */ | 708 | #endif /* !ENABLE_PLATFORM_MINGW32 */ |
709 | |||
710 | // Useful when we do know that pid is valid, and we just want to wait | ||
711 | // for it to exit. Not existing pid is fatal. waitpid() status is not returned. | ||
712 | int FAST_FUNC wait_for_exitstatus(pid_t pid) | ||
713 | { | ||
714 | int exit_status, n; | ||
715 | |||
716 | n = safe_waitpid(pid, &exit_status, 0); | ||
717 | if (n < 0) | ||
718 | bb_simple_perror_msg_and_die("waitpid"); | ||
719 | return exit_status; | ||
720 | } | ||
721 | |||
722 | #if !ENABLE_PLATFORM_MINGW32 | ||
723 | void FAST_FUNC xsettimeofday(const struct timeval *tv) | ||
724 | { | ||
725 | if (settimeofday(tv, NULL)) | ||
726 | bb_simple_perror_msg_and_die("settimeofday"); | ||
727 | } | ||
728 | #endif | ||
729 | |||
730 | void FAST_FUNC xgettimeofday(struct timeval *tv) | ||
731 | { | ||
732 | #if 0 | ||
733 | if (gettimeofday(tv, NULL)) | ||
734 | bb_simple_perror_msg_and_die("gettimeofday"); | ||
735 | #else | ||
736 | /* Never fails on Linux */ | ||
737 | gettimeofday(tv, NULL); | ||
738 | #endif | ||
739 | } | ||