|
| 1 | +diff --git a/main/asterisk.c b/main/asterisk.c |
| 2 | +index b0f8a14311..ee89c45ad9 100644 |
| 3 | +--- a/main/asterisk.c |
| 4 | ++++ b/main/asterisk.c |
| 5 | +@@ -1709,6 +1709,37 @@ static int ast_tryconnect(void) |
| 6 | + return 1; |
| 7 | + } |
| 8 | + |
| 9 | ++static int ast_is_starting(void) |
| 10 | ++{ |
| 11 | ++ /* Don't use kill since that only works if Asterisk was started as the same user. */ |
| 12 | ++ struct stat st; |
| 13 | ++ FILE *f; |
| 14 | ++ long file_pid; |
| 15 | ++ char procpath[PATH_MAX]; |
| 16 | ++ |
| 17 | ++ /* Get current value from PID file */ |
| 18 | ++ f = fopen(ast_config_AST_PID, "r"); |
| 19 | ++ if (!f) { |
| 20 | ++ return 0; /* PID file doesn't exist? No way to tell. */ |
| 21 | ++ } |
| 22 | ++ if (fscanf(f, "%ld", &file_pid) < 1) { |
| 23 | ++ file_pid = 0; /* Failure */ |
| 24 | ++ } |
| 25 | ++ fclose(f); |
| 26 | ++ if (!file_pid) { |
| 27 | ++ return 0; |
| 28 | ++ } |
| 29 | ++ |
| 30 | ++ /* Check if such a process is running */ |
| 31 | ++ snprintf(procpath, sizeof(procpath), "/proc/%ld", file_pid); |
| 32 | ++ if (stat(procpath, &st) == -1 && errno == ENOENT) { |
| 33 | ++ /* Process doesn't exist */ |
| 34 | ++ return 0; |
| 35 | ++ } |
| 36 | ++ return 1; |
| 37 | ++} |
| 38 | ++ |
| 39 | ++ |
| 40 | + /*! \brief Urgent handler |
| 41 | + * |
| 42 | + * Called by soft_hangup to interrupt the poll, read, or other |
| 43 | +@@ -4080,6 +4111,12 @@ int main(int argc, char *argv[]) |
| 44 | + exit(1); |
| 45 | + } |
| 46 | + |
| 47 | ++ if (ast_is_starting()) { |
| 48 | ++ fprintf(stderr, "Asterisk is currently starting. Use 'asterisk -r' to connect momentarily.\n"); |
| 49 | ++ printf("%s", term_quit()); |
| 50 | ++ exit(1); |
| 51 | ++ } |
| 52 | ++ |
| 53 | + #ifdef HAVE_CAP |
| 54 | + child_cap = cap_from_text("cap_net_admin-eip"); |
| 55 | + #endif |
0 commit comments