/*
* 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.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
#include "stdarg.h"
#include "stdlib.h"
#include "fcntl.h"
#include "lpsched.h"
static void check_link();
/**
** lpfsck()
**/
#define F 0
#define D 1
#define P 2
#define S 3
static void proto (int, int, ...);
static int va_makepath(va_list *, char **);
static void _rename (char *, char *, ...);
void
lpfsck(void)
{
/*
* Force log messages to go into the log file instead of stdout.
*/
am_in_background = 1;
/*
* Most of these lines repeat the prototype file from the
* packaging and should match those items exactly.
* (In fact, they probably ought to be generated from that file,
* but that work is for a rainy day...)
*/
/*
* DIRECTORIES:
*/
/*
* DIRECTORIES: not described in the packaging
*/
/*
* THE MAIN FIFO:
*/
/*
* SYMBOLIC LINKS:
* Watch out! These names are given in the reverse
* order found in the prototype file (sorry!)
*/
/* S, 1, Lp_Tmp, Local_System, ... DONE BELOW */
/*
* OTHER FILES:
*/
/*
* SPECIAL CASE:
* If the "temp" symbolic link already exists,
* but is not correct, assume the machine's nodename changed.
* Rename directories that include the nodename, if possible,
* so that unprinted requests are saved. Then change the
* symbolic link.
* Watch out for a ``symbolic link'' that isn't!
*/
default:
break;
case S_IFDIR:
break;
case S_IFLNK:
check_link();
break;
}
return;
}
static void
{
int len;
char *real_dir;
char *old_system;
return;
}
/*
* If the symbolic link contained trailing slashes, remove
* them.
*/
len--;
}
return;
}
/*
* Check that symlink points to something.
* There should be at least 2 characters
* a '/' and another character.
*/
return;
}
else
old_system++;
/*
* The "rename()" system call (buried
* inside the "_rename()" routine) should
* succeed, even though we blindly created
* the new directory earlier, as the only
* directory entries should be . and ..
* (although if someone already created
* them, we'll note the fact).
*/
}
}
/**
** proto()
**/
static void
{
char *path,
*symbolic;
int exist,
err;
switch (type) {
case S:
if (!exist)
return;
case D:
if (!rm_ok)
else {
exist = 0;
}
}
if (!exist)
break;
case F:
if (!rm_ok)
else {
exist = 0;
}
}
if (!exist)
break;
case P:
/*
* Either a pipe or a file.
*/
if (exist &&
if (!rm_ok)
else {
exist = 0;
}
}
if (!exist)
break;
}
return;
}
/*
* va_makepath()
*
* Takes a variable length list of path components and attempts to string them
* together into a path. It returns a heap-allocated string via the output
* parameter 'ret', and returns an integer success value: < 0 indicates failure,
* 0 indicates success. Note that 'ret' will never be NULL (unless the system
* is so overloaded that it can't allocate a single byte), and should always be
* free()d.
*/
static int
{
char *component;
int buflen;
return (-1);
}
}
/* remove the trailing slash */
}
return (-1);
}
return (0);
}
/**
** _rename()
**/
static void
{
char * prefix;
char * old;
char * new;
int err;
fail (
"Rename failed; prefix \"%s\" is a truncated name.\n",
);
note (
"Rename of %s to %s failed because %s exists.\n",
old,
new,
);
else
fail (
"Rename of %s to %s failed (%s).\n",
old,
new,
);
return;
}