Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config file parsing errors may trigger incorrect threading [rt.cpan.org #67643] #14

Closed
toddr opened this issue Sep 22, 2020 · 1 comment

Comments

@toddr
Copy link
Owner

toddr commented Sep 22, 2020

Migrated from rt.cpan.org#67643 (status was 'open')

Requestors:

From fbriere@cpan.org on 2011-04-21 01:53:15
:

(This is a forward of
<http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=623540>.)

Here's an easy demonstration:

  $ dbiproxy --configfile foo
  Can't locate object method "self" via package "Thread" at
/usr/share/perl5/Net/Daemon/Log.pm line 82.

Basically, if Net::Daemon cannot properly parse the config file, it will
call Fatal(), and thus Log(), to report the error.  Log() expects the
mode to have already been set, which it hasn't yet, as it is done a bit
later in the constructor (since picking a default value may depend on
other config options).

I guess the easiest fix would be to set the mode so 'single' at first;
there's not much threading information to report anyway.


From m.nooning@comcast.net on 2011-04-21 12:12:08
:

You look like you are using Net-Daemon 0.47.  Please try the newest
module, Net-Daemon-0.48.tar.gz

Thanks



From fbriere@fbriere.net on 2011-04-22 00:48:54
:

On Thu, Apr 21, 2011 at 08:12:09AM -0400, Malcolm Nooning via RT wrote:
> You look like you are using Net-Daemon 0.47.  Please try the newest
> module, Net-Daemon-0.48.tar.gz

  $ perl -Ilib -MNet::Daemon -le 'print $Net::Daemon::VERSION; $d = new Net::Daemon { mode => "threads", configfile => "foo" };'
  0.48
  Can't locate object method "self" via package "Thread" at lib/Net/Daemon/Log.pm line 82.

Notice how everything works fine once the post-configfile mode-setting
has been done:

  $ perl -Ilib -MNet::Daemon -le 'print $Net::Daemon::VERSION; $d = new Net::Daemon { mode => "threads" }; $d->Fatal("ouch!")'
  0.48
  ouch! at -e line 1. at lib/Net/Daemon/Log.pm line 136.


-- 
Keep the number of passes in a compiler to a minimum.
		-- D. Gries


From m.nooning@comcast.net on 2011-04-22 14:02:25
:

I get the same error if foo does not exist.  Does foo exist for you?
C:\>perl -Ilib -MNet::Daemon -le "print $Net::Daemon::VERSION; $d = new
Net::Daemon { mode => "threads", configfile => "foo" };"
0.48

C:\>
C:\>del foo

C:\>perl -Ilib -MNet::Daemon -le "print $Net::Daemon::VERSION; $d = new
Net::Daemon { mode => "threads", configfile => "foo" };"
0.48
Can't locate object method "self" via package "Thread" at
C:/Perl/site/lib/Net/Daemon/Log.pm line 82.

I copied, pasted (um, and fixed the missing commas) the Config_File
example from the Net-Daemon CPAN site, as pasted below.  Note that this
example will not actually work.  It only shows that the error goes away
if there is a valid config file.  Notice that I changed the mode to
threads in the config file.  That will not matter since I did not intend
to actually use the newly created daemon.

------- Paste
# Load external modules; this is not required unless you use
# the chroot() option.
#require DBD::mysql;
#require DBD::CSV;

{
    # 'chroot' => '/var/dbiproxy',
    'facility' => 'daemon',
    'pidfile' => '/var/dbiproxy/dbiproxy.pid',
    'user' => 'nobody',
    'group' => 'nobody',
    'localport' => '1003',
    'mode' => 'threads',

    # Access control
    'clients' => [
        # Accept the local
        {
            'mask' => '^192\.168\.1\.\d+$',
            'accept' => 1
        },
        # Accept myhost.company.com
        {
            'mask' => '^myhost\.company\.com$',
            'accept' => 1
        },
        # Deny everything else
        {
            'mask' => '.*',
            'accept' => 0
        }
    ]
}




From fbriere@fbriere.net on 2011-04-23 15:31:46
:

On Fri, Apr 22, 2011 at 10:02:26AM -0400, Malcolm Nooning via RT wrote:
> I get the same error if foo does not exist.  Does foo exist for you?

No, it does not.  The idea was to trigger a parsing error.

> It only shows that the error goes away if there is a valid config file.

Yes, that is the point.

If you look at the constructor, you'll see that it calls ReadConfigFile,
and then performs some sanitation on the "mode" config value and loads
the required modules accordingly.

However, if ReadConfigFile() fails, it will call Fatal(), and thus
Log(), which attempts to print some information about the current
thread.  This assumes that "mode" has been set and the appropriate
modules loaded, which is not yet the case at that point.


-- 
Eternal nothingness is fine if you happen to be dressed for it.
		-- Woody Allen


From m.nooning@comcast.net on 2011-04-23 16:33:19
:

In site/lib/Net/daemon.pm, I will add the mode assignment shown, after 
the shown bless statement.
     bless($self, (ref($class) || $class));

     $self->{'mode'} = 'single'; # Provide a default

In the future, if someone forgets or misspells the config file name, a 
much more identifying error report will be printed.  I now properly get 
the error report below.

C:\>del foo
C:\>perl -Ilib -MNet::Daemon -le "print $Net::Daemon::VERSION; $d = new 
Net::Daemon { mode => "threads", configfile => "foo" };"
0.48
No such config file: foo at C:/Perl/site/lib/Net/Daemon.pm line 201. at 
C:/Perl/site/lib/Net/Daemon/Log.pm line 136.

I know how frustrating a misleading error report can be.  When I get a 
little more time I will update the module, test it on my Linux and 
Windows machines, and then upload it.

Thanks

On 4/23/2011 11:31 AM, fbriere@fbriere.net via RT wrote:
>         Queue: Net-Daemon
>   Ticket<URL: http://rt.cpan.org/Ticket/Display.html?id=67643>
>
> On Fri, Apr 22, 2011 at 10:02:26AM -0400, Malcolm Nooning via RT wrote:
>> I get the same error if foo does not exist.  Does foo exist for you?
> No, it does not.  The idea was to trigger a parsing error.
>
>> It only shows that the error goes away if there is a valid config file.
> Yes, that is the point.
>
> If you look at the constructor, you'll see that it calls ReadConfigFile,
> and then performs some sanitation on the "mode" config value and loads
> the required modules accordingly.
>
> However, if ReadConfigFile() fails, it will call Fatal(), and thus
> Log(), which attempts to print some information about the current
> thread.  This assumes that "mode" has been set and the appropriate
> modules loaded, which is not yet the case at that point.
>
>


@toddr
Copy link
Owner Author

toddr commented Sep 25, 2020

Support for Thread.pm has been removed in 3420a67

@toddr toddr closed this as completed Sep 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant