Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
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
savoirfairelinux
jami-daemon
Commits
a087b326
Commit
a087b326
authored
13 years ago
by
Tristan Matthews
Browse files
Options
Downloads
Patches
Plain Diff
* #8613: make check should fail early if another sflphone is running
parent
8b402ee6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
daemon/src/fileutils.cpp
+71
-0
71 additions, 0 deletions
daemon/src/fileutils.cpp
daemon/src/fileutils.h
+1
-0
1 addition, 0 deletions
daemon/src/fileutils.h
daemon/src/main.cpp
+8
-70
8 additions, 70 deletions
daemon/src/main.cpp
daemon/test/main.cpp
+3
-0
3 additions, 0 deletions
daemon/test/main.cpp
with
83 additions
and
70 deletions
daemon/src/fileutils.cpp
+
71
−
0
View file @
a087b326
...
...
@@ -29,7 +29,30 @@
*/
#include
<libgen.h>
#include
<dirent.h>
#include
<sys/stat.h>
#include
<cstdio>
#include
<cstdlib>
#include
<signal.h>
#include
"global.h"
namespace
{
// returns true if directory exists
bool
check_dir
(
const
char
*
path
)
{
DIR
*
dir
=
opendir
(
path
);
if
(
!
dir
)
{
// doesn't exist
if
(
mkdir
(
path
,
0755
)
!=
0
)
{
// couldn't create the dir
perror
(
path
);
return
false
;
}
}
else
closedir
(
dir
);
return
true
;
}
}
namespace
fileutils
{
static
char
*
program_dir
=
NULL
;
...
...
@@ -44,4 +67,52 @@ const char *get_program_dir()
return
program_dir
;
}
bool
create_pidfile
()
{
const
char
*
const
xdg_env
=
XDG_CACHE_HOME
;
std
::
string
path
=
xdg_env
?
xdg_env
:
std
::
string
(
HOMEDIR
)
+
DIR_SEPARATOR_STR
".cache/"
;
if
(
!
check_dir
(
path
.
c_str
()))
return
false
;
path
+=
"sflphone"
;
if
(
!
check_dir
(
path
.
c_str
()))
return
false
;
std
::
string
pidfile
=
path
+
"/"
PIDFILE
;
FILE
*
fp
=
fopen
(
pidfile
.
c_str
(),
"r"
);
if
(
fp
)
{
// PID file exists. Check the former process still alive or not. If alive, give user a hint.
int
oldPid
;
if
(
fscanf
(
fp
,
"%d"
,
&
oldPid
)
!=
1
)
{
ERROR
(
"Couldn't read pidfile %s"
,
pidfile
.
c_str
());
return
false
;
}
fclose
(
fp
);
if
(
kill
(
oldPid
,
0
)
==
0
)
{
ERROR
(
"There is already a sflphoned daemon running in the system. Starting Failed."
);
return
false
;
}
}
// write pid file
fp
=
fopen
(
pidfile
.
c_str
(),
"w"
);
if
(
!
fp
)
{
perror
(
pidfile
.
c_str
());
return
false
;
}
else
{
std
::
ostringstream
pidstr
;
pidstr
<<
getpid
();
fputs
(
pidstr
.
str
().
c_str
(),
fp
);
fclose
(
fp
);
}
return
true
;
}
}
This diff is collapsed.
Click to expand it.
daemon/src/fileutils.h
+
1
−
0
View file @
a087b326
...
...
@@ -34,6 +34,7 @@
namespace
fileutils
{
void
set_program_dir
(
char
*
program_path
);
const
char
*
get_program_dir
();
bool
create_pidfile
();
}
#endif // __FILEUTILS_H__
This diff is collapsed.
Click to expand it.
daemon/src/main.cpp
+
8
−
70
View file @
a087b326
/*
* Copyright (C) 2004
, 2005, 2006, 2008, 2009, 2010, 2011
Savoir-Faire Linux Inc.
* Copyright (C) 2004
-2012
Savoir-Faire Linux Inc.
* Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com>
* Author: Yan Morin <yan.morin@savoirfairelinux.com>
* Author: Laurielle Lea <laurielle.lea@savoirfairelinux.com>
...
...
@@ -30,22 +30,19 @@
* as that of the covered work.
*/
#include
<libintl.h>
#include
<cstring>
#ifdef HAVE_CONFIG_H
#include
"config.h"
#endif
#include
<iostream>
#include
<memory>
// for auto_ptr
#include
<string>
#include
<dirent.h>
#include
<sys/stat.h>
#include
<cc++/common.h>
#include
"global.h"
#include
"fileutils.h"
#include
"dbus/dbusmanager.h"
#include
"manager.h"
#include
"audio/audiolayer.h"
ost
::
CommandOptionNoArg
console
(
"console"
,
"c"
,
"Log in console (instead of syslog)"
);
...
...
@@ -58,25 +55,7 @@ ost::CommandOptionNoArg help(
"help"
,
"h"
,
"Print help"
);
// returns true if directory exists
static
bool
check_dir
(
const
char
*
path
)
{
DIR
*
dir
=
opendir
(
path
);
if
(
!
dir
)
{
// doesn't exist
if
(
mkdir
(
path
,
0755
)
!=
0
)
{
// couldn't create the dir
perror
(
path
);
return
false
;
}
}
else
{
closedir
(
dir
);
}
return
true
;
}
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
fileutils
::
set_program_dir
(
argv
[
0
]);
// makeCommandOptionParse allocates the object with operator new, so
...
...
@@ -84,7 +63,7 @@ main(int argc, char **argv)
// TODO: This should eventually be replaced with std::unique_ptr for C++0x
std
::
auto_ptr
<
ost
::
CommandOptionParse
>
args
(
ost
::
makeCommandOptionParse
(
argc
,
argv
,
""
));
printf
(
"SFLphone Daemon "
VERSION
", by Savoir-Faire Linux 2004-201
1
\n
"
\
printf
(
"SFLphone Daemon "
VERSION
", by Savoir-Faire Linux 2004-201
2
\n
"
\
"http://www.sflphone.org/
\n
"
);
if
(
help
.
numSet
)
{
...
...
@@ -99,50 +78,9 @@ main(int argc, char **argv)
Logger
::
setConsoleLog
(
console
.
numSet
);
Logger
::
setDebugMode
(
debug
.
numSet
);
const
char
*
xdg_env
=
XDG_CACHE_HOME
;
std
::
string
path
=
xdg_env
?
xdg_env
:
std
::
string
(
HOMEDIR
)
+
DIR_SEPARATOR_STR
".cache/"
;
if
(
!
check_dir
(
path
.
c_str
()))
return
1
;
path
=
path
+
"sflphone"
;
if
(
!
check_dir
(
path
.
c_str
()))
if
(
!
fileutils
::
create_pidfile
())
return
1
;
std
::
string
pidfile
=
path
+
"/"
PIDFILE
;
FILE
*
fp
=
fopen
(
pidfile
.
c_str
(),
"r"
);
if
(
fp
)
{
// PID file exists. Check the former process still alive or not. If alive, give user a hint.
int
oldPid
;
if
(
fscanf
(
fp
,
"%d"
,
&
oldPid
)
!=
1
)
{
std
::
cerr
<<
"Couldn't read pidfile "
<<
pidfile
<<
std
::
endl
;
return
1
;
}
fclose
(
fp
);
if
(
kill
(
oldPid
,
0
)
==
0
)
{
std
::
cerr
<<
"There is already a sflphoned daemon running in the system. Starting Failed."
<<
std
::
endl
;
return
1
;
}
}
// write pid file
fp
=
fopen
(
pidfile
.
c_str
(),
"w"
);
if
(
!
fp
)
{
perror
(
pidfile
.
c_str
());
return
1
;
}
else
{
std
::
ostringstream
pidstr
;
pidstr
<<
getpid
();
fputs
(
pidstr
.
str
().
c_str
()
,
fp
);
fclose
(
fp
);
}
try
{
Manager
::
instance
().
init
();
}
catch
(
const
std
::
exception
&
e
)
{
...
...
This diff is collapsed.
Click to expand it.
daemon/test/main.cpp
+
3
−
0
View file @
a087b326
...
...
@@ -31,6 +31,7 @@
#include
"logger.h"
#include
"manager.h"
#include
"constants.h"
#include
"fileutils.h"
#include
<cstdlib>
...
...
@@ -57,6 +58,8 @@ int main(int argc, char* argv[])
printf
(
"
\n
SFLphone Daemon Test Suite, by Savoir-Faire Linux 2004-2010
\n\n
"
);
Logger
::
setConsoleLog
(
true
);
Logger
::
setDebugMode
(
true
);
if
(
!
fileutils
::
create_pidfile
())
return
1
;
int
argvIndex
=
1
;
bool
xmlOutput
=
false
;
...
...
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