dhcp: add --pidfile option to DHCP client daemon

This commit is contained in:
Dan Williams
2017-05-26 23:48:29 -05:00
parent 7cda9af13f
commit a38dd5f7a0
3 changed files with 28 additions and 5 deletions

View File

@ -15,7 +15,9 @@
package main
import (
"flag"
"fmt"
"log"
"net/rpc"
"os"
"path/filepath"
@ -30,7 +32,15 @@ const socketPath = "/run/cni/dhcp.sock"
func main() {
if len(os.Args) > 1 && os.Args[1] == "daemon" {
runDaemon()
var pidfilePath string
daemonFlags := flag.NewFlagSet("daemon", flag.ExitOnError)
daemonFlags.StringVar(&pidfilePath, "pidfile", "", "optional path to write daemon PID to")
daemonFlags.Parse(os.Args[2:])
if err := runDaemon(pidfilePath); err != nil {
log.Printf(err.Error())
os.Exit(1)
}
} else {
skel.PluginMain(cmdAdd, cmdDel, version.All)
}