hastd.c (218041) | hastd.c (218044) |
---|---|
1/*- 2 * Copyright (c) 2009-2010 The FreeBSD Foundation 3 * Copyright (c) 2010-2011 Pawel Jakub Dawidek <pjd@FreeBSD.org> 4 * All rights reserved. 5 * 6 * This software was developed by Pawel Jakub Dawidek under sponsorship from 7 * the FreeBSD Foundation. 8 * --- 15 unchanged lines hidden (view full) --- 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2009-2010 The FreeBSD Foundation 3 * Copyright (c) 2010-2011 Pawel Jakub Dawidek <pjd@FreeBSD.org> 4 * All rights reserved. 5 * 6 * This software was developed by Pawel Jakub Dawidek under sponsorship from 7 * the FreeBSD Foundation. 8 * --- 15 unchanged lines hidden (view full) --- 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31#include <sys/cdefs.h> |
32__FBSDID("$FreeBSD: head/sbin/hastd/hastd.c 218041 2011-01-28 21:48:15Z pjd $"); | 32__FBSDID("$FreeBSD: head/sbin/hastd/hastd.c 218044 2011-01-28 21:56:47Z pjd $"); |
33 34#include <sys/param.h> 35#include <sys/linker.h> 36#include <sys/module.h> | 33 34#include <sys/param.h> 35#include <sys/linker.h> 36#include <sys/module.h> |
37#include <sys/stat.h> |
|
37#include <sys/wait.h> 38 39#include <assert.h> 40#include <err.h> 41#include <errno.h> 42#include <libutil.h> 43#include <signal.h> 44#include <stdbool.h> --- 69 unchanged lines hidden (view full) --- 114 proto_close(cfg->hc_controlin); 115 proto_close(cfg->hc_controlconn); 116 proto_close(cfg->hc_listenconn); 117 (void)pidfile_close(pfh); 118 hook_fini(); 119 pjdlog_fini(); 120} 121 | 38#include <sys/wait.h> 39 40#include <assert.h> 41#include <err.h> 42#include <errno.h> 43#include <libutil.h> 44#include <signal.h> 45#include <stdbool.h> --- 69 unchanged lines hidden (view full) --- 115 proto_close(cfg->hc_controlin); 116 proto_close(cfg->hc_controlconn); 117 proto_close(cfg->hc_listenconn); 118 (void)pidfile_close(pfh); 119 hook_fini(); 120 pjdlog_fini(); 121} 122 |
123static const char * 124dtype2str(mode_t mode) 125{ 126 127 if (S_ISBLK(mode)) 128 return ("block device"); 129 else if (S_ISCHR(mode)) 130 return ("character device"); 131 else if (S_ISDIR(mode)) 132 return ("directory"); 133 else if (S_ISFIFO(mode)) 134 return ("pipe or FIFO"); 135 else if (S_ISLNK(mode)) 136 return ("symbolic link"); 137 else if (S_ISREG(mode)) 138 return ("regular file"); 139 else if (S_ISSOCK(mode)) 140 return ("socket"); 141 else if (S_ISWHT(mode)) 142 return ("whiteout"); 143 else 144 return ("unknown"); 145} 146 147void 148descriptors_assert(const struct hast_resource *res, int pjdlogmode) 149{ 150 char msg[256]; 151 struct stat sb; 152 long maxfd; 153 bool isopen; 154 mode_t mode; 155 int fd; 156 157 /* 158 * At this point descriptor to syslog socket is closed, so if we want 159 * to log assertion message, we have to first store it in 'msg' local 160 * buffer and then open syslog socket and log it. 161 */ 162 msg[0] = '\0'; 163 164 maxfd = sysconf(_SC_OPEN_MAX); 165 if (maxfd < 0) { 166 pjdlog_errno(LOG_WARNING, "sysconf(_SC_OPEN_MAX) failed"); 167 maxfd = 16384; 168 } 169 for (fd = 0; fd <= maxfd; fd++) { 170 if (fstat(fd, &sb) == 0) { 171 isopen = true; 172 mode = sb.st_mode; 173 } else if (errno == EBADF) { 174 isopen = false; 175 mode = 0; 176 } else { 177 isopen = true; /* silence gcc */ 178 mode = 0; /* silence gcc */ 179 snprintf(msg, sizeof(msg), 180 "Unable to fstat descriptor %d: %s", fd, 181 strerror(errno)); 182 } 183 if (fd == STDIN_FILENO || fd == STDOUT_FILENO || 184 fd == STDERR_FILENO) { 185 if (!isopen) { 186 snprintf(msg, sizeof(msg), 187 "Descriptor %d (%s) is closed, but should be open.", 188 fd, (fd == STDIN_FILENO ? "stdin" : 189 (fd == STDOUT_FILENO ? "stdout" : "stderr"))); 190 break; 191 } 192 } else if (fd == proto_descriptor(res->hr_event)) { 193 if (!isopen) { 194 snprintf(msg, sizeof(msg), 195 "Descriptor %d (event) is closed, but should be open.", 196 fd); 197 break; 198 } 199 if (!S_ISSOCK(mode)) { 200 snprintf(msg, sizeof(msg), 201 "Descriptor %d (event) is %s, but should be %s.", 202 fd, dtype2str(mode), dtype2str(S_IFSOCK)); 203 break; 204 } 205 } else if (fd == proto_descriptor(res->hr_ctrl)) { 206 if (!isopen) { 207 snprintf(msg, sizeof(msg), 208 "Descriptor %d (ctrl) is closed, but should be open.", 209 fd); 210 break; 211 } 212 if (!S_ISSOCK(mode)) { 213 snprintf(msg, sizeof(msg), 214 "Descriptor %d (ctrl) is %s, but should be %s.", 215 fd, dtype2str(mode), dtype2str(S_IFSOCK)); 216 break; 217 } 218 } else if (res->hr_role == HAST_ROLE_SECONDARY && 219 fd == proto_descriptor(res->hr_remotein)) { 220 if (!isopen) { 221 snprintf(msg, sizeof(msg), 222 "Descriptor %d (remote in) is closed, but should be open.", 223 fd); 224 break; 225 } 226 if (!S_ISSOCK(mode)) { 227 snprintf(msg, sizeof(msg), 228 "Descriptor %d (remote in) is %s, but should be %s.", 229 fd, dtype2str(mode), dtype2str(S_IFSOCK)); 230 break; 231 } 232 } else if (res->hr_role == HAST_ROLE_SECONDARY && 233 fd == proto_descriptor(res->hr_remoteout)) { 234 if (!isopen) { 235 snprintf(msg, sizeof(msg), 236 "Descriptor %d (remote out) is closed, but should be open.", 237 fd); 238 break; 239 } 240 if (!S_ISSOCK(mode)) { 241 snprintf(msg, sizeof(msg), 242 "Descriptor %d (remote out) is %s, but should be %s.", 243 fd, dtype2str(mode), dtype2str(S_IFSOCK)); 244 break; 245 } 246 } else { 247 if (isopen) { 248 snprintf(msg, sizeof(msg), 249 "Descriptor %d is open (%s), but should be closed.", 250 fd, dtype2str(mode)); 251 break; 252 } 253 } 254 } 255 if (msg[0] != '\0') { 256 pjdlog_init(pjdlogmode); 257 pjdlog_prefix_set("[%s] (%s) ", res->hr_name, 258 role2str(res->hr_role)); 259 PJDLOG_ABORT("%s", msg); 260 } 261} 262 |
|
122static void 123child_exit_log(unsigned int pid, int status) 124{ 125 126 if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { 127 pjdlog_debug(1, "Worker process exited gracefully (pid=%u).", 128 pid); 129 } else if (WIFSIGNALED(status)) { --- 746 unchanged lines hidden --- | 263static void 264child_exit_log(unsigned int pid, int status) 265{ 266 267 if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { 268 pjdlog_debug(1, "Worker process exited gracefully (pid=%u).", 269 pid); 270 } else if (WIFSIGNALED(status)) { --- 746 unchanged lines hidden --- |