Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mongoose
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Gitlab has been updated. More info
here
.
Show more breadcrumbs
Ganil-acq
GANILinux
linux-service
library
mongoose
Commits
e62e4839
Commit
e62e4839
authored
10 years ago
by
Sergey Lyubka
Browse files
Options
Downloads
Patches
Plain Diff
Keeping absolute path for config file
parent
8be30350
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/server.c
+24
-15
24 additions, 15 deletions
examples/server.c
with
24 additions
and
15 deletions
examples/server.c
+
24
−
15
View file @
e62e4839
...
@@ -86,10 +86,13 @@ typedef struct stat file_stat_t;
...
@@ -86,10 +86,13 @@ typedef struct stat file_stat_t;
static
int
exit_flag
;
static
int
exit_flag
;
static
char
server_name
[
50
];
// Set by init_server_name()
static
char
server_name
[
50
];
// Set by init_server_name()
static
char
config_file
[
PATH_MAX
];
// Set by process_command_line_arguments
()
static
char
s_
config_file
[
PATH_MAX
];
// Set by process_command_line_arguments
static
struct
mg_server
*
server
;
// Set by start_mongoose()
static
struct
mg_server
*
server
;
// Set by start_mongoose()
static
const
char
*
s_default_document_root
=
"."
;
static
const
char
*
s_default_document_root
=
"."
;
static
const
char
*
s_default_listening_port
=
"8080"
;
static
const
char
*
s_default_listening_port
=
"8080"
;
static
char
**
s_argv
=
{
NULL
};
static
void
set_options
(
char
*
argv
[]);
#if !defined(CONFIG_FILE)
#if !defined(CONFIG_FILE)
#define CONFIG_FILE "mongoose.conf"
#define CONFIG_FILE "mongoose.conf"
...
@@ -189,32 +192,34 @@ static void set_option(char **options, const char *name, const char *value) {
...
@@ -189,32 +192,34 @@ static void set_option(char **options, const char *name, const char *value) {
}
}
static
void
process_command_line_arguments
(
char
*
argv
[],
char
**
options
)
{
static
void
process_command_line_arguments
(
char
*
argv
[],
char
**
options
)
{
char
line
[
MAX_CONF_FILE_LINE_SIZE
],
opt
[
sizeof
(
line
)],
val
[
sizeof
(
line
)],
*
p
;
char
line
[
MAX_CONF_FILE_LINE_SIZE
],
opt
[
sizeof
(
line
)],
val
[
sizeof
(
line
)],
*
p
,
cpath
[
PATH_MAX
];
FILE
*
fp
=
NULL
;
FILE
*
fp
=
NULL
;
size_t
i
,
cmd_line_opts_start
=
1
,
line_no
=
0
;
size_t
i
,
cmd_line_opts_start
=
1
,
line_no
=
0
;
// Should we use a config file ?
// Should we use a config file ?
if
(
argv
[
1
]
!=
NULL
&&
argv
[
1
][
0
]
!=
'-'
)
{
if
(
argv
[
1
]
!=
NULL
&&
argv
[
1
][
0
]
!=
'-'
)
{
snprintf
(
c
onfig_file
,
sizeof
(
config_file
),
"%s"
,
argv
[
1
]);
snprintf
(
c
path
,
sizeof
(
cpath
),
"%s"
,
argv
[
1
]);
cmd_line_opts_start
=
2
;
cmd_line_opts_start
=
2
;
}
else
if
((
p
=
strrchr
(
argv
[
0
],
DIRSEP
))
==
NULL
)
{
}
else
if
((
p
=
strrchr
(
argv
[
0
],
DIRSEP
))
==
NULL
)
{
// No command line flags specified. Look where binary lives
// No command line flags specified. Look where binary lives
snprintf
(
c
onfig_file
,
sizeof
(
config_file
),
"%s"
,
CONFIG_FILE
);
snprintf
(
c
path
,
sizeof
(
cpath
),
"%s"
,
CONFIG_FILE
);
}
else
{
}
else
{
snprintf
(
c
onfig_file
,
sizeof
(
config_file
),
"%.*s%c%s"
,
snprintf
(
c
path
,
sizeof
(
cpath
),
"%.*s%c%s"
,
(
int
)
(
p
-
argv
[
0
]),
argv
[
0
],
DIRSEP
,
CONFIG_FILE
);
(
int
)
(
p
-
argv
[
0
]),
argv
[
0
],
DIRSEP
,
CONFIG_FILE
);
}
}
abs_path
(
cpath
,
s_config_file
,
sizeof
(
s_config_file
));
fp
=
fopen
(
config_file
,
"r"
);
fp
=
fopen
(
s_
config_file
,
"r"
);
// If config file was set in command line and open failed, die
// If config file was set in command line and open failed, die
if
(
cmd_line_opts_start
==
2
&&
fp
==
NULL
)
{
if
(
cmd_line_opts_start
==
2
&&
fp
==
NULL
)
{
die
(
"Cannot open config file %s: %s"
,
config_file
,
strerror
(
errno
));
die
(
"Cannot open config file %s: %s"
,
s_
config_file
,
strerror
(
errno
));
}
}
// Load config file settings first
// Load config file settings first
if
(
fp
!=
NULL
)
{
if
(
fp
!=
NULL
)
{
fprintf
(
stderr
,
"Loading config file %s
\n
"
,
config_file
);
fprintf
(
stderr
,
"Loading config file %s
\n
"
,
s_
config_file
);
// Loop over the lines in config file
// Loop over the lines in config file
while
(
fgets
(
line
,
sizeof
(
line
),
fp
)
!=
NULL
)
{
while
(
fgets
(
line
,
sizeof
(
line
),
fp
)
!=
NULL
)
{
...
@@ -228,7 +233,7 @@ static void process_command_line_arguments(char *argv[], char **options) {
...
@@ -228,7 +233,7 @@ static void process_command_line_arguments(char *argv[], char **options) {
if
(
sscanf
(
line
,
"%s %[^
\r\n
#]"
,
opt
,
val
)
!=
2
)
{
if
(
sscanf
(
line
,
"%s %[^
\r\n
#]"
,
opt
,
val
)
!=
2
)
{
printf
(
"%s: line %d is invalid, ignoring it:
\n
%s"
,
printf
(
"%s: line %d is invalid, ignoring it:
\n
%s"
,
config_file
,
(
int
)
line_no
,
line
);
s_
config_file
,
(
int
)
line_no
,
line
);
}
else
{
}
else
{
set_option
(
options
,
opt
,
val
);
set_option
(
options
,
opt
,
val
);
}
}
...
@@ -314,11 +319,11 @@ static void set_absolute_path(char *options[], const char *option_name) {
...
@@ -314,11 +319,11 @@ static void set_absolute_path(char *options[], const char *option_name) {
// Not absolute. Use the directory where mongoose executable lives
// Not absolute. Use the directory where mongoose executable lives
// be the relative directory for everything.
// be the relative directory for everything.
// Extract mongoose executable directory into path.
// Extract mongoose executable directory into path.
if
((
p
=
strrchr
(
config_file
,
DIRSEP
))
==
NULL
)
{
if
((
p
=
strrchr
(
s_
config_file
,
DIRSEP
))
==
NULL
)
{
getcwd
(
path
,
sizeof
(
path
));
getcwd
(
path
,
sizeof
(
path
));
}
else
{
}
else
{
snprintf
(
path
,
sizeof
(
path
),
"%.*s"
,
(
int
)
(
p
-
config_file
),
snprintf
(
path
,
sizeof
(
path
),
"%.*s"
,
(
int
)
(
p
-
s_
config_file
),
config_file
);
s_
config_file
);
}
}
strncat
(
path
,
"/"
,
sizeof
(
path
)
-
1
);
strncat
(
path
,
"/"
,
sizeof
(
path
)
-
1
);
...
@@ -396,9 +401,7 @@ int modify_passwords_file(const char *fname, const char *domain,
...
@@ -396,9 +401,7 @@ int modify_passwords_file(const char *fname, const char *domain,
#endif
#endif
static
void
start_mongoose
(
int
argc
,
char
*
argv
[])
{
static
void
start_mongoose
(
int
argc
,
char
*
argv
[])
{
char
*
options
[
MAX_OPTIONS
];
s_argv
=
argv
;
int
i
;
if
((
server
=
mg_create_server
(
NULL
,
EV_HANDLER
))
==
NULL
)
{
if
((
server
=
mg_create_server
(
NULL
,
EV_HANDLER
))
==
NULL
)
{
die
(
"%s"
,
"Failed to start Mongoose."
);
die
(
"%s"
,
"Failed to start Mongoose."
);
}
}
...
@@ -418,6 +421,12 @@ static void start_mongoose(int argc, char *argv[]) {
...
@@ -418,6 +421,12 @@ static void start_mongoose(int argc, char *argv[]) {
if
(
argc
==
2
&&
(
!
strcmp
(
argv
[
1
],
"-h"
)
||
!
strcmp
(
argv
[
1
],
"--help"
)))
{
if
(
argc
==
2
&&
(
!
strcmp
(
argv
[
1
],
"-h"
)
||
!
strcmp
(
argv
[
1
],
"--help"
)))
{
show_usage_and_exit
();
show_usage_and_exit
();
}
}
set_options
(
argv
);
}
static
void
set_options
(
char
*
argv
[])
{
char
*
options
[
MAX_OPTIONS
];
int
i
;
options
[
0
]
=
NULL
;
options
[
0
]
=
NULL
;
set_option
(
options
,
"document_root"
,
s_default_document_root
);
set_option
(
options
,
"document_root"
,
s_default_document_root
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment