Print this page
10703 smatch unreachable code checking needs reworking
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
   1 /*
   2  * This file and its contents are supplied under the terms of the
   3  * Common Development and Distribution License ("CDDL"), version 1.0.
   4  * You may only use this file in accordance with the terms of version
   5  * 1.0 of the CDDL.
   6  *
   7  * A full copy of the text of the CDDL should have accompanied this
   8  * source.  A copy of the CDDL is also available via the Internet at
   9  * http://www.illumos.org/license/CDDL.
  10  */
  11 
  12 /*
  13  * Copyright 2018 Joyent, Inc.
  14  */
  15 
  16 /*
  17  * Validate various fcntl(2) and flock(3C) operations.
  18  */
  19 
  20 #include "util.h"
  21 #include <err.h>
  22 #include <errno.h>
  23 #include <fcntl.h>
  24 #include <libgen.h>
  25 #include <signal.h>
  26 #include <stdlib.h>
  27 #include <strings.h>
  28 #include <sys/debug.h>
  29 #include <sys/file.h>
  30 #include <sys/stat.h>
  31 #include <sys/wait.h>
  32 #include <unistd.h>
  33 


 310 
 311 
 312 static int
 313 flock_wait(pid_t pid)
 314 {
 315         int childstat = 0;
 316 
 317         while (waitpid(pid, &childstat, 0) == -1) {
 318                 if (errno == EINTR)
 319                         continue;
 320 
 321                 err(EXIT_FAILURE, "Failed to wait on child");
 322         }
 323 
 324         if (WIFEXITED(childstat)) {
 325                 return (WEXITSTATUS(childstat));
 326         } else if (WIFSIGNALED(childstat)) {
 327                 return (1);
 328         } else {
 329                 abort();
 330                 return (1);
 331         }
 332 }
 333 
 334 
 335 static void
 336 flock_cleanup_child(pid_t pid, int fds[])
 337 {
 338         (void) flock_wait(pid);
 339         (void) close(fds[0]);
 340         (void) close(fds[1]);
 341 }
 342 
 343 
 344 static void
 345 flock_test_upgrade_downgrade(void)
 346 {
 347         lockinfo_t afd1, afd2, afd3;
 348         pid_t pid;
 349         int fds[2];
 350 


   1 /*
   2  * This file and its contents are supplied under the terms of the
   3  * Common Development and Distribution License ("CDDL"), version 1.0.
   4  * You may only use this file in accordance with the terms of version
   5  * 1.0 of the CDDL.
   6  *
   7  * A full copy of the text of the CDDL should have accompanied this
   8  * source.  A copy of the CDDL is also available via the Internet at
   9  * http://www.illumos.org/license/CDDL.
  10  */
  11 
  12 /*
  13  * Copyright 2019 Joyent, Inc.
  14  */
  15 
  16 /*
  17  * Validate various fcntl(2) and flock(3C) operations.
  18  */
  19 
  20 #include "util.h"
  21 #include <err.h>
  22 #include <errno.h>
  23 #include <fcntl.h>
  24 #include <libgen.h>
  25 #include <signal.h>
  26 #include <stdlib.h>
  27 #include <strings.h>
  28 #include <sys/debug.h>
  29 #include <sys/file.h>
  30 #include <sys/stat.h>
  31 #include <sys/wait.h>
  32 #include <unistd.h>
  33 


 310 
 311 
 312 static int
 313 flock_wait(pid_t pid)
 314 {
 315         int childstat = 0;
 316 
 317         while (waitpid(pid, &childstat, 0) == -1) {
 318                 if (errno == EINTR)
 319                         continue;
 320 
 321                 err(EXIT_FAILURE, "Failed to wait on child");
 322         }
 323 
 324         if (WIFEXITED(childstat)) {
 325                 return (WEXITSTATUS(childstat));
 326         } else if (WIFSIGNALED(childstat)) {
 327                 return (1);
 328         } else {
 329                 abort();

 330         }
 331 }
 332 
 333 
 334 static void
 335 flock_cleanup_child(pid_t pid, int fds[])
 336 {
 337         (void) flock_wait(pid);
 338         (void) close(fds[0]);
 339         (void) close(fds[1]);
 340 }
 341 
 342 
 343 static void
 344 flock_test_upgrade_downgrade(void)
 345 {
 346         lockinfo_t afd1, afd2, afd3;
 347         pid_t pid;
 348         int fds[2];
 349