Print this page
8485 Remove set but unused variables in usr/src/cmd


   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*

  23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 
  28 /*
  29  * special.c
  30  *
  31  * This module contains code required to remove special contents from
  32  * the contents file when a pkgrm is done on a system upgraded to use
  33  * the new database.
  34  */
  35 
  36 #include <stdio.h>
  37 #include <stdlib.h>
  38 #include <assert.h>
  39 #include <errno.h>
  40 #include <unistd.h>
  41 #include <string.h>
  42 #include <time.h>


 482  * file.  The contents file will get changed only in the case that the
 483  * entire operation has succeeded.
 484  *
 485  *  ient        The number of entries.
 486  *  ppcfent     The entries to remove.
 487  *  pcroot      The alternate install root.  Could be NULL.  In this
 488  *              case, assume root is '/'
 489  *
 490  * Result: 0 on success, nonzero on failure.  If an error occurs, an
 491  *    error string will get output to standard error alerting the user.
 492  * Side effects: The contents file may change as a result of this call,
 493  *    such that lines in the in the file will be changed or removed.
 494  *    If the call fails, a t.contents file may be left behind.  This
 495  *    temporary file should be removed subsequently.
 496  */
 497 int
 498 special_contents_remove(int ient, struct cfent **ppcfent, const char *pcroot)
 499 {
 500         int result = 0;         /* Assume we will succeed.  Return result. */
 501         char **ppcSC = NULL;    /* The special contents rules, sorted. */
 502         int i, j;               /* Indexes into contents & special contents */
 503         FILE *fpi = NULL,       /* Input of contents file */
 504             *fpo = NULL;        /* Output to temp contents file */
 505         char cpath[PATH_MAX],   /* Contents file path */
 506             tcpath[PATH_MAX];   /* Temp contents file path */
 507         const char *pccontents = "var/sadm/install/contents";
 508         const char *pctcontents = "var/sadm/install/t.contents";
 509         char line[LINESZ];      /* Reads in and writes out contents lines. */
 510         time_t t;               /* Used to create a timestamp comment. */
 511         int max;                /* Max number of special contents entries. */
 512         int *piIndex;           /* An index to ppcfents to remove from cfile */
 513 
 514         cpath[0] = tcpath[0] = '\0';
 515 
 516         if (ient == 0 || ppcfent == NULL || ppcfent[0] == NULL) {
 517                 goto remove_done;
 518         }
 519 
 520         if ((get_special_contents(pcroot, &ppcSC, &max)) != 0) {
 521                 result = 1;
 522                 goto remove_done;


 582         }
 583 
 584         if (generate_special_contents_rules(ient, ppcfent, ppcSC, max, &piIndex)
 585             != 0) {
 586                 result = 1;
 587                 goto remove_done;
 588         }
 589 
 590         /*
 591          * Copy contents to t.contents unless there is an entry in
 592          * the ppcfent array which corresponds to an index set to 1.
 593          *
 594          * These items are the removed package contents which matche an
 595          * entry in ppcSC (the special_contents rules).
 596          *
 597          * Since both the contents and rules are sorted, we can
 598          * make a single efficient pass.
 599          */
 600         (void) memset(line, 0, LINESZ);
 601 
 602         for (i = 0, j = 0; fgets(line, LINESZ, fpi) != NULL; ) {
 603 
 604                 char *pcpath = NULL;
 605 
 606                 /*
 607                  * Note:  This could be done better:  We should figure out
 608                  * which are the last 2 lines and only trim those off.
 609                  * This will suffice to do this and will only be done as
 610                  * part of special_contents handling.
 611                  */
 612                 if (line[0] == '#')
 613                         continue; /* Do not copy the final 2 comment lines */
 614 
 615                 pcpath = get_path(line);
 616 
 617                 if (pcpath != NULL && i < ient) {
 618                         int k;
 619                         while (piIndex[i] == 0)
 620                                 i++;
 621 
 622                         if (i < ient)




   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2017 Gary Mills
  24  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
  25  * Use is subject to license terms.
  26  */
  27 
  28 
  29 /*
  30  * special.c
  31  *
  32  * This module contains code required to remove special contents from
  33  * the contents file when a pkgrm is done on a system upgraded to use
  34  * the new database.
  35  */
  36 
  37 #include <stdio.h>
  38 #include <stdlib.h>
  39 #include <assert.h>
  40 #include <errno.h>
  41 #include <unistd.h>
  42 #include <string.h>
  43 #include <time.h>


 483  * file.  The contents file will get changed only in the case that the
 484  * entire operation has succeeded.
 485  *
 486  *  ient        The number of entries.
 487  *  ppcfent     The entries to remove.
 488  *  pcroot      The alternate install root.  Could be NULL.  In this
 489  *              case, assume root is '/'
 490  *
 491  * Result: 0 on success, nonzero on failure.  If an error occurs, an
 492  *    error string will get output to standard error alerting the user.
 493  * Side effects: The contents file may change as a result of this call,
 494  *    such that lines in the in the file will be changed or removed.
 495  *    If the call fails, a t.contents file may be left behind.  This
 496  *    temporary file should be removed subsequently.
 497  */
 498 int
 499 special_contents_remove(int ient, struct cfent **ppcfent, const char *pcroot)
 500 {
 501         int result = 0;         /* Assume we will succeed.  Return result. */
 502         char **ppcSC = NULL;    /* The special contents rules, sorted. */
 503         int i;                  /* Index into contents & special contents */
 504         FILE *fpi = NULL,       /* Input of contents file */
 505             *fpo = NULL;        /* Output to temp contents file */
 506         char cpath[PATH_MAX],   /* Contents file path */
 507             tcpath[PATH_MAX];   /* Temp contents file path */
 508         const char *pccontents = "var/sadm/install/contents";
 509         const char *pctcontents = "var/sadm/install/t.contents";
 510         char line[LINESZ];      /* Reads in and writes out contents lines. */
 511         time_t t;               /* Used to create a timestamp comment. */
 512         int max;                /* Max number of special contents entries. */
 513         int *piIndex;           /* An index to ppcfents to remove from cfile */
 514 
 515         cpath[0] = tcpath[0] = '\0';
 516 
 517         if (ient == 0 || ppcfent == NULL || ppcfent[0] == NULL) {
 518                 goto remove_done;
 519         }
 520 
 521         if ((get_special_contents(pcroot, &ppcSC, &max)) != 0) {
 522                 result = 1;
 523                 goto remove_done;


 583         }
 584 
 585         if (generate_special_contents_rules(ient, ppcfent, ppcSC, max, &piIndex)
 586             != 0) {
 587                 result = 1;
 588                 goto remove_done;
 589         }
 590 
 591         /*
 592          * Copy contents to t.contents unless there is an entry in
 593          * the ppcfent array which corresponds to an index set to 1.
 594          *
 595          * These items are the removed package contents which matche an
 596          * entry in ppcSC (the special_contents rules).
 597          *
 598          * Since both the contents and rules are sorted, we can
 599          * make a single efficient pass.
 600          */
 601         (void) memset(line, 0, LINESZ);
 602 
 603         for (i = 0; fgets(line, LINESZ, fpi) != NULL; ) {
 604 
 605                 char *pcpath = NULL;
 606 
 607                 /*
 608                  * Note:  This could be done better:  We should figure out
 609                  * which are the last 2 lines and only trim those off.
 610                  * This will suffice to do this and will only be done as
 611                  * part of special_contents handling.
 612                  */
 613                 if (line[0] == '#')
 614                         continue; /* Do not copy the final 2 comment lines */
 615 
 616                 pcpath = get_path(line);
 617 
 618                 if (pcpath != NULL && i < ient) {
 619                         int k;
 620                         while (piIndex[i] == 0)
 621                                 i++;
 622 
 623                         if (i < ient)