summaryrefslogtreecommitdiff
path: root/source3/lib/pidfile.c
diff options
context:
space:
mode:
authorVolker Lendecke <vlendec@samba.org>2007-06-24 13:40:58 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:23:34 -0500
commit32d22501842ebbf02d7de94785e866e49d1545b2 (patch)
tree9950870e356e89f403495ee047ecfded0fbbb4bf /source3/lib/pidfile.c
parent9f7bb48dd3ee9e884135868773b3e0123cf0f9a6 (diff)
downloadsamba-32d22501842ebbf02d7de94785e866e49d1545b2.tar.gz
samba-32d22501842ebbf02d7de94785e866e49d1545b2.tar.bz2
samba-32d22501842ebbf02d7de94785e866e49d1545b2.zip
r23595: One pstring a day...
(This used to be commit 669eff902a20f3023360918ede6672d37b1f7d44)
Diffstat (limited to 'source3/lib/pidfile.c')
-rw-r--r--source3/lib/pidfile.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/source3/lib/pidfile.c b/source3/lib/pidfile.c
index 89ab6d799b..9dc4f2f186 100644
--- a/source3/lib/pidfile.c
+++ b/source3/lib/pidfile.c
@@ -34,12 +34,15 @@ pid_t pidfile_pid(const char *name)
char pidstr[20];
pid_t pid;
unsigned int ret;
- pstring pidFile;
+ char * pidFile;
- slprintf(pidFile, sizeof(pidFile)-1, "%s/%s.pid", lp_piddir(), name);
+ if (asprintf(&pidFile, "%s/%s.pid", lp_piddir(), name) == -1) {
+ return 0;
+ }
fd = sys_open(pidFile, O_NONBLOCK | O_RDONLY, 0644);
if (fd == -1) {
+ SAFE_FREE(pidFile);
return 0;
}
@@ -68,12 +71,14 @@ pid_t pidfile_pid(const char *name)
goto noproc;
}
+ SAFE_FREE(pidFile);
close(fd);
return (pid_t)ret;
noproc:
close(fd);
unlink(pidFile);
+ SAFE_FREE(pidFile);
return 0;
}
@@ -83,14 +88,14 @@ void pidfile_create(const char *program_name)
int fd;
char buf[20];
char *short_configfile;
- pstring name;
- pstring pidFile;
+ char *name;
+ char *pidFile;
pid_t pid;
/* Add a suffix to the program name if this is a process with a
* none default configuration file name. */
if (strcmp( CONFIGFILE, dyn_CONFIGFILE) == 0) {
- strncpy( name, program_name, sizeof( name)-1);
+ name = SMB_STRDUP(program_name);
} else {
short_configfile = strrchr( dyn_CONFIGFILE, '/');
if (short_configfile == NULL) {
@@ -100,10 +105,15 @@ void pidfile_create(const char *program_name)
/* full/relative path provided */
short_configfile++;
}
- slprintf( name, sizeof( name)-1, "%s-%s", program_name, short_configfile+1);
+ if (asprintf(&name, "%s-%s", program_name,
+ short_configfile+1) == -1) {
+ smb_panic("asprintf failed");
+ }
}
- slprintf(pidFile, sizeof(pidFile)-1, "%s/%s.pid", lp_piddir(), name);
+ if (asprintf(&pidFile, "%s/%s.pid", lp_piddir(), name) == -1) {
+ smb_panic("asprintf failed");
+ }
pid = pidfile_pid(name);
if (pid != 0) {
@@ -133,4 +143,6 @@ void pidfile_create(const char *program_name)
exit(1);
}
/* Leave pid file open & locked for the duration... */
+ SAFE_FREE(name);
+ SAFE_FREE(pidFile);
}