+int pidfile_open(const char *name)
+{
+ if (name) {
+ pidfile = fopen(name, "w");
+ if (!pidfile)
+ return -1;
+ fprintf(pidfile, "%d\n", getpid());
+ return fflush(pidfile);
+ }
+ return 0;
+}
+
+int pidfile_refresh(void)
+{
+ if (pidfile) {
+ rewind(pidfile);
+ ftruncate(fileno(pidfile), 0);
+ fprintf(pidfile, "%d\n", getpid());
+ return fflush(pidfile);
+ }
+ return 0;
+}
+
+static void pidfile_close(void)
+{
+ if (pidfile) {
+ rewind(pidfile);
+ ftruncate(fileno(pidfile), 0);
+ fclose(pidfile);
+ pidfile = NULL;
+ }
+}
+
+extern initcall_t __madinit[], __madexit[];
+
+static void common_shutdown(void)