Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
savoirfairelinux
jami-daemon
Commits
4a8ae4e2
Commit
4a8ae4e2
authored
Apr 12, 2012
by
Tristan Matthews
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
* #9782: use fstreams instead of fscanf
Does type checking.
parent
cf06b9ae
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
19 deletions
+11
-19
daemon/src/fileutils.cpp
daemon/src/fileutils.cpp
+11
-19
No files found.
daemon/src/fileutils.cpp
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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment