mirror of
https://gogs.blitter.com/RLabs/goutmp
synced 2024-08-14 19:26:41 +00:00
Fixed crash when ttyname(STDIN_FILENO) returns NULL (if parent program is a daemon)
* TODO: add ability for callers to C.pututmp() to provide pty dev name for above case Signed-off-by: Russ Magee <rmagee@gmail.com>
This commit is contained in:
parent
9a2ce6f43e
commit
907ffc4058
1 changed files with 10 additions and 9 deletions
19
goutmp.go
19
goutmp.go
|
@ -17,22 +17,26 @@ package goutmp
|
|||
//
|
||||
//
|
||||
//void pututmp(struct utmp* entry, char* name, char* host) {
|
||||
// //int32_t stat = system("echo ---- pre ----;who");
|
||||
// //TODO: if ttyname returns NULL, it's probably a network
|
||||
// // connection and the pty should be passed in to this func.
|
||||
// char* stdinName = ttyname(STDIN_FILENO);
|
||||
// if( !stdinName ) {
|
||||
// stdinName = "/dev/ptyN";
|
||||
// }
|
||||
//
|
||||
// entry->ut_type = USER_PROCESS;
|
||||
// entry->ut_pid = getpid();
|
||||
// strcpy(entry->ut_line, ttyname(STDIN_FILENO) + strlen("/dev/"));
|
||||
// strcpy(entry->ut_line, stdinName + strlen("/dev/"));
|
||||
// /* only correct for ptys named /dev/tty[pqr][0-9a-z] */
|
||||
//
|
||||
// strcpy(entry->ut_id, ttyname(STDIN_FILENO) + strlen("/dev/tty"));
|
||||
// strcpy(entry->ut_id, stdinName + strlen("/dev/tty"));
|
||||
//
|
||||
// entry->ut_time = time(NULL);
|
||||
// strcpy(entry->ut_user, name);
|
||||
// strcpy(entry->ut_host, host);
|
||||
// entry->ut_addr = 0;
|
||||
// setutent();
|
||||
// pututline(entry);
|
||||
//
|
||||
// //stat = system("echo ---- post ----;who");
|
||||
//}
|
||||
//
|
||||
//void unpututmp(struct utmp* entry) {
|
||||
|
@ -43,8 +47,6 @@ package goutmp
|
|||
// setutent();
|
||||
// pututline(entry);
|
||||
//
|
||||
// //int32_t stat = system("echo ---- cleanup ----;who; lastlog");
|
||||
//
|
||||
// endutent();
|
||||
//}
|
||||
//
|
||||
|
@ -78,7 +80,6 @@ import "C"
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"os/user"
|
||||
"strings"
|
||||
|
@ -111,7 +112,7 @@ func GetHost(addr string) (h string) {
|
|||
func Put_utmp(user string, host string) UtmpEntry {
|
||||
var entry UtmpEntry
|
||||
|
||||
log.Println("Put_utmp:host ", host, " user ", user)
|
||||
//log.Println("Put_utmp:host ", host, " user ", user)
|
||||
C.pututmp(&entry.entry, C.CString(user), C.CString(host))
|
||||
return entry
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue