Print this page
10137 smatch fixes for setuname

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/setuname/setuname.c
          +++ new/usr/src/cmd/setuname/setuname.c
↓ open down ↓ 19 lines elided ↑ open up ↑
  20   20   */
  21   21  /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
  22   22  /*        All Rights Reserved   */
  23   23  
  24   24  
  25   25  /*
  26   26   * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  27   27   * Use is subject to license terms.
  28   28   */
  29   29  
  30      -#pragma ident   "%Z%%M% %I%     %E% SMI"       /* SVr4.0 1.3 */
       30 +/*
       31 + * Copyright (c) 2018, Joyent, Inc.
       32 + */
  31   33  
  32   34  /*
  33   35   *  setuname [-t] [-s name] [-n node] 
  34   36   */
  35   37  
  36   38  /*
  37   39   *  Header files referenced:
  38   40   *      <stdio.h>       Standard I/O 
  39   41   *      <unistd.h>      Standard UNIX definitions
  40   42   *      <string.h>      String handling 
↓ open down ↓ 404 lines elided ↑ open up ↑
 445  447  #ifdef sun
 446  448          if (kvm_kread(kd, utsname_addr, &utsname, sizeof (utsname)) ==
 447  449              sizeof (utsname)) {
 448  450                  if (sysname)
 449  451                          (void) strncpy(utsname.sysname, sysname,
 450  452                              sizeof (utsname.sysname));
 451  453                  if (nodename)
 452  454                          (void) strncpy(utsname.nodename, nodename,
 453  455                              sizeof (utsname.nodename));
 454  456                  (void) kvm_kwrite(kd, utsname_addr, &utsname, sizeof (utsname));
 455      -                kvm_close(kd);
      457 +                (void) kvm_close(kd);
 456  458          } else
 457  459                  return (-1);
 458  460  #else /* sun */
 459  461          if ((memfd = open("/dev/kmem", O_RDWR, 0)) > 0) {
 460  462              if ((lseek(memfd, (long) utsname_addr, SEEK_SET) != -1) && 
 461  463                  (read(memfd, &utsname, sizeof(utsname)) == sizeof(utsname))) {
 462  464                  if (sysname) (void) strncpy(utsname.sysname, sysname, sizeof(utsname.sysname));
 463  465                  if (nodename) (void) strncpy(utsname.nodename, nodename, sizeof(utsname.nodename));
 464  466                  (void) lseek(memfd, (long) utsname_addr, SEEK_SET);
 465  467                  (void) write(memfd, &utsname, sizeof(utsname));
↓ open down ↓ 31 lines elided ↑ open up ↑
 497  499                  oldsigint = signal(SIGINT, SIG_IGN);
 498  500  
 499  501              /* Write the new setuname "rc" file */
 500  502                  if (sysname != NULL) {
 501  503                          if ((fd = fopen(RC_FILENAME, "w")) != (FILE *) NULL) {
 502  504                                  (void) fprintf(fd, "# %s\n", sysnm);
 503  505                                  (void) fprintf(fd, "#\n");
 504  506                                  (void) fprintf(fd, "# This script, generated by the setuname command,\n");
 505  507                                  (void) fprintf(fd, "# sets the system's system-name\n");
 506  508                                  (void) fprintf(fd, "#\n");
 507      -                        if (sysnm && *sysnm) 
 508      -                                (void) fprintf(fd, "setuname -t -s %s\n", sysnm);
 509      -                        (void) fclose(fd);
      509 +                                if (sysnm && *sysnm)
      510 +                                        (void) fprintf(fd, "setuname -t -s %s\n", sysnm);
      511 +                                (void) fclose(fd);
 510  512                          } else return(rtncd = -1);
 511  513                  }
 512  514  
 513  515                  if(nodename != NULL) {
 514  516                          char curname[SYS_NMLN];
 515  517                          int curlen;
 516  518                          FILE *file;
 517  519  
 518  520                          if ((file = fopen("/etc/nodename", "r")) != NULL) {
 519  521                                  curlen = fread(curname, sizeof(char), SYS_NMLN, file);
↓ open down ↓ 33 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX