From 696875f82762047b983d1f002ca9a88d458e64b5 Mon Sep 17 00:00:00 2001 From: Paul Wise Date: Mon, 29 Sep 2014 10:50:19 +0800 Subject: [PATCH] Port LastlogTimes object to platforms with a 64-bit lastlog.ll_time Fixes this error from merulo, an ia64 machine: Traceback (most recent call last): File "/etc/cron.weekly/puppet-mail-big-homedirs", line 256, in HomedirReminder().run() File "/etc/cron.weekly/puppet-mail-big-homedirs", line 166, in __init__ self.lastlog_times = LastlogTimes() File "/etc/cron.weekly/puppet-mail-big-homedirs", line 125, in __init__ lastlog_time, _, _ = list(struct.unpack(self.LASTLOG_STRUCT, record)) struct.error: unpack requires a string argument of length 292 --- modules/porterbox/files/mail-big-homedirs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/modules/porterbox/files/mail-big-homedirs b/modules/porterbox/files/mail-big-homedirs index 42118055..763afa53 100755 --- a/modules/porterbox/files/mail-big-homedirs +++ b/modules/porterbox/files/mail-big-homedirs @@ -114,10 +114,21 @@ class SendmailError(Error): pass class LastlogTimes(dict): - LASTLOG_STRUCT = '=L32s256s' + LASTLOG_STRUCT_32 = '=L32s256s' + LASTLOG_STRUCT_64 = '=Q32s256s' def __init__(self): - record_size = struct.calcsize(self.LASTLOG_STRUCT) + record_size_32 = struct.calcsize(self.LASTLOG_STRUCT_32) + record_size_64 = struct.calcsize(self.LASTLOG_STRUCT_64) + lastlog_size = os.path.getsize('/var/log/lastlog') + if 0 == (lastlog_size % record_size_32): + self.LASTLOG_STRUCT = self.LASTLOG_STRUCT_32 + record_size = record_size_32 + elif 0 == (lastlog_size % record_size_64): + self.LASTLOG_STRUCT = self.LASTLOG_STRUCT_64 + record_size = record_size_64 + else: + raise RuntimeError('Unknown architecture, cannot interpret /var/log/lastlog file size (%d)' % lastlog_size) with open('/var/log/lastlog', 'r') as fp: uid = -1 # there is one record per uid in lastlog for record in iter(lambda: fp.read(record_size), ''): -- 2.39.2