#!/bin/sh set -eu if [ ! -e /var/run/utmp ]; then echo "/var/run/utmp does not exist; skipping test" exit 77 fi if [ -n "${DEB_HOST_GNU_TYPE:-}" ]; then CROSS_COMPILE="$DEB_HOST_GNU_TYPE-gcc" else CROSS_COMPILE="cc" fi cat < test_library2_runner.c #include #include #include #include #include #include #define _XOPEN_SOURCE 600 #define __USE_XOPEN2KXSI #define __USE_XOPEN_EXTENDED #include #define CHECK(x) do { \ int _ret = (x); \ if (_ret != 0) { \ printf(#x " returned %d: %s\n", _ret, strerror(errno)); \ exit (1); \ } \ } while(0) int main() { setbuf(stdout, NULL); const int i = posix_openpt(O_RDWR | O_NOCTTY); printf("## open ptmx returned %d\n", i); CHECK(grantpt(i)); CHECK(unlockpt(i)); printf("## ptsname: %s\n", ptsname(i)); printf("## doing libutempter add\n"); CHECK(!utempter_add_record(i, "hostname_test_161803398875")); printf("## checking who\n"); CHECK(system("who -a /run/utmp")); printf("## doing libutempter del\n"); CHECK(!utempter_remove_added_record()); printf("## checking who\n"); CHECK(system("who -a /run/utmp")); printf("## DONE\n"); } EOF ${CROSS_COMPILE} -Wall -Wextra -Werror -O2 test_library2_runner.c -lutempter -o test_library2_runner ./test_library2_runner if [ $(./test_library2_runner | grep -c hostname_test_161803398875) -ne 1 ]; then echo "inserted hostname not found" exit 1 else echo "inserted hostname found" fi