Deleted Added
full compact
xutil.c (42629) xutil.c (51292)
1/*
1/*
2 * Copyright (c) 1997-1998 Erez Zadok
2 * Copyright (c) 1997-1999 Erez Zadok
3 * Copyright (c) 1990 Jan-Simon Pendry
4 * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
5 * Copyright (c) 1990 The Regents of the University of California.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * Jan-Simon Pendry at Imperial College, London.
10 *

--- 22 unchanged lines hidden (view full) ---

33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * %W% (Berkeley) %G%
40 *
3 * Copyright (c) 1990 Jan-Simon Pendry
4 * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
5 * Copyright (c) 1990 The Regents of the University of California.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * Jan-Simon Pendry at Imperial College, London.
10 *

--- 22 unchanged lines hidden (view full) ---

33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * %W% (Berkeley) %G%
40 *
41 * $Id: xutil.c,v 1.2 1998/12/27 06:25:24 ezk Exp $
41 * $Id: xutil.c,v 1.6 1999/09/08 23:36:53 ezk Exp $
42 *
43 */
44
45#ifdef HAVE_CONFIG_H
46# include <config.h>
47#endif /* HAVE_CONFIG_H */
48#include <am_defs.h>
49#include <amu.h>
50
42 *
43 */
44
45#ifdef HAVE_CONFIG_H
46# include <config.h>
47#endif /* HAVE_CONFIG_H */
48#include <am_defs.h>
49#include <amu.h>
50
51FILE *logfp = stderr; /* Log errors to stderr initially */
51/*
52 * Logfp is the default logging device, and is initialized to stderr by
53 * default in dplog/plog below, and in
54 * amd/amfs_program.c:amfs_program_exec().
55 */
56FILE *logfp = NULL;
52
53static char *am_progname = "unknown"; /* "amd" */
54static char am_hostname[MAXHOSTNAMELEN + 1] = "unknown"; /* Hostname */
55pid_t am_mypid = -1; /* process ID */
56serv_state amd_state; /* amd's state */
57int foreground = 1; /* 1 == this is the top-level server */
58#ifdef DEBUG
59int debug_flags = 0;

--- 207 unchanged lines hidden (view full) ---

267 }
268 malloc_verify();
269}
270#endif /* DEBUG_MEM */
271
272
273/*
274 * Take a log format string and expand occurrences of %m
57
58static char *am_progname = "unknown"; /* "amd" */
59static char am_hostname[MAXHOSTNAMELEN + 1] = "unknown"; /* Hostname */
60pid_t am_mypid = -1; /* process ID */
61serv_state amd_state; /* amd's state */
62int foreground = 1; /* 1 == this is the top-level server */
63#ifdef DEBUG
64int debug_flags = 0;

--- 207 unchanged lines hidden (view full) ---

272 }
273 malloc_verify();
274}
275#endif /* DEBUG_MEM */
276
277
278/*
279 * Take a log format string and expand occurrences of %m
275 * with the current error code taken from errno.
280 * with the current error code taken from errno. Make sure
281 * 'e' never gets longer than maxlen characters.
276 */
277static void
282 */
283static void
278expand_error(char *f, char *e)
284expand_error(char *f, char *e, int maxlen)
279{
280 extern int sys_nerr;
285{
286 extern int sys_nerr;
281 char *p;
287 char *p, *q;
282 int error = errno;
288 int error = errno;
289 int len = 0;
283
290
284 for (p = f; (*e = *p); e++, p++) {
291 for (p = f, q = e; (*q = *p) && len < maxlen; len++, q++, p++) {
285 if (p[0] == '%' && p[1] == 'm') {
286 const char *errstr;
287 if (error < 0 || error >= sys_nerr)
288 errstr = NULL;
289 else
292 if (p[0] == '%' && p[1] == 'm') {
293 const char *errstr;
294 if (error < 0 || error >= sys_nerr)
295 errstr = NULL;
296 else
290 errstr = sys_errlist[error];
297#ifdef HAVE_STRERROR
298 errstr = strerror(error);
299#else /* not HAVE_STRERROR */
300 errstr = sys_errlist[error];
301#endif /* not HAVE_STRERROR */
291 if (errstr)
302 if (errstr)
292 strcpy(e, errstr);
303 strcpy(q, errstr);
293 else
304 else
294 sprintf(e, "Error %d", error);
295 e += strlen(e) - 1;
305 sprintf(q, "Error %d", error);
306 len += strlen(q) - 1;
307 q += strlen(q) - 1;
296 p++;
297 }
298 }
308 p++;
309 }
310 }
311 e[maxlen-1] = '\0'; /* null terminate, to be sure */
299}
300
301
302/*
303 * Output the time of day and hostname to the logfile
304 */
305static void
306show_time_host_and_name(int lvl)

--- 55 unchanged lines hidden (view full) ---

362}
363
364
365void
366dplog(char *fmt, ...)
367{
368 va_list ap;
369
312}
313
314
315/*
316 * Output the time of day and hostname to the logfile
317 */
318static void
319show_time_host_and_name(int lvl)

--- 55 unchanged lines hidden (view full) ---

375}
376
377
378void
379dplog(char *fmt, ...)
380{
381 va_list ap;
382
383 if (!logfp)
384 logfp = stderr; /* initialize before possible first use */
385
370 va_start(ap, fmt);
371 real_plog(XLOG_DEBUG, fmt, ap);
372 va_end(ap);
373}
374#endif /* DEBUG */
375
376
377void
378plog(int lvl, char *fmt, ...)
379{
380 va_list ap;
381
386 va_start(ap, fmt);
387 real_plog(XLOG_DEBUG, fmt, ap);
388 va_end(ap);
389}
390#endif /* DEBUG */
391
392
393void
394plog(int lvl, char *fmt, ...)
395{
396 va_list ap;
397
398 if (!logfp)
399 logfp = stderr; /* initialize before possible first use */
400
382 va_start(ap, fmt);
383 real_plog(lvl, fmt, ap);
384 va_end(ap);
385}
386
387
388static void
389real_plog(int lvl, char *fmt, va_list vargs)

--- 6 unchanged lines hidden (view full) ---

396
397 if (!(xlog_level & lvl))
398 return;
399
400#ifdef DEBUG_MEM
401 checkup_mem();
402#endif /* DEBUG_MEM */
403
401 va_start(ap, fmt);
402 real_plog(lvl, fmt, ap);
403 va_end(ap);
404}
405
406
407static void
408real_plog(int lvl, char *fmt, va_list vargs)

--- 6 unchanged lines hidden (view full) ---

415
416 if (!(xlog_level & lvl))
417 return;
418
419#ifdef DEBUG_MEM
420 checkup_mem();
421#endif /* DEBUG_MEM */
422
404 expand_error(fmt, efmt);
423 expand_error(fmt, efmt, 1024);
405
424
425 /*
426 * XXX: ptr is 1024 bytes long. It is possible to write into it
427 * more than 1024 bytes, if efmt is already large, and vargs expand
428 * as well.
429 */
406 vsprintf(ptr, efmt, vargs);
430 vsprintf(ptr, efmt, vargs);
431 msg[1023] = '\0'; /* null terminate, to be sure */
407
408 ptr += strlen(ptr);
409 if (ptr[-1] == '\n')
410 *--ptr = '\0';
411
412#ifdef HAVE_SYSLOG
413 if (syslogging) {
414 switch (lvl) { /* from mike <mcooper@usc.edu> */

--- 196 unchanged lines hidden (view full) ---

611 xlog_level_init = xl;
612 else
613 xl |= xlog_level_init;
614 xlog_level = xl;
615 }
616 return rc;
617}
618
432
433 ptr += strlen(ptr);
434 if (ptr[-1] == '\n')
435 *--ptr = '\0';
436
437#ifdef HAVE_SYSLOG
438 if (syslogging) {
439 switch (lvl) { /* from mike <mcooper@usc.edu> */

--- 196 unchanged lines hidden (view full) ---

636 xlog_level_init = xl;
637 else
638 xl |= xlog_level_init;
639 xlog_level = xl;
640 }
641 return rc;
642}
643
644#ifdef LOG_DAEMON
619/*
620 * get syslog facility to use.
621 * logfile can be "syslog", "syslog:daemon", "syslog:local7", etc.
622 */
623static int
624get_syslog_facility(const char *logfile)
625{
626 char *facstr;

--- 15 unchanged lines hidden (view full) ---

642#ifdef LOG_USER
643 if (STREQ(facstr, "user"))
644 return LOG_USER;
645#endif /* not LOG_USER */
646#ifdef LOG_MAIL
647 if (STREQ(facstr, "mail"))
648 return LOG_MAIL;
649#endif /* not LOG_MAIL */
645/*
646 * get syslog facility to use.
647 * logfile can be "syslog", "syslog:daemon", "syslog:local7", etc.
648 */
649static int
650get_syslog_facility(const char *logfile)
651{
652 char *facstr;

--- 15 unchanged lines hidden (view full) ---

668#ifdef LOG_USER
669 if (STREQ(facstr, "user"))
670 return LOG_USER;
671#endif /* not LOG_USER */
672#ifdef LOG_MAIL
673 if (STREQ(facstr, "mail"))
674 return LOG_MAIL;
675#endif /* not LOG_MAIL */
650#ifdef LOG_DAEMON
676
651 if (STREQ(facstr, "daemon"))
652 return LOG_DAEMON;
677 if (STREQ(facstr, "daemon"))
678 return LOG_DAEMON;
653#endif /* not LOG_DAEMON */
679
654#ifdef LOG_AUTH
655 if (STREQ(facstr, "auth"))
656 return LOG_AUTH;
657#endif /* not LOG_AUTH */
658#ifdef LOG_SYSLOG
659 if (STREQ(facstr, "syslog"))
660 return LOG_SYSLOG;
661#endif /* not LOG_SYSLOG */

--- 45 unchanged lines hidden (view full) ---

707 if (STREQ(facstr, "local7"))
708 return LOG_LOCAL7;
709#endif /* not LOG_LOCAL7 */
710
711 /* didn't match anything else */
712 plog(XLOG_WARNING, "unknown syslog facility \"%s\", using LOG_DAEMON", facstr);
713 return LOG_DAEMON;
714}
680#ifdef LOG_AUTH
681 if (STREQ(facstr, "auth"))
682 return LOG_AUTH;
683#endif /* not LOG_AUTH */
684#ifdef LOG_SYSLOG
685 if (STREQ(facstr, "syslog"))
686 return LOG_SYSLOG;
687#endif /* not LOG_SYSLOG */

--- 45 unchanged lines hidden (view full) ---

733 if (STREQ(facstr, "local7"))
734 return LOG_LOCAL7;
735#endif /* not LOG_LOCAL7 */
736
737 /* didn't match anything else */
738 plog(XLOG_WARNING, "unknown syslog facility \"%s\", using LOG_DAEMON", facstr);
739 return LOG_DAEMON;
740}
741#endif /* not LOG_DAEMON */
715
716
717/*
718 * Change current logfile
719 */
720int
721switch_to_logfile(char *logfile, int old_umask)
722{

--- 150 unchanged lines hidden ---
742
743
744/*
745 * Change current logfile
746 */
747int
748switch_to_logfile(char *logfile, int old_umask)
749{

--- 150 unchanged lines hidden ---