]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
wrap fork so we can drop priority in child processes
authorAnthony Minessale <anthm@freeswitch.org>
Mon, 1 Oct 2012 17:14:30 +0000 (12:14 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Mon, 1 Oct 2012 18:38:45 +0000 (13:38 -0500)
src/include/switch_core.h
src/mod/endpoints/mod_gsmopen/asterisk/celliax_additional.c
src/mod/endpoints/mod_gsmopen/gsmopen_protocol.cpp
src/mod/formats/mod_shell_stream/mod_shell_stream.c
src/mod/xml_int/mod_xml_scgi/xml_scgi_server.pl
src/switch.c
src/switch_core.c
src/switch_xml.c

index 507f18a166f614b01cc4fca2a17261872353c4bb..efd983ded879449f359d855e8103f2b5b670598a 100644 (file)
@@ -2368,6 +2368,9 @@ SWITCH_DECLARE(void) switch_core_recovery_untrack(switch_core_session_t *session
 SWITCH_DECLARE(void) switch_core_recovery_track(switch_core_session_t *session);
 SWITCH_DECLARE(void) switch_core_recovery_flush(const char *technology, const char *profile_name);
 
+                                                               
+SWITCH_DECLARE(pid_t) switch_fork(void);
+
 SWITCH_END_EXTERN_C
 #endif
 /* For Emacs:
index f72c8d8552287292372da3a2f2df0e6700ccfe7f..efae699ab766174c655bc5ea6cd7c95ad57d747a 100644 (file)
@@ -1185,7 +1185,7 @@ int celliax_serial_getstatus_AT(struct celliax_pvt *p)
 
             NOTICA("incoming SMS message:>>>%s<<<\n", CELLIAX_P_LOG, p->sms_message);
             pipe(fd1);
-            pid1 = fork();
+            pid1 = switch_fork();
 
             if (pid1 == 0) {    //child
               int err;
@@ -1735,7 +1735,7 @@ int celliax_serial_read_AT(struct celliax_pvt *p, int look_for_ack, int timeout_
 
                 NOTICA("incoming SMS message:>>>%s<<<\n", CELLIAX_P_LOG, p->sms_message);
                 pipe(fd1);
-                pid1 = fork();
+                pid1 = switch_fork();
 
                 if (pid1 == 0) {    //child
                   int err;
index ffa4e3d014416a4dfd1a5a6a67340a2606973acf..5bdda08f81edb2df95e51487560fdae2cfdffbb2 100644 (file)
@@ -3101,7 +3101,7 @@ int gsmopen_serial_getstatus_AT(private_t *tech_pvt)
 
                                                DEBUGA_AT("incoming SMS message:---%s---\n", GSMOPEN_P_LOG, p->sms_message);
                                                pipe(fd1);
-                                               pid1 = fork();
+                                               pid1 = switch_fork();
 
                                                if (pid1 == 0) {        //child
                                                        int err;
index 38969c84f696181d2bbfa33089d0f8461e8d3f04..a682eb424d65d3d20058a213f108176321462bad 100644 (file)
@@ -108,7 +108,7 @@ static switch_status_t shell_stream_file_open(switch_file_handle_t *handle, cons
        if (pipe(context->fds)) {
                goto error;
        } else {                                        /* good to go */
-               context->pid = fork();
+               context->pid = switch_fork();
 
                if (context->pid < 0) { /* ok maybe not */
                        goto error;
index 0f4af275bc999ac7377bf1c51d5a65d6ac70827f..c10fd515eeb86eebcffc72639e35e217178a07e9 100644 (file)
@@ -65,7 +65,7 @@ $SIG{CHLD} = "IGNORE";
 
 while (my $request = $scgi->accept) {
   # fork every new req into its own process (optional)
-  my $pid = fork();
+  my $pid = switch_fork();
 
   if ($pid) {
     $request->close();
index 4f8678a97f7e4e1c301f3ff3b498ac3d550e1bd7..0ddefbc5daf7f2d0739c7c2fd571ec61dacd21e8 100644 (file)
@@ -262,7 +262,7 @@ static void daemonize(int do_wait)
                }
        }
 
-       pid = fork();
+       pid = switch_fork();
 
        switch (pid) {
        case 0:         /* child process */
index 1d87d9ce2efd0f2e59f2ccae2d84be8e3ebbe55b..70d4cd5d0ff01ea1a98e894a4eec0728116d478c 100644 (file)
@@ -2731,15 +2731,33 @@ SWITCH_DECLARE(void) switch_close_extra_files(int *keep, int keep_ttl)
 }
 
 
-
 #ifdef WIN32
 static int switch_system_fork(const char *cmd, switch_bool_t wait)
 {
        return switch_system_thread(cmd, wait);
 }
 
+SWITCH_DECLARE(pid_t) switch_fork(void)
+{
+       return -1;
+}
+
+
 #else
 
+SWITCH_DECLARE(pid_t) switch_fork(void)
+{
+       int i = fork();
+
+       if (!i) {
+               set_low_priority();
+       }
+
+       return i;
+}
+
+
+
 static int switch_system_fork(const char *cmd, switch_bool_t wait)
 {
        int pid;
@@ -2747,7 +2765,7 @@ static int switch_system_fork(const char *cmd, switch_bool_t wait)
 
        switch_core_set_signal_handlers();
 
-       pid = fork();
+       pid = switch_fork();
        
        if (pid) {
                if (wait) {
@@ -2757,7 +2775,6 @@ static int switch_system_fork(const char *cmd, switch_bool_t wait)
        } else {
                switch_close_extra_files(NULL, 0);
                
-               set_low_priority();
                if (system(dcmd) == -1) {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to execute because of a command error : %s\n", dcmd);
                }
@@ -2793,7 +2810,7 @@ SWITCH_DECLARE(int) switch_stream_system_fork(const char *cmd, switch_stream_han
        if (pipe(fds)) {
                goto end;
        } else {                                        /* good to go */
-               pid = fork();
+               pid = switch_fork();
 
                if (pid < 0) {                  /* ok maybe not */
                        close(fds[0]);
index a4da3ca6cfceb2f8bf851b732c0d0e1c3f012736..f441567cacc5ddbc4ea7e5301075404ad80b5b11 100644 (file)
@@ -1238,7 +1238,7 @@ static FILE *preprocess_exec(const char *cwd, const char *command, FILE *write_f
        if (pipe(fds)) {
                goto end;
        } else {                                        /* good to go */
-               pid = fork();
+               pid = switch_fork();
 
                if (pid < 0) {                  /* ok maybe not */
                        close(fds[0]);