Skip to content

Commit

Permalink
Merge pull request #20 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 1.4.5
  • Loading branch information
andyone committed Jan 20, 2016
2 parents ec0c695 + 5381e11 commit ab417d9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ sudo: false
os:
- linux
- osx
- freebsd

env:
- EK_TEST_PORT=8080
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Changelog

#### v1.4.5

* `[pid]` Fixed bug with pid file creation
* `[pid]` Increased coverage

#### v1.4.4

* `[errutil]` Added method Num which returns number of errors
Expand Down
22 changes: 10 additions & 12 deletions pid/pid.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,18 @@ func Create(name string) error {
if fsutil.IsExist(pidFile) {
err = os.Remove(pidFile)

fmt.Println(pidFile, err)

if err != nil {
return err
}
}

fd, err := os.OpenFile(pidFile, os.O_RDWR|os.O_CREATE, 0644)

if err != nil {
return err
}

_, err = fd.WriteString(fmt.Sprintf("%d\n", os.Getpid()))

return err
return ioutil.WriteFile(
pidFile,
[]byte(fmt.Sprintf("%d\n", os.Getpid())),
0644,
)
}

// Remove remove file with process pid file
Expand All @@ -69,9 +67,7 @@ func Remove(name string) error {

pidFile := Dir + "/" + normalizePidFilename(name)

os.Remove(pidFile)

return nil
return os.Remove(pidFile)
}

// Get return pid from pid file
Expand Down Expand Up @@ -100,6 +96,7 @@ func Get(name string) int {

// ////////////////////////////////////////////////////////////////////////////////// //

// checkPidDir check dir path and return error if dir not ok
func checkPidDir(path string) error {
switch {
case fsutil.IsExist(path) == false:
Expand All @@ -115,6 +112,7 @@ func checkPidDir(path string) error {
return nil
}

// normalizePidFilename return pidfile name with extension
func normalizePidFilename(name string) string {
if !strings.Contains(name, ".pid") {
return name + ".pid"
Expand Down

0 comments on commit ab417d9

Please sign in to comment.