struct CitContext *CtdlGetContextArray (int *count);
void CtdlFillSystemContext(struct CitContext *context, char *name);
+int CtdlTrySingleUser(void);
+void CtdlEndSingleUser(void);
+int CtdlWantSingleUser(void);
+int CtdlIsSingleUser(void);
/*
static int is_running = 0;
if (CtdlAccessCheck(ac_internal)) return;
- if (is_running) {
+
+ if (CtdlTrySingleUser())
+ {
+ CtdlMakeTempFileName(artv_tempfilename1, sizeof artv_tempfilename1);
+ CtdlMakeTempFileName(artv_tempfilename2, sizeof artv_tempfilename2);
+
+ extract_token(cmd, cmdbuf, 0, '|', sizeof cmd);
+ if (!strcasecmp(cmd, "export")) artv_do_export();
+ else if (!strcasecmp(cmd, "import")) artv_do_import();
+ else if (!strcasecmp(cmd, "dump")) artv_do_dump();
+ else cprintf("%d illegal command\n", ERROR + ILLEGAL_VALUE);
+
+ unlink(artv_tempfilename1);
+ unlink(artv_tempfilename2);
+
+ CtdlEndSingleUser();
+ }
+ else
+ {
cprintf("%d The importer/exporter is already running.\n",
ERROR + RESOURCE_BUSY);
- return;
}
- is_running = 1;
-
- CtdlMakeTempFileName(artv_tempfilename1, sizeof artv_tempfilename1);
- CtdlMakeTempFileName(artv_tempfilename2, sizeof artv_tempfilename2);
-
- extract_token(cmd, cmdbuf, 0, '|', sizeof cmd);
- if (!strcasecmp(cmd, "export")) artv_do_export();
- else if (!strcasecmp(cmd, "import")) artv_do_import();
- else if (!strcasecmp(cmd, "dump")) artv_do_dump();
- else cprintf("%d illegal command\n", ERROR + ILLEGAL_VALUE);
-
- unlink(artv_tempfilename1);
- unlink(artv_tempfilename2);
-
- is_running = 0;
}
int enable_syslog = 0;
+/* Flag for single user mode */
+static int want_single_user = 0;
+
+/* Try to go single user */
+
+int CtdlTrySingleUser(void)
+{
+ int can_do = 0;
+
+ begin_critical_section(S_SINGLE_USER);
+ if (want_single_user)
+ can_do = 0;
+ else
+ {
+ can_do = 1;
+ want_single_user = 1;
+ }
+ end_critical_section(S_SINGLE_USER);
+ return can_do;
+}
+
+void CtdlEndSingleUser(void)
+{
+ begin_critical_section(S_SINGLE_USER);
+ want_single_user = 0;
+ end_critical_section(S_SINGLE_USER);
+}
+
+
+int CtdlWantSingleUser(void)
+{
+ return want_single_user;
+}
+
+int CtdlIsSingleUser(void)
+{
+ if (want_single_user)
+ {
+ /* check for only one context here */
+ if (num_sessions == 1)
+ return TRUE;
+ }
+ return FALSE;
+}
+
+
/*
* CtdlLogPrintf() ... Write logging information
*/
CtdlThreadNode *this_thread, *that_thread;
time_t now;
+ /* Don't start scheduled threads if the system wants single user mode */
+ if (CtdlWantSingleUser())
+ return;
+
if (try_critical_section(S_SCHEDULE_LIST))
return; /* If this list is locked we wait till the next chance */