watchdogd.c (143831) | watchdogd.c (149434) |
---|---|
1/* 2 * Copyright (c) 2003-2004 Sean M. Kelly <smkelly@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * SUCH DAMAGE. 25 */ 26 27/* 28 * Software watchdog daemon. 29 */ 30 31#include <sys/types.h> | 1/* 2 * Copyright (c) 2003-2004 Sean M. Kelly <smkelly@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * SUCH DAMAGE. 25 */ 26 27/* 28 * Software watchdog daemon. 29 */ 30 31#include <sys/types.h> |
32__FBSDID("$FreeBSD: head/usr.sbin/watchdogd/watchdogd.c 143831 2005-03-19 01:46:37Z marius $"); | 32__FBSDID("$FreeBSD: head/usr.sbin/watchdogd/watchdogd.c 149434 2005-08-24 19:28:33Z pjd $"); |
33 | 33 |
34#include <sys/param.h> |
|
34#include <sys/rtprio.h> 35#include <sys/stat.h> 36#include <sys/time.h> 37#include <sys/watchdog.h> 38 39#include <err.h> 40#include <errno.h> 41#include <fcntl.h> | 35#include <sys/rtprio.h> 36#include <sys/stat.h> 37#include <sys/time.h> 38#include <sys/watchdog.h> 39 40#include <err.h> 41#include <errno.h> 42#include <fcntl.h> |
43#include <libutil.h> |
|
42#include <math.h> 43#include <paths.h> 44#include <signal.h> 45#include <stdio.h> 46#include <stdlib.h> 47#include <string.h> 48#include <sysexits.h> 49#include <unistd.h> --- 20 unchanged lines hidden (view full) --- 70 71/* 72 * Periodically pat the watchdog, preventing it from firing. 73 */ 74int 75main(int argc, char *argv[]) 76{ 77 struct rtprio rtp; | 44#include <math.h> 45#include <paths.h> 46#include <signal.h> 47#include <stdio.h> 48#include <stdlib.h> 49#include <string.h> 50#include <sysexits.h> 51#include <unistd.h> --- 20 unchanged lines hidden (view full) --- 72 73/* 74 * Periodically pat the watchdog, preventing it from firing. 75 */ 76int 77main(int argc, char *argv[]) 78{ 79 struct rtprio rtp; |
78 FILE *fp; | 80 struct pidfh *pfh; 81 pid_t otherpid; |
79 80 if (getuid() != 0) 81 errx(EX_SOFTWARE, "not super user"); 82 83 parseargs(argc, argv); 84 85 rtp.type = RTP_PRIO_REALTIME; 86 rtp.prio = 0; 87 if (rtprio(RTP_SET, 0, &rtp) == -1) 88 err(EX_OSERR, "rtprio"); 89 90 if (watchdog_init() == -1) 91 errx(EX_SOFTWARE, "unable to initialize watchdog"); 92 93 if (is_daemon) { 94 if (watchdog_onoff(1) == -1) 95 exit(EX_SOFTWARE); 96 | 82 83 if (getuid() != 0) 84 errx(EX_SOFTWARE, "not super user"); 85 86 parseargs(argc, argv); 87 88 rtp.type = RTP_PRIO_REALTIME; 89 rtp.prio = 0; 90 if (rtprio(RTP_SET, 0, &rtp) == -1) 91 err(EX_OSERR, "rtprio"); 92 93 if (watchdog_init() == -1) 94 errx(EX_SOFTWARE, "unable to initialize watchdog"); 95 96 if (is_daemon) { 97 if (watchdog_onoff(1) == -1) 98 exit(EX_SOFTWARE); 99 |
100 pfh = pidfile_open(pidfile, 0644, &otherpid); 101 if (pfh == NULL) { 102 if (errno == EEXIST) { 103 errx(EX_SOFTWARE, "%s already running, pid: %d", 104 getprogname(), otherpid); 105 } 106 warn("Cannot open or create pidfile"); 107 } 108 |
|
97 if (debugging == 0 && daemon(0, 0) == -1) { 98 watchdog_onoff(0); | 109 if (debugging == 0 && daemon(0, 0) == -1) { 110 watchdog_onoff(0); |
111 pidfile_remove(pfh); |
|
99 err(EX_OSERR, "daemon"); 100 } 101 102 signal(SIGHUP, SIG_IGN); 103 signal(SIGINT, sighandler); 104 signal(SIGTERM, sighandler); 105 | 112 err(EX_OSERR, "daemon"); 113 } 114 115 signal(SIGHUP, SIG_IGN); 116 signal(SIGINT, sighandler); 117 signal(SIGTERM, sighandler); 118 |
106 fp = fopen(pidfile, "w"); 107 if (fp != NULL) { 108 fprintf(fp, "%d\n", getpid()); 109 fclose(fp); 110 } | 119 pidfile_write(pfh); |
111 112 watchdog_loop(); 113 114 /* exiting */ 115 watchdog_onoff(0); | 120 121 watchdog_loop(); 122 123 /* exiting */ 124 watchdog_onoff(0); |
116 unlink(pidfile); | 125 pidfile_remove(pfh); |
117 return (EX_OK); 118 } else { 119 if (passive) 120 timeout |= WD_PASSIVE; 121 else 122 timeout |= WD_ACTIVE; 123 if (watchdog_patpat() < 0 && 124 (timeout & WD_INTERVAL) != WD_TO_NEVER) --- 154 unchanged lines hidden --- | 126 return (EX_OK); 127 } else { 128 if (passive) 129 timeout |= WD_PASSIVE; 130 else 131 timeout |= WD_ACTIVE; 132 if (watchdog_patpat() < 0 && 133 (timeout & WD_INTERVAL) != WD_TO_NEVER) --- 154 unchanged lines hidden --- |