summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2015-01-19 10:52:11 +0100
committerVolker Lendecke <vl@samba.org>2015-02-26 18:28:31 +0100
commit1237b006d5fad9523fb7e7bf9ecb09df66afb7f6 (patch)
treee81670af6c2b0bdc8eabf8582dc32b2df18b022a /lib
parentbd6bc30693ce989588d8ebebeb717f4e82d590c4 (diff)
downloadsamba-1237b006d5fad9523fb7e7bf9ecb09df66afb7f6.tar.gz
samba-1237b006d5fad9523fb7e7bf9ecb09df66afb7f6.tar.xz
samba-1237b006d5fad9523fb7e7bf9ecb09df66afb7f6.zip
lib: Simplify pidfile.c
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Thu Feb 26 18:28:31 CET 2015 on sn-devel-104
Diffstat (limited to 'lib')
-rw-r--r--lib/util/pidfile.c19
1 files changed, 6 insertions, 13 deletions
diff --git a/lib/util/pidfile.c b/lib/util/pidfile.c
index 4960be66e9..5590780dd5 100644
--- a/lib/util/pidfile.c
+++ b/lib/util/pidfile.c
@@ -34,19 +34,17 @@
*/
pid_t pidfile_pid(const char *piddir, const char *name)
{
+ size_t len = strlen(piddir) + strlen(name) + 6;
+ char pidFile[len];
int fd;
char pidstr[20];
pid_t ret = -1;
- char *pidFile;
- if (asprintf(&pidFile, "%s/%s.pid", piddir, name) < 0) {
- return 0;
- }
+ snprintf(pidFile, sizeof(pidFile), "%s/%s.pid", piddir, name);
fd = open(pidFile, O_NONBLOCK | O_RDONLY, 0644);
if (fd == -1) {
- SAFE_FREE(pidFile);
return 0;
}
@@ -76,7 +74,6 @@ pid_t pidfile_pid(const char *piddir, const char *name)
}
close(fd);
- SAFE_FREE(pidFile);
DEBUG(10, ("Process with PID=%d is running.\n", (int)ret));
return ret;
@@ -85,7 +82,6 @@ pid_t pidfile_pid(const char *piddir, const char *name)
DEBUG(10, ("Deleting %s, since %d is not a Samba process.\n", pidFile,
(int)ret));
unlink(pidFile);
- SAFE_FREE(pidFile);
return 0;
}
@@ -94,15 +90,13 @@ pid_t pidfile_pid(const char *piddir, const char *name)
*/
void pidfile_create(const char *piddir, const char *name)
{
+ size_t len = strlen(piddir) + strlen(name) + 6;
+ char pidFile[len];
int fd;
char buf[20];
- char *pidFile;
pid_t pid;
- if (asprintf(&pidFile, "%s/%s.pid", piddir, name) < 0) {
- DEBUG(0,("ERROR: Out of memory\n"));
- exit(1);
- }
+ snprintf(pidFile, sizeof(pidFile), "%s/%s.pid", piddir, name);
pid = pidfile_pid(piddir, name);
if (pid != 0) {
@@ -135,7 +129,6 @@ void pidfile_create(const char *piddir, const char *name)
}
/* Leave pid file open & locked for the duration... */
- SAFE_FREE(pidFile);
}
void pidfile_unlink(const char *piddir, const char *name)