// File: /workspace/github_cpp_makefile_star2_O3/wangyufei95[P]watchdog_linux/watchdog.cpp
// Function: Supervisor::parseArgs(int, char**)
bool Supervisor::parseArgs(int argc, char* argv[]) 
	{
	  if (argc <= 1) 
	  {
		printHelp();
		return false;
	  }

	  struct option opts[] = {
		  					  {"fork",no_argument,nullptr,'f'},
							  {"delay-limit", required_argument, nullptr, 'l'},
							  {"restart-on-error", no_argument, nullptr, 'e'},
							  {"restart-on-crash", no_argument, nullptr, 'c'},
							  {0, 0, 0, 0}
							  };

	  int logLevel = 2;

	  for (;;) 
	  {
		int long_index = 0;
		switch (getopt_long(argc, argv, "fp:l:fec", opts, &long_index)) 
		{
			case 'f':
				fork_= true;
				break;
		  	case 'l':
			// TODO: ensure optarg is a number
				restartDelayLimit_ = atoi(optarg);
        		break;
      		case 'e':
        		restartOnError_ = true;
        		break;
      		case 'c':
        		restartOnCrash_ = true;
        		break;
      		case 0:  // long option with (val!=nullptr && flag=0)
        		break;
      		case -1: {
        // EOF - everything parsed.
        		if (optind == argc) 
				{
          			logger()->error("no program path given");
          			return false;
        		}

        std::vector<std::string> args;
        while (optind < argc) 
		{
          args.push_back(argv[optind++]);
        }

        if (args[0].empty() || args[0][0] != '/') 
		{
          logger()->error("program path must be absolute.");
          return false;
        }

        if (getuid() && getuid()) 
		{
          logger()->error("Must run as (setuid) root. Please fix permissions.");
          return false;
        }

        if (fork_) 
		{
          int rv = daemon(1, 1);   //�ɹ�Ϊ0  ʧ��Ϊ-1
          if (rv < 0) 
		  {
            logger()->error("Could not daemonize into background. %s",
                            strerror(errno));

            return false;
          }
        }

        logger_.setLogLevel(logLevel);

        program_.reset(new Program(logger(), args[0], args, mainPidfile_));

        auto signals = {SIGINT,  SIGQUIT, SIGTERM, SIGCONT,
                        SIGUSR1, SIGUSR2, SIGTTIN, SIGTTOU};

        for (int sig : signals) 
		{
          signal(sig, &Supervisor::sighandler);
        }

        return true;
      }
      case '?':  // ambiguous match / unknown arg
      default:
        return false;
    }
  }
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
cmpl $0x1, %esi
jg 0x5ea4
leaq 0x26b4(%rip), %rdi      # 0x854e
callq 0x3580
jmp 0x5f73
movq %rdx, %r14
movl %esi, %r15d
movq %rdi, -0x30(%rbp)
leaq 0x4e1b(%rip), %rsi      # 0xacd0
leaq -0x110(%rbp), %rdi
movl $0xa0, %edx
callq 0x32d0
leaq 0x2408(%rip), %r13      # 0x82d5
leaq -0x38(%rbp), %rbx
leaq 0x2148(%rip), %r12      # 0x8020
movl $0x0, -0x38(%rbp)
movl %r15d, %edi
movq %r14, %rsi
movq %r13, %rdx
leaq -0x110(%rbp), %rcx
movq %rbx, %r8
callq 0x3600
leal -0x63(%rax), %ecx
cmpl $0x9, %ecx
ja 0x5f18
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
movq -0x30(%rbp), %rax
movl $0x1, 0x80(%rax)
jmp 0x5ed8
testl %eax, %eax
je 0x5ed8
jmp 0x5f50
movq -0x30(%rbp), %rax
movb $0x1, 0x84(%rax)
jmp 0x5ed8
movq -0x30(%rbp), %rax
movl $0x1, 0x7c(%rax)
jmp 0x5ed8
movq 0x5061(%rip), %rax      # 0xafa0
movq (%rax), %rdi
callq 0x35a0
movq -0x30(%rbp), %rcx
movl %eax, 0x78(%rcx)
jmp 0x5ed8
cmpl $-0x1, %eax
jne 0x5f73
movq 0x506c(%rip), %rbx      # 0xafc8
movl (%rbx), %eax
cmpl %r15d, %eax
jne 0x5f89
leaq 0x2374(%rip), %rsi      # 0x82de
movq -0x30(%rbp), %rdi
callq 0x6924
xorl %ebx, %ebx
movl %ebx, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorps %xmm0, %xmm0
leaq -0x50(%rbp), %rcx
movaps %xmm0, (%rcx)
movq $0x0, 0x10(%rcx)
leaq -0x70(%rbp), %r12
leaq -0x31(%rbp), %r13
leal 0x1(%rax), %ecx
movl %ecx, (%rbx)
cltq
movq (%r14,%rax,8), %rsi
movq %r12, %rdi
movq %r13, %rdx
callq 0x3120
leaq -0x50(%rbp), %rdi
movq %r12, %rsi
callq 0x73f0
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x5fd7
callq 0x3370
movl (%rbx), %eax
cmpl %r15d, %eax
jl 0x5fa3
movq -0x50(%rbp), %rax
leaq 0x230b(%rip), %rsi      # 0x82f4
cmpq $0x0, 0x8(%rax)
je 0x6017
movq (%rax), %rax
cmpb $0x2f, (%rax)
movq -0x30(%rbp), %rbx
jne 0x601b
callq 0x3180
testl %eax, %eax
je 0x6033
callq 0x3180
testl %eax, %eax
je 0x6033
leaq 0x22fe(%rip), %rsi      # 0x8313
jmp 0x601b
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
callq 0x6924
xorl %ebx, %ebx
leaq -0x50(%rbp), %rdi
callq 0x6638
jmp 0x5f75
cmpb $0x1, 0x84(%rbx)
jne 0x604f
movl $0x1, %edi
movl $0x1, %esi
callq 0x3460
testl %eax, %eax
js 0x60b6
movl $0x2, 0x20(%rbx)
movl $0x88, %edi
callq 0x33b0
movq %rax, %r14
leaq -0x50(%rbp), %rcx
movq (%rcx), %rdx
leaq 0x50(%rbx), %r8
movq %rax, %rdi
movq %rbx, %rsi
callq 0x59be
addq $0x28, %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x763c
xorl %r14d, %r14d
leaq 0x269e(%rip), %r15      # 0x8730
leaq 0x89(%rip), %rbx        # 0x6122
movl (%r14,%r15), %edi
movq %rbx, %rsi
callq 0x3450
addq $0x4, %r14
cmpq $0x20, %r14
jne 0x6099
movb $0x1, %bl
jmp 0x6025
callq 0x3040
movl (%rax), %edi
callq 0x30e0
leaq 0x227d(%rip), %rsi      # 0x8346
movq %rbx, %rdi
movq %rax, %rdx
callq 0x6838
jmp 0x6023
jmp 0x60e5
movq %rax, %rbx
movq %r14, %rdi
jmp 0x60fa
jmp 0x60e5
movq %rax, %rbx
jmp 0x60ff
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x60ff
callq 0x3370
leaq -0x50(%rbp), %rdi
callq 0x6638
movq %rbx, %rdi
callq 0x3630