Commit 87b7a33
committed
fix: Prevent file descriptor leaks in hook subprocess calls
**Problem**: EIO error (errno -5) on fd 17 when hooks executed due to
improper file descriptor handling in subprocess invocations.
**Root Cause**: Subprocesses (uuidgen, date, mnemosyne, jq) were
inheriting file descriptors from parent process without proper stdin
protection, causing read attempts on invalid/closed fds.
**Solution**: Added stdin protection to all subprocess calls:
- Commands that don't read stdin: Added `< /dev/null` (uuidgen, date, mnemosyne recall)
- jq with `-n` flag: Added `< /dev/null` (doesn't read stdin)
- jq reading files: Changed from `jq ... "$FILE"` to `jq ... < "$FILE"` (explicit stdin)
- jq in pipes: No stdin redirect needed (pipe IS stdin)
**Changes**:
- .claude/hooks/session-start.sh: Protected uuidgen, mnemosyne recall, jq -n calls
- .claude/hooks/post-tool-use.sh: Protected uuidgen, date, jq file reads
- .claude/hooks/on-stop.sh: Changed jq file reads to use stdin redirect
**Testing**:
✅ All hooks execute cleanly in silent mode (CC_HOOK_DEBUG=0)
✅ Debug output works correctly (CC_HOOK_DEBUG=1)
✅ Memory debt tracking functions properly
✅ No fd errors or warnings
**Related**: Complements terminal corruption fixes (#eec1a33, #048f26d)1 parent 048f26d commit 87b7a33
3 files changed
+11
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
| 14 | + | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | | - | |
| 133 | + | |
134 | 134 | | |
0 commit comments