Re: cron: fix incorrect error message

2012-05-08 Thread Okan Demirmen
On Tue 2012.05.08 at 00:07 -0400, Lawrence Teo wrote:
 This diff fixes the error message for one of the log_it() calls in cron
 (was probably a pasto).  While here, also fix the style for two other
 log_it() calls.
 
 Lawrence
 
 Index: cron.c
 ===
 RCS file: /cvs/src/usr.sbin/cron/cron.c,v
 retrieving revision 1.43
 diff -u -p -r1.43 cron.c
 --- cron.c22 Aug 2011 19:32:42 -  1.43
 +++ cron.c8 May 2012 03:42:12 -
 @@ -100,7 +100,7 @@ main(int argc, char *argv[]) {
   set_cron_cwd();
  
   if (putenv(PATH=_PATH_DEFPATH)  0) {
 - log_it(CRON, getpid(), DEATH, can't malloc);
 + log_it(CRON, getpid(), DEATH, can't set PATH);

Not really a pasto; from putenv():

P = (char **)realloc(lastenv, sizeof(char *) * (cnt + 2));
if (!P)
return (-1);

Of course, further up, one can get -1 from putenv() if '=' is missing,
but we already sent that char, so really, the above is an accurate
message...especially since this check is done early.

   exit(EXIT_FAILURE);
   }
  
 @@ -113,7 +113,7 @@ main(int argc, char *argv[]) {
   } else if (NoFork == 0) {
   switch (fork()) {
   case -1:
 - log_it(CRON,getpid(),DEATH,can't fork);
 + log_it(CRON, getpid(), DEATH, can't fork);
   exit(EXIT_FAILURE);
   break;
   case 0:
 @@ -126,7 +126,7 @@ main(int argc, char *argv[]) {
   if (fd != STDERR_FILENO)
   (void) close(fd);
   }
 - log_it(CRON,getpid(),STARTUP,CRON_VERSION);
 + log_it(CRON, getpid(), STARTUP, CRON_VERSION);
   break;
   default:
   /* parent process should just die */



Re: cron: fix incorrect error message

2012-05-08 Thread Thomas Pfaff
On Tue, 8 May 2012 09:55:53 -0400
Okan Demirmen o...@demirmen.com wrote:
 
 Not really a pasto; from putenv():
 
   P = (char **)realloc(lastenv, sizeof(char *) * (cnt + 2));

*puke*

Ok?

Index: setenv.c
===
RCS file: /cvs/src/lib/libc/stdlib/setenv.c,v
retrieving revision 1.13
diff -u -p -r1.13 setenv.c
--- setenv.c23 Aug 2010 22:31:50 -  1.13
+++ setenv.c8 May 2012 16:13:01 -
@@ -71,7 +71,7 @@ putenv(char *str)
for (P = environ; *P != NULL; P++)
;
cnt = P - environ;
-   P = (char **)realloc(lastenv, sizeof(char *) * (cnt + 2));
+   P = realloc(lastenv, sizeof(char *) * (cnt + 2));
if (!P)
return (-1);
if (lastenv != environ)
@@ -127,7 +127,7 @@ setenv(const char *name, const char *val
for (P = environ; *P != NULL; P++)
;
cnt = P - environ;
-   P = (char **)realloc(lastenv, sizeof(char *) * (cnt + 2));
+   P = realloc(lastenv, sizeof(char *) * (cnt + 2));
if (!P)
return (-1);
if (lastenv != environ)



Re: cron: fix incorrect error message

2012-05-08 Thread Joerg Sonnenberger
On Tue, May 08, 2012 at 06:19:55PM +0200, Thomas Pfaff wrote:
 On Tue, 8 May 2012 09:55:53 -0400
 Okan Demirmen o...@demirmen.com wrote:
  
  Not really a pasto; from putenv():
  
  P = (char **)realloc(lastenv, sizeof(char *) * (cnt + 2));
 
 *puke*
 
 Ok?

If you want to drop the first cast, you might want to spell it
sizeof(*P) as well...

Joerg



Re: cron: fix incorrect error message

2012-05-08 Thread Thomas Pfaff
On Tue, 8 May 2012 18:22:51 +0200
Joerg Sonnenberger jo...@britannica.bec.de wrote:

 On Tue, May 08, 2012 at 06:19:55PM +0200, Thomas Pfaff wrote:
  On Tue, 8 May 2012 09:55:53 -0400
  Okan Demirmen o...@demirmen.com wrote:
   
   Not really a pasto; from putenv():
   
 P = (char **)realloc(lastenv, sizeof(char *) * (cnt + 2));
  
  *puke*
  
  Ok?
 
 If you want to drop the first cast, you might want to spell it
 sizeof(*P) as well...


Sure,

Index: setenv.c
===
RCS file: /cvs/src/lib/libc/stdlib/setenv.c,v
retrieving revision 1.13
diff -u -p -r1.13 setenv.c
--- setenv.c23 Aug 2010 22:31:50 -  1.13
+++ setenv.c8 May 2012 16:47:57 -
@@ -71,11 +71,11 @@ putenv(char *str)
for (P = environ; *P != NULL; P++)
;
cnt = P - environ;
-   P = (char **)realloc(lastenv, sizeof(char *) * (cnt + 2));
+   P = realloc(lastenv, sizeof(*P) * (cnt + 2));
if (!P)
return (-1);
if (lastenv != environ)
-   memcpy(P, environ, cnt * sizeof(char *));
+   memcpy(P, environ, cnt * sizeof(*P));
lastenv = environ = P;
environ[cnt] = str;
environ[cnt + 1] = NULL;
@@ -127,11 +127,11 @@ setenv(const char *name, const char *val
for (P = environ; *P != NULL; P++)
;
cnt = P - environ;
-   P = (char **)realloc(lastenv, sizeof(char *) * (cnt + 2));
+   P = realloc(lastenv, sizeof(*P) * (cnt + 2));
if (!P)
return (-1);
if (lastenv != environ)
-   memcpy(P, environ, cnt * sizeof(char *));
+   memcpy(P, environ, cnt * sizeof(*P));
lastenv = environ = P;
offset = cnt;
environ[cnt + 1] = NULL;



cron: fix incorrect error message

2012-05-07 Thread Lawrence Teo
This diff fixes the error message for one of the log_it() calls in cron
(was probably a pasto).  While here, also fix the style for two other
log_it() calls.

Lawrence

Index: cron.c
===
RCS file: /cvs/src/usr.sbin/cron/cron.c,v
retrieving revision 1.43
diff -u -p -r1.43 cron.c
--- cron.c  22 Aug 2011 19:32:42 -  1.43
+++ cron.c  8 May 2012 03:42:12 -
@@ -100,7 +100,7 @@ main(int argc, char *argv[]) {
set_cron_cwd();
 
if (putenv(PATH=_PATH_DEFPATH)  0) {
-   log_it(CRON, getpid(), DEATH, can't malloc);
+   log_it(CRON, getpid(), DEATH, can't set PATH);
exit(EXIT_FAILURE);
}
 
@@ -113,7 +113,7 @@ main(int argc, char *argv[]) {
} else if (NoFork == 0) {
switch (fork()) {
case -1:
-   log_it(CRON,getpid(),DEATH,can't fork);
+   log_it(CRON, getpid(), DEATH, can't fork);
exit(EXIT_FAILURE);
break;
case 0:
@@ -126,7 +126,7 @@ main(int argc, char *argv[]) {
if (fd != STDERR_FILENO)
(void) close(fd);
}
-   log_it(CRON,getpid(),STARTUP,CRON_VERSION);
+   log_it(CRON, getpid(), STARTUP, CRON_VERSION);
break;
default:
/* parent process should just die */