Print this page
7711 SMF: Finish implementing support for degraded state
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/svc/startd/log.c
+++ new/usr/src/cmd/svc/startd/log.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 * Copyright 2011 Nexenta Systems. All rights reserved.
25 + * Copyright 2017 RackTop Systems.
25 26 */
26 27
27 28 /*
28 29 * log.c - debugging and logging functions
29 30 *
30 31 * Logging destinations
31 32 * svc.startd(1M) supports three logging destinations: the system log, a
32 33 * daemon-specific log (in the /var/svc/log hierarchy by default), and to the
33 34 * standard output (redirected to the /var/svc/log/svc.startd.log file by
34 35 * default). Any or all of these destinations may be used to
35 36 * communicate a specific message; the audiences for each destination differ.
36 37 *
37 38 * Generic messages associated with svc.startd(1M) are made by the
38 39 * log_framework() and log_error() functions. For these messages, svc.startd
39 40 * logs under its own name and under the LOG_DAEMON facility when issuing
40 41 * events to the system log. By design, severities below LOG_NOTICE are never
41 42 * issued to the system log.
42 43 *
43 44 * Messages associated with a specific service instance are logged using the
44 45 * log_instance() or log_instance_fmri() functions. These messages are always
45 46 * sent to the appropriate per-instance log file.
46 47 *
47 48 * In the case of verbose or debug boot, the log_transition() function
48 49 * displays messages regarding instance transitions to the system console,
49 50 * until the expected login services are available.
50 51 *
51 52 * Finally, log_console() displays messages to the system consoles and
52 53 * the master restarter log file. This is used when booting to a milestone
53 54 * other than 'all'.
54 55 *
55 56 * Logging detail
56 57 * The constants for severity from <syslog.h> are reused, with a specific
57 58 * convention here. (It is worth noting that the #define values for the LOG_
58 59 * levels are such that more important severities have lower values.) The
59 60 * severity determines the importance of the event, and its addressibility by
60 61 * the administrator. Each severity level's use is defined below, along with
61 62 * an illustrative example.
62 63 *
63 64 * LOG_EMERG Not used presently.
64 65 *
65 66 * LOG_ALERT An unrecoverable operation requiring external
66 67 * intervention has occurred. Includes an inability to
67 68 * write to the smf(5) repository (due to svc.configd(1M)
68 69 * absence, due to permissions failures, etc.). Message
69 70 * should identify component at fault.
70 71 *
71 72 * LOG_CRIT An unrecoverable operation internal to svc.startd(1M)
72 73 * has occurred. Failure should be recoverable by restart
73 74 * of svc.startd(1M).
74 75 *
75 76 * LOG_ERR An smf(5) event requiring administrative intervention
76 77 * has occurred. Includes instance being moved to the
77 78 * maintenance state.
78 79 *
79 80 * LOG_WARNING A potentially destabilizing smf(5) event not requiring
80 81 * administrative intervention has occurred.
81 82 *
82 83 * LOG_NOTICE A noteworthy smf(5) event has occurred. Includes
83 84 * individual instance failures.
84 85 *
85 86 * LOG_INFO A noteworthy operation internal to svc.startd(1M) has
86 87 * occurred. Includes recoverable failures or otherwise
87 88 * unexpected outcomes.
88 89 *
89 90 * LOG_DEBUG An internal operation only of interest to a
90 91 * svc.startd(1M) developer has occurred.
91 92 *
92 93 * Logging configuration
93 94 * The preferred approach is to set the logging property values
94 95 * in the options property group of the svc.startd default instance. The
95 96 * valid values are "quiet", "verbose", and "debug". "quiet" is the default;
96 97 * "verbose" and "debug" allow LOG_INFO and LOG_DEBUG logging requests to
97 98 * reach the svc.startd.log file, respectively.
98 99 */
99 100
100 101 #include <sys/stat.h>
101 102 #include <sys/statvfs.h>
102 103 #include <sys/time.h>
103 104 #include <sys/types.h>
104 105 #include <assert.h>
105 106 #include <errno.h>
106 107 #include <fcntl.h>
107 108 #include <kstat.h>
108 109 #include <libgen.h>
109 110 #include <libintl.h>
110 111 #include <libuutil.h>
111 112 #include <locale.h>
112 113 #include <malloc.h>
113 114 #include <pthread.h>
114 115 #include <stdarg.h>
115 116 #include <stdio.h>
116 117 #include <strings.h>
117 118 #include <syslog.h>
118 119 #include <unistd.h>
119 120 #include <zone.h>
120 121
121 122 #include "startd.h"
122 123
123 124
124 125 #define LOGBUF_SZ (60 * 80) /* 60 lines */
125 126
126 127 static FILE *logfile = NULL;
127 128
128 129 /*
129 130 * This parameter can be modified using mdb to turn on & off extended
130 131 * internal debug logging. Although a performance loss can be expected.
131 132 */
132 133 static int internal_debug_flags = 0x0;
133 134
134 135 #ifndef NDEBUG
135 136 /*
136 137 * This is a circular buffer for all (even those not emitted externally)
137 138 * logging messages. To read it properly you should start after the first
138 139 * null, go until the second, and then go back to the beginning until the
139 140 * first null. Or use ::startd_log in mdb.
140 141 */
141 142 static char logbuf[LOGBUF_SZ] = "";
142 143 static pthread_mutex_t logbuf_mutex = PTHREAD_MUTEX_INITIALIZER;
143 144 #endif
144 145
145 146 static void
146 147 xstrftime_poststart(char *buf, size_t bufsize, struct timeval *time)
147 148 {
148 149 long sec, usec;
149 150
150 151 sec = time->tv_sec - st->st_start_time.tv_sec;
151 152 usec = time->tv_usec - st->st_start_time.tv_usec;
152 153
153 154 if (usec < 0) {
154 155 sec -= 1;
155 156 usec += 1000000;
156 157 }
157 158
158 159 (void) snprintf(buf, bufsize, "start + %d.%02ds", sec, usec / 10000);
159 160 }
160 161
161 162 static void
162 163 vlog_prefix(int severity, const char *prefix, const char *format, va_list args)
163 164 {
164 165 char buf[512], *cp;
165 166 char timebuf[LOG_DATE_SIZE];
166 167 struct timeval now;
167 168 struct tm ltime;
168 169
169 170 #ifdef NDEBUG
170 171 if (severity > st->st_log_level_min)
171 172 return;
172 173 #endif
173 174
174 175 if (gettimeofday(&now, NULL) != 0)
175 176 (void) fprintf(stderr, "gettimeofday(3C) failed: %s\n",
176 177 strerror(errno));
177 178
178 179 if (st->st_log_timezone_known)
179 180 (void) strftime(timebuf, sizeof (timebuf), "%b %e %T",
180 181 localtime_r(&now.tv_sec, <ime));
181 182 else
182 183 xstrftime_poststart(timebuf, sizeof (timebuf), &now);
183 184
184 185 (void) snprintf(buf, sizeof (buf), "%s/%d%s: ", timebuf, pthread_self(),
185 186 prefix);
186 187 cp = strchr(buf, '\0');
187 188 (void) vsnprintf(cp, sizeof (buf) - (cp - buf), format, args);
188 189
189 190 #ifndef NDEBUG
190 191 /* Copy into logbuf. */
191 192 (void) pthread_mutex_lock(&logbuf_mutex);
192 193 if (strlen(logbuf) + strlen(buf) + 1 <= sizeof (logbuf))
193 194 (void) strcat(logbuf, buf);
194 195 else
195 196 (void) strlcpy(logbuf, buf, sizeof (logbuf));
196 197 (void) pthread_mutex_unlock(&logbuf_mutex);
197 198
198 199 if (severity > st->st_log_level_min)
199 200 return;
200 201 #endif
201 202
202 203 if (st->st_log_flags & STARTD_LOG_FILE && logfile) {
203 204 (void) fputs(buf, logfile);
204 205 (void) fflush(logfile);
205 206 }
206 207 if (st->st_log_flags & STARTD_LOG_TERMINAL)
207 208 (void) fputs(buf, stdout);
208 209 if (st->st_log_flags & STARTD_LOG_SYSLOG && st->st_log_timezone_known)
209 210 vsyslog(severity, format, args);
210 211 }
211 212
212 213 /*PRINTFLIKE2*/
213 214 void
214 215 log_error(int severity, const char *format, ...)
215 216 {
216 217 va_list args;
217 218
218 219 va_start(args, format);
219 220 vlog_prefix(severity, " ERROR", format, args);
220 221 va_end(args);
221 222 }
222 223
223 224 /*PRINTFLIKE2*/
224 225 void
225 226 log_framework(int severity, const char *format, ...)
226 227 {
227 228 va_list args;
228 229
229 230 va_start(args, format);
230 231 vlog_prefix(severity, "", format, args);
231 232 va_end(args);
232 233 }
233 234
234 235 /*
235 236 * log_framework2() differs from log_framework() by the fact that
236 237 * some checking are done before logging the messages in the internal
237 238 * buffer for performance reasons.
238 239 * The messages aren't logged if:
239 240 * - severity >= LOG_DEBUG and
240 241 * - st_log_level_min < LOG_DEBUG and
241 242 * - internal_debug_flags is not set for 'flags'
242 243 */
243 244 void
244 245 log_framework2(int severity, int flags, const char *format, ...)
245 246 {
246 247 va_list args;
247 248
248 249 if ((severity < LOG_DEBUG) ||
249 250 (internal_debug_flags & flags) ||
250 251 st->st_log_level_min >= LOG_DEBUG) {
251 252 va_start(args, format);
252 253 vlog_prefix(severity, "", format, args);
253 254 va_end(args);
254 255 }
255 256 }
256 257
257 258 /*
258 259 * void log_preexec()
259 260 *
260 261 * log_preexec() should be invoked prior to any exec(2) calls, to prevent the
261 262 * logfile and syslogd file descriptors from being leaked to child processes.
262 263 * Why openlog(3C) lacks a close-on-exec option is a minor mystery.
263 264 */
264 265 void
265 266 log_preexec()
266 267 {
267 268 closelog();
268 269 }
269 270
270 271 /*
271 272 * void setlog()
272 273 * Close file descriptors and redirect output.
273 274 */
274 275 void
275 276 setlog(const char *logstem)
276 277 {
277 278 int fd;
278 279 char logfile[PATH_MAX];
279 280
280 281 closefrom(0);
281 282
282 283 (void) open("/dev/null", O_RDONLY);
283 284
284 285 (void) snprintf(logfile, PATH_MAX, "%s/%s", st->st_log_prefix, logstem);
285 286
286 287 (void) umask(fmask);
287 288 fd = open(logfile, O_WRONLY|O_CREAT|O_APPEND,
288 289 S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
289 290 (void) umask(dmask);
290 291
291 292 if (fd == -1)
292 293 return;
293 294
294 295 (void) dup2(fd, STDOUT_FILENO);
295 296 (void) dup2(fd, STDERR_FILENO);
296 297
297 298 if (fd != STDOUT_FILENO && fd != STDERR_FILENO)
298 299 startd_close(fd);
299 300 }
300 301
301 302 static int
302 303 log_dir_writeable(const char *path)
303 304 {
304 305 int fd;
305 306 struct statvfs svb;
306 307
307 308 if ((fd = open(path, O_RDONLY, 0644)) == -1)
308 309 return (-1);
309 310
310 311 if (fstatvfs(fd, &svb) == -1)
311 312 return (-1);
312 313
313 314 if (svb.f_flag & ST_RDONLY) {
314 315 (void) close(fd);
315 316
316 317 fd = -1;
317 318 }
318 319
319 320 return (fd);
320 321 }
321 322
322 323 static void
323 324 vlog_instance(const char *fmri, const char *logstem, boolean_t canlog,
324 325 const char *format, va_list args)
325 326 {
326 327 char logfile[PATH_MAX];
327 328 char *message;
328 329 char omessage[1024];
329 330 int fd, err;
330 331 char timebuf[LOG_DATE_SIZE];
331 332 struct tm ltime;
332 333 struct timeval now;
333 334
334 335 (void) snprintf(logfile, PATH_MAX, "%s/%s", st->st_log_prefix,
335 336 logstem);
336 337
337 338 (void) umask(fmask);
338 339 fd = open(logfile, O_WRONLY|O_CREAT|O_APPEND,
339 340 S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
340 341 err = errno;
341 342 (void) umask(dmask);
342 343
343 344 if (fd == -1) {
344 345 if (canlog)
345 346 log_error(LOG_NOTICE, "Could not log for %s: open(%s) "
346 347 "failed with %s.\n", fmri, logfile, strerror(err));
347 348
348 349 return;
349 350 }
350 351
351 352 (void) vsnprintf(omessage, sizeof (omessage), format, args);
352 353
353 354 if (gettimeofday(&now, NULL) != 0)
354 355 (void) fprintf(stderr, "gettimeofday(3C) failed: %s\n",
355 356 strerror(errno));
356 357
357 358 if (st->st_log_timezone_known)
358 359 (void) strftime(timebuf, sizeof (timebuf), "%b %e %T",
359 360 localtime_r(&now.tv_sec, <ime));
360 361 else
361 362 xstrftime_poststart(timebuf, sizeof (timebuf), &now);
362 363
363 364 message = uu_msprintf("[ %s %s ]\n", timebuf, omessage);
364 365
365 366 if (message == NULL) {
366 367 if (canlog)
367 368 log_error(LOG_NOTICE, "Could not log for %s: %s.\n",
368 369 fmri, uu_strerror(uu_error()));
369 370 } else {
370 371 if (write(fd, message, strlen(message)) < 0 && canlog)
371 372 log_error(LOG_NOTICE, "Could not log for %s: write(%d) "
372 373 "failed with %s.\n", fmri, fd,
373 374 strerror(errno));
374 375
375 376 uu_free(message);
376 377 }
377 378
378 379 if (close(fd) != 0 && canlog)
379 380 log_framework(LOG_NOTICE, "close(%d) failed: %s.\n", fd,
380 381 strerror(errno));
381 382 }
382 383
383 384 /*
384 385 * void log_instance(const restarter_inst_t *, boolean_t, const char *, ...)
385 386 *
386 387 * The log_instance() format is "[ month day time message ]". (The
387 388 * brackets distinguish svc.startd messages from method output.) We avoid
388 389 * calling log_*() functions on error when canlog is not set, since we may
389 390 * be called from a child process.
390 391 *
391 392 * When adding new calls to this function, consider: If this is called before
392 393 * any instances have started, then it should be called with canlog clear,
393 394 * lest we spew errors to the console when booted on the miniroot.
394 395 */
395 396 /*PRINTFLIKE3*/
396 397 void
397 398 log_instance(const restarter_inst_t *inst, boolean_t canlog,
398 399 const char *format, ...)
399 400 {
400 401 va_list args;
401 402
402 403 va_start(args, format);
403 404 vlog_instance(inst->ri_i.i_fmri, inst->ri_logstem, canlog, format,
404 405 args);
405 406 va_end(args);
406 407 }
407 408
408 409 /*
409 410 * void log_instance_fmri(const char *, const char *,boolean_t, const char *,
410 411 * ...)
411 412 *
412 413 * The log_instance_fmri() format is "[ month day time message ]". (The
413 414 * brackets distinguish svc.startd messages from method output.) We avoid
414 415 * calling log_*() functions on error when canlog is not set, since we may
415 416 * be called from a child process.
416 417 *
417 418 * For new calls to this function, see the warning in log_instance()'s
418 419 * comment.
419 420 */
420 421 /*PRINTFLIKE4*/
421 422 void
422 423 log_instance_fmri(const char *fmri, const char *logstem, boolean_t canlog,
423 424 const char *format, ...)
424 425 {
425 426 va_list args;
426 427
427 428 va_start(args, format);
428 429 vlog_instance(fmri, logstem, canlog, format, args);
429 430 va_end(args);
430 431 }
431 432
432 433 /*
433 434 * void log_transition(const restarter_inst_t *, start_outcome_t)
434 435 *
435 436 * The log_transition() format is
436 437 *
437 438 * [ _service_fmri_ _participle_ (_common_name_) ]
438 439 *
439 440 * Again, brackets separate messages from specific service instance output to
440 441 * the console.
441 442 */
442 443 void
443 444 log_transition(const restarter_inst_t *inst, start_outcome_t outcome)
444 445 {
445 446 char *message;
446 447 char omessage[1024];
447 448 char *action;
448 449 int severity;
449 450
450 451 if (outcome == START_REQUESTED) {
451 452 char *cname = NULL;
452 453
453 454 cname = inst->ri_common_name;
454 455 if (cname == NULL)
455 456 cname = inst->ri_C_common_name;
456 457
457 458 if (!(st->st_boot_flags & STARTD_BOOT_VERBOSE))
458 459 return;
459 460
460 461 if (inst->ri_start_index > 1)
461 462 return;
462 463
463 464 if (cname)
464 465 (void) snprintf(omessage, sizeof (omessage), " (%s)",
465 466 cname);
466 467 else
467 468 *omessage = '\0';
↓ open down ↓ |
433 lines elided |
↑ open up ↑ |
468 469
469 470 action = gettext("starting");
470 471
471 472 message = uu_msprintf("[ %s %s%s ]\n",
472 473 inst->ri_i.i_fmri + strlen("svc:/"), action,
473 474 omessage);
474 475
475 476 severity = LOG_INFO;
476 477 } else {
477 478 switch (outcome) {
479 + case DEGRADE_REQUESTED:
480 + action = gettext("transitioned to degraded by "
481 + "request (see 'svcs -xv' for details)");
482 + break;
478 483 case MAINT_REQUESTED:
479 484 action = gettext("transitioned to maintenance by "
480 485 "request (see 'svcs -xv' for details)");
481 486 break;
482 487 case START_FAILED_REPEATEDLY:
483 488 action = gettext("failed repeatedly: transitioned to "
484 489 "maintenance (see 'svcs -xv' for details)");
485 490 break;
486 491 case START_FAILED_CONFIGURATION:
487 492 action = gettext("misconfigured: transitioned to "
488 493 "maintenance (see 'svcs -xv' for details)");
489 494 break;
490 495 case START_FAILED_FATAL:
491 496 action = gettext("failed fatally: transitioned to "
492 497 "maintenance (see 'svcs -xv' for details)");
493 498 break;
494 499 case START_FAILED_TIMEOUT_FATAL:
495 500 action = gettext("timed out: transitioned to "
496 501 "maintenance (see 'svcs -xv' for details)");
497 502 break;
498 503 case START_FAILED_OTHER:
499 504 action = gettext("failed: transitioned to "
500 505 "maintenance (see 'svcs -xv' for details)");
501 506 break;
502 507 case START_REQUESTED:
503 508 assert(outcome != START_REQUESTED);
504 509 /*FALLTHROUGH*/
505 510 default:
506 511 action = gettext("outcome unknown?");
507 512 }
508 513
509 514 message = uu_msprintf("[ %s %s ]\n",
510 515 inst->ri_i.i_fmri + strlen("svc:/"), action);
511 516
512 517 severity = LOG_ERR;
513 518 }
514 519
515 520
516 521 if (message == NULL) {
517 522 log_error(LOG_NOTICE,
518 523 "Could not log boot message for %s: %s.\n",
519 524 inst->ri_i.i_fmri, uu_strerror(uu_error()));
520 525 } else {
521 526 /*
522 527 * All significant errors should to go to syslog to
523 528 * communicate appropriate information even for systems
524 529 * without a console connected during boot. Send the
525 530 * message to stderr only if the severity is lower than
526 531 * (indicated by >) LOG_ERR.
527 532 */
528 533 if (!st->st_log_login_reached && severity > LOG_ERR) {
529 534 /*LINTED*/
530 535 if (fprintf(stderr, message) < 0)
531 536 log_error(LOG_NOTICE, "Could not log for %s: "
532 537 "fprintf() failed with %s.\n",
533 538 inst->ri_i.i_fmri, strerror(errno));
534 539 } else {
535 540 log_framework(severity, "%s %s\n",
536 541 inst->ri_i.i_fmri + strlen("svc:/"), action);
537 542 }
538 543
539 544 uu_free(message);
540 545 }
541 546 }
542 547
543 548 /*
544 549 * log_console - log a message to the consoles and to syslog
545 550 *
546 551 * This logs a message as-is to the console (and auxiliary consoles),
547 552 * as well as to the master restarter log.
548 553 */
549 554 /*PRINTFLIKE2*/
550 555 void
551 556 log_console(int severity, const char *format, ...)
552 557 {
553 558 va_list args;
554 559
555 560 va_start(args, format);
556 561 vlog_prefix(severity, "", format, args);
557 562 va_end(args);
558 563
559 564 va_start(args, format);
560 565 (void) vfprintf(stderr, format, args);
561 566 va_end(args);
562 567 }
563 568
564 569 /*
565 570 * void log_init()
566 571 *
567 572 * Set up the log files, if necessary, for the current invocation. This
568 573 * function should be called before any other functions in this file. Set the
569 574 * syslog(3C) logging mask such that severities of the importance of
570 575 * LOG_NOTICE and above are passed through, but lower severity messages are
571 576 * masked out.
572 577 *
573 578 * It may be called multiple times to change the logging configuration due to
574 579 * administrative request.
575 580 */
576 581 void
577 582 log_init()
578 583 {
579 584 int dirfd, logfd;
580 585 char *dir;
581 586 struct stat sb;
582 587
583 588 if (st->st_start_time.tv_sec == 0) {
584 589 if (getzoneid() != GLOBAL_ZONEID) {
585 590 st->st_start_time.tv_sec = time(NULL);
586 591 } else {
587 592 /*
588 593 * We need to special-case the BOOT_TIME utmp entry, and
589 594 * drag that value out of the kernel if it's there.
590 595 */
591 596 kstat_ctl_t *kc;
592 597 kstat_t *ks;
593 598 kstat_named_t *boot;
594 599
595 600 if (((kc = kstat_open()) != 0) &&
596 601 ((ks = kstat_lookup(kc, "unix", 0, "system_misc"))
597 602 != NULL) &&
598 603 (kstat_read(kc, ks, NULL) != -1) &&
599 604 ((boot = kstat_data_lookup(ks, "boot_time")) !=
600 605 NULL)) {
601 606 /*
602 607 * If we're here, then we've successfully found
603 608 * the boot_time kstat... use its value.
604 609 */
605 610 st->st_start_time.tv_sec = boot->value.ul;
606 611 } else {
607 612 st->st_start_time.tv_sec = time(NULL);
608 613 }
609 614
610 615 if (kc)
611 616 (void) kstat_close(kc);
612 617 }
613 618 }
614 619
615 620 /*
616 621 * Establish our timezone if the appropriate directory is available.
617 622 */
618 623 if (!st->st_log_timezone_known && stat(FS_TIMEZONE_DIR, &sb) == 0) {
619 624 tzset();
620 625 st->st_log_timezone_known = 1;
621 626 }
622 627
623 628 /*
624 629 * Establish our locale if the appropriate directory is available. Set
625 630 * the locale string from the environment so we can extract template
626 631 * information correctly, if the locale directories aren't yet
627 632 * available.
628 633 */
629 634 if (st->st_locale != NULL)
630 635 free(st->st_locale);
631 636
632 637 if ((st->st_locale = getenv("LC_ALL")) == NULL)
633 638 if ((st->st_locale = getenv("LC_MESSAGES")) == NULL)
634 639 st->st_locale = getenv("LANG");
635 640
636 641 if (!st->st_log_locale_known && stat(FS_LOCALE_DIR, &sb) == 0) {
637 642 (void) setlocale(LC_ALL, "");
638 643 st->st_locale = setlocale(LC_MESSAGES, NULL);
639 644 if (st->st_locale)
640 645 st->st_log_locale_known = 1;
641 646
642 647 (void) textdomain(TEXT_DOMAIN);
643 648 }
644 649
645 650 if (st->st_locale) {
646 651 st->st_locale = safe_strdup(st->st_locale);
647 652 xstr_sanitize(st->st_locale);
648 653 }
649 654
650 655 if (logfile) {
651 656 (void) fclose(logfile);
652 657 logfile = NULL;
653 658 }
654 659
655 660 /*
656 661 * Set syslog(3C) behaviour in all cases.
657 662 */
658 663 closelog();
659 664 openlog("svc.startd", LOG_PID | LOG_CONS, LOG_DAEMON);
660 665 (void) setlogmask(LOG_UPTO(LOG_NOTICE));
661 666
662 667 if ((dirfd = log_dir_writeable(LOG_PREFIX_NORMAL)) == -1) {
663 668 if ((dirfd = log_dir_writeable(LOG_PREFIX_EARLY)) == -1)
664 669 return;
665 670 else
666 671 dir = LOG_PREFIX_EARLY;
667 672 } else {
668 673 dir = LOG_PREFIX_NORMAL;
669 674 }
670 675
671 676 st->st_log_prefix = dir;
672 677
673 678 (void) umask(fmask);
674 679 if ((logfd = openat(dirfd, STARTD_DEFAULT_LOG,
675 680 O_CREAT | O_RDWR | O_APPEND, 0644)) == -1) {
676 681 (void) close(dirfd);
677 682 (void) umask(dmask);
678 683 return;
679 684 }
680 685
681 686 (void) close(dirfd);
682 687 (void) umask(dmask);
683 688
684 689 if ((logfile = fdopen(logfd, "a")) == NULL)
685 690 if (errno != EROFS)
686 691 log_error(LOG_WARNING, "can't open logfile %s/%s",
687 692 dir, STARTD_DEFAULT_LOG);
688 693
689 694 if (logfile &&
690 695 fcntl(fileno(logfile), F_SETFD, FD_CLOEXEC) == -1)
691 696 log_error(LOG_WARNING,
692 697 "couldn't mark logfile close-on-exec: %s\n",
693 698 strerror(errno));
694 699 }
↓ open down ↓ |
207 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX