Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
celllframe-node
Manage
Activity
Members
Labels
Plan
Issues
5
Issue boards
Milestones
Code
Merge requests
17
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Show more breadcrumbs
cellframe
celllframe-node
Commits
ebb7d8c7
Commit
ebb7d8c7
authored
6 months ago
by
Constantin P.
💬
Browse files
Options
Downloads
Plain Diff
Conflict resolved
parents
0f6a5dc9
3e0190f5
No related branches found
No related tags found
1 merge request
!1710
Hotfixes 1007
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sources/cellframe-node.c
+40
-31
40 additions, 31 deletions
sources/cellframe-node.c
with
40 additions
and
31 deletions
sources/cellframe-node.c
+
40
−
31
View file @
ebb7d8c7
...
...
@@ -33,6 +33,8 @@
#include
<sys/types.h>
#include
<getopt.h>
#include
<signal.h>
#include
<errno.h>
#include
<unistd.h>
#ifdef _WIN32
#include
<winsock2.h>
...
...
@@ -125,12 +127,9 @@
#define MEMPOOL_URL "/mempool"
#define MAIN_URL "/"
void
parse_args
(
int
argc
,
const
char
**
argv
);
void
exit_if_server_already_running
(
void
);
static
int
s_proc_running_check
(
const
char
*
a_path
);
#ifndef DAP_OS_WINDOWS
static
const
char
*
s_pid_file_path
=
NULL
;
#endif
extern
int
errno
;
#ifdef DAP_OS_ANDROID
#include
"dap_app_cli.h"
...
...
@@ -211,15 +210,18 @@ int main( int argc, const char **argv )
#ifndef DAP_OS_WINDOWS
char
l_default_dir
[
MAX_PATH
]
=
{
'\0'
};
sprintf
(
l_default_dir
,
"%s/tmp"
,
g_sys_dir_path
);
s_pid_file_path
=
dap_config_get_item_str_path_default
(
g_config
,
"resources"
,
"pid_path"
,
l_default_dir
)
;
save_process_pid_in_file
(
s_pid_file_path
);
char
*
l_pid_file_path
=
dap_config_get_item_str_path_default
(
g_config
,
"resources"
,
"pid_path"
,
l_default_dir
);
int
l_pid_check
=
s_proc_running_check
(
l_pid_file_path
);
DAP_DELETE
(
l_pid_file_path
);
if
(
l_pid_check
)
return
2
;
#else
if
(
s_proc_running_check
(
"DAP_CELLFRAME_NODE_74E9201D33F7F7F684D2FEF1982799A79B6BF94"
"B568446A8D1DE947B00E3C75060F3FD5BF277592D02F77D7E50935E56"
)
)
return
2
;
#endif
log_it
(
L_DEBUG
,
"Parsing command line args"
);
#if !DAP_OS_ANDROID
parse_args
(
argc
,
argv
);
#endif
l_debug_mode
=
dap_config_get_item_bool_default
(
g_config
,
"general"
,
"debug_mode"
,
false
);
...
...
@@ -540,7 +542,7 @@ static struct option long_options[] = {
{
NULL
,
0
,
NULL
,
0
}
// must be a last element
};
void
parse_args
(
int
argc
,
const
char
**
argv
)
{
/*
void parse_args( int argc, const char **argv ) {
int opt, option_index = 0, is_daemon = 0;
...
...
@@ -575,7 +577,7 @@ void parse_args( int argc, const char **argv ) {
case 'D':
{
log_it( L_INFO, "Daemonize server starting..." );
exit_if_server_already_running
(
);
//
exit_if_server_already_running( );
is_daemon = 1;
daemonize_process( );
break;
...
...
@@ -586,27 +588,34 @@ void parse_args( int argc, const char **argv ) {
}
}
if
(
!
is_daemon
)
exit_if_server_already_running
(
);
}
void
exit_if_server_already_running
(
void
)
{
//if( !is_daemon )
// exit_if_server_already_running( );
}*/
int
s_proc_running_check
(
const
char
*
a_path
)
{
#ifdef DAP_OS_WINDOWS
CreateEvent
(
0
,
TRUE
,
FALSE
,
"DAP_CELLFRAME_NODE_74E9201D33F7F7F684D2FEF1982799A79B6BF94B568446A8D1DE947B00E3C75060F3FD5BF277592D02F77D7E50935E56"
);
if
(
GetLastError
()
==
ERROR_ALREADY_EXISTS
)
{
log_it
(
L_WARNING
,
"DapServer is already running, multiple instances are prohibited by config. Exiting..."
);
exit
(
-
2
);
}
CreateEvent
(
0
,
TRUE
,
FALSE
,
a_path
);
return
GetLastError
()
==
ERROR_ALREADY_EXISTS
?
(
log_it
(
L_ERROR
,
"dap_server is already running"
),
1
)
:
0
;
#else
pid_t
pid
=
get_pid_from_file
(
s_pid_file_path
);
struct
flock
lock
=
{
.
l_type
=
F_WRLCK
};
int
fd
=
open
(
s_pid_file_path
,
O_WRONLY
);
if
(
fcntl
(
fd
,
F_SETLK
,
&
lock
)
==
-
1
)
{
log_it
(
L_WARNING
,
"DapServer is already running, pid %"
DAP_UINT64_FORMAT_U
", multiple instances are prohibited by config. Exiting..."
,
(
uint64_t
)
pid
);
exit
(
-
2
);
}
FILE
*
l_pidfile
=
fopen
(
a_path
,
"r"
);
if
(
l_pidfile
)
{
pid_t
f_pid
=
0
;
fscanf
(
l_pidfile
,
"%d"
,
&
f_pid
);
if
(
lockf
(
fileno
(
l_pidfile
),
F_TEST
,
0
)
==
-
1
)
{
return
log_it
(
L_ERROR
,
"Error %ld:
\"
%s
\"
, dap_server is already running with PID %d"
,
errno
,
dap_strerror
(
errno
),
f_pid
),
1
;
}
else
l_pidfile
=
freopen
(
a_path
,
"w"
,
l_pidfile
);
}
else
l_pidfile
=
fopen
(
a_path
,
"w"
);
if
(
!
l_pidfile
)
return
log_it
(
L_ERROR
,
"Can't open file %s for writing, error %d: %s"
,
a_path
,
errno
,
dap_strerror
(
errno
)),
2
;
fprintf
(
l_pidfile
,
"%d"
,
getpid
());
fflush
(
l_pidfile
);
return
lockf
(
fileno
(
l_pidfile
),
F_TLOCK
,
sizeof
(
pid_t
));
#endif
}
...
...
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