#!/bin/perl # (C) Copyright 1993 Rahul Dhesi, All Rights Reserved # ... except that permission is granted for copying and creation # of derivative works under the same conditions as perl. # $Header: /local/undoc/RCS/wtrim,v 1.13 1993/07/09 15:41:58 dhesi Exp $ # Trim the wtmp file to hold a specified number of records. # This script is offered "as is", though it appears to work under SunOS 4.1. # # <1> Rahul Dhesi # <2> dhesi@cirrus.com # <3> cmc@srg-ssr.ch solaris hacks # <4> sean@ch.swissbank.com Added comments/tabs # CAVEATS: # 1. There are two race conditions; one is minimized by creating an # /etc/nologin file, whose creation causes the second race condition. # Search for 'RACE CONDITION'. # 2. There is no check for the filesystem filling up while a temporary # copy of the wtmp file is made. $myname = "wtrim.pl"; $default = "/var/adm/[wu]tmp[x]"; if (@ARGV != 2) { print < $bs * $scale) { $bs *= $scale; $skip = int ($skip / $scale); } # delete first to save disk space unlink $OLD_WTMP; # disable logins (just for a second) if (! -e $nologin) { open (NOLOGIN, ">$nologin_new") || &exit("$myname: error: can't write to $nologin_new: $!\n"); print NOLOGIN <$NEW_WTMP 2>/dev/null"; # RACE CONDITION link ($WTMP, $OLD_WTMP) || &exit("$myname: error: link failed: $!\n"); rename($NEW_WTMP, $WTMP) || &exit("$myname: error: rename failed: $!\n"); &exit(); sub exit { local($msg) = @_; # re-enable logins $disabled && unlink $nologin; unlink $NEW_WTMP; unlink $nologin_new; if ($msg) { print $msg; exit(1); } exit(0); }; # END