~jamesodhunt/ubuntu/saucy/upstart/1.9.1

« back to all changes in this revision

Viewing changes to init/main.c

  • Committer: James Hunt
  • Date: 2013-06-28 15:57:37 UTC
  • mfrom: (1436.2.1)
  • Revision ID: james.hunt@ubuntu.com-20130628155737-8bskclzrhmjvpm6e
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
92
92
static void handle_confdir      (void);
93
93
static void handle_logdir       (void);
94
94
static int  console_type_setter (NihOption *option, const char *arg);
 
95
static int  conf_dir_setter     (NihOption *option, const char *arg);
95
96
 
96
97
 
97
98
/**
103
104
static int state_fd = -1;
104
105
 
105
106
/**
106
 
 * conf_dir:
107
 
 *
108
 
 * Full path to job configuration file directory.
109
 
 *
 
107
 * conf_dirs:
 
108
 *
 
109
 * Array of full paths to job configuration file directories.
110
110
 **/
111
 
static char *conf_dir = NULL;
 
111
static char **conf_dirs = NULL;
112
112
 
113
113
/**
114
114
 * initial_event:
141
141
 **/
142
142
static NihOption options[] = {
143
143
        { 0, "confdir", N_("specify alternative directory to load configuration files from"),
144
 
                NULL, "DIR", &conf_dir, NULL },
 
144
                NULL, "DIR", NULL, conf_dir_setter },
145
145
 
146
146
        { 0, "default-console", N_("default value for console stanza"),
147
147
                NULL, "VALUE", NULL, console_type_setter },
193
193
      char *argv[])
194
194
{
195
195
        char **args = NULL;
196
 
        char **dirs = NULL;
197
196
        int    ret;
198
197
#ifdef HAVE_SELINUX
199
198
        int    enforce = 0;
215
214
        }
216
215
#endif /* HAVE_SELINUX */
217
216
 
 
217
        conf_dirs = NIH_MUST (nih_str_array_new (NULL));
 
218
 
218
219
        args_copy = NIH_MUST (nih_str_array_copy (NULL, NULL, argv));
219
220
 
220
221
        nih_main_init (args_copy[0]);
552
553
        }
553
554
 
554
555
        /* Read configuration */
555
 
        if (! user_mode)
 
556
        if (! user_mode) {
 
557
                char   *conf_dir;
 
558
                int     len = 0;
 
559
 
 
560
                nih_assert (conf_dirs[0]);
 
561
 
 
562
                /* Count entries */
 
563
                for (char **d = conf_dirs; d && *d; d++, len++)
 
564
                        ;
 
565
 
 
566
                nih_assert (len);
 
567
 
 
568
                /* Use last value specified */
 
569
                conf_dir = conf_dirs[len-1];
 
570
 
556
571
                NIH_MUST (conf_source_new (NULL, CONFFILE, CONF_FILE));
557
572
 
558
 
        if (conf_dir)
 
573
                nih_debug ("Using configuration directory %s", conf_dir);
559
574
                NIH_MUST (conf_source_new (NULL, conf_dir, CONF_JOB_DIR));
 
575
        } else {
 
576
                nih_local char **dirs = NULL;
560
577
 
561
 
        if (user_mode) {
562
578
                dirs = NIH_MUST (get_user_upstart_dirs ());
563
 
                for (char **d = dirs; d && *d; d++)
 
579
 
 
580
                for (char **d = conf_dirs[0] ? conf_dirs : dirs; d && *d; d++) {
 
581
                        nih_debug ("Using configuration directory %s", *d);
564
582
                        NIH_MUST (conf_source_new (NULL, *d, CONF_JOB_DIR));
565
 
                nih_free (dirs);
 
583
                }
566
584
        }
567
585
 
 
586
        nih_free (conf_dirs);
 
587
 
568
588
        job_class_environment_init ();
569
589
 
570
590
        conf_reload ();
723
743
                sigemptyset (&mask);
724
744
                sigprocmask (SIG_SETMASK, &mask, NULL);
725
745
 
726
 
                /* Emit the Restarted signal so that any listing Instance Init
 
746
                /* Emit the Restarted signal so that any listening Instance Init
727
747
                 * knows that it needs to restart too.
728
748
                 */
729
749
                control_notify_restarted();
1014
1034
/**
1015
1035
 * handle_confdir:
1016
1036
 *
1017
 
 * Determine where system configuration files should be loaded from.
 
1037
 * Determine where system configuration files should be loaded from
 
1038
 * if not specified on the command-line.
1018
1039
 **/
1019
1040
static void
1020
1041
handle_confdir (void)
1021
1042
{
1022
 
        char *dir;
 
1043
        char  *dir;
 
1044
 
 
1045
        nih_assert (conf_dirs);
1023
1046
 
1024
1047
        /* user has already specified directory on command-line */
1025
 
        if (conf_dir)
1026
 
                goto out;
 
1048
        if (conf_dirs[0])
 
1049
                return;
1027
1050
 
1028
1051
        if (user_mode)
1029
1052
                return;
1030
1053
 
1031
 
        conf_dir = CONFDIR;
1032
 
 
1033
1054
        dir = getenv (CONFDIR_ENV);
1034
 
        if (! dir)
1035
 
                return;
1036
 
 
1037
 
        conf_dir = dir;
1038
 
 
1039
 
out:
1040
 
        nih_debug ("Using alternate configuration directory %s",
1041
 
                        conf_dir);
 
1055
 
 
1056
        NIH_MUST (nih_str_array_add (&conf_dirs, NULL, NULL, dir ? dir : CONFDIR));
1042
1057
}
1043
1058
 
1044
1059
/**
1093
1108
 
1094
1109
         return 0;
1095
1110
}
 
1111
 
 
1112
/**  
 
1113
 * NihOption setter function to handle selection of configuration file
 
1114
 * directories.
 
1115
 *
 
1116
 * Returns: 0 on success, -1 on invalid console type.
 
1117
 **/
 
1118
static int
 
1119
conf_dir_setter (NihOption *option, const char *arg)
 
1120
{
 
1121
        nih_assert (conf_dirs);
 
1122
        nih_assert (option);
 
1123
 
 
1124
        NIH_MUST (nih_str_array_add (&conf_dirs, NULL, NULL, arg));
 
1125
 
 
1126
        return 0;
 
1127
}