Bell 32V development
authorTom London <tbl@research.uucp>
Fri, 19 Jan 1979 05:57:58 +0000 (00:57 -0500)
committerTom London <tbl@research.uucp>
Fri, 19 Jan 1979 05:57:58 +0000 (00:57 -0500)
Work on file usr/src/cmd/uucp/logent.c

Co-Authored-By: John Reiser <jfr@research.uucp>
Synthesized-from: 32v

usr/src/cmd/uucp/logent.c [new file with mode: 0644]

diff --git a/usr/src/cmd/uucp/logent.c b/usr/src/cmd/uucp/logent.c
new file mode 100644 (file)
index 0000000..a0d9760
--- /dev/null
@@ -0,0 +1,115 @@
+#include "uucp.h"
+#include <sys/types.h>
+#include <time.h>
+
+
+char Tmplog[MAXFULLNAME] = "";
+FILE *Lp = NULL;
+
+/*******
+ *     logent(text, status)    make log entry
+ *     char *text, *status;
+ *
+ *     return code - none
+ */
+
+logent(text, status)
+char *text, *status;
+{
+       int n;
+       FILE *fp;
+       if (Lp != NULL) {
+               /*  make entry in existing temp log file  */
+               mlogent(Lp, status, text);
+               return;
+       }
+
+       if (ulockf(LOGLOCK, 10l) == 0) {
+               if ((fp = fopen(LOGFILE, "a")) == NULL) {
+                       rmlock(LOGLOCK);
+               }
+               else {
+                       mlogent(fp, status, text);
+                       fclose(fp);
+                       rmlock(LOGLOCK);
+                       return;
+               }
+       }
+
+       /*  make a temp log file  */
+       for (n = 0; n < 10; n++) {
+               sprintf(Tmplog, "%s/LOG.%05d.%1d", LOGDIR, getpid(), n);
+               if (access(Tmplog, 0) == -1)
+                       break;
+       }
+       if ((Lp = fopen(Tmplog, "w")) == NULL)
+               return;
+       chmod(Tmplog, 0222);
+       setbuf(Lp, NULL);
+       mlogent(Lp, status, text);
+       return;
+}
+
+/***
+ *     mlogent(fp, status, text)  - make a log entry
+ */
+
+mlogent(fp, status, text)
+char *text, *status;
+FILE *fp;
+{
+       struct tm *tp;
+       extern struct tm *localtime();
+       time_t clock;
+       time(&clock);
+       tp = localtime(&clock);
+       fprintf(fp, "%s %s ", User, Rmtname);
+       fprintf(fp, "(%d/%d-%d:%d) ", tp->tm_mon + 1,
+               tp->tm_mday, tp->tm_hour, tp->tm_min);
+       fprintf(fp, "%s (%s)\n", status, text);
+       return;
+}
+
+/***
+ *     logcls()        close log file
+ *
+ *     return codes:  none
+ */
+
+logcls()
+{
+       if (Lp != NULL) {
+               fclose(Lp);
+               chmod(Tmplog, 0666);
+       }
+       return;
+}
+
+
+/***
+ *     syslog(text)    make system log entry
+ *     char *text;
+ *
+ *     return codes - none
+ */
+
+syslog(text)
+char *text;
+{
+       struct tm *tp;
+       extern struct tm *localtime();
+       time_t clock;
+       FILE *fp;
+
+       time(&clock);
+       tp = localtime(&clock);
+       fp = fopen(SYSLOG, "a");
+       if (fp == NULL)
+               return;
+       fprintf(fp, "%s %s ", User, Rmtname);
+       fprintf(fp, "(%d/%d-%d:%d) ", tp->tm_mon + 1,
+               tp->tm_mday, tp->tm_hour, tp->tm_min);
+       fprintf(fp, "%s\n", text);
+       fclose(fp);
+       return;
+}