--- freem/src/mumps.c 2025/04/16 05:37:06 1.24
+++ freem/src/mumps.c 2025/05/14 12:22:04 1.28
@@ -1,5 +1,5 @@
/*
- * $Id: mumps.c,v 1.24 2025/04/16 05:37:06 snw Exp $
+ * $Id: mumps.c,v 1.28 2025/05/14 12:22:04 snw Exp $
* main module of freem
*
*
@@ -24,6 +24,18 @@
* along with FreeM. If not, see .
*
* $Log: mumps.c,v $
+ * Revision 1.28 2025/05/14 12:22:04 snw
+ * Further work on shared memory
+ *
+ * Revision 1.27 2025/04/17 00:34:04 snw
+ * More logging improvements
+ *
+ * Revision 1.26 2025/04/16 17:36:12 snw
+ * Add FreeBSD shm cleanup script
+ *
+ * Revision 1.25 2025/04/16 05:57:42 snw
+ * Remove non-useful procctl calls
+ *
* Revision 1.24 2025/04/16 05:37:06 snw
* Refine FreeBSD ASLR fix
*
@@ -122,9 +134,6 @@
#include
#include
#include "log.h"
-#if defined(__FreeBSD__)
-# include
-#endif
#if defined(HAVE_GETOPT_H)
# include
#endif
@@ -218,10 +227,6 @@ int main (int argc, char **argv, char **
strcpy (stack0, argv[0]);
stcnv_c2m (stack0);
-#if defined(__FreeBSD__)
- int prcdta = PROC_ASLR_FORCE_DISABLE;
-#endif
-
/* strncpy (config_file, SYSCONFDIR"/freem.conf", 100); */
@@ -524,12 +529,14 @@ int main (int argc, char **argv, char **
}
#endif
+
if (run_daemon == TRUE) {
if (geteuid () != 0 && nofork == FALSE) {
logprintf (FM_LOG_FATAL, "freem: forking daemon must be run as root");
}
}
+
if ((nofork == TRUE) && (run_daemon == FALSE)) {
freem_usage ();
exit (1);
@@ -598,14 +605,18 @@ int main (int argc, char **argv, char **
}
}
+ logprintf (FM_LOG_INFO, "environment: privilege shedding complete");
+
}
else {
logprintf (FM_LOG_INFO, "environment: not running as superuser; not shedding privileges");
}
+ logprintf (FM_LOG_INFO, "environment: reopening stdin, stdout, and stderr");
freopen ("/dev/null", "r", stdin);
freopen ("/dev/null", "w+", stdout);
freopen ("/dev/null", "w+", stderr);
+ logprintf (FM_LOG_INFO, "environment: stdin, stdout, and stderr reopened");
run_daemon = TRUE;
nofork = FALSE;
@@ -619,6 +630,7 @@ int main (int argc, char **argv, char **
snprintf (pid_file_path, PATH_MAX - 1, "%s/freem/run/%s.pid", LOCALSTATEDIR, shm_env);
+ logprintf (FM_LOG_INFO, "environment: opening pid file %s", pid_file_path);
pid_fd = open (pid_file_path, O_RDWR | O_CREAT, 0640);
errsav = errno;
@@ -632,6 +644,7 @@ int main (int argc, char **argv, char **
}
sprintf (pidfile_buf, "%ld\n", (long) getpid ());
+ logprintf (FM_LOG_INFO, "environment: writing pid file");
write (pid_fd, pidfile_buf, strlen (pidfile_buf));
}
@@ -760,14 +773,7 @@ int main (int argc, char **argv, char **
else {
fm_initialized = TRUE;
}
- }
-
-#if defined(__FreeBSD__)
- if ((first_process == FALSE) && (procctl (P_PID, getpid (), PROC_ASLR_CTL, &prcdta) == -1)) {
- fprintf (stderr, "freem: could not disable address space layout randomization for pid %ld; program operation may be unreliable [error %s]\n", getpid(), strerror (errno));
}
-#endif
-
if (first_process == TRUE) {
@@ -795,7 +801,7 @@ int main (int argc, char **argv, char **
logprintf (FM_LOG_WARNING, "environment: entering maintenance mode");
- for (slot = shm_config->hdr->jobtab_head; slot != NULL; slot = slot->next) {
+ for (slot = SOA(shm_config->hdr->jobtab_head); slot != NULL; slot = SOA(slot->next)) {
if ((slot->pid != pid) && ((slot->flags & JFLG_FMADM) != JFLG_FMADM)) {
kill (slot->pid, SIGINT);
@@ -849,13 +855,14 @@ int main (int argc, char **argv, char **
exit (0);
}
-
+
job_gc_mark ();
job_set_status (pid, JSTAT_IDLE);
sleep (1);
job_set_status (pid, JSTAT_HOUSEKEEPING);
job_gc_sweep ();
+
sleep (1);
}