From 6b94a9b6588112328fa2738b1c149b48908f5029 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 5 Sep 2015 00:34:21 -0600 Subject: clean up logging --- src/inotify/syscall.go | 9 ++++++++- src/nshd/hackers_git/hackers.go | 1 + src/nshd/hackers_git/hackers_parse.go | 8 ++++---- src/nshd/hackers_git/hackers_watch.go | 20 ++++++++++---------- src/nslcd_proto/func_handlerequest.go.sh | 1 + src/nslcd_proto/io.go | 4 ++-- 6 files changed, 26 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/inotify/syscall.go b/src/inotify/syscall.go index 245bc41..1b5c426 100644 --- a/src/inotify/syscall.go +++ b/src/inotify/syscall.go @@ -8,6 +8,13 @@ import ( type Cint C.int +func pathError(op string, path string, err error) error { + if err == nil { + return nil + } + return &os.PathError{Op: op, Path: path, Err: err} +} + /* Create and initialize inotify instance. */ func inotify_init() (Cint, error) { fd, errno := syscall.InotifyInit() @@ -24,7 +31,7 @@ func inotify_init1(flags Cint) (Cint, error) { events specified by MASK. */ func inotify_add_watch(fd Cint, name string, mask uint32) (Cint, error) { wd, errno := syscall.InotifyAddWatch(int(fd), name, mask) - return Cint(wd), os.NewSyscallError("inotify_add_watch", errno) + return Cint(wd), pathError("inotify_add_watch", name, errno) } /* Remove the watch specified by WD from the inotify instance FD. */ diff --git a/src/nshd/hackers_git/hackers.go b/src/nshd/hackers_git/hackers.go index 60e6dd9..0f2dd3d 100644 --- a/src/nshd/hackers_git/hackers.go +++ b/src/nshd/hackers_git/hackers.go @@ -43,6 +43,7 @@ func NewHackers(config Config) *Hackers { } err := o.Reload() if err != nil { + logger.Err("Could not initialize hackers.git: %v", err) return nil } o.workers.Add(1) diff --git a/src/nshd/hackers_git/hackers_parse.go b/src/nshd/hackers_git/hackers_parse.go index 14140da..f1f360f 100644 --- a/src/nshd/hackers_git/hackers_parse.go +++ b/src/nshd/hackers_git/hackers_parse.go @@ -111,12 +111,12 @@ func load_user_password(filename string) (hash string) { hash = "!" file, err := os.Open(filename) if err != nil { - logger.Info("Could not open: %q: %v", filename, err) + logger.Debug("hackers.git: %v", err) return } contents, err := ioutil.ReadAll(file) if err != nil { - logger.Info("Error while reading: %q: %v", filename, err) + logger.Debug("hackers.git: Error while reading: %q: %v", filename, err) return } lines := strings.Split(string(contents), "\n") @@ -127,10 +127,10 @@ func load_user_password(filename string) (hash string) { if lines[1] == "" { hash = lines[0] } else { - logger.Info("Invalid password format in file: %q", filename) + logger.Debug("hackers.git: Invalid password format in file: %q", filename) } default: - logger.Info("Invalid password format in file: %q", filename) + logger.Debug("hackers.git: Invalid password format in file: %q", filename) } return } diff --git a/src/nshd/hackers_git/hackers_watch.go b/src/nshd/hackers_git/hackers_watch.go index f1c4018..da008f8 100644 --- a/src/nshd/hackers_git/hackers_watch.go +++ b/src/nshd/hackers_git/hackers_watch.go @@ -29,7 +29,7 @@ func (o *Hackers) watchHomedir(uid int32) { o.in_wd2uid[wd] = uid } else { delete(o.in_uid2wd, uid) - logger.Info("could not watch: %s", o.users[uid].passwd.HomeDir) + logger.Debug("hackers.git: %v", err) } user := o.users[uid] user.passwd.PwHash = load_user_password(user.passwd.HomeDir + "/.password") @@ -39,7 +39,7 @@ func (o *Hackers) watchHomedir(uid int32) { func (o *Hackers) unwatchHomedir(wd inotify.Cint) { err := o.in_fd.RmWatch(wd) if err != nil { - logger.Warning("could not remove watch: %v", wd) + logger.Warning("hackers.git: %v", err) return } uid := o.in_wd2uid[wd] @@ -72,14 +72,14 @@ func (o *Hackers) reload() (err error) { o.in_uid2wd = make(map[int32]inotify.Cint, len(filenames)) o.in_wd2uid = make(map[inotify.Cint]int32, len(filenames)) for _, filename := range filenames { - logger.Info("Loading yaml file: %s", filename) + logger.Debug("hackers.git: Loading yaml file: %s", filename) user, err := load_user_yaml(filename) if err == nil { o.users[user.passwd.UID] = user - logger.Info("... success") + logger.Debug("hackers.git: ... success") o.watchHomedir(user.passwd.UID) } else { - logger.Info("... error: %v", err) + logger.Debug("hackers.git: ... error: %v", err) } } @@ -122,7 +122,7 @@ func (o *Hackers) worker_handle_passwd(uid int32) { } func worker_error(format string, a ...interface{}) { - logger.Err(format, a) + logger.Err("hackers.git: "+ format, a) os.Exit(int(lsb.EXIT_FAILURE)) } @@ -150,15 +150,15 @@ func (o *Hackers) worker() { panic("recieved child event from inotify, but no child name") } filename := o.cfg.Yamldir + "/" + *event.Name - logger.Info("Loading yaml file: %s", filename) + logger.Debug("hackers.git: Loading yaml file: %s", filename) user, err := load_user_yaml(filename) if err == nil { // User added/updated - logger.Info("... success") + logger.Debug("hackers.git: ... success") o.worker_handle_user_add(user) } else if user.passwd.UID >= 0 { // User became invalid - logger.Info("... error: %v", err) + logger.Debug("hackers.git: ... error: %v", err) o.worker_handle_user_del(user.passwd.UID) } } else { @@ -184,7 +184,7 @@ func (o *Hackers) worker() { o.worker_handle_passwd(o.in_wd2uid[event.Wd]) } } else { - logger.Debug("event didn't match: %#v", event) + logger.Debug("hackers.git: event didn't match: %#v", event) } } } diff --git a/src/nslcd_proto/func_handlerequest.go.sh b/src/nslcd_proto/func_handlerequest.go.sh index 185db73..62ef231 100755 --- a/src/nslcd_proto/func_handlerequest.go.sh +++ b/src/nslcd_proto/func_handlerequest.go.sh @@ -30,6 +30,7 @@ while read -r request; do case NSLCD_ACTION_${request^^}: var req Request_${request} read(in, &req) + fmt.Printf("request: %#v\n", req) res = backend.${request}(cred, req) EOT done < "$requests" diff --git a/src/nslcd_proto/io.go b/src/nslcd_proto/io.go index 321a87c..87783ac 100644 --- a/src/nslcd_proto/io.go +++ b/src/nslcd_proto/io.go @@ -70,7 +70,7 @@ func write(fd io.Writer, data interface{}) { write(fd, v.Field(i).Interface()) } default: - panic("Invalid structure for NSLCD protocol data") + panic(fmt.Sprintf("Invalid structure to write NSLCD protocol data from: %T ( %#v )", data, data)) } } } @@ -139,7 +139,7 @@ func read(fd io.Reader, data interface{}) { read(fd, v.Field(i).Interface()) } default: - panic("Invalid structure for NSLCD protocol data") + panic(fmt.Sprintf("The argument to nslcd_proto.read() must be a pointer: %T ( %#v )", data, data)) } } } -- cgit v1.2.3-54-g00ecf