| 201 | } |
| 202 | |
| 203 | bool daemon_developer_mode(char *argv[]) |
| 204 | { |
| 205 | bool developer = false, debug = false; |
| 206 | const char *entropy_override, *time_override; |
| 207 | |
| 208 | for (int i = 1; argv[i]; i++) { |
| 209 | if (streq(argv[i], "--dev-debug-self")) |
| 210 | debug = true; |
| 211 | else if (streq(argv[i], "--developer")) |
| 212 | developer = true; |
| 213 | } |
| 214 | |
| 215 | if (!developer) |
| 216 | return false; |
| 217 | |
| 218 | if (debug) { |
| 219 | /* Don't let this mess up stdout, so redir to /dev/null */ |
| 220 | char *cmd = tal_fmt(NULL, "${DEBUG_TERM:-gnome-terminal --} gdb -ex 'attach %u' %s >/dev/null &", getpid(), argv[0]); |
| 221 | fprintf(stderr, "Running %s\n", cmd); |
| 222 | /* warn_unused_result is fascist bullshit. |
| 223 | * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425 */ |
| 224 | if (system(cmd)) |
| 225 | ; |
| 226 | tal_free(cmd); |
| 227 | /* Continue in the debugger. */ |
| 228 | kill(getpid(), SIGSTOP); |
| 229 | } |
| 230 | |
| 231 | /* We can override cryptographic randomness with this var in development |
| 232 | * mode, for reproducible results */ |
| 233 | entropy_override = getenv("CLN_DEV_ENTROPY_SEED"); |
| 234 | if (entropy_override) |
| 235 | dev_override_randbytes(argv[0], atol(entropy_override)); |
| 236 | |
| 237 | /* We can also control TIME ITSELF! */ |
| 238 | time_override = getenv("CLN_DEV_SET_TIME"); |
| 239 | if (time_override) { |
| 240 | struct timeabs t; |
| 241 | t.ts.tv_nsec = 0; |
| 242 | t.ts.tv_sec = atol(time_override); |
| 243 | dev_override_clock_time(t); |
| 244 | } |
| 245 | |
| 246 | /* This checks for any tal_steal loops, but it's not free: |
| 247 | * only use if we're already using the fairly heavy memleak |
| 248 | * detection. */ |
| 249 | if (getenv("LIGHTNINGD_DEV_MEMLEAK")) |
| 250 | add_steal_notifiers(NULL); |
| 251 | |
| 252 | return true; |
| 253 | } |
no test coverage detected