#endif
/*
- * If we did change from root to a normal user, do some
- * more work.
+ * The directories for PID files and logs must exist. We
+ * need to create them if we're told to write files to
+ * those directories.
*
- * Try to create the various output directories. Because
- * this creation is new in 3.0.9, it's a soft fail.
+ * Because this creation is new in 3.0.9, it's a soft
+ * fail.
*
- * And once we're done with all of the above work,
- * permanently change the UID.
*/
- if (do_suid) {
+ if (main_config.write_pid) {
char *my_dir;
my_dir = talloc_strdup(NULL, run_dir);
my_dir, strerror(errno));
}
talloc_free(my_dir);
+ }
- if (default_log.dst == L_DST_FILES) {
- my_dir = talloc_strdup(NULL, radlog_dir);
- if (rad_mkdir(my_dir, 0750, server_uid, server_gid) < 0) {
- DEBUG("Failed to create logdir %s: %s",
- my_dir, strerror(errno));
- }
- talloc_free(my_dir);
+ if (default_log.dst == L_DST_FILES) {
+ char *my_dir;
+
+ my_dir = talloc_strdup(NULL, radlog_dir);
+ if (rad_mkdir(my_dir, 0750, server_uid, server_gid) < 0) {
+ DEBUG("Failed to create logdir %s: %s",
+ my_dir, strerror(errno));
}
+ talloc_free(my_dir);
+ }
+ /*
+ * Once we're done with all of the privileged work,
+ * permanently change the UID.
+ */
+ if (do_suid) {
rad_suid_set_down_uid(server_uid);
rad_suid_down();
}
int status;
int argval;
bool spawn_flag = true;
- bool write_pid = false;
bool display_version = false;
int flag = 0;
int from_child[2] = {-1, -1};
case 'P':
/* Force the PID to be written, even in -f mode */
- write_pid = true;
+ main_config.write_pid = true;
break;
case 's': /* Single process mode */
tls_global_init();
#endif
+ /*
+ * Write the PID always if we're running as a daemon.
+ */
+ if (main_config.daemonize) main_config.write_pid = true;
+
/*
* Read the configuration files, BEFORE doing anything else.
*/
radius_stats_init(0);
#endif
- /*
- * Write the PID always if we're running as a daemon.
- */
- if (main_config.daemonize) write_pid = true;
-
/*
* Write the PID after we've forked, so that we write the correct one.
*/
- if (write_pid) {
+ if (main_config.write_pid) {
FILE *fp;
fp = fopen(main_config.pid_file, "w");