From owner-freebsd-hackers Wed Jan 22 22:59:56 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id WAA02428 for hackers-outgoing; Wed, 22 Jan 1997 22:59:56 -0800 (PST) Received: from fredriks-1.pr.mcs.net (fredriks-1.pr.mcs.net [205.164.50.241]) by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id WAA02423 for ; Wed, 22 Jan 1997 22:59:53 -0800 (PST) Received: from fredriks-1.pr.mcs.net (fredriks-2.pr.mcs.net [205.164.50.242]) by fredriks-1.pr.mcs.net (8.8.4/8.6.6) with SMTP id AAA14328 for ; Thu, 23 Jan 1997 00:59:29 -0600 (CST) Message-ID: <32E70C51.41C67EA6@mcs.com> Date: Thu, 23 Jan 1997 00:59:29 -0600 From: Lars Fredriksen Reply-To: fredriks@mcs.com Organization: Flaaklypa Hackers X-Mailer: Mozilla 3.0 (X11; I; FreeBSD 3.0-CURRENT i386) MIME-Version: 1.0 To: hackers@freebsd.org Subject: Modifications to pppd to make it log connecton times Content-Type: multipart/mixed; boundary="------------446B9B3D2781E494167EB0E7" Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk This is a multi-part message in MIME format. --------------446B9B3D2781E494167EB0E7 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi, Here are context diffs to pppd that makes pppd log the total time in minutes that it has been connected(similar to what ppp does). I don't know if I have caught every way pppd can exit(it obviously doesn't do this if it dumps core or the machine panics) to make sure the data is printed out, but it does work for the normal cases for sure. This helps one track online time and you can write scripts to monitor this so that you don't use over your limit(if your account have such limits). Please comment on them, or commit them (if they are deemed appropriate) or let me know and I can commit them as well. Sincerely, Lars --------------446B9B3D2781E494167EB0E7 Content-Type: text/plain; charset=us-ascii; name="auth.c.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="auth.c.diff" Index: auth.c =================================================================== RCS file: /home/ncvs/src/usr.sbin/pppd/auth.c,v retrieving revision 1.10 diff -c -r1.10 auth.c *** auth.c 1997/01/14 07:15:59 1.10 --- auth.c 1997/01/17 05:40:32 *************** *** 131,142 **** link_terminated(unit) int unit; { if (phase == PHASE_DEAD) return; if (logged_in) ppplogout(); phase = PHASE_DEAD; ! syslog(LOG_NOTICE, "Connection terminated."); } /* --- 131,148 ---- link_terminated(unit) int unit; { + extern time_t etime, stime; + extern int minutes; + if (phase == PHASE_DEAD) return; if (logged_in) ppplogout(); phase = PHASE_DEAD; ! etime = time((time_t *) NULL); ! minutes = (etime-stime)/60; ! syslog(LOG_NOTICE, "Connection terminated, connected for %d minutes\n", ! minutes > 1 ? minutes : 1); } /* --------------446B9B3D2781E494167EB0E7 Content-Type: text/plain; charset=us-ascii; name="main.c.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="main.c.diff" Index: main.c =================================================================== RCS file: /home/ncvs/src/usr.sbin/pppd/main.c,v retrieving revision 1.8 diff -c -r1.8 main.c *** main.c 1997/01/14 07:16:16 1.8 --- main.c 1997/01/17 05:40:37 *************** *** 71,76 **** --- 71,78 ---- static pid_t pid; /* Our pid */ static pid_t pgrpid; /* Process Group ID */ static uid_t uid; /* Our real user-id */ + time_t etime,stime; /* End and Start time */ + int minutes; /* connection duration */ int fd = -1; /* Device file descriptor */ *************** *** 221,226 **** --- 223,229 ---- } pid = getpid(); p = getlogin(); + stime = time((time_t *) NULL); if (p == NULL) { pw = getpwuid(uid); if (pw != NULL && pw->pw_name != NULL) *************** *** 468,474 **** return; if (len == 0) { ! syslog(LOG_NOTICE, "Modem hangup"); hungup = 1; lcp_lowerdown(0); /* serial link is no longer available */ phase = PHASE_DEAD; --- 471,479 ---- return; if (len == 0) { ! etime = time((time_t *) NULL); ! minutes = (etime-stime)/60; ! syslog(LOG_NOTICE, "Modem hangup, connected for %d minutes", (minutes >1) ? minutes : 1); hungup = 1; lcp_lowerdown(0); /* serial link is no longer available */ phase = PHASE_DEAD; --------------446B9B3D2781E494167EB0E7--