summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);
}