gsm: Implement the size checking of the hello packet
[lcr.git] / route.c
diff --git a/route.c b/route.c
index f72d6b0..3caed2b 100644 (file)
--- a/route.c
+++ b/route.c
@@ -1902,6 +1902,7 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
        struct admin_list       *admin;
        time_t                  now;
        struct tm               *now_tm;
+       int                     pid, status;
 
        /* reset timeout action */
        e_match_to_action = NULL;
@@ -2071,9 +2072,11 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
 
                                case MATCH_EXECUTE:
                                j = 0;
+#if 0
                                argv[j++] = (char *)"/bin/sh";
                                argv[j++] = (char *)"-c";
                                argv[j++] = cond->string_value;
+#endif
                                argv[j++] = cond->string_value;
                                argv[j++] = e_extdialing;
                                argv[j++] = (char *)numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype, options.national, options.international);
@@ -2083,8 +2086,18 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
                                argv[j++] = isdn_port;
                                argv[j++] = e_callerinfo.imsi;
                                argv[j++] = NULL; /* check also number of args above */
-                               if (execve("/bin/sh", argv, environ) == 0)
-                                       istrue = 1;
+                               switch ((pid = fork())) {
+                               case 0:
+                                       execve(cond->string_value, argv, environ);
+                                       perror("execve");
+                                       exit(1);
+                               case -1:
+                                       break;
+                               default:
+                                       waitpid(pid, &status, 0);
+                                       if (0 == WEXITSTATUS(status))
+                                               istrue = 1;
+                               }
                                break;
 
                                case MATCH_DEFAULT:
@@ -2300,12 +2313,13 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
 
                        cond = cond->next;
                }
-               if (timeout>now_ll && match==1) /* the matching rule with timeout in the future */
-               if (match_timeout == 0 || timeout < match_timeout) { /* first timeout or lower */
-                       /* set timeout in the furture */
-                       match_timeout = timeout;
-                       e_match_to_action = rule->action_first;
-                       e_match_to_extdialing = e_dialinginfo.id + dialing_required;
+               if (timeout>now_ll && match==1) { /* the matching rule with timeout in the future */
+                       if (match_timeout == 0 || timeout < match_timeout) { /* first timeout or lower */
+                               /* set timeout in the furture */
+                               match_timeout = timeout;
+                               e_match_to_action = rule->action_first;
+                               e_match_to_extdialing = e_dialinginfo.id + dialing_required;
+                       }
                        match = 0; /* matches in the future */
                }
                if (match == 1) {
@@ -2325,7 +2339,7 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
        if (match_timeout == 0)
                unsched_timer(&e_match_timeout); /* no timeout */
        else {
-               schedule_timer(&e_match_timeout, match_timeout / 1000000, match_timeout % 1000000);
+               schedule_timer(&e_match_timeout, (match_timeout-now_ll) / 1000000, (match_timeout-now_ll) % 1000000);
        }
        return(action);
 }