Permalink
Browse files

add function to mask passwords

  • Loading branch information...
justone committed Feb 27, 2014
1 parent 4a6849f commit 2b83dd76f374dfecbea027288f1d1761fc67756c
Showing with 22 additions and 0 deletions.
  1. +22 −0 process.go
View
@@ -0,0 +1,22 @@
package main
import (
"os"
"reflect"
"strings"
"unsafe"
)
// from http://stackoverflow.com/questions/14926020/setting-process-name-as-seen-by-ps-in-go
func MaskProcessArg(index int) error {
existing := os.Args[index]
argv0str := (*reflect.StringHeader)(unsafe.Pointer(&os.Args[index]))
argv0 := (*[1 << 30]byte)(unsafe.Pointer(argv0str.Data))[:argv0str.Len]
n := copy(argv0, strings.Repeat("x", len(existing)))
if n < len(argv0) {
argv0[n] = 0
}
return nil
}

0 comments on commit 2b83dd7

Please sign in to comment.