74
76
static void usr1_handler (void *data, NihSignal *signal);
77
static void handle_confdir (void);
79
static void handle_confdir (void);
80
static void handle_logdir (void);
81
static int console_type_setter (NihOption *option, const char *arg);
119
120
static int disable_startup_event = FALSE;
121
extern int use_session_bus;
122
extern int disable_sessions;
123
extern int disable_job_logging;
124
extern int use_session_bus;
125
extern int default_console;
126
extern char *log_dir;
129
135
{ 0, "confdir", N_("specify alternative directory to load configuration files from"),
130
136
NULL, "DIR", &conf_dir, NULL },
132
{ 0, "no-sessions", N_("Disable user and chroot sessions"),
138
{ 0, "default-console", N_("default value for console stanza"),
139
NULL, "VALUE", NULL, console_type_setter },
141
{ 0, "logdir", N_("specify alternative directory to store job output logs in"),
142
NULL, "DIR", &log_dir, NULL },
144
{ 0, "no-log", N_("disable job logging"),
145
NULL, NULL, &disable_job_logging, NULL },
147
{ 0, "no-sessions", N_("disable user and chroot sessions"),
133
148
NULL, NULL, &disable_sessions, NULL },
135
150
{ 0, "no-startup-event", N_("do not emit any startup event (for testing)"),
224
244
* resetting it to sane defaults unless we're inheriting from another
225
245
* init process which we know left it in a sane state.
227
if (system_setup_console (CONSOLE_OUTPUT, (! restart)) < 0)
228
nih_free (nih_error_get ());
247
if (system_setup_console (CONSOLE_OUTPUT, (! restart)) < 0) {
250
err = nih_error_get ();
251
nih_warn ("%s: %s", _("Unable to initialize console, will try /dev/null"),
255
if (system_setup_console (CONSOLE_NONE, FALSE) < 0) {
256
err = nih_error_get ();
257
nih_fatal ("%s: %s", _("Unable to initialize console as /dev/null"),
230
265
/* Set the PATH environment variable */
231
266
setenv ("PATH", PATH, TRUE);
383
/* Adjust our OOM priority to the default, which will be inherited
386
if (JOB_DEFAULT_OOM_SCORE_ADJ) {
387
char filename[PATH_MAX];
391
snprintf (filename, sizeof (filename),
392
"/proc/%d/oom_score_adj", getpid ());
393
oom_value = JOB_DEFAULT_OOM_SCORE_ADJ;
394
fd = fopen (filename, "w");
395
if ((! fd) && (errno == ENOENT)) {
396
snprintf (filename, sizeof (filename),
397
"/proc/%d/oom_adj", getpid ());
398
oom_value = (JOB_DEFAULT_OOM_SCORE_ADJ
399
* ((JOB_DEFAULT_OOM_SCORE_ADJ < 0) ? 17 : 15)) / 1000;
400
fd = fopen (filename, "w");
403
nih_warn ("%s: %s", _("Unable to set default oom score"),
406
fprintf (fd, "%d\n", oom_value);
409
nih_warn ("%s: %s", _("Unable to set default oom score"),
348
415
/* Read configuration */
349
416
NIH_MUST (conf_source_new (NULL, CONFFILE, CONF_FILE));
350
417
NIH_MUST (conf_source_new (NULL, conf_dir, CONF_JOB_DIR));
387
454
/* Now that the startup is complete, send all further logging output
388
455
* to kmsg instead of to the console.
390
if (system_setup_console (CONSOLE_NONE, FALSE) < 0)
391
nih_free (nih_error_get ());
457
if (system_setup_console (CONSOLE_NONE, FALSE) < 0) {
460
err = nih_error_get ();
461
nih_fatal ("%s: %s", _("Unable to setup standard file descriptors"),
393
468
nih_log_set_logger (logger_kmsg);
891
* Determine directory where job log files should be written to.
898
/* user has already specified directory on command-line */
902
log_dir = JOB_LOGDIR;
904
dir = getenv (LOGDIR_ENV);
911
nih_debug ("Using alternate log directory %s",
916
* NihOption setter function to handle selection of default console
919
* Returns 1 on success, -1 on invalid console type.
922
console_type_setter (NihOption *option, const char *arg)
926
default_console = (int)job_class_console_type (arg);
928
if (default_console == -1) {
929
nih_fatal ("%s: %s", _("invalid console type specified"), arg);