Skip to content

Commit

Permalink
split main function;
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoqing committed Mar 23, 2021
1 parent b5d3055 commit 632d0c6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ graftcp-local/.gopath

*.o
*.d
*.a
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ TARGET = graftcp $(GRAFTCP_LOCAL_BIN)

all:: $(TARGET)

graftcp: main.o util.o string-set.o

graftcp: cmd.o libgraftcp.a
$(CC) $^ -o $@

libgraftcp.a: main.o util.o string-set.o
$(AR) rcs $@ $^

%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<

Expand Down
5 changes: 5 additions & 0 deletions cmd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
int _main(int argc, char **argv);

int main(int argc, char **argv){
return _main(argc, argv);
}
16 changes: 13 additions & 3 deletions graftcp-local/main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package main

import (
"flag"
_flag "flag"
"fmt"
"os"
"syscall"

"context"
"github.com/jedisct1/dlog"
"github.com/kardianos/service"
)
Expand Down Expand Up @@ -58,7 +59,9 @@ func (app *App) Stop(s service.Service) error {
return nil
}

func main() {
func local_main(cmdName string, args []string, ctx... context.Context) {
flag := _flag.NewFlagSet(cmdName, _flag.ExitOnError)

var configFile string
dlog.Init("graftcp-local", dlog.SeverityInfo, "")

Expand Down Expand Up @@ -90,7 +93,10 @@ func main() {
flag.StringVar(&configFile, "config", "", "Path to the configuration file")
flag.StringVar(&app.PipePath, "pipepath", "/tmp/graftcplocal.fifo", "Pipe path for graftcp to send address info")
v := flag.Bool("version", false, "Print the graftcp-local version information")
flag.Parse()
if err := flag.Parse(args); err!= nil{
fmt.Printf("Wrong command line arguments for %s: %s\n", cmdName, err.Error())
os.Exit(1)
}
if *v {
fmt.Printf("graftcp-local version %s\n", version)
os.Exit(0)
Expand Down Expand Up @@ -127,3 +133,7 @@ func main() {
app.Start(nil)
}
}

func main(){
local_main(os.Args[0], os.Args[1:])
}
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ static void usage(char **argv)
"\n", argv[0]);
}

int main(int argc, char **argv)
int _main(int argc, char **argv)
{
int opt, index;
bool ignore_local = true;
Expand Down

0 comments on commit 632d0c6

Please sign in to comment.