tests: do not truncate pid to 16 bits
authorMike Gilbert <floppym@gentoo.org>
Fri, 8 May 2020 03:28:50 +0000 (23:28 -0400)
committerAndreas Schneider <asn@samba.org>
Thu, 14 May 2020 10:46:13 +0000 (12:46 +0200)
On Linux, pid_t is a 32-bit type, and the kernel permits pids up to 22
bits in length.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14373

Signed-off-by: Mike Gilbert <floppym@gentoo.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
tests/torture.c

index e55ebcfa136832d26107d1d6cc8503041034fc9e..595f504a5b3351a6af9138e0a35a778d8361cbfa 100644 (file)
@@ -255,8 +255,7 @@ void torture_teardown_socket_dir(void **state)
 void torture_teardown_echo_srv(void **state)
 {
        struct torture_state *s = *state;
-       char buf[8] = {0};
-       long int tmp;
+       char buf[12] = {0}; /* -2147483648 + null byte */
        ssize_t rc;
        pid_t pid;
        int fd;
@@ -277,13 +276,12 @@ void torture_teardown_echo_srv(void **state)
 
        buf[sizeof(buf) - 1] = '\0';
 
-       tmp = strtol(buf, NULL, 10);
-       if (tmp == 0 || tmp > 0xFFFF || errno == ERANGE) {
+       errno = 0;
+       pid = strtol(buf, NULL, 10);
+       if (pid == 0 || errno != 0) {
                goto done;
        }
 
-       pid = (pid_t)(tmp & 0xFFFF);
-
        for (count = 0; count < 10; count++) {
                /* Make sure the daemon goes away! */
                kill(pid, SIGTERM);