// File: /workspace/github_cpp_makefile_star2_O1/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 $0x108, %rsp            # imm = 0x108
cmpl $0x1, %esi
jg 0x5eb3
leaq 0x26b6(%rip), %rdi      # 0x854e
callq 0x3580
xorl %eax, %eax
andb $0x1, %al
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %rbx
movl %esi, %r14d
movq %rdi, %r15
leaq 0x4e0d(%rip), %rsi      # 0xacd0
leaq -0x130(%rbp), %rdi
movl $0xa0, %edx
callq 0x32d0
leaq 0x28(%r15), %rax
movq %rax, -0x68(%rbp)
movq %r15, -0x30(%rbp)
leaq 0x50(%r15), %rax
movq %rax, -0x70(%rbp)
movq 0x50d9(%rip), %r12      # 0xafc8
leaq -0x90(%rbp), %r13
movl %eax, %r15d
movl $0x0, -0x3c(%rbp)
movl %r14d, %edi
movq %rbx, %rsi
leaq 0x23c8(%rip), %rdx      # 0x82d5
leaq -0x130(%rbp), %rcx
leaq -0x3c(%rbp), %r8
callq 0x3600
movl %eax, %ecx
xorl %edx, %edx
leal -0x63(%rcx), %eax
cmpl $0x9, %eax
ja 0x5f4b
leaq 0x20f0(%rip), %rsi      # 0x8020
movslq (%rsi,%rax,4), %rcx
addq %rsi, %rcx
xorl %eax, %eax
jmpq *%rcx
movq -0x30(%rbp), %rax
movl $0x1, 0x80(%rax)
jmp 0x5f8b
cmpl $-0x1, %ecx
je 0x5f9d
movl $0x0, %eax
testl %ecx, %ecx
je 0x5f8b
jmp 0x5f90
movq 0x503e(%rip), %rax      # 0xafa0
movq (%rax), %rdi
callq 0x35a0
movq -0x30(%rbp), %rcx
movl %eax, 0x78(%rcx)
jmp 0x5f8b
movq -0x30(%rbp), %rax
movl $0x1, 0x7c(%rax)
jmp 0x5f8b
movq -0x30(%rbp), %rax
movb $0x1, 0x84(%rax)
movb $0x1, %dl
movl %r15d, %eax
testb %dl, %dl
jne 0x5ef6
jmp 0x5e9f
cmpl %r14d, (%r12)
jne 0x5fb9
movq -0x30(%rbp), %rdi
leaq 0x2330(%rip), %rsi      # 0x82de
callq 0x6998
xorl %edx, %edx
xorl %eax, %eax
jmp 0x5f90
xorps %xmm0, %xmm0
movaps %xmm0, -0x60(%rbp)
movq $0x0, -0x50(%rbp)
movl (%r12), %eax
cmpl %r14d, %eax
jge 0x600d
leal 0x1(%rax), %ecx
movl %ecx, (%r12)
cltq
movq (%rbx,%rax,8), %rsi
movq %r13, %rdi
leaq -0x31(%rbp), %rdx
callq 0x3120
leaq -0x60(%rbp), %rdi
movq %r13, %rsi
callq 0x744c
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x5fc8
callq 0x3370
jmp 0x5fc8
movq -0x60(%rbp), %rax
cmpq $0x0, 0x8(%rax)
leaq 0x22d7(%rip), %rsi      # 0x82f4
je 0x6047
movq (%rax), %rax
cmpb $0x2f, (%rax)
leaq 0x22c8(%rip), %rsi      # 0x82f4
jne 0x6047
callq 0x3180
testl %eax, %eax
je 0x6063
callq 0x3180
leaq 0x22d0(%rip), %rsi      # 0x8313
testl %eax, %eax
je 0x6063
movq -0x30(%rbp), %rdi
callq 0x6998
xorl %r15d, %r15d
leaq -0x60(%rbp), %rdi
callq 0x66b6
xorl %edx, %edx
jmp 0x5f8d
movq -0x30(%rbp), %rax
cmpb $0x1, 0x84(%rax)
jne 0x60af
movl $0x1, %edi
movl $0x1, %esi
callq 0x3460
testl %eax, %eax
jns 0x60ab
movl %eax, -0x38(%rbp)
callq 0x3040
movl (%rax), %edi
callq 0x30e0
movq -0x30(%rbp), %rdi
leaq 0x22a9(%rip), %rsi      # 0x8346
movq %rax, %rdx
callq 0x68ac
xorl %r15d, %r15d
movl -0x38(%rbp), %eax
testl %eax, %eax
js 0x6053
movq -0x30(%rbp), %r15
movl $0x2, 0x20(%r15)
movl $0x88, %edi
callq 0x33b0
movq %rax, %r12
movq -0x60(%rbp), %rdx
movq %rax, %rdi
movq %r15, %rsi
leaq -0x60(%rbp), %rcx
movq -0x70(%rbp), %r8
callq 0x599e
movq -0x68(%rbp), %rdi
movq %r12, %rsi
callq 0x7698
xorl %r15d, %r15d
leaq 0x263b(%rip), %r13      # 0x8730
leaq 0x78(%rip), %r12        # 0x6174
movl (%r15,%r13), %edi
movq %r12, %rsi
callq 0x3450
addq $0x4, %r15
cmpq $0x20, %r15
jne 0x60fc
movb $0x1, %r15b
leaq -0x90(%rbp), %r13
movq 0x4ea5(%rip), %r12      # 0xafc8
jmp 0x6053
jmp 0x6134
movq %rax, %rbx
movq %r12, %rdi
jmp 0x614c
jmp 0x6134
movq %rax, %rbx
jmp 0x6151
movq %rax, %rbx
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x6151
callq 0x3370
leaq -0x60(%rbp), %rdi
callq 0x66b6
movq %rbx, %rdi
callq 0x3630