protodir.c revision 6d98517adc1eff16d9ed42954b8a8b19f7dc44db
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <strings.h>
#include <errno.h>
#include <dirent.h>
#include "list.h"
#include "protodir.h"
#include "arch.h"
#include "exception_list.h"
#define FS " \t\n"
static char *
{
char *p;
char *l_next;
char *l_pos;
static char curpath[MAXPATHLEN];
/* if absolute path - no relocation required */
if (link[0] == '/')
*p = '\0';
do {
*p = '\0';
else
curpath[0] = '\0';
/* if not . then we process */
if (curpath[0])
if (l_next) {
} else
}
} while (l_next);
return (curpath);
}
static int
const char *pkgname)
{
if (!e)
e->flag = 0;
return (-1);
}
return (-1);
}
/*
* Just ignore 'legacy' entries. These are not present in the proto
* area at all. They're phantoms.
*/
return (0);
line);
return (-1);
}
/*
* The '=' operator is subtly different for link and non-link
* entries. For the hard or soft link case, the left hand side
* exists in the proto area and is created by the package.
*
* When the file is an editable file, it's very likely that the
* right hand side is only a fragment of that file, which is
* delivered by multiple packages in the consolidation. Thus it
* can't exist in the proto area, and because we can't really
* know where the file's root directory is, we should skip the
* file.
*
* For all other filetypes, assume the right hand side is in the
* proto area.
*/
*src++ = '\0';
return (0);
} else {
}
}
/*
* if a basedir has a value, prepend it to the filename
*/
if (basedir[0])
else
if (e->file_type != SYM_LINK_T) {
if ((e->file_type == CHAR_DEV_T) ||
(e->file_type == BLOCK_DEV_T)) {
"error: bad line(major number) : %s\n",
line);
return (-1);
}
"error: bad line(minor number) : %s\n",
line);
return (-1);
}
} else {
e->major = -1;
e->minor = -1;
}
"error: bad line(permission) : %s\n", line);
return (-1);
}
"error: bad line(owner) : %s\n", line);
return (-1);
}
"error: bad line(group) : %s\n", line);
return (-1);
}
}
e->inode = 0;
e->ref_cnt = 1;
e->link_parent = NULL;
e = NULL;
return (1);
/* add entry to pkgs */
"warning: %s: Duplicate entry for %s\n",
return (-1);
}
"warning: %s: permissions %#o of %s do not match "
"previous permissions %#o\n",
}
"warning: %s: owner \"%s\" of %s does not match "
"previous owner \"%s\"\n",
}
"warning: %s: group \"%s\" of %s does not match "
"previous group \"%s\"\n",
}
} else {
/*
* Signal an error only if this is something that's not on the
* exception list.
*/
"warning: %s: duplicate entry for %s - ignored\n",
return (-1);
}
}
return (0);
}
static int
const char *pkgname)
{
if (!e)
e->flag = 0;
*src++ = '\0';
} else {
"error: %s: hard link does not have destination (%s)\n",
return (0);
}
/*
* if a basedir has a value, prepend it to the filename
*/
if (basedir[0])
else
/*
* now we need to find the file that we link to - to do this
* we build a key.
*/
"error: %s: hardlink to non-existent file: %s=%s\n",
return (0);
}
"error: %s: hardlink must link to a file or directory "
return (0);
}
e->link_parent = p;
p->link_sib = e;
p->ref_cnt++;
e = NULL;
return (1);
} else {
/*
* Signal an error only if this is something that's not on the
* exception list.
*/
"warning: %s: duplicate entry for %s - ignored\n",
return (-1);
}
}
return (0);
}
/*
* open up the pkginfo file and find the ARCH= and the BASEDIR= macros.
* I will set the arch and basedir variables based on these fields.
*/
static void
{
char pkginfofile[MAXPATHLEN];
char architecture[MAXPATHLEN];
int hits = 0;
int i;
int index;
architecture[0] = '\0';
basedir[0] = '\0';
/*
* determine whether the pkginfo file is a pkginfo.tmpl or
* a pkginfo file
*/
"pkginfo.tmpl");
"pkginfo");
return;
}
}
index = 0;
/*
* remove any '"' in the ARCH field.
*/
for (i = 5; buf[i]; i++) {
if (buf[i] != '"')
}
/* -1 because above copy included '\n' */
hits += 1;
index = 0;
/*
* remove any '"' in the BASEDIR field, and
* strip off a leading '/' if present.
*/
for (i = 8; buf[i]; i++) {
if (buf[i] != '"' &&
}
}
/* -1 because above copy included '\n' */
hits += 2;
}
}
(void) fclose(pkginfo_fp);
if (architecture[0])
"warning: Unknown architecture %s found in %s\n",
}
}
/*
* The first pass through the prototype file goes through and reads
* in all the entries except 'hard links'. Those must be processed
* in a second pass.
*
* If any !includes are found in the prototype file this routine
* will be called recursively.
*
* Args:
* protofile - full pathname to prototype file to be processed.
* protodir - directory in which prototype file resides.
* list - list to which elements will be added
* arch - architecture of current prototype
* basedir - basedir for package
* pkgname - name of package
*
* Returns:
* returns number of items added to list.
*
*/
static int
{
int elem_count = 0;
char include_file[MAXPATHLEN];
return (0);
}
/*
* first pass through file - process everything but
* hard links.
*/
int rc;
switch (buf[0]) {
case FILE_T:
case EDIT_T:
case VOLATILE_T:
case DIR_T:
case SYM_LINK_T:
case CHAR_DEV_T:
case BLOCK_DEV_T:
pkgname)) >= 0) {
elem_count += rc;
} else {
"error: Errors found in %s\n", protofile);
}
break;
case LINK_T:
case 'i':
case '#':
case '\n':
break;
case '!':
/* Is this an include statement - if so process */
/* burn white space */
while ((*inc_file == ' ') ||
(*inc_file == '\t'))
inc_file++;
if (*inc_file) {
/* remove trailing \n */
inc_file);
elem_count +=
pkgname);
} else {
"warning: bad !include statement "
"in prototype %s : %s\n",
}
} else {
"warning: unexpected ! notation in "
}
break;
default:
"warning: unexpected line in prototype %s : %s\n",
break;
}
}
return (elem_count);
}
/*
* The second pass through the prototype file goes through and reads
* and processes only the 'hard links' in the prototype file. These
* are resolved and added accordingly to the elements list(list).
*
* If any !includes are found in the prototype file this routine
* will be called recursively.
*
* Args:
* protofile - full pathname to prototype file to be processed.
* protodir - directory in which prototype file resides.
* list - list to which elements will be added
* arch - architecture of current prototype
* basedir - basedir for package
* pkgname - package name
*
* Returns:
* returns number of items added to list.
*
*/
static int
{
int elem_count = 0;
char include_file[MAXPATHLEN];
return (0);
}
/*
* second pass through prototype file - process the hard links
* now.
*/
int rc;
pkgname)) >= 0) {
elem_count += rc;
} else {
"error: Errors found in %s\n", protofile);
}
/*
* This is a file to include
*/
/* burn white space */
inc_file++;
if (*inc_file) {
/* remove trailing \n */
/* build up include file name to be opened. */
/*
* recursively call this routine to process the
* !include file.
*/
elem_count +=
} else {
"warning: Bad !include statement in "
}
}
return (elem_count);
}
/*
* Args:
* pkgname - name of package being processed
* protodir - pathname to package defs directory
* list - List of elements read in, elements are added to this
* as they are read in.
* verbose - verbose output
*
* Returns:
* number of elements added to list
*/
int
{
char protofile[MAXPATHLEN];
char basedir[MAXPATHLEN];
short arch;
int count = 0;
/*
* skip any packages we've already handled (because of
* dependencies)
*/
if (processed_package(pkgname)) {
return (0);
}
/*
* find the prototype file. Legal forms of the name are:
* prototype
* prototype_<mach> (where mach == (sparc || i386 || ppc)
*/
if (verbose) {
"warning: no prototype "
"file found in %s, "
"skipping...\n",
protodir);
}
} else
return (0);
}
} else {
return (0);
}
}
/* print_list(list); */
return (count);
}
int
{
char protodir[MAXPATHLEN];
int count = 0;
exit(1);
}
/*
* let's not check "." and ".." - I don't really like this
* but I wasn't really sure you could be sure that they
* are always the first two entries in the directory
* structure - so I put it in the loop.
*
* Also - we skip all directories that are names .del-*.
* and any SCCS directories too.
*/
continue;
continue;
}
if (verbose) {
"warning: %s not a directory\n", protodir);
}
continue;
}
verbose);
verbose);
}
if (verbose)
return (count);
}