version 1.22, 2025/04/15 16:49:36
|
version 1.28, 2025/05/14 12:22:04
|
Line 24
|
Line 24
|
* along with FreeM. If not, see <https://www.gnu.org/licenses/>. |
* along with FreeM. If not, see <https://www.gnu.org/licenses/>. |
* |
* |
* $Log$ |
* $Log$ |
|
* 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 |
|
* |
|
* Revision 1.23 2025/04/16 05:33:15 snw |
|
* Try to use procctl function to fix ASLR problem on FreeBSD |
|
* |
* Revision 1.22 2025/04/15 16:49:36 snw |
* Revision 1.22 2025/04/15 16:49:36 snw |
* Make use of logprintf throughout codebase |
* Make use of logprintf throughout codebase |
* |
* |
Line 116
|
Line 134
|
#include <pwd.h> |
#include <pwd.h> |
#include <grp.h> |
#include <grp.h> |
#include "log.h" |
#include "log.h" |
|
|
#if defined(HAVE_GETOPT_H) |
#if defined(HAVE_GETOPT_H) |
# include <getopt.h> |
# include <getopt.h> |
#endif |
#endif |
Line 210 int main (int argc, char **argv, char **
|
Line 227 int main (int argc, char **argv, char **
|
strcpy (stack0, argv[0]); |
strcpy (stack0, argv[0]); |
stcnv_c2m (stack0); |
stcnv_c2m (stack0); |
|
|
|
|
/* strncpy (config_file, SYSCONFDIR"/freem.conf", 100); */ |
/* strncpy (config_file, SYSCONFDIR"/freem.conf", 100); */ |
|
|
|
|
Line 513 int main (int argc, char **argv, char **
|
Line 529 int main (int argc, char **argv, char **
|
} |
} |
#endif |
#endif |
|
|
|
|
if (run_daemon == TRUE) { |
if (run_daemon == TRUE) { |
if (geteuid () != 0 && nofork == FALSE) { |
if (geteuid () != 0 && nofork == FALSE) { |
logprintf (FM_LOG_FATAL, "freem: forking daemon must be run as root"); |
logprintf (FM_LOG_FATAL, "freem: forking daemon must be run as root"); |
} |
} |
} |
} |
|
|
|
|
if ((nofork == TRUE) && (run_daemon == FALSE)) { |
if ((nofork == TRUE) && (run_daemon == FALSE)) { |
freem_usage (); |
freem_usage (); |
exit (1); |
exit (1); |
Line 587 int main (int argc, char **argv, char **
|
Line 605 int main (int argc, char **argv, char **
|
} |
} |
} |
} |
|
|
|
logprintf (FM_LOG_INFO, "environment: privilege shedding complete"); |
|
|
} |
} |
else { |
else { |
logprintf (FM_LOG_INFO, "environment: not running as superuser; not shedding privileges"); |
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", "r", stdin); |
freopen ("/dev/null", "w+", stdout); |
freopen ("/dev/null", "w+", stdout); |
freopen ("/dev/null", "w+", stderr); |
freopen ("/dev/null", "w+", stderr); |
|
logprintf (FM_LOG_INFO, "environment: stdin, stdout, and stderr reopened"); |
|
|
run_daemon = TRUE; |
run_daemon = TRUE; |
nofork = FALSE; |
nofork = FALSE; |
Line 608 int main (int argc, char **argv, char **
|
Line 630 int main (int argc, char **argv, char **
|
|
|
snprintf (pid_file_path, PATH_MAX - 1, "%s/freem/run/%s.pid", LOCALSTATEDIR, shm_env); |
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); |
pid_fd = open (pid_file_path, O_RDWR | O_CREAT, 0640); |
errsav = errno; |
errsav = errno; |
|
|
Line 621 int main (int argc, char **argv, char **
|
Line 644 int main (int argc, char **argv, char **
|
} |
} |
|
|
sprintf (pidfile_buf, "%ld\n", (long) getpid ()); |
sprintf (pidfile_buf, "%ld\n", (long) getpid ()); |
|
logprintf (FM_LOG_INFO, "environment: writing pid file"); |
write (pid_fd, pidfile_buf, strlen (pidfile_buf)); |
write (pid_fd, pidfile_buf, strlen (pidfile_buf)); |
|
|
} |
} |
Line 749 int main (int argc, char **argv, char **
|
Line 773 int main (int argc, char **argv, char **
|
else { |
else { |
fm_initialized = TRUE; |
fm_initialized = TRUE; |
} |
} |
} |
} |
|
|
if (first_process == TRUE) { |
if (first_process == TRUE) { |
|
|
Line 777 int main (int argc, char **argv, char **
|
Line 801 int main (int argc, char **argv, char **
|
|
|
logprintf (FM_LOG_WARNING, "environment: entering maintenance mode"); |
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)) { |
if ((slot->pid != pid) && ((slot->flags & JFLG_FMADM) != JFLG_FMADM)) { |
kill (slot->pid, SIGINT); |
kill (slot->pid, SIGINT); |
Line 831 int main (int argc, char **argv, char **
|
Line 855 int main (int argc, char **argv, char **
|
exit (0); |
exit (0); |
|
|
} |
} |
|
|
job_gc_mark (); |
job_gc_mark (); |
job_set_status (pid, JSTAT_IDLE); |
job_set_status (pid, JSTAT_IDLE); |
sleep (1); |
sleep (1); |
|
|
job_set_status (pid, JSTAT_HOUSEKEEPING); |
job_set_status (pid, JSTAT_HOUSEKEEPING); |
job_gc_sweep (); |
job_gc_sweep (); |
|
|
sleep (1); |
sleep (1); |
} |
} |
|
|