Cron has a homegrown vis-like function for logging commands.
We have vis(3) so let's use it instead...

 - todd

Index: do_command.c
===================================================================
RCS file: /cvs/src/usr.sbin/cron/do_command.c,v
retrieving revision 1.50
diff -u -p -u -r1.50 do_command.c
--- do_command.c        25 Oct 2015 21:30:11 -0000      1.50
+++ do_command.c        29 Oct 2015 21:32:03 -0000
@@ -18,6 +18,7 @@
  */
 
 #include "cron.h"
+#include "vis.h"
 
 static void            child_process(entry *, user *);
 
@@ -125,10 +126,11 @@ child_process(entry *e, user *u)
                 * PID is part of the log message.
                 */
                if ((e->flags & DONT_LOG) == 0) {
-                       char *x = mkprints((u_char *)e->cmd, strlen(e->cmd));
-
-                       log_it(usernm, getpid(), "CMD", x);
-                       free(x);
+                       char *x;
+                       if (stravis(&x, e->cmd, 0) != -1) {
+                               log_it(usernm, getpid(), "CMD", x);
+                               free(x);
+                       }
                }
 
                /* that's the last thing we'll log.  close the log files.
Index: funcs.h
===================================================================
RCS file: /cvs/src/usr.sbin/cron/funcs.h,v
retrieving revision 1.20
diff -u -p -u -r1.20 funcs.h
--- funcs.h     29 Oct 2015 21:19:09 -0000      1.20
+++ funcs.h     29 Oct 2015 21:32:03 -0000
@@ -59,13 +59,10 @@ int         strtot(const char *nptr, char **end
 
 char           *env_get(char *, char **),
                *arpadate(time_t *),
-               *mkprints(unsigned char *, unsigned int),
                *first_word(char *, char *),
                **env_init(void),
                **env_copy(char **),
                **env_set(char **, char *);
-
-void           mkprint(char *, unsigned char *, int);
 
 user           *load_user(int, struct passwd *, const char *),
                *find_user(cron_db *, const char *);
Index: misc.c
===================================================================
RCS file: /cvs/src/usr.sbin/cron/misc.c,v
retrieving revision 1.62
diff -u -p -u -r1.62 misc.c
--- misc.c      29 Oct 2015 21:19:09 -0000      1.62
+++ misc.c      29 Oct 2015 21:32:03 -0000
@@ -307,57 +307,6 @@ first_word(char *s, char *t)
        return (rb);
 }
 
-/* warning:
- *     heavily ascii-dependent.
- */
-void
-mkprint(dst, src, len)
-       char *dst;
-       unsigned char *src;
-       int len;
-{
-       /*
-        * XXX
-        * We know this routine can't overflow the dst buffer because mkprints()
-        * allocated enough space for the worst case.
-        */
-       while (len-- > 0)
-       {
-               unsigned char ch = *src++;
-
-               if (ch < ' ') {                 /* control character */
-                       *dst++ = '^';
-                       *dst++ = ch + '@';
-               } else if (ch < 0177) {         /* printable */
-                       *dst++ = ch;
-               } else if (ch == 0177) {        /* delete/rubout */
-                       *dst++ = '^';
-                       *dst++ = '?';
-               } else {                        /* parity character */
-                       snprintf(dst, 5, "\\%03o", ch);
-                       dst += strlen(dst);
-               }
-       }
-       *dst = '\0';
-}
-
-/* warning:
- *     returns a pointer to malloc'd storage, you must call free yourself.
- */
-char *
-mkprints(src, len)
-       unsigned char *src;
-       unsigned int len;
-{
-       char *dst = malloc(len*4 + 1);
-
-       if (dst)
-               mkprint(dst, src, len);
-
-       return (dst);
-}
-
-
 static gid_t save_egid;
 int swap_gids() { save_egid = getegid(); return (setegid(getgid())); }
 int swap_gids_back() { return (setegid(save_egid)); }

Reply via email to