+static int
+instance_removepid(struct service_instance *in) {
+ if (!in->pidfile)
+ return 0;
+ if (unlink(in->pidfile)) {
+ ERROR("Failed to removed pidfile: %s: %d - %s\n",
+ in->pidfile, errno, strerror(errno));
+ return 1;
+ }
+ return 0;
+}
+
+static int
+instance_writepid(struct service_instance *in)
+{
+ FILE *_pidfile;
+
+ if (!in->pidfile) {
+ return 0;
+ }
+ _pidfile = fopen(in->pidfile, "w");
+ if (_pidfile == NULL) {
+ ERROR("failed to open pidfile for writing: %s: %d (%s)",
+ in->pidfile, errno, strerror(errno));
+ return 1;
+ }
+ if (fprintf(_pidfile, "%d\n", in->proc.pid) < 0) {
+ ERROR("failed to write pidfile: %s: %d (%s)",
+ in->pidfile, errno, strerror(errno));
+ return 2;
+ }
+ if (fclose(_pidfile)) {
+ ERROR("failed to close pidfile: %s: %d (%s)",
+ in->pidfile, errno, strerror(errno));
+ return 3;
+ }
+
+ return 0;
+}
+