Index: configure
--- configure.orig	2024-12-11 18:32:32.242947000 +0100
+++ configure	2024-12-11 18:37:19.408127000 +0100
@@ -13930,6 +13930,12 @@
 fi
 
 
+ac_fn_c_check_header_compile "$LINENO" "sys/types.h" "ac_cv_header_sys_types_h" "$ac_includes_default"
+if test "x$ac_cv_header_sys_types_h" = xyes
+then :
+  printf "%s\n" "#define HAVE_SYS_TYPES 1" >>confdefs.h
+
+fi
 ac_fn_c_check_header_compile "$LINENO" "alloca.h" "ac_cv_header_alloca_h" "$ac_includes_default"
 if test "x$ac_cv_header_alloca_h" = xyes
 then :
Index: src/file.c
--- src/file.c.orig	2024-12-10 15:29:56.000000000 +0100
+++ src/file.c	2024-12-11 18:32:32.243919000 +0100
@@ -101,6 +101,9 @@
         Util_monitId(Run.files.id);
         /* Set the location of monit's state file */
         if (Run.files.state == NULL) {
+                if (!getuid())
+                    snprintf(buf, STRLEN, "%s/%s", MYSTATEDIR, MYSTATEFILE);
+                else
                 snprintf(buf, STRLEN, "%s/.%s", Run.Env.home, MYSTATEFILE);
                 Run.files.state = Str_dup(buf);
         }
@@ -115,27 +118,11 @@
 
 char *file_findControlFile(void) {
         char *rcfile = CALLOC(sizeof(char), STRLEN + 1);
-        snprintf(rcfile, STRLEN, "%s/.%s", Run.Env.home, MONITRC);
+        snprintf(rcfile, STRLEN, "@l_prefix@/etc/monit/%s", MONITRC);
         if (File_exist(rcfile)) {
                 return rcfile;
         }
-        snprintf(rcfile, STRLEN, "/etc/%s", MONITRC);
-        if (File_exist(rcfile)) {
-                return rcfile;
-        }
-        snprintf(rcfile, STRLEN, "%s/%s", SYSCONFDIR, MONITRC);
-        if (File_exist(rcfile)) {
-                return rcfile;
-        }
-        snprintf(rcfile, STRLEN, "/usr/local/etc/%s", MONITRC);
-        if (File_exist(rcfile)) {
-                return rcfile;
-        }
-        if (File_exist(MONITRC)) {
-                snprintf(rcfile, STRLEN, "%s/%s", Run.Env.cwd, MONITRC);
-                return rcfile;
-        }
-        Log_error("Cannot find the Monit control file at ~/.%s, /etc/%s, %s/%s, /usr/local/etc/%s or at ./%s \n", MONITRC, MONITRC, SYSCONFDIR, MONITRC, MONITRC, MONITRC);
+        Log_error("Cannot find the control file at %s\n", rcfile);
         exit(1);
 }
 
Index: src/monit.h
--- src/monit.h.orig	2024-12-10 15:29:56.000000000 +0100
+++ src/monit.h	2024-12-11 18:32:32.244200000 +0100
@@ -124,6 +124,7 @@
 
 #define ARGMAX             64
 #define MYPIDDIR           PIDDIR
+#define MYSTATEDIR         PIDDIR
 #define MYPIDFILE          "monit.pid"
 #define MYSTATEFILE        "monit.state"
 #define MYIDFILE           "monit.id"
