Skip to content

Merge pull request #1 from icattlecoder/dev#5

Open
icattlecoder wants to merge 2 commits intodevfrom
master
Open

Merge pull request #1 from icattlecoder/dev#5
icattlecoder wants to merge 2 commits intodevfrom
master

Conversation

@icattlecoder
Copy link
Owner

@icattlecoder icattlecoder commented Aug 2, 2023

init

✨ PR Description

Purpose: Fix daemon flag detection to handle both short-form and explicit true value formats, enabling proper daemonization behavior across different command-line argument patterns.
Main changes:

  • Extended daemon flag condition to recognize "-d" short form in addition to "-d=true" format for improved CLI compatibility
  • Modified flag parsing logic to convert any recognized daemon flag to "-d=false" for proper subprocess initialization

Generated by LinearB AI and added by gitStream.
AI-generated content may contain inaccuracies. Please verify before using.
💡 Tip: You can customize your AI Description using Guidelines Learn how

Greptile Summary

Fixed critical infinite recursion bug by extending daemon flag detection to handle both -d and -d=true formats.

  • Previously only recognized -d=true, causing infinite subprocess spawning when users passed -d
  • Now correctly identifies both flag formats and converts them to -d=false for child processes
  • Minor edge case: space-separated format -d true may leave dangling true argument, though unlikely to cause issues in practice

Confidence Score: 4/5

  • This PR is safe to merge with minimal risk
  • The fix addresses a critical infinite recursion bug with a simple, logical change. The code correctly handles the two most common flag formats. Only minor edge case with space-separated format that's unlikely to occur in practice.
  • No files require special attention

Important Files Changed

Filename Overview
godaemon.go Fixed daemon flag detection to handle both -d and -d=true formats, preventing infinite subprocess spawning

Sequence Diagram

sequenceDiagram
    participant User
    participant MainProcess
    participant FlagParser
    participant ChildProcess
    
    User->>MainProcess: Start app with -d flag
    MainProcess->>FlagParser: Parse command line args
    FlagParser->>FlagParser: Check if -d or -d=true present
    
    alt Daemon flag detected (-d or -d=true)
        FlagParser->>FlagParser: Set *godaemon = true
        MainProcess->>MainProcess: Loop through os.Args
        MainProcess->>MainProcess: Find -d or -d=true
        MainProcess->>MainProcess: Replace with -d=false
        MainProcess->>ChildProcess: Spawn subprocess with modified args
        ChildProcess-->>MainProcess: Return PID
        MainProcess->>User: Print PID
        MainProcess->>MainProcess: Exit(0)
        
        Note over ChildProcess: Child runs with -d=false
        ChildProcess->>FlagParser: Parse args with -d=false
        FlagParser->>FlagParser: Set *godaemon = false
        ChildProcess->>ChildProcess: Skip daemonization
        ChildProcess->>ChildProcess: Continue normal execution
    else No daemon flag
        MainProcess->>MainProcess: Continue normal execution
    end
Loading

Copy link

@linearb linearb bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✨ PR Review

LGTM

Generated by LinearB AI and added by gitStream.
AI-generated content may contain inaccuracies. Please verify before using.
💡 Tip: You can customize your AI Review using Guidelines Learn how

@linearb linearb bot added the 1 min review label Jan 4, 2026
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

i := 0
for ; i < len(args); i++ {
if args[i] == "-d=true" {
if args[i] == "-d" || args[i] == "-d=true" {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: The space-separated format -d true is also valid for Go boolean flags. When this format is used, the loop finds -d and converts it to -d=false, but leaves true as a dangling argument. Consider handling this case:

Suggested change
if args[i] == "-d" || args[i] == "-d=true" {
if args[i] == "-d" || args[i] == "-d=true" {
if args[i] == "-d" && i+1 < len(args) && args[i+1] == "true" {
args = append(args[:i+1], args[i+2:]...)
}
args[i] = "-d=false"
break
}
Prompt To Fix With AI
This is a comment left during a code review.
Path: godaemon.go
Line: 20:20

Comment:
**style:** The space-separated format `-d true` is also valid for Go boolean flags. When this format is used, the loop finds `-d` and converts it to `-d=false`, but leaves `true` as a dangling argument. Consider handling this case:

```suggestion
			if args[i] == "-d" || args[i] == "-d=true" {
				if args[i] == "-d" && i+1 < len(args) && args[i+1] == "true" {
					args = append(args[:i+1], args[i+2:]...)
				}
				args[i] = "-d=false"
				break
			}
```

How can I resolve this? If you propose a fix, please make it concise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants