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
4a8ae4e2
Commit
4a8ae4e2
authored
12 years ago
by
Tristan Matthews
Browse files
Options
Downloads
Patches
Plain Diff
* #9782: use fstreams instead of fscanf
Does type checking.
parent
cf06b9ae
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
daemon/src/fileutils.cpp
+11
-19
11 additions, 19 deletions
daemon/src/fileutils.cpp
with
11 additions
and
19 deletions
daemon/src/fileutils.cpp
+
11
−
19
View file @
4a8ae4e2
...
...
@@ -31,13 +31,13 @@
#include
<libgen.h>
#include
<dirent.h>
#include
<sys/stat.h>
#include
<
c
st
dio
>
#include
<
f
st
ream
>
#include
<cstdlib>
#include
<signal.h>
#include
<string>
#include
<sstream>
#include
<iostream>
#include
"fileutils.h"
#include
"logger.h"
namespace
{
// returns true if directory exists
...
...
@@ -84,38 +84,30 @@ bool create_pidfile()
return
false
;
std
::
string
pidfile
=
path
+
"/"
PIDFILE
;
FILE
*
fp
=
fopen
(
pidfile
.
c_str
()
,
"r"
);
std
::
ifstream
is
(
pidfile
.
c_str
());
if
(
fp
)
{
if
(
is
)
{
// PID file exists. Check if the former process is 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
);
is
>>
oldPid
;
if
(
kill
(
oldPid
,
0
)
==
0
)
{
ERROR
(
"There is already a sflphoned daemon running in the system. Starting Failed."
);
// Use cerr because logging has not been initialized
std
::
cerr
<<
"There is already a sflphoned daemon running in "
<<
"the system. Starting Failed."
<<
std
::
endl
;
return
false
;
}
}
// write pid file
fp
=
fopen
(
pidfile
.
c_str
()
,
"w"
);
std
::
ofstream
os
(
pidfile
.
c_str
());
if
(
!
fp
)
{
if
(
!
os
)
{
perror
(
pidfile
.
c_str
());
return
false
;
}
else
{
std
::
ostringstream
pidstr
;
pidstr
<<
getpid
();
fputs
(
pidstr
.
str
().
c_str
(),
fp
);
fclose
(
fp
);
os
<<
getpid
();
}
return
true
;
...
...
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