{"action":"created","comment":{"url":"https://api.github.com/repos/inverse-inc/packetfence/pulls/comments/39174560","id":39174560,"diff_hunk":"@@ -128,44 +128,100 @@ our %DISPATCH = (\n     'sleep'              => \\&server_sleep,\n );\n \n-while($RUNNING) {\n-    my $socket;\n-    my $line;\n-    eval {\n-        $socket = $listner->accept();\n-        #Check if a signal was caught\n-        unless (defined $socket || $! == EINTR) {\n-            die(\"Can't accept connection: $!\\n\");\n-        }\n-        if($socket) {\n-            chomp( $line = <$socket> );\n-\n-            if($line eq \"exit\") {exit}\n-\n-            my $query = decode_json($line);\n-            #use Data::Dumper;\n-            #print Dumper($query);\n-\n-            # we support hash namespaced queries\n-            # where\n-            #  - line = 'config' return the whole config hash\n-            #  - line = 'config;value' return the value in the config hash\n-            my $method = $query->{method};\n-            if (exists $DISPATCH{$method}) {\n-                $DISPATCH{$method}->($query, $socket);\n-            } else {\n-                print STDERR \"Unknown method $query->{method}\";\n-                print \"undef\";\n+\n+my $configuration = pfconfig::config->new;\n+\n+our $PARENT_PID = $$;\n+my %CHILDREN;\n+my $IS_CHILD = 0;\n+my $CHILDREN_TO_START = $configuration->element('general', 'children') || 2;\n+\n+sub start_children {\n+    my $i = 1;\n+    while($i <= $CHILDREN_TO_START){\n+        run_child($i);\n+        $i++;\n+    }\n+}\n+\n+sub run_child {\n+    my ($id) = @_;\n+    my $pid = fork();\n+    if($pid) {\n+        $CHILDREN{$pid} = $id;\n+        $SIG{CHLD} = \"IGNORE\";\n+    } elsif ($pid == 0) {\n+        $SIG{CHLD} = \"DEFAULT\";\n+        $IS_CHILD = 1;\n+        _run_child($id);\n+    } else {\n+    }\n+}\n+\n+sub _run_child {\n+    my ($id) = @_;\n+    $0 = \"pfconfig - \".$id;\n+    while($RUNNING) {\n+        my $socket;\n+        my $line;\n+        eval {\n+            $socket = $listner->accept();\n+            #Check if a signal was caught\n+            unless (defined $socket || $! == EINTR) {\n+                die(\"Can't accept connection: $!\\n\");\n             }\n+            if($socket) {\n+                chomp( $line = <$socket> );\n+\n+                if($line eq \"exit\") {exit}\n+\n+                my $query = decode_json($line);\n+                #use Data::Dumper;\n+                #print Dumper($query);\n+\n+                # we support hash namespaced queries\n+                # where\n+                #  - line = 'config' return the whole config hash\n+                #  - line = 'config;value' return the value in the config hash\n+\n+                my $method = $query->{method};\n+                if (exists $DISPATCH{$method}) {\n+                    $DISPATCH{$method}->($query, $socket);\n+                } else {\n+                    print STDERR \"Unknown method $query->{method}\";\n+                    print \"undef\";\n+                }\n+            }\n+        };\n+        if($@){\n+            print STDERR \"$line : $@\";\n+            send_output(\"undef\", $socket) if $socket;\n+        }\n+        #Stop running if parent is no longer alive\n+        unless(is_parent_alive()) {\n+            $logger->error(\"Parent is no longer running shutting down\");\n+            $RUNNING = 0;\n         }\n-    };\n-    if($@){\n-        print STDERR \"$line : $@\";\n-        send_output(\"undef\", $socket) if $socket;\n     }\n+\n+    $logger->info(\"Stop running\");\n }\n \n-$logger->info(\"Stop running\\n\");\n+sub is_parent_alive {\n+    kill (0,$PARENT_PID)\n+}\n+\n+start_children();\n+while($RUNNING){\n+    sleep 1;","path":"sbin/pfconfig","position":122,"original_position":122,"commit_id":"56bb490d2b6958509b5587701beba2a84951cb23","original_commit_id":"56bb490d2b6958509b5587701beba2a84951cb23","user":{"login":"jrouzierinverse","id":2727473,"avatar_url":"https://avatars.githubusercontent.com/u/2727473?v=3","gravatar_id":"","url":"https://api.github.com/users/jrouzierinverse","html_url":"https://github.com/jrouzierinverse","followers_url":"https://api.github.com/users/jrouzierinverse/followers","following_url":"https://api.github.com/users/jrouzierinverse/following{/other_user}","gists_url":"https://api.github.com/users/jrouzierinverse/gists{/gist_id}","starred_url":"https://api.github.com/users/jrouzierinverse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrouzierinverse/subscriptions","organizations_url":"https://api.github.com/users/jrouzierinverse/orgs","repos_url":"https://api.github.com/users/jrouzierinverse/repos","events_url":"https://api.github.com/users/jrouzierinverse/events{/privacy}","received_events_url":"https://api.github.com/users/jrouzierinverse/received_events","type":"User","site_admin":false},"body":"I think we should sit down and discuss the different options to obtain that goal using the best practices for multi process daemons. ","created_at":"2015-09-10T15:35:14Z","updated_at":"2015-09-10T15:35:14Z","html_url":"https://github.com/inverse-inc/packetfence/pull/871#discussion_r39174560","pull_request_url":"https://api.github.com/repos/inverse-inc/packetfence/pulls/871","_links":{"self":{"href":"https://api.github.com/repos/inverse-inc/packetfence/pulls/comments/39174560"},"html":{"href":"https://github.com/inverse-inc/packetfence/pull/871#discussion_r39174560"},"pull_request":{"href":"https://api.github.com/repos/inverse-inc/packetfence/pulls/871"}}},"pull_request":{"url":"https://api.github.com/repos/inverse-inc/packetfence/pulls/871","id":44037627,"html_url":"https://github.com/inverse-inc/packetfence/pull/871","diff_url":"https://github.com/inverse-inc/packetfence/pull/871.diff","patch_url":"https://github.com/inverse-inc/packetfence/pull/871.patch","issue_url":"https://api.github.com/repos/inverse-inc/packetfence/issues/871","number":871,"state":"open","locked":false,"title":"Allow for pfconfig to fork","user":{"login":"julsemaan","id":3857942,"avatar_url":"https://avatars.githubusercontent.com/u/3857942?v=3","gravatar_id":"","url":"https://api.github.com/users/julsemaan","html_url":"https://github.com/julsemaan","followers_url":"https://api.github.com/users/julsemaan/followers","following_url":"https://api.github.com/users/julsemaan/following{/other_user}","gists_url":"https://api.github.com/users/julsemaan/gists{/gist_id}","starred_url":"https://api.github.com/users/julsemaan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/julsemaan/subscriptions","organizations_url":"https://api.github.com/users/julsemaan/orgs","repos_url":"https://api.github.com/users/julsemaan/repos","events_url":"https://api.github.com/users/julsemaan/events{/privacy}","received_events_url":"https://api.github.com/users/julsemaan/received_events","type":"User","site_admin":false},"body":"# Description\r\nAllows for pfconfig to fork and serve concurent request in order to make configuration access faster when having a lot of disposable threads/processes\r\n\r\n# Impacts\r\nConfiguration access, basically pretty much PacketFence as a whole\r\n\r\n# Delete branch after merge\r\nYES\r\n\r\n# NEWS file entries\r\n## Enhancements\r\n* pfconfig is now able to process multiple requests concurently via process forking","created_at":"2015-09-02T20:22:05Z","updated_at":"2015-09-10T15:35:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"de8ee6d71d78647185b9bb0d4021380b2cda0390","assignee":null,"milestone":{"url":"https://api.github.com/repos/inverse-inc/packetfence/milestones/9","html_url":"https://github.com/inverse-inc/packetfence/milestones/PacketFence-5.4","labels_url":"https://api.github.com/repos/inverse-inc/packetfence/milestones/9/labels","id":1185948,"number":9,"title":"PacketFence-5.4","description":"","creator":{"login":"louismunro","id":193997,"avatar_url":"https://avatars.githubusercontent.com/u/193997?v=3","gravatar_id":"","url":"https://api.github.com/users/louismunro","html_url":"https://github.com/louismunro","followers_url":"https://api.github.com/users/louismunro/followers","following_url":"https://api.github.com/users/louismunro/following{/other_user}","gists_url":"https://api.github.com/users/louismunro/gists{/gist_id}","starred_url":"https://api.github.com/users/louismunro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/louismunro/subscriptions","organizations_url":"https://api.github.com/users/louismunro/orgs","repos_url":"https://api.github.com/users/louismunro/repos","events_url":"https://api.github.com/users/louismunro/events{/privacy}","received_events_url":"https://api.github.com/users/louismunro/received_events","type":"User","site_admin":false},"open_issues":65,"closed_issues":19,"state":"open","created_at":"2015-06-29T19:23:15Z","updated_at":"2015-09-10T00:27:40Z","due_on":"2015-09-14T04:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/inverse-inc/packetfence/pulls/871/commits","review_comments_url":"https://api.github.com/repos/inverse-inc/packetfence/pulls/871/comments","review_comment_url":"https://api.github.com/repos/inverse-inc/packetfence/pulls/comments{/number}","comments_url":"https://api.github.com/repos/inverse-inc/packetfence/issues/871/comments","statuses_url":"https://api.github.com/repos/inverse-inc/packetfence/statuses/56bb490d2b6958509b5587701beba2a84951cb23","head":{"label":"julsemaan:feature/pfconfig-fork","ref":"feature/pfconfig-fork","sha":"56bb490d2b6958509b5587701beba2a84951cb23","user":{"login":"julsemaan","id":3857942,"avatar_url":"https://avatars.githubusercontent.com/u/3857942?v=3","gravatar_id":"","url":"https://api.github.com/users/julsemaan","html_url":"https://github.com/julsemaan","followers_url":"https://api.github.com/users/julsemaan/followers","following_url":"https://api.github.com/users/julsemaan/following{/other_user}","gists_url":"https://api.github.com/users/julsemaan/gists{/gist_id}","starred_url":"https://api.github.com/users/julsemaan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/julsemaan/subscriptions","organizations_url":"https://api.github.com/users/julsemaan/orgs","repos_url":"https://api.github.com/users/julsemaan/repos","events_url":"https://api.github.com/users/julsemaan/events{/privacy}","received_events_url":"https://api.github.com/users/julsemaan/received_events","type":"User","site_admin":false},"repo":{"id":9198603,"name":"packetfence","full_name":"julsemaan/packetfence","owner":{"login":"julsemaan","id":3857942,"avatar_url":"https://avatars.githubusercontent.com/u/3857942?v=3","gravatar_id":"","url":"https://api.github.com/users/julsemaan","html_url":"https://github.com/julsemaan","followers_url":"https://api.github.com/users/julsemaan/followers","following_url":"https://api.github.com/users/julsemaan/following{/other_user}","gists_url":"https://api.github.com/users/julsemaan/gists{/gist_id}","starred_url":"https://api.github.com/users/julsemaan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/julsemaan/subscriptions","organizations_url":"https://api.github.com/users/julsemaan/orgs","repos_url":"https://api.github.com/users/julsemaan/repos","events_url":"https://api.github.com/users/julsemaan/events{/privacy}","received_events_url":"https://api.github.com/users/julsemaan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/julsemaan/packetfence","description":"PacketFence is a fully supported, trusted, Free and Open Source network access control (NAC) solution. Boasting an impressive feature set including a captive-portal for registration and remediation, centralized wired and wireless management, powerful guest management options, 802.1X support, layer-2 isolation of problematic devices; PacketFence can be used to effectively secure networks small to very large heterogeneous networks.","fork":true,"url":"https://api.github.com/repos/julsemaan/packetfence","forks_url":"https://api.github.com/repos/julsemaan/packetfence/forks","keys_url":"https://api.github.com/repos/julsemaan/packetfence/keys{/key_id}","collaborators_url":"https://api.github.com/repos/julsemaan/packetfence/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/julsemaan/packetfence/teams","hooks_url":"https://api.github.com/repos/julsemaan/packetfence/hooks","issue_events_url":"https://api.github.com/repos/julsemaan/packetfence/issues/events{/number}","events_url":"https://api.github.com/repos/julsemaan/packetfence/events","assignees_url":"https://api.github.com/repos/julsemaan/packetfence/assignees{/user}","branches_url":"https://api.github.com/repos/julsemaan/packetfence/branches{/branch}","tags_url":"https://api.github.com/repos/julsemaan/packetfence/tags","blobs_url":"https://api.github.com/repos/julsemaan/packetfence/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/julsemaan/packetfence/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/julsemaan/packetfence/git/refs{/sha}","trees_url":"https://api.github.com/repos/julsemaan/packetfence/git/trees{/sha}","statuses_url":"https://api.github.com/repos/julsemaan/packetfence/statuses/{sha}","languages_url":"https://api.github.com/repos/julsemaan/packetfence/languages","stargazers_url":"https://api.github.com/repos/julsemaan/packetfence/stargazers","contributors_url":"https://api.github.com/repos/julsemaan/packetfence/contributors","subscribers_url":"https://api.github.com/repos/julsemaan/packetfence/subscribers","subscription_url":"https://api.github.com/repos/julsemaan/packetfence/subscription","commits_url":"https://api.github.com/repos/julsemaan/packetfence/commits{/sha}","git_commits_url":"https://api.github.com/repos/julsemaan/packetfence/git/commits{/sha}","comments_url":"https://api.github.com/repos/julsemaan/packetfence/comments{/number}","issue_comment_url":"https://api.github.com/repos/julsemaan/packetfence/issues/comments{/number}","contents_url":"https://api.github.com/repos/julsemaan/packetfence/contents/{+path}","compare_url":"https://api.github.com/repos/julsemaan/packetfence/compare/{base}...{head}","merges_url":"https://api.github.com/repos/julsemaan/packetfence/merges","archive_url":"https://api.github.com/repos/julsemaan/packetfence/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/julsemaan/packetfence/downloads","issues_url":"https://api.github.com/repos/julsemaan/packetfence/issues{/number}","pulls_url":"https://api.github.com/repos/julsemaan/packetfence/pulls{/number}","milestones_url":"https://api.github.com/repos/julsemaan/packetfence/milestones{/number}","notifications_url":"https://api.github.com/repos/julsemaan/packetfence/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/julsemaan/packetfence/labels{/name}","releases_url":"https://api.github.com/repos/julsemaan/packetfence/releases{/id}","created_at":"2013-04-03T15:52:51Z","updated_at":"2014-06-17T14:56:13Z","pushed_at":"2015-09-10T00:29:49Z","git_url":"git://github.com/julsemaan/packetfence.git","ssh_url":"git@github.com:julsemaan/packetfence.git","clone_url":"https://github.com/julsemaan/packetfence.git","svn_url":"https://github.com/julsemaan/packetfence","homepage":"http://www.packetfence.org","size":142147,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"stable"}},"base":{"label":"inverse-inc:devel","ref":"devel","sha":"fbe5eada34a78f5ad6e63b4e3cd5d0a4f9ebf334","user":{"login":"inverse-inc","id":1203154,"avatar_url":"https://avatars.githubusercontent.com/u/1203154?v=3","gravatar_id":"","url":"https://api.github.com/users/inverse-inc","html_url":"https://github.com/inverse-inc","followers_url":"https://api.github.com/users/inverse-inc/followers","following_url":"https://api.github.com/users/inverse-inc/following{/other_user}","gists_url":"https://api.github.com/users/inverse-inc/gists{/gist_id}","starred_url":"https://api.github.com/users/inverse-inc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inverse-inc/subscriptions","organizations_url":"https://api.github.com/users/inverse-inc/orgs","repos_url":"https://api.github.com/users/inverse-inc/repos","events_url":"https://api.github.com/users/inverse-inc/events{/privacy}","received_events_url":"https://api.github.com/users/inverse-inc/received_events","type":"Organization","site_admin":false},"repo":{"id":3595658,"name":"packetfence","full_name":"inverse-inc/packetfence","owner":{"login":"inverse-inc","id":1203154,"avatar_url":"https://avatars.githubusercontent.com/u/1203154?v=3","gravatar_id":"","url":"https://api.github.com/users/inverse-inc","html_url":"https://github.com/inverse-inc","followers_url":"https://api.github.com/users/inverse-inc/followers","following_url":"https://api.github.com/users/inverse-inc/following{/other_user}","gists_url":"https://api.github.com/users/inverse-inc/gists{/gist_id}","starred_url":"https://api.github.com/users/inverse-inc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inverse-inc/subscriptions","organizations_url":"https://api.github.com/users/inverse-inc/orgs","repos_url":"https://api.github.com/users/inverse-inc/repos","events_url":"https://api.github.com/users/inverse-inc/events{/privacy}","received_events_url":"https://api.github.com/users/inverse-inc/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/inverse-inc/packetfence","description":"PacketFence is a fully supported, trusted, Free and Open Source network access control (NAC) solution. Boasting an impressive feature set including a captive-portal for registration and remediation, centralized wired and wireless management, powerful guest management options, 802.1X support, layer-2 isolation of problematic devices; PacketFence can be used to effectively secure networks small to very large heterogeneous networks.","fork":false,"url":"https://api.github.com/repos/inverse-inc/packetfence","forks_url":"https://api.github.com/repos/inverse-inc/packetfence/forks","keys_url":"https://api.github.com/repos/inverse-inc/packetfence/keys{/key_id}","collaborators_url":"https://api.github.com/repos/inverse-inc/packetfence/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/inverse-inc/packetfence/teams","hooks_url":"https://api.github.com/repos/inverse-inc/packetfence/hooks","issue_events_url":"https://api.github.com/repos/inverse-inc/packetfence/issues/events{/number}","events_url":"https://api.github.com/repos/inverse-inc/packetfence/events","assignees_url":"https://api.github.com/repos/inverse-inc/packetfence/assignees{/user}","branches_url":"https://api.github.com/repos/inverse-inc/packetfence/branches{/branch}","tags_url":"https://api.github.com/repos/inverse-inc/packetfence/tags","blobs_url":"https://api.github.com/repos/inverse-inc/packetfence/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/inverse-inc/packetfence/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/inverse-inc/packetfence/git/refs{/sha}","trees_url":"https://api.github.com/repos/inverse-inc/packetfence/git/trees{/sha}","statuses_url":"https://api.github.com/repos/inverse-inc/packetfence/statuses/{sha}","languages_url":"https://api.github.com/repos/inverse-inc/packetfence/languages","stargazers_url":"https://api.github.com/repos/inverse-inc/packetfence/stargazers","contributors_url":"https://api.github.com/repos/inverse-inc/packetfence/contributors","subscribers_url":"https://api.github.com/repos/inverse-inc/packetfence/subscribers","subscription_url":"https://api.github.com/repos/inverse-inc/packetfence/subscription","commits_url":"https://api.github.com/repos/inverse-inc/packetfence/commits{/sha}","git_commits_url":"https://api.github.com/repos/inverse-inc/packetfence/git/commits{/sha}","comments_url":"https://api.github.com/repos/inverse-inc/packetfence/comments{/number}","issue_comment_url":"https://api.github.com/repos/inverse-inc/packetfence/issues/comments{/number}","contents_url":"https://api.github.com/repos/inverse-inc/packetfence/contents/{+path}","compare_url":"https://api.github.com/repos/inverse-inc/packetfence/compare/{base}...{head}","merges_url":"https://api.github.com/repos/inverse-inc/packetfence/merges","archive_url":"https://api.github.com/repos/inverse-inc/packetfence/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/inverse-inc/packetfence/downloads","issues_url":"https://api.github.com/repos/inverse-inc/packetfence/issues{/number}","pulls_url":"https://api.github.com/repos/inverse-inc/packetfence/pulls{/number}","milestones_url":"https://api.github.com/repos/inverse-inc/packetfence/milestones{/number}","notifications_url":"https://api.github.com/repos/inverse-inc/packetfence/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/inverse-inc/packetfence/labels{/name}","releases_url":"https://api.github.com/repos/inverse-inc/packetfence/releases{/id}","created_at":"2012-03-01T20:21:13Z","updated_at":"2015-09-01T04:07:04Z","pushed_at":"2015-09-10T15:23:47Z","git_url":"git://github.com/inverse-inc/packetfence.git","ssh_url":"git@github.com:inverse-inc/packetfence.git","clone_url":"https://github.com/inverse-inc/packetfence.git","svn_url":"https://github.com/inverse-inc/packetfence","homepage":"http://www.packetfence.org","size":164868,"stargazers_count":131,"watchers_count":131,"language":"Perl","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":67,"mirror_url":null,"open_issues_count":186,"forks":67,"open_issues":186,"watchers":131,"default_branch":"devel"}},"_links":{"self":{"href":"https://api.github.com/repos/inverse-inc/packetfence/pulls/871"},"html":{"href":"https://github.com/inverse-inc/packetfence/pull/871"},"issue":{"href":"https://api.github.com/repos/inverse-inc/packetfence/issues/871"},"comments":{"href":"https://api.github.com/repos/inverse-inc/packetfence/issues/871/comments"},"review_comments":{"href":"https://api.github.com/repos/inverse-inc/packetfence/pulls/871/comments"},"review_comment":{"href":"https://api.github.com/repos/inverse-inc/packetfence/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/inverse-inc/packetfence/pulls/871/commits"},"statuses":{"href":"https://api.github.com/repos/inverse-inc/packetfence/statuses/56bb490d2b6958509b5587701beba2a84951cb23"}}}}