svn commit: samba r23595 - in branches: SAMBA_3_0/source/lib
SAMBA_3_0_26/source/lib
vlendec at samba.org
vlendec at samba.org
Sun Jun 24 13:41:00 GMT 2007
Author: vlendec
Date: 2007-06-24 13:40:58 +0000 (Sun, 24 Jun 2007)
New Revision: 23595
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=23595
Log:
One pstring a day...
Modified:
branches/SAMBA_3_0/source/lib/pidfile.c
branches/SAMBA_3_0_26/source/lib/pidfile.c
Changeset:
Modified: branches/SAMBA_3_0/source/lib/pidfile.c
===================================================================
--- branches/SAMBA_3_0/source/lib/pidfile.c 2007-06-24 13:24:20 UTC (rev 23594)
+++ branches/SAMBA_3_0/source/lib/pidfile.c 2007-06-24 13:40:58 UTC (rev 23595)
@@ -34,12 +34,15 @@
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 @@
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 @@
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 @@
/* 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 @@
exit(1);
}
/* Leave pid file open & locked for the duration... */
+ SAFE_FREE(name);
+ SAFE_FREE(pidFile);
}
Modified: branches/SAMBA_3_0_26/source/lib/pidfile.c
===================================================================
--- branches/SAMBA_3_0_26/source/lib/pidfile.c 2007-06-24 13:24:20 UTC (rev 23594)
+++ branches/SAMBA_3_0_26/source/lib/pidfile.c 2007-06-24 13:40:58 UTC (rev 23595)
@@ -34,12 +34,15 @@
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 @@
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 @@
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 @@
/* 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 @@
exit(1);
}
/* Leave pid file open & locked for the duration... */
+ SAFE_FREE(name);
+ SAFE_FREE(pidFile);
}
More information about the samba-cvs
mailing list