Changeset 2aa05d4ff7651db8e132f49e6248b0f29a88bffa
- Timestamp:
- 04/22/12 14:26:59
(1 year ago)
- Author:
- Theo Schlossnagle <jesus@omniti.com>
- git-committer:
- Theo Schlossnagle <jesus@omniti.com> 1335104819 -0400
- git-parent:
[658ca094d9985caeb69da119a4a9ebc6f063e8b7]
- git-author:
- Theo Schlossnagle <jesus@omniti.com> 1335104819 -0400
- Message:
Add support for -D -D which will foreground the parent, but still fork and manage the child. Mainly for debugging dysfunctional parent-child relationships.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r86e0c6a |
r2aa05d4 |
|
| 215 | 215 | } |
|---|
| 216 | 216 | |
|---|
| 217 | | if(foreground) return passed_child_main(); |
|---|
| | 217 | if(foreground == 1) return passed_child_main(); |
|---|
| 218 | 218 | |
|---|
| 219 | 219 | watchdog_timeout_str = getenv("WATCHDOG_TIMEOUT"); |
|---|
| … | … | |
| 224 | 224 | } |
|---|
| 225 | 225 | |
|---|
| 226 | | /* This isn't inherited across forks... */ |
|---|
| 227 | | if(lockfd >= 0) noit_lockfile_release(lockfd); |
|---|
| 228 | | |
|---|
| 229 | | fd = open("/dev/null", O_RDWR); |
|---|
| 230 | | dup2(fd, STDIN_FILENO); |
|---|
| 231 | | dup2(fd, STDOUT_FILENO); |
|---|
| 232 | | dup2(fd, STDERR_FILENO); |
|---|
| 233 | | if(fork()) exit(0); |
|---|
| 234 | | setsid(); |
|---|
| 235 | | if(fork()) exit(0); |
|---|
| 236 | | |
|---|
| 237 | | /* Reacquire the lock */ |
|---|
| 238 | | if(*lockfile) { |
|---|
| 239 | | if(noit_lockfile_acquire(lockfile) < 0) { |
|---|
| 240 | | noitL(noit_stderr, "Failed to acquire lock: %s\n", lockfile); |
|---|
| 241 | | exit(-1); |
|---|
| | 226 | if(foreground < 1) { |
|---|
| | 227 | /* This isn't inherited across forks... */ |
|---|
| | 228 | if(lockfd >= 0) noit_lockfile_release(lockfd); |
|---|
| | 229 | |
|---|
| | 230 | fd = open("/dev/null", O_RDWR); |
|---|
| | 231 | dup2(fd, STDIN_FILENO); |
|---|
| | 232 | dup2(fd, STDOUT_FILENO); |
|---|
| | 233 | dup2(fd, STDERR_FILENO); |
|---|
| | 234 | if(fork()) exit(0); |
|---|
| | 235 | setsid(); |
|---|
| | 236 | if(fork()) exit(0); |
|---|
| | 237 | |
|---|
| | 238 | /* Reacquire the lock */ |
|---|
| | 239 | if(*lockfile) { |
|---|
| | 240 | if(noit_lockfile_acquire(lockfile) < 0) { |
|---|
| | 241 | noitL(noit_stderr, "Failed to acquire lock: %s\n", lockfile); |
|---|
| | 242 | exit(-1); |
|---|
| | 243 | } |
|---|
| 242 | 244 | } |
|---|
| 243 | 245 | } |
|---|
| r6e0e4eb |
r2aa05d4 |
|
| 121 | 121 | break; |
|---|
| 122 | 122 | case 'D': |
|---|
| 123 | | foreground = 1; |
|---|
| | 123 | foreground++; |
|---|
| 124 | 124 | break; |
|---|
| 125 | 125 | case 'd': |
|---|
| r87c5db7 |
r2aa05d4 |
|
| 124 | 124 | break; |
|---|
| 125 | 125 | case 'D': |
|---|
| 126 | | foreground = 1; |
|---|
| | 126 | foreground++; |
|---|
| 127 | 127 | break; |
|---|
| 128 | 128 | default: |
|---|