Disable a debug option
[platform/upstream/curl.git] / tests / tftpserver.pl
1 #!/usr/bin/env perl
2 #***************************************************************************
3 #                                  _   _ ____  _
4 #  Project                     ___| | | |  _ \| |
5 #                             / __| | | | |_) | |
6 #                            | (__| |_| |  _ <| |___
7 #                             \___|\___/|_| \_\_____|
8 #
9 # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10 #
11 # This software is licensed as described in the file COPYING, which
12 # you should have received as part of this distribution. The terms
13 # are also available at https://curl.se/docs/copyright.html.
14 #
15 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16 # copies of the Software, and permit persons to whom the Software is
17 # furnished to do so, under the terms of the COPYING file.
18 #
19 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 # KIND, either express or implied.
21 #
22 # SPDX-License-Identifier: curl
23 #
24 #***************************************************************************
25
26 use strict;
27 use warnings;
28
29 BEGIN {
30     push(@INC, $ENV{'srcdir'}) if(defined $ENV{'srcdir'});
31     push(@INC, ".");
32 }
33
34 use serverhelp qw(
35     server_pidfilename
36     server_logfilename
37     );
38
39 use pathhelp qw(
40     exe_ext
41     );
42
43 my $verbose = 0;     # set to 1 for debugging
44 my $port = 8997;     # just a default
45 my $ipvnum = 4;      # default IP version of tftp server
46 my $idnum = 1;       # default tftp server instance number
47 my $proto = 'tftp';  # protocol the tftp server speaks
48 my $pidfile;
49 my $portfile;
50 my $logfile;
51 my $srcdir;
52 my $fork;
53
54 my $flags  = "";
55 my $path   = '.';
56 my $logdir = $path .'/log';
57
58 while(@ARGV) {
59     if($ARGV[0] eq '--pidfile') {
60         if($ARGV[1]) {
61             $pidfile = $ARGV[1];
62             shift @ARGV;
63         }
64     }
65     elsif($ARGV[0] eq '--portfile') {
66         if($ARGV[1]) {
67             $portfile = $ARGV[1];
68             shift @ARGV;
69         }
70     }
71     elsif($ARGV[0] eq '--logfile') {
72         if($ARGV[1]) {
73             $logfile = $ARGV[1];
74             shift @ARGV;
75         }
76     }
77     elsif($ARGV[0] eq '--logdir') {
78         if($ARGV[1]) {
79             $logdir = $ARGV[1];
80             shift @ARGV;
81         }
82     }
83     elsif($ARGV[0] eq '--srcdir') {
84         if($ARGV[1]) {
85             $srcdir = $ARGV[1];
86             shift @ARGV;
87         }
88     }
89     elsif($ARGV[0] eq '--ipv4') {
90         $ipvnum = 4;
91     }
92     elsif($ARGV[0] eq '--ipv6') {
93         $ipvnum = 6;
94     }
95     elsif($ARGV[0] eq '--port') {
96         if($ARGV[1] =~ /^(\d+)$/) {
97             $port = $1;
98             shift @ARGV;
99         }
100     }
101     elsif($ARGV[0] eq '--id') {
102         if($ARGV[1] =~ /^(\d+)$/) {
103             $idnum = $1 if($1 > 0);
104             shift @ARGV;
105         }
106     }
107     elsif($ARGV[0] eq '--verbose') {
108         $verbose = 1;
109     }
110     else {
111         print STDERR "\nWarning: tftpserver.pl unknown parameter: $ARGV[0]\n";
112     }
113     shift @ARGV;
114 }
115
116 if(!$srcdir) {
117     $srcdir = $ENV{'srcdir'} || '.';
118 }
119 if(!$pidfile) {
120     $pidfile = server_pidfilename($path, $proto, $ipvnum, $idnum);
121 }
122 if(!$logfile) {
123     $logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);
124 }
125
126 $flags .= "--pidfile \"$pidfile\" ".
127     "--portfile \"$portfile\" ".
128     "--logfile \"$logfile\" ".
129     "--logdir \"$logdir\" ";
130 $flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\"";
131
132 $| = 1;
133 exec("exec server/tftpd".exe_ext('SRV')." $flags");