From bdf19c16648afb50b922e417fafbe858bd14e935 Mon Sep 17 00:00:00 2001 From: Russ Magee Date: Fri, 29 Jun 2018 14:36:31 -0700 Subject: [PATCH] Use utmp APIs rather than utmpx to be more portable --- goutmp.go | 20 +++++++++----------- main/test.go | 15 ++++++++------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/goutmp.go b/goutmp.go index 1a463be..8f93293 100644 --- a/goutmp.go +++ b/goutmp.go @@ -5,20 +5,18 @@ package goutmp //#include //#include //#include -//#include //#include //#include //#include //#include // //#include -//#include //#include // //typedef char char_t; // // -//void pututmp(struct utmpx* entry, char* name, char* host) { +//void pututmp(struct utmp* entry, char* name, char* host) { // //int32_t stat = system("echo ---- pre ----;who"); // // entry->ut_type = USER_PROCESS; @@ -31,23 +29,23 @@ package goutmp // strcpy(entry->ut_user, name); // strcpy(entry->ut_host, host); // entry->ut_addr = 0; -// setutxent(); -// pututxline(entry); +// setutent(); +// pututline(entry); // // //stat = system("echo ---- post ----;who"); //} // -//void unpututmp(struct utmpx* entry) { +//void unpututmp(struct utmp* entry) { // entry->ut_type = DEAD_PROCESS; // memset(entry->ut_line, 0, UT_LINESIZE); // entry->ut_time = 0; // memset(entry->ut_user, 0, UT_NAMESIZE); -// setutxent(); -// pututxline(entry); +// setutent(); +// pututline(entry); // // //int32_t stat = system("echo ---- cleanup ----;who; lastlog"); // -// endutxent(); +// endutent(); //} // //int putlastlogentry(int64_t t, int uid, char* line, char* host) { @@ -86,9 +84,9 @@ import ( "time" ) -// UtmpEntry wraps the C struct utmpx +// UtmpEntry wraps the C struct utmp type UtmpEntry struct { - entry C.struct_utmpx + entry C.struct_utmp } // return remote client hostname or IP if host lookup fails diff --git a/main/test.go b/main/test.go index 518f1a5..ddcbc7b 100644 --- a/main/test.go +++ b/main/test.go @@ -1,14 +1,15 @@ package main import ( - "blitter.com/go/goutmp" + "blitter.com/go/goutmp" + "time" ) func main() { - user := "bin" - host := "test.example.com" - utmp := goutmp.Put_utmp(user, host) - goutmp.Put_lastlog_entry("hkexsh", user, host) - goutmp.Unput_utmp(utmp) + user := "bin" + host := "test.example.com" + utmp := goutmp.Put_utmp(user, host) + goutmp.Put_lastlog_entry("hkexsh", user, host) + time.Sleep(10 * time.Second) + goutmp.Unput_utmp(utmp) } -