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;
}
goto noproc;
}
+ SAFE_FREE(pidFile);
close(fd);
return (pid_t)ret;
noproc:
close(fd);
unlink(pidFile);
+ SAFE_FREE(pidFile);
return 0;
}
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) {
/* 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) {
exit(1);
}
/* Leave pid file open & locked for the duration... */
+ SAFE_FREE(name);
+ SAFE_FREE(pidFile);
}